Skip to content

Commit 5dba14e

Browse files
Refactoring ydb/library/backup/backup.cpp (#12536)
1 parent 251a022 commit 5dba14e

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

ydb/library/backup/backup.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,26 @@ void DropTable(TDriver driver, const TString& path) {
453453
VerifyStatus(status, TStringBuilder() << "Drop table " << path.Quote() << " failed");
454454
}
455455

456+
TFsPath CreateDirectory(const TFsPath& folderPath, const TString& name) {
457+
TFsPath childFolderPath = folderPath.Child(name);
458+
LOG_D("Process " << childFolderPath.GetPath().Quote());
459+
childFolderPath.MkDir();
460+
return childFolderPath;
461+
}
462+
463+
void WriteProtoToFile(const google::protobuf::Message& proto, const TFsPath& folderPath, const NDump::NFiles::TFileInfo& fileInfo) {
464+
TString protoStr;
465+
google::protobuf::TextFormat::PrintToString(proto, &protoStr);
466+
LOG_D("Write " << fileInfo.LogObjectType << " into " << folderPath.Child(fileInfo.FileName).GetPath().Quote());
467+
TFile outFile(folderPath.Child(fileInfo.FileName), CreateAlways | WrOnly);
468+
outFile.Write(protoStr.data(), protoStr.size());
469+
}
470+
456471
void BackupPermissions(TDriver driver, const TString& dbPrefix, const TString& path, const TFsPath& folderPath) {
457472
auto entry = DescribePath(driver, JoinDatabasePath(dbPrefix, path));
458473
Ydb::Scheme::ModifyPermissionsRequest proto;
459474
entry.SerializeTo(proto);
460-
461-
TString permissionsStr;
462-
google::protobuf::TextFormat::PrintToString(proto, &permissionsStr);
463-
LOG_D("Write ACL into " << folderPath.Child(NDump::NFiles::Permissions().FileName).GetPath().Quote());
464-
465-
TFile outFile(folderPath.Child(NDump::NFiles::Permissions().FileName), CreateAlways | WrOnly);
466-
outFile.Write(permissionsStr.data(), permissionsStr.size());
475+
WriteProtoToFile(proto, folderPath, NDump::NFiles::Permissions());
467476
}
468477

469478
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
478487
auto desc = DescribeTable(driver, fullPath);
479488
auto proto = ProtoFromTableDescription(desc, preservePoolKinds);
480489

481-
TString schemaStr;
482-
google::protobuf::TextFormat::PrintToString(proto, &schemaStr);
483-
LOG_D("Write scheme into " << folderPath.Child(NDump::NFiles::TableScheme().FileName).GetPath().Quote());
484-
TFile outFile(folderPath.Child(NDump::NFiles::TableScheme().FileName), CreateAlways | WrOnly);
485-
outFile.Write(schemaStr.data(), schemaStr.size());
486-
490+
WriteProtoToFile(proto, folderPath, NDump::NFiles::TableScheme());
487491
BackupPermissions(driver, dbPrefix, path, folderPath);
488492

489493
if (!schemaOnly) {
@@ -552,9 +556,7 @@ void BackupFolderImpl(TDriver driver, const TString& dbPrefix, const TString& ba
552556
continue;
553557
}
554558

555-
TFsPath childFolderPath = folderPath.Child(dbIt.GetRelPath());
556-
LOG_D("Process " << childFolderPath.GetPath().Quote());
557-
childFolderPath.MkDir();
559+
auto childFolderPath = CreateDirectory(folderPath, dbIt.GetRelPath());
558560
TFile(childFolderPath.Child(NDump::NFiles::Incomplete().FileName), CreateAlways).Close();
559561
if (schemaOnly) {
560562
if (dbIt.IsTable()) {

0 commit comments

Comments
 (0)