diff options
author | stanislav_shchetinin <st-shchetinin@ydb.tech> | 2024-12-12 12:15:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-12 12:15:28 +0300 |
commit | 5dba14eaa0dbaa004072ca605d9d89c009ed2168 (patch) | |
tree | 5bec884357483847b66a245d898a1a004a5e6130 | |
parent | 251a0223ea52130db0d8b5c2815a97f64c3febae (diff) | |
download | ydb-5dba14eaa0dbaa004072ca605d9d89c009ed2168.tar.gz |
Refactoring ydb/library/backup/backup.cpp (#12536)
-rw-r--r-- | ydb/library/backup/backup.cpp | 34 |
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()) { |