aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstanislav_shchetinin <st-shchetinin@ydb.tech>2024-12-12 12:15:28 +0300
committerGitHub <noreply@github.com>2024-12-12 12:15:28 +0300
commit5dba14eaa0dbaa004072ca605d9d89c009ed2168 (patch)
tree5bec884357483847b66a245d898a1a004a5e6130
parent251a0223ea52130db0d8b5c2815a97f64c3febae (diff)
downloadydb-5dba14eaa0dbaa004072ca605d9d89c009ed2168.tar.gz
Refactoring ydb/library/backup/backup.cpp (#12536)
-rw-r--r--ydb/library/backup/backup.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/ydb/library/backup/backup.cpp b/ydb/library/backup/backup.cpp
index 8a09412ae6..2905284f80 100644
--- a/ydb/library/backup/backup.cpp
+++ b/ydb/library/backup/backup.cpp
@@ -453,17 +453,26 @@ void DropTable(TDriver driver, const TString& path) {
VerifyStatus(status, TStringBuilder() << "Drop table " << path.Quote() << " failed");
}
+TFsPath CreateDirectory(const TFsPath& folderPath, const TString& name) {
+ TFsPath childFolderPath = folderPath.Child(name);
+ LOG_D("Process " << childFolderPath.GetPath().Quote());
+ childFolderPath.MkDir();
+ return childFolderPath;
+}
+
+void WriteProtoToFile(const google::protobuf::Message& proto, const TFsPath& folderPath, const NDump::NFiles::TFileInfo& fileInfo) {
+ TString protoStr;
+ google::protobuf::TextFormat::PrintToString(proto, &protoStr);
+ LOG_D("Write " << fileInfo.LogObjectType << " into " << folderPath.Child(fileInfo.FileName).GetPath().Quote());
+ TFile outFile(folderPath.Child(fileInfo.FileName), CreateAlways | WrOnly);
+ outFile.Write(protoStr.data(), protoStr.size());
+}
+
void BackupPermissions(TDriver driver, const TString& dbPrefix, const TString& path, const TFsPath& folderPath) {
auto entry = DescribePath(driver, JoinDatabasePath(dbPrefix, path));
Ydb::Scheme::ModifyPermissionsRequest proto;
entry.SerializeTo(proto);
-
- TString permissionsStr;
- google::protobuf::TextFormat::PrintToString(proto, &permissionsStr);
- LOG_D("Write ACL into " << folderPath.Child(NDump::NFiles::Permissions().FileName).GetPath().Quote());
-
- TFile outFile(folderPath.Child(NDump::NFiles::Permissions().FileName), CreateAlways | WrOnly);
- outFile.Write(permissionsStr.data(), permissionsStr.size());
+ WriteProtoToFile(proto, folderPath, NDump::NFiles::Permissions());
}
void BackupTable(TDriver driver, const TString& dbPrefix, const TString& backupPrefix, const TString& path,
@@ -478,12 +487,7 @@ void BackupTable(TDriver driver, const TString& dbPrefix, const TString& backupP
auto desc = DescribeTable(driver, fullPath);
auto proto = ProtoFromTableDescription(desc, preservePoolKinds);
- TString schemaStr;
- google::protobuf::TextFormat::PrintToString(proto, &schemaStr);
- LOG_D("Write scheme into " << folderPath.Child(NDump::NFiles::TableScheme().FileName).GetPath().Quote());
- TFile outFile(folderPath.Child(NDump::NFiles::TableScheme().FileName), CreateAlways | WrOnly);
- outFile.Write(schemaStr.data(), schemaStr.size());
-
+ WriteProtoToFile(proto, folderPath, NDump::NFiles::TableScheme());
BackupPermissions(driver, dbPrefix, path, folderPath);
if (!schemaOnly) {
@@ -552,9 +556,7 @@ void BackupFolderImpl(TDriver driver, const TString& dbPrefix, const TString& ba
continue;
}
- TFsPath childFolderPath = folderPath.Child(dbIt.GetRelPath());
- LOG_D("Process " << childFolderPath.GetPath().Quote());
- childFolderPath.MkDir();
+ auto childFolderPath = CreateDirectory(folderPath, dbIt.GetRelPath());
TFile(childFolderPath.Child(NDump::NFiles::Incomplete().FileName), CreateAlways).Close();
if (schemaOnly) {
if (dbIt.IsTable()) {