66#include < ydb/public/lib/ydb_cli/common/recursive_remove.h>
77#include < ydb/public/lib/ydb_cli/dump/util/util.h>
88#include < ydb/public/lib/yson_value/ydb_yson_value.h>
9+ #include < ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
910#include < ydb/public/sdk/cpp/client/ydb_driver/driver.h>
1011#include < ydb/public/sdk/cpp/client/ydb_result/result.h>
1112#include < ydb/public/sdk/cpp/client/ydb_table/table.h>
@@ -34,6 +35,8 @@ namespace NYdb::NBackup {
3435
3536static constexpr const char *SCHEME_FILE_NAME = " scheme.pb" ;
3637static constexpr const char *PERMISSIONS_FILE_NAME = " permissions.pb" ;
38+ static constexpr const char *CHANGEFEED_DESCRIPTION_FILE_NAME = " changefeed_description.pb" ;
39+ static constexpr const char *TOPIC_DESCRIPTION_FILE_NAME = " topic_description.pb" ;
3740static constexpr const char *INCOMPLETE_DATA_FILE_NAME = " incomplete.csv" ;
3841static constexpr const char *INCOMPLETE_FILE_NAME = " incomplete" ;
3942static constexpr const char *EMPTY_FILE_NAME = " empty_dir" ;
@@ -471,6 +474,52 @@ void BackupPermissions(TDriver driver, const TString& dbPrefix, const TString& p
471474 outFile.Write (permissionsStr.data (), permissionsStr.size ());
472475}
473476
477+ TFsPath CreateDirectory (const TFsPath& folderPath, const TString& name) {
478+ TFsPath childFolderPath = folderPath.Child (name);
479+ LOG_D (" Process " << childFolderPath.GetPath ().Quote ());
480+ childFolderPath.MkDir ();
481+ return childFolderPath;
482+ }
483+
484+ Ydb::Table::ChangefeedDescription ProtoFromChangefeedDesc (const NTable::TChangefeedDescription& changefeedDesc) {
485+ Ydb::Table::ChangefeedDescription protoChangeFeedDesc;
486+ changefeedDesc.SerializeTo (protoChangeFeedDesc);
487+ return protoChangeFeedDesc;
488+ }
489+
490+ NTopic::TTopicDescription GetTopicDescription (TDriver driver, const TString& path) {
491+ NYdb::NTopic::TTopicClient client (driver);
492+ auto result =
493+ client.DescribeTopic (path).GetValueSync ();
494+ return result.GetTopicDescription ();
495+ }
496+
497+ void WriteProtoToFile (const google::protobuf::Message& proto, const TFsPath& folderPath, const TString& fileName) {
498+ TString changefeedStr;
499+ google::protobuf::TextFormat::PrintToString (proto, &changefeedStr);
500+ LOG_D (" Write changefeed into " << folderPath.Child (fileName).GetPath ().Quote ());
501+ TFile outFile (folderPath.Child (fileName), CreateAlways | WrOnly);
502+ outFile.Write (changefeedStr.data (), changefeedStr.size ());
503+ }
504+
505+ void BackupChangefeeds (TDriver driver, const TString& dbPrefix, const TString& path, const TFsPath& folderPath) {
506+
507+ const auto dirPath = JoinDatabasePath (dbPrefix, path);
508+ auto desc = DescribeTable (driver, dirPath);
509+
510+ for (const auto & changefeedDesc : desc.GetChangefeedDescriptions ()) {
511+ TFsPath changefeedDirPath = CreateDirectory (folderPath, changefeedDesc.GetName ());
512+
513+ auto protoChangeFeedDesc = ProtoFromChangefeedDesc (changefeedDesc);
514+ auto a = JoinDatabasePath (dirPath, changefeedDesc.GetName ());
515+ const auto topicDescription = GetTopicDescription (driver, JoinDatabasePath (dirPath, changefeedDesc.GetName ()));
516+ const auto & protoTopicDescription = NYdb::TProtoAccessor::GetProto (topicDescription);
517+
518+ WriteProtoToFile (protoChangeFeedDesc, changefeedDirPath, CHANGEFEED_DESCRIPTION_FILE_NAME);
519+ WriteProtoToFile (protoTopicDescription, changefeedDirPath, TOPIC_DESCRIPTION_FILE_NAME);
520+ }
521+ }
522+
474523void BackupTable (TDriver driver, const TString& dbPrefix, const TString& backupPrefix, const TString& path,
475524 const TFsPath& folderPath, bool schemaOnly, bool preservePoolKinds, bool ordered) {
476525 Y_ENSURE (!path.empty ());
@@ -489,6 +538,7 @@ void BackupTable(TDriver driver, const TString& dbPrefix, const TString& backupP
489538 TFile outFile (folderPath.Child (SCHEME_FILE_NAME), CreateAlways | WrOnly);
490539 outFile.Write (schemaStr.data (), schemaStr.size ());
491540
541+ BackupChangefeeds (driver, dbPrefix, path, folderPath);
492542 BackupPermissions (driver, dbPrefix, path, folderPath);
493543
494544 if (!schemaOnly) {
0 commit comments