1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Fix issues with remote/local command logging options.

Logging was being enable on local/remote processes even if --log-subprocess was not specified, so fix that.

Also, make sure that stderr is enabled at error level as it was on Perl.  This helps expose error information for debugging.

For remotes, suppress log and lock paths since these are not applicable on remote hosts.  These options should be set in the local config if they need to be overridden.
This commit is contained in:
David Steele 2019-03-16 15:00:02 +04:00
parent d377e926c8
commit b2b2cf0511
4 changed files with 66 additions and 4 deletions

View File

@ -22,6 +22,10 @@
<p>Fix issues when a path option is / terminated.</p>
</release-item>
<release-item>
<p>Fix issues with <code>remote</code>/<code>local</code> command logging options.</p>
</release-item>
</release-bug-list>
<release-development-list>

View File

@ -96,6 +96,14 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protoco
// Add the type
kvPut(optionReplace, varNewStr(strNew(cfgOptionName(cfgOptType))), varNewStr(strNew("backup")));
// Only enable file logging on the local when requested
kvPut(
optionReplace, varNewStr(strNew(cfgOptionName(cfgOptLogLevelFile))),
cfgOptionBool(cfgOptLogSubprocess) ? cfgOption(cfgOptLogLevelFile) : varNewStrZ("off"));
// Always output errors on stderr for debugging purposes
kvPut(optionReplace, varNewStr(strNew(cfgOptionName(cfgOptLogLevelStderr))), varNewStrZ("error"));
result = strLstMove(cfgExecParam(cfgCmdLocal, optionReplace), MEM_CONTEXT_OLD());
}
MEM_CONTEXT_TEMP_END();
@ -210,6 +218,18 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc
if (!cfgOptionTest(cfgOptProcess))
kvPut(optionReplace, varNewStr(strNew(cfgOptionName(cfgOptProcess))), varNewInt((int)protocolId));
// Don't pass log-path or lock-path since these are host specific
kvPut(optionReplace, varNewStr(strNew(cfgOptionName(cfgOptLogPath))), NULL);
kvPut(optionReplace, varNewStr(strNew(cfgOptionName(cfgOptLockPath))), NULL);
// Only enable file logging on the remote when requested
kvPut(
optionReplace, varNewStr(strNew(cfgOptionName(cfgOptLogLevelFile))),
cfgOptionBool(cfgOptLogSubprocess) ? cfgOption(cfgOptLogLevelFile) : varNewStrZ("off"));
// Always output errors on stderr for debugging purposes
kvPut(optionReplace, varNewStr(strNew(cfgOptionName(cfgOptLogLevelStderr))), varNewStrZ("error"));
// Don't pass the stanza if it is set. It is better if the remote is stanza-agnostic so the client can operate on multiple
// stanzas without starting a new remote. Once the Perl code is removed the stanza option can be removed from the remote
// command.

View File

@ -557,7 +557,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: protocol
total: 7
total: 8
perlReq: true
coverage:

View File

@ -86,6 +86,40 @@ testRun(void)
TEST_RESULT_BOOL(repoIsLocal(), false, "repo is remote");
}
// *****************************************************************************************************************************
if (testBegin("protocolLocalParam()"))
{
StringList *argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
strLstAddZ(argList, "archive-get");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_STR(
strPtr(strLstJoin(protocolLocalParam(protocolStorageTypeRepo, 0), "|")),
strPtr(
strNew(
"--command=archive-get|--host-id=1|--log-level-file=off|--log-level-stderr=error|--process=0|--stanza=test1"
"|--type=backup|local")),
"local protocol params");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
strLstAddZ(argList, "--log-subprocess");
strLstAddZ(argList, "archive-get");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_STR(
strPtr(strLstJoin(protocolLocalParam(protocolStorageTypeRepo, 1), "|")),
strPtr(
strNew(
"--command=archive-get|--host-id=1|--log-level-file=info|--log-level-stderr=error|--log-subprocess|--process=1"
"|--stanza=test1|--type=backup|local")),
"local protocol params with replacements");
}
// *****************************************************************************************************************************
if (testBegin("protocolRemoteParam()"))
{
@ -102,13 +136,15 @@ testRun(void)
strPtr(
strNew(
"-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|repo-host-user@repo-host"
"|pgbackrest --command=archive-get --process=0 --type=backup remote")),
"|pgbackrest --command=archive-get --log-level-file=off --log-level-stderr=error --process=0 --type=backup"
" remote")),
"remote protocol params");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
strLstAddZ(argList, "--log-subprocess");
strLstAddZ(argList, "--repo1-host=repo-host");
strLstAddZ(argList, "--repo1-host-port=444");
strLstAddZ(argList, "--repo1-host-config=/path/pgbackrest.conf");
@ -124,7 +160,8 @@ testRun(void)
strNew(
"-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|-p|444|repo-host-user@repo-host"
"|pgbackrest --command=archive-get --config=/path/pgbackrest.conf --config-include-path=/path/include"
" --config-path=/path/config --process=1 --type=backup remote")),
" --config-path=/path/config --log-level-file=info --log-level-stderr=error --log-subprocess --process=1"
" --type=backup remote")),
"remote protocol params with replacements");
// -------------------------------------------------------------------------------------------------------------------------
@ -144,7 +181,8 @@ testRun(void)
strPtr(
strNew(
"-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|pgbackrest@repo-host"
"|pgbackrest --command=archive-get --process=3 --type=backup remote")),
"|pgbackrest --command=archive-get --log-level-file=off --log-level-stderr=error --process=3 --type=backup"
" remote")),
"remote protocol params for local");
}