You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Add pgIsLocalVerify().
This functionality is required in commands other than restore, so centralize it.
This commit is contained in:
@ -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
|
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
|
$(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
|
$(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
|
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
|
||||||
|
@ -2009,8 +2009,7 @@ cmdRestore(void)
|
|||||||
userInit();
|
userInit();
|
||||||
|
|
||||||
// PostgreSQL must be local
|
// PostgreSQL must be local
|
||||||
if (!pgIsLocal(1))
|
pgIsLocalVerify();
|
||||||
THROW(HostInvalidError, CFGCMD_RESTORE " command must be run on the " PG_NAME " host");
|
|
||||||
|
|
||||||
// Validate restore path
|
// Validate restore path
|
||||||
restorePathValidate();
|
restorePathValidate();
|
||||||
|
@ -12,7 +12,9 @@ Protocol Helper
|
|||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "config/exec.h"
|
#include "config/exec.h"
|
||||||
#include "config/protocol.h"
|
#include "config/protocol.h"
|
||||||
|
#include "postgres/version.h"
|
||||||
#include "protocol/helper.h"
|
#include "protocol/helper.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Constants
|
Constants
|
||||||
@ -104,6 +106,18 @@ pgIsLocal(unsigned int hostId)
|
|||||||
FUNCTION_LOG_RETURN(BOOL, !cfgOptionTest(cfgOptPgHost + hostId - 1));
|
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
|
Get the command line required for local protocol execution
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
@ -40,6 +40,10 @@ void protocolRemoteFree(unsigned int hostId);
|
|||||||
Getters
|
Getters
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
bool pgIsLocal(unsigned int hostId);
|
bool pgIsLocal(unsigned int hostId);
|
||||||
|
|
||||||
|
// Error if PostgreSQL is not local, i.e. pg-host is set
|
||||||
|
void pgIsLocalVerify(void);
|
||||||
|
|
||||||
bool repoIsLocal(void);
|
bool repoIsLocal(void);
|
||||||
void repoIsLocalVerify(void);
|
void repoIsLocalVerify(void);
|
||||||
|
|
||||||
|
@ -136,6 +136,8 @@ testRun(void)
|
|||||||
TEST_ERROR_FMT(repoIsLocalVerify(), HostInvalidError, "archive-get command must be run on the repository host");
|
TEST_ERROR_FMT(repoIsLocalVerify(), HostInvalidError, "archive-get command must be run on the repository host");
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
TEST_TITLE("pg1 is local");
|
||||||
|
|
||||||
argList = strLstNew();
|
argList = strLstNew();
|
||||||
strLstAddZ(argList, "pgbackrest");
|
strLstAddZ(argList, "pgbackrest");
|
||||||
strLstAddZ(argList, "--stanza=test1");
|
strLstAddZ(argList, "--stanza=test1");
|
||||||
@ -145,8 +147,25 @@ testRun(void)
|
|||||||
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
||||||
|
|
||||||
TEST_RESULT_BOOL(pgIsLocal(1), true, "pg is local");
|
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();
|
argList = strLstNew();
|
||||||
strLstAddZ(argList, "pgbackrest");
|
strLstAddZ(argList, "pgbackrest");
|
||||||
strLstAddZ(argList, "--stanza=test1");
|
strLstAddZ(argList, "--stanza=test1");
|
||||||
|
Reference in New Issue
Block a user