Skip to content

Forbid empty database in ydb admin database restore #14783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions ydb/public/lib/ydb_cli/commands/ydb_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ TCommandDatabaseRestore::TCommandDatabaseRestore()
void TCommandDatabaseRestore::Config(TConfig& config) {
TYdbCommand::Config(config);
config.SetFreeArgsNum(0);
config.AllowEmptyDatabase = true; // it is possible to retrieve database path from dump

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

auto settings = NDump::TRestoreDatabaseSettings()
.WaitNodesDuration(WaitNodesDuration);

if (!config.Database.empty()) {
settings.Database(config.Database);
config.Database.clear(); // always connect directly to cluster
}
.WaitNodesDuration(WaitNodesDuration)
.Database(config.Database);

NDump::TClient client(CreateDriver(config), std::move(log));
NStatusHelpers::ThrowOnErrorOrPrintIssues(client.RestoreDatabase(FilePath, settings));
Expand Down
5 changes: 5 additions & 0 deletions ydb/public/lib/ydb_cli/dump/restore_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,11 @@ TRestoreResult TRestoreClient::FindClusterRootPath() {
return Result<TRestoreResult>();
}

LOG_D("Try to find cluster root path");

auto status = NDump::ListDirectory(SchemeClient, "/");
if (!status.IsSuccess()) {
LOG_E("Error finding cluster root path: " << status.GetIssues().ToOneLineString());
return status;
}

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