mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-05-27 22:37:55 +02:00
Add local option for cfgExecParam().
cfgExecParam() was originally written to provide options for remote processes. Remotes processes do not have access to the local config so it was necessary to pass every non-default option. Local processes on the other hand, e.g. archive-get, archive-get-async, archive-push-async, and local, do have access to the local config and therefore don't need every parameter to be passed on the command-line. The previous way was not wrong, but it was overly verbose and did not align with the way Perl had worked. Update cfgExecParam() to accept a local option which excludes options from the command line which can be read from local configs.
This commit is contained in:
parent
3f18040aab
commit
5b64c93e8b
@ -216,7 +216,7 @@ cmdArchiveGet(void)
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_LOG_LEVEL_STDERR_STR), VARSTRDEF("off"));
|
||||
|
||||
// Generate command options
|
||||
StringList *commandExec = cfgExecParam(cfgCmdArchiveGetAsync, optionReplace);
|
||||
StringList *commandExec = cfgExecParam(cfgCmdArchiveGetAsync, optionReplace, true);
|
||||
strLstInsert(commandExec, 0, cfgExe());
|
||||
|
||||
// Clean the current queue using the list of WAL that we ideally want in the queue. queueNeed()
|
||||
|
@ -299,7 +299,7 @@ cmdArchivePush(void)
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_LOG_LEVEL_STDERR_STR), VARSTRDEF("off"));
|
||||
|
||||
// Generate command options
|
||||
StringList *commandExec = cfgExecParam(cfgCmdArchivePushAsync, optionReplace);
|
||||
StringList *commandExec = cfgExecParam(cfgCmdArchivePushAsync, optionReplace, true);
|
||||
strLstInsert(commandExec, 0, cfgExe());
|
||||
strLstAdd(commandExec, strPath(walFile));
|
||||
|
||||
|
@ -13,11 +13,12 @@ Exec Configuration
|
||||
Generate a list of options required for execution of a new command, replacing options as specified in optionReplace
|
||||
***********************************************************************************************************************************/
|
||||
StringList *
|
||||
cfgExecParam(ConfigCommand commandId, const KeyValue *optionReplace)
|
||||
cfgExecParam(ConfigCommand commandId, const KeyValue *optionReplace, bool local)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(ENUM, commandId);
|
||||
FUNCTION_LOG_PARAM(KEY_VALUE, optionReplace);
|
||||
FUNCTION_LOG_PARAM(BOOL, local); // Will the new process be running on the same host?
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
StringList *result = NULL;
|
||||
@ -73,7 +74,7 @@ cfgExecParam(ConfigCommand commandId, const KeyValue *optionReplace)
|
||||
strLstAdd(result, strNewFmt("--reset-%s", cfgOptionName(optionId)));
|
||||
}
|
||||
// Else format the value if found
|
||||
else if (value != NULL)
|
||||
else if (value != NULL && (!local || exists || cfgOptionSource(optionId) == cfgSourceParam))
|
||||
{
|
||||
if (varType(value) == varTypeBool)
|
||||
{
|
||||
|
@ -10,6 +10,6 @@ Exec Configuration
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
StringList *cfgExecParam(ConfigCommand commandId, const KeyValue *optionReplace);
|
||||
StringList *cfgExecParam(ConfigCommand commandId, const KeyValue *optionReplace, bool local);
|
||||
|
||||
#endif
|
||||
|
@ -133,7 +133,7 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protoco
|
||||
// Always output errors on stderr for debugging purposes
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_LOG_LEVEL_STDERR_STR), VARSTRDEF("error"));
|
||||
|
||||
result = strLstMove(cfgExecParam(cfgCmdLocal, optionReplace), MEM_CONTEXT_OLD());
|
||||
result = strLstMove(cfgExecParam(cfgCmdLocal, optionReplace, true), MEM_CONTEXT_OLD());
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
@ -300,7 +300,7 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc
|
||||
// Add the type
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), isRepo ? VARSTRDEF("backup") : VARSTRDEF("db"));
|
||||
|
||||
StringList *commandExec = cfgExecParam(cfgCmdRemote, optionReplace);
|
||||
StringList *commandExec = cfgExecParam(cfgCmdRemote, optionReplace, false);
|
||||
strLstInsert(commandExec, 0, cfgOptionStr(isRepo ? cfgOptRepoHostCmd : cfgOptPgHostCmd + hostIdx));
|
||||
strLstAdd(result, strLstJoin(commandExec, " "));
|
||||
|
||||
|
@ -31,7 +31,7 @@ testRun(void)
|
||||
unsetenv("PGBACKREST_REPO1_CIPHER_PASS");
|
||||
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(cfgExecParam(cfgCmdLocal, NULL), "|")),
|
||||
strPtr(strLstJoin(cfgExecParam(cfgCmdLocal, NULL, false), "|")),
|
||||
strPtr(
|
||||
strNewFmt(
|
||||
"--no-config|--log-subprocess|--reset-neutral-umask|--pg1-path=\"%s/db path\"|--repo1-path=%s/repo"
|
||||
@ -50,14 +50,17 @@ testRun(void)
|
||||
strLstAddZ(argList, "--recovery-option=a=b");
|
||||
strLstAddZ(argList, "--recovery-option=c=d");
|
||||
strLstAddZ(argList, "restore");
|
||||
|
||||
setenv("PGBACKREST_REPO1_HOST", "bogus", true);
|
||||
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||||
unsetenv("PGBACKREST_REPO1_HOST");
|
||||
|
||||
KeyValue *optionReplace = kvNew();
|
||||
kvPut(optionReplace, varNewStr(strNew("repo1-path")), varNewStr(strNew("/replace/path")));
|
||||
kvPut(optionReplace, varNewStr(strNew("stanza")), NULL);
|
||||
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(cfgExecParam(cfgCmdRestore, optionReplace), "|")),
|
||||
strPtr(strLstJoin(cfgExecParam(cfgCmdRestore, optionReplace, true), "|")),
|
||||
strPtr(
|
||||
strNewFmt(
|
||||
"--db-include=1|--db-include=2|--pg1-path=%s/db|--recovery-option=a=b|--recovery-option=c=d"
|
||||
|
Loading…
x
Reference in New Issue
Block a user