Skip to content

Commit 67c0c46

Browse files
authored
Forbid empty database in ydb admin database restore (#14783)
1 parent 6df1995 commit 67c0c46

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ydb/public/lib/ydb_cli/commands/ydb_admin.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ TCommandDatabaseRestore::TCommandDatabaseRestore()
7070
void TCommandDatabaseRestore::Config(TConfig& config) {
7171
TYdbCommand::Config(config);
7272
config.SetFreeArgsNum(0);
73-
config.AllowEmptyDatabase = true; // it is possible to retrieve database path from dump
7473

7574
config.Opts->AddLongOption('i', "input", "Path in a local filesystem to a directory with dump.")
7675
.RequiredArgument("PATH")
@@ -91,12 +90,8 @@ int TCommandDatabaseRestore::Run(TConfig& config) {
9190
log->SetFormatter(GetPrefixLogFormatter(""));
9291

9392
auto settings = NDump::TRestoreDatabaseSettings()
94-
.WaitNodesDuration(WaitNodesDuration);
95-
96-
if (!config.Database.empty()) {
97-
settings.Database(config.Database);
98-
config.Database.clear(); // always connect directly to cluster
99-
}
93+
.WaitNodesDuration(WaitNodesDuration)
94+
.Database(config.Database);
10095

10196
NDump::TClient client(CreateDriver(config), std::move(log));
10297
NStatusHelpers::ThrowOnErrorOrPrintIssues(client.RestoreDatabase(FilePath, settings));

ydb/public/lib/ydb_cli/dump/restore_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,11 @@ TRestoreResult TRestoreClient::FindClusterRootPath() {
571571
return Result<TRestoreResult>();
572572
}
573573

574+
LOG_D("Try to find cluster root path");
575+
574576
auto status = NDump::ListDirectory(SchemeClient, "/");
575577
if (!status.IsSuccess()) {
578+
LOG_E("Error finding cluster root path: " << status.GetIssues().ToOneLineString());
576579
return status;
577580
}
578581

@@ -806,6 +809,8 @@ TRestoreResult TRestoreClient::RestoreDatabaseImpl(const TString& fsPath, const
806809
if (auto result = CreateDatabase(CmsClient, dbPath, TCreateDatabaseSettings(dbDesc)); !result.IsSuccess()) {
807810
if (result.GetStatus() == EStatus::ALREADY_EXISTS) {
808811
LOG_W("Database " << dbPath.Quote() << " already exists, continue restoring to this database");
812+
} else if (result.GetStatus() == EStatus::UNAUTHORIZED) {
813+
LOG_W("Not enough rights to create database " << dbPath.Quote() << ", try to restore to existing database");
809814
} else {
810815
return result;
811816
}

0 commit comments

Comments
 (0)