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

Add pgIsLocalVerify().

This functionality is required in commands other than restore, so centralize it.
This commit is contained in:
David Steele 2020-02-12 15:47:07 -07:00
parent e2c304d473
commit dac8119bf1
5 changed files with 39 additions and 3 deletions

View File

@ -554,7 +554,7 @@ protocol/client.o: protocol/client.c build.auto.h common/assert.h common/debug.h
protocol/command.o: protocol/command.c build.auto.h common/assert.h common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/string.h common/type/stringz.h common/type/variant.h common/type/variantList.h protocol/command.h
$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c protocol/command.c -o protocol/command.o
protocol/helper.o: protocol/helper.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/exec.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/stringz.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/exec.h config/protocol.h protocol/client.h protocol/command.h protocol/helper.h protocol/server.h
protocol/helper.o: protocol/helper.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/exec.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/stringz.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/exec.h config/protocol.h postgres/version.h protocol/client.h protocol/command.h protocol/helper.h protocol/server.h version.h
$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c protocol/helper.c -o protocol/helper.o
protocol/parallel.o: protocol/parallel.c build.auto.h common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringz.h common/type/variant.h common/type/variantList.h protocol/client.h protocol/command.h protocol/parallel.h protocol/parallelJob.h

View File

@ -2009,8 +2009,7 @@ cmdRestore(void)
userInit();
// PostgreSQL must be local
if (!pgIsLocal(1))
THROW(HostInvalidError, CFGCMD_RESTORE " command must be run on the " PG_NAME " host");
pgIsLocalVerify();
// Validate restore path
restorePathValidate();

View File

@ -12,7 +12,9 @@ Protocol Helper
#include "config/config.h"
#include "config/exec.h"
#include "config/protocol.h"
#include "postgres/version.h"
#include "protocol/helper.h"
#include "version.h"
/***********************************************************************************************************************************
Constants
@ -104,6 +106,18 @@ pgIsLocal(unsigned int hostId)
FUNCTION_LOG_RETURN(BOOL, !cfgOptionTest(cfgOptPgHost + hostId - 1));
}
/**********************************************************************************************************************************/
void
pgIsLocalVerify(void)
{
FUNCTION_TEST_VOID();
if (!pgIsLocal(1))
THROW_FMT(HostInvalidError, "%s command must be run on the " PG_NAME " host", cfgCommandName(cfgCommand()));
FUNCTION_TEST_RETURN_VOID();
}
/***********************************************************************************************************************************
Get the command line required for local protocol execution
***********************************************************************************************************************************/

View File

@ -40,6 +40,10 @@ void protocolRemoteFree(unsigned int hostId);
Getters
***********************************************************************************************************************************/
bool pgIsLocal(unsigned int hostId);
// Error if PostgreSQL is not local, i.e. pg-host is set
void pgIsLocalVerify(void);
bool repoIsLocal(void);
void repoIsLocalVerify(void);

View File

@ -136,6 +136,8 @@ testRun(void)
TEST_ERROR_FMT(repoIsLocalVerify(), HostInvalidError, "archive-get command must be run on the repository host");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("pg1 is local");
argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
@ -145,8 +147,25 @@ testRun(void)
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_BOOL(pgIsLocal(1), true, "pg is local");
TEST_RESULT_VOID(pgIsLocalVerify(), "verify pg is local");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("pg1 is not local");
argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
strLstAddZ(argList, "--" CFGOPT_PG1_HOST "=test1");
strLstAddZ(argList, "--pg1-path=/path/to");
strLstAddZ(argList, "restore");
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_BOOL(pgIsLocal(1), false, "pg is remote");
TEST_ERROR_FMT(pgIsLocalVerify(), HostInvalidError, "restore command must be run on the PostgreSQL host");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("pg7 is not local");
argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");