44
55#include < ydb/public/api/protos/ydb_table.pb.h>
66#include < ydb/public/lib/ydb_cli/common/recursive_remove.h>
7+ #include < ydb/public/lib/ydb_cli/common/retry_func.h>
78#include < ydb/public/lib/ydb_cli/dump/files/files.h>
89#include < ydb/public/lib/ydb_cli/dump/util/util.h>
910#include < ydb/public/lib/yson_value/ydb_yson_value.h>
11+ #include < ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
1012#include < ydb/public/sdk/cpp/client/ydb_driver/driver.h>
1113#include < ydb/public/sdk/cpp/client/ydb_result/result.h>
1214#include < ydb/public/sdk/cpp/client/ydb_table/table.h>
15+ #include < ydb/public/sdk/cpp/client/ydb_topic/topic.h>
1316#include < ydb/public/sdk/cpp/client/ydb_value/value.h>
1417
1518#include < library/cpp/containers/stack_vector/stack_vec.h>
@@ -475,6 +478,36 @@ void BackupPermissions(TDriver driver, const TString& dbPrefix, const TString& p
475478 WriteProtoToFile (proto, folderPath, NDump::NFiles::Permissions ());
476479}
477480
481+ Ydb::Table::ChangefeedDescription ProtoFromChangefeedDesc (const NTable::TChangefeedDescription& changefeedDesc) {
482+ Ydb::Table::ChangefeedDescription protoChangeFeedDesc;
483+ changefeedDesc.SerializeTo (protoChangeFeedDesc);
484+ return protoChangeFeedDesc;
485+ }
486+
487+ NTopic::TDescribeTopicResult DescribeTopic (TDriver driver, const TString& path) {
488+ NYdb::NTopic::TTopicClient client (driver);
489+ return NConsoleClient::RetryFunction ([&]() {
490+ return client.DescribeTopic (path).GetValueSync ();
491+ });
492+ }
493+
494+ void BackupChangefeeds (TDriver driver, const TString& tablePath, const TFsPath& folderPath) {
495+ auto desc = DescribeTable (driver, tablePath);
496+
497+ for (const auto & changefeedDesc : desc.GetChangefeedDescriptions ()) {
498+ TFsPath changefeedDirPath = CreateDirectory (folderPath, changefeedDesc.GetName ());
499+
500+ auto protoChangeFeedDesc = ProtoFromChangefeedDesc (changefeedDesc);
501+ const auto descTopicResult = DescribeTopic (driver, JoinDatabasePath (tablePath, changefeedDesc.GetName ()));
502+ VerifyStatus (descTopicResult);
503+ const auto & topicDescription = descTopicResult.GetTopicDescription ();
504+ const auto protoTopicDescription = NYdb::TProtoAccessor::GetProto (topicDescription);
505+
506+ WriteProtoToFile (protoChangeFeedDesc, changefeedDirPath, NDump::NFiles::Changefeed ());
507+ WriteProtoToFile (protoTopicDescription, changefeedDirPath, NDump::NFiles::Topic ());
508+ }
509+ }
510+
478511void BackupTable (TDriver driver, const TString& dbPrefix, const TString& backupPrefix, const TString& path,
479512 const TFsPath& folderPath, bool schemaOnly, bool preservePoolKinds, bool ordered) {
480513 Y_ENSURE (!path.empty ());
@@ -486,8 +519,9 @@ void BackupTable(TDriver driver, const TString& dbPrefix, const TString& backupP
486519
487520 auto desc = DescribeTable (driver, fullPath);
488521 auto proto = ProtoFromTableDescription (desc, preservePoolKinds);
489-
490522 WriteProtoToFile (proto, folderPath, NDump::NFiles::TableScheme ());
523+
524+ BackupChangefeeds (driver, JoinDatabasePath (dbPrefix, path), folderPath);
491525 BackupPermissions (driver, dbPrefix, path, folderPath);
492526
493527 if (!schemaOnly) {
0 commit comments