You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Make --repo optional for remaining commands except stanza-delete.
Some commands (repo-*, verify) still required the --repo option but it makes sense to give them the same treatment as backup and simply use the first repo when one is not specified. This leaves stanza-delete as the only remaining command that requires --repo. This is by design to enhance safe usage.
This commit is contained in:
@ -66,6 +66,7 @@
|
||||
<commit subject="Make --repo optional for backup command."/>
|
||||
<commit subject="Refactor archive-push command warnings to work like archive-get."/>
|
||||
<commit subject="Add write fault-tolerance to archive-push command."/>
|
||||
<commit subject="Make --repo optional for remaining commands except stanza-delete."/>
|
||||
|
||||
<release-item-contributor-list>
|
||||
<release-item-contributor id="cynthia.shang"/>
|
||||
|
@ -68,10 +68,9 @@ cfgLoadUpdateOption(void)
|
||||
{
|
||||
FUNCTION_LOG_VOID(logLevelTrace);
|
||||
|
||||
// Make sure repo option is set for the default command role when it is not internal and more than one repo is configured or the
|
||||
// first configured repo is not key 1. Filter out any commands where this does not apply.
|
||||
if (!cfgCommandHelp() && cfgCommand() != cfgCmdBackup && cfgCommand() != cfgCmdInfo && cfgCommand() != cfgCmdExpire &&
|
||||
cfgCommand() != cfgCmdArchiveGet && cfgCommand() != cfgCmdRestore && cfgOptionValid(cfgOptRepo) &&
|
||||
// Make sure the repo option is set for the stanza-delete command when more than one repo is configured or the first configured
|
||||
// repo is not key 1.
|
||||
if (!cfgCommandHelp() && cfgOptionValid(cfgOptRepo) && cfgCommand() == cfgCmdStanzaDelete &&
|
||||
!cfgOptionTest(cfgOptRepo) && (cfgOptionGroupIdxTotal(cfgOptGrpRepo) > 1 || cfgOptionGroupIdxToKey(cfgOptGrpRepo, 0) != 1))
|
||||
{
|
||||
THROW_FMT(
|
||||
|
@ -190,7 +190,9 @@ testRun(void)
|
||||
// File
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
argList = strLstNew();
|
||||
strLstAdd(argList, strNewFmt("--repo-path=%s/repo/aaa", testPath()));
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/bogus");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH_REPO "/aaa");
|
||||
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
|
||||
strLstAddZ(argList, "--output=json");
|
||||
harnessCfgLoad(cfgCmdRepoLs, argList);
|
||||
|
||||
@ -228,6 +230,7 @@ testRun(void)
|
||||
|
||||
// Needed for tests
|
||||
setenv("PGBACKREST_REPO1_CIPHER_PASS", "xxx", true);
|
||||
setenv("PGBACKREST_REPO2_CIPHER_PASS", "xxx", true);
|
||||
|
||||
// Test files and buffers
|
||||
const String *fileName = STRDEF("file.txt");
|
||||
@ -434,8 +437,10 @@ testRun(void)
|
||||
TEST_TITLE("put encrypted backup.history manifest");
|
||||
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
|
||||
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/bogus");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH_REPO);
|
||||
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 2, CIPHER_TYPE_AES_256_CBC);
|
||||
strLstAddZ(argList, "--" CFGOPT_CIPHER_PASS "=custom");
|
||||
strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/backup.history/2020/label.manifest.gz");
|
||||
harnessCfgLoad(cfgCmdRepoPut, argList);
|
||||
@ -542,7 +547,9 @@ testRun(void)
|
||||
TEST_TITLE("get file outside of the repo error");
|
||||
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawFmt(argList, cfgOptRepoPath, "%s/repo", testPath());
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/bogus");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH_REPO);
|
||||
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
|
||||
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
|
||||
strLstAddZ(argList, "/somewhere/" INFO_ARCHIVE_FILE);
|
||||
harnessCfgLoad(cfgCmdRepoGet, argList);
|
||||
@ -757,7 +764,9 @@ testRun(void)
|
||||
TEST_TITLE("remove file");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAdd(argList, strNewFmt("--repo-path=%s/repo", testPath()));
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/bogus");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH_REPO);
|
||||
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
|
||||
strLstAddZ(argList, "path/aaa.txt");
|
||||
harnessCfgLoad(cfgCmdRepoRm, argList);
|
||||
|
||||
|
@ -938,16 +938,9 @@ testRun(void)
|
||||
if (testBegin("cmdVerify(), verifyProcess() - errors"))
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
// Load Parameters with multi-repo
|
||||
StringList *argList = strLstDup(argListBase);
|
||||
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 4, "%s/repo4", testPath());
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
harnessCfgLoad(cfgCmdVerify, argList), OptionRequiredError, "verify command requires option: repo\n"
|
||||
"HINT: this command requires a specific repository to operate on");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
// Load Parameters with multi-repo
|
||||
hrnCfgArgRawZ(argList, cfgOptRepo, "1");
|
||||
harnessCfgLoad(cfgCmdVerify, argList);
|
||||
|
||||
// Store valid archive/backup info files
|
||||
|
Reference in New Issue
Block a user