You've already forked pgbackrest
							
							
				mirror of
				https://github.com/pgbackrest/pgbackrest.git
				synced 2025-10-30 23:37:45 +02:00 
			
		
		
		
	Allow pg storage to be remote.
None of the currently migrated commands needed remote pg storage but now backup, check, stanza-* will need it.
This commit is contained in:
		| @@ -512,7 +512,7 @@ storage/posix/write.o: storage/posix/write.c build.auto.h common/assert.h common | ||||
| storage/read.o: storage/read.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/read.intern.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/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h storage/read.h storage/read.intern.h | ||||
| 	$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c storage/read.c -o storage/read.o | ||||
|  | ||||
| storage/remote/protocol.o: storage/remote/protocol.c build.auto.h command/backup/pageChecksum.h common/assert.h common/compress/gzip/compress.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/crypto/hash.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/filter/size.h common/io/io.h common/io/read.h common/io/read.intern.h common/io/write.h common/io/write.intern.h common/log.h common/logLevel.h common/memContext.h common/regExp.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h protocol/server.h storage/helper.h storage/info.h storage/read.h storage/read.intern.h storage/remote/protocol.h storage/storage.h storage/storage.intern.h storage/write.h storage/write.intern.h version.h | ||||
| storage/remote/protocol.o: storage/remote/protocol.c build.auto.h command/backup/pageChecksum.h common/assert.h common/compress/gzip/compress.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/crypto/hash.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/filter/size.h common/io/io.h common/io/read.h common/io/read.intern.h common/io/write.h common/io/write.intern.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/regExp.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h protocol/server.h storage/helper.h storage/info.h storage/read.h storage/read.intern.h storage/remote/protocol.h storage/storage.h storage/storage.intern.h storage/write.h storage/write.intern.h version.h | ||||
| 	$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c storage/remote/protocol.c -o storage/remote/protocol.o | ||||
|  | ||||
| storage/remote/read.o: storage/remote/read.c build.auto.h common/assert.h common/compress/gzip/compress.h common/compress/gzip/decompress.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/read.intern.h common/io/write.h common/io/write.intern.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/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h protocol/client.h protocol/command.h protocol/server.h storage/info.h storage/read.h storage/read.intern.h storage/remote/protocol.h storage/remote/read.h storage/remote/storage.h storage/remote/storage.intern.h storage/storage.h storage/storage.intern.h storage/write.h storage/write.intern.h version.h | ||||
|   | ||||
| @@ -68,6 +68,26 @@ repoIsLocal(void) | ||||
|     FUNCTION_TEST_RETURN(!cfgOptionTest(cfgOptRepoHost)); | ||||
| } | ||||
|  | ||||
| /*********************************************************************************************************************************** | ||||
| Is pg local? | ||||
| ***********************************************************************************************************************************/ | ||||
| bool | ||||
| pgIsLocal(void) | ||||
| { | ||||
|     FUNCTION_TEST_VOID(); | ||||
|     FUNCTION_TEST_RETURN(!cfgOptionTest(cfgOptPgHost + (cfgOptionTest(cfgOptHostId) ? cfgOptionUInt(cfgOptHostId) - 1 : 0))); | ||||
| } | ||||
|  | ||||
| /*********************************************************************************************************************************** | ||||
| Get host id if host-id option is set, otherwise return default id 1 | ||||
| ***********************************************************************************************************************************/ | ||||
| unsigned int | ||||
| protocolHostId(void) | ||||
| { | ||||
|     FUNCTION_TEST_VOID(); | ||||
|     FUNCTION_TEST_RETURN(cfgOptionTest(cfgOptHostId) ? cfgOptionUInt(cfgOptHostId) : 1); | ||||
| } | ||||
|  | ||||
| /*********************************************************************************************************************************** | ||||
| Get the command line required for local protocol execution | ||||
| ***********************************************************************************************************************************/ | ||||
| @@ -79,8 +99,6 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protoco | ||||
|         FUNCTION_LOG_PARAM(UINT, protocolId); | ||||
|     FUNCTION_LOG_END(); | ||||
|  | ||||
|     ASSERT(protocolStorageType == protocolStorageTypeRepo);         // ??? Hard-coded until the function supports pg remotes | ||||
|  | ||||
|     StringList *result = NULL; | ||||
|  | ||||
|     MEM_CONTEXT_TEMP_BEGIN() | ||||
| @@ -180,7 +198,11 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc | ||||
|         FUNCTION_LOG_PARAM(UINT, protocolId); | ||||
|     FUNCTION_LOG_END(); | ||||
|  | ||||
|     ASSERT(protocolStorageType == protocolStorageTypeRepo);         // ??? Hard-coded until the function supports pg remotes | ||||
|     // Is this a repo remote? | ||||
|     bool isRepo = protocolStorageType == protocolStorageTypeRepo; | ||||
|  | ||||
|     // Get the host index.  Default to 0 if host-id is not set. | ||||
|     unsigned int hostIdx = isRepo ? 0 : protocolHostId() - 1; | ||||
|  | ||||
|     // Fixed parameters for ssh command | ||||
|     StringList *result = strLstNew(); | ||||
| @@ -192,31 +214,63 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc | ||||
|     strLstAddZ(result, "PasswordAuthentication=no"); | ||||
|  | ||||
|     // Append port if specified | ||||
|     if (cfgOptionTest(cfgOptRepoHostPort)) | ||||
|     ConfigOption optHostPort = isRepo ? cfgOptRepoHostPort : cfgOptPgHostPort + hostIdx; | ||||
|  | ||||
|     if (cfgOptionTest(optHostPort)) | ||||
|     { | ||||
|         strLstAddZ(result, "-p"); | ||||
|         strLstAdd(result, strNewFmt("%u", cfgOptionUInt(cfgOptRepoHostPort))); | ||||
|         strLstAdd(result, strNewFmt("%u", cfgOptionUInt(optHostPort))); | ||||
|     } | ||||
|  | ||||
|     // Append user/host | ||||
|     strLstAdd(result, strNewFmt("%s@%s", strPtr(cfgOptionStr(cfgOptRepoHostUser)), strPtr(cfgOptionStr(cfgOptRepoHost)))); | ||||
|     strLstAdd( | ||||
|         result, | ||||
|         strNewFmt( | ||||
|             "%s@%s", strPtr(cfgOptionStr(isRepo ? cfgOptRepoHostUser : cfgOptPgHostUser + hostIdx)), | ||||
|             strPtr(cfgOptionStr(isRepo ? cfgOptRepoHost : cfgOptPgHost + hostIdx)))); | ||||
|  | ||||
|     // Option replacements | ||||
|     KeyValue *optionReplace = kvNew(); | ||||
|  | ||||
|     // Replace config options with the host versions | ||||
|     if (cfgOptionSource(cfgOptRepoHostConfig) != cfgSourceDefault) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_CONFIG_STR), cfgOption(cfgOptRepoHostConfig)); | ||||
|     unsigned int optConfig = isRepo ? cfgOptRepoHostConfig : cfgOptPgHostConfig + hostIdx; | ||||
|  | ||||
|     if (cfgOptionSource(cfgOptRepoHostConfigIncludePath) != cfgSourceDefault) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_CONFIG_INCLUDE_PATH_STR), cfgOption(cfgOptRepoHostConfigIncludePath)); | ||||
|     if (cfgOptionSource(optConfig) != cfgSourceDefault) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_CONFIG_STR), cfgOption(optConfig)); | ||||
|  | ||||
|     if (cfgOptionSource(cfgOptRepoHostConfigPath) != cfgSourceDefault) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_CONFIG_PATH_STR), cfgOption(cfgOptRepoHostConfigPath)); | ||||
|     unsigned int optConfigIncludePath = isRepo ? cfgOptRepoHostConfigIncludePath : cfgOptPgHostConfigIncludePath + hostIdx; | ||||
|  | ||||
|     if (cfgOptionSource(optConfigIncludePath) != cfgSourceDefault) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_CONFIG_INCLUDE_PATH_STR), cfgOption(optConfigIncludePath)); | ||||
|  | ||||
|     unsigned int optConfigPath = isRepo ? cfgOptRepoHostConfigPath : cfgOptPgHostConfigPath + hostIdx; | ||||
|  | ||||
|     if (cfgOptionSource(optConfigPath) != cfgSourceDefault) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_CONFIG_PATH_STR), cfgOption(optConfigPath)); | ||||
|  | ||||
|     // Use a C remote | ||||
|     kvPut(optionReplace, VARSTR(CFGOPT_C_STR), VARBOOL(true)); | ||||
|  | ||||
|     // Copy pg options to index 0 since that's what the remote will be expecting | ||||
|     if (hostIdx != 0) | ||||
|     { | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_PG1_PATH_STR), cfgOption(cfgOptPgPath + hostIdx)); | ||||
|  | ||||
|         if (cfgOptionSource(cfgOptPgSocketPath + hostIdx) != cfgSourceDefault) | ||||
|             kvPut(optionReplace, VARSTR(CFGOPT_PG1_SOCKET_PATH_STR), cfgOption(cfgOptPgSocketPath + hostIdx)); | ||||
|  | ||||
|         if (cfgOptionSource(cfgOptPgPort + hostIdx) != cfgSourceDefault) | ||||
|             kvPut(optionReplace, VARSTR(CFGOPT_PG1_PORT_STR), cfgOption(cfgOptPgPort + hostIdx)); | ||||
|     } | ||||
|  | ||||
|     // Remove pg options that are not needed on the remote.  This is to reduce clustter and make debugging options easier. | ||||
|     for (unsigned int pgIdx = 1; pgIdx < cfgOptionIndexTotal(cfgOptPgPath); pgIdx++) | ||||
|     { | ||||
|         kvPut(optionReplace, VARSTRZ(cfgOptionName(cfgOptPgPath + pgIdx)), NULL); | ||||
|         kvPut(optionReplace, VARSTRZ(cfgOptionName(cfgOptPgSocketPath + pgIdx)), NULL); | ||||
|         kvPut(optionReplace, VARSTRZ(cfgOptionName(cfgOptPgPort + pgIdx)), NULL); | ||||
|     } | ||||
|  | ||||
|     // Add the command option (or use the current command option if it is valid) | ||||
|     if (!cfgOptionTest(cfgOptCommand)) | ||||
|         kvPut(optionReplace, VARSTR(CFGOPT_COMMAND_STR), VARSTRZ(cfgCommandName(cfgCommand()))); | ||||
| @@ -238,10 +292,10 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc | ||||
|     kvPut(optionReplace, VARSTR(CFGOPT_LOG_LEVEL_STDERR_STR), VARSTRDEF("error")); | ||||
|  | ||||
|     // Add the type | ||||
|     kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), VARSTRDEF("backup")); | ||||
|     kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), isRepo ? VARSTRDEF("backup") : VARSTRDEF("db")); | ||||
|  | ||||
|     StringList *commandExec = cfgExecParam(cfgCmdRemote, optionReplace); | ||||
|     strLstInsert(commandExec, 0, cfgOptionStr(cfgOptRepoHostCmd)); | ||||
|     strLstInsert(commandExec, 0, cfgOptionStr(isRepo ? cfgOptRepoHostCmd : cfgOptPgHostCmd + hostIdx)); | ||||
|     strLstAdd(result, strLstJoin(commandExec, " ")); | ||||
|  | ||||
|     FUNCTION_LOG_RETURN(STRING_LIST, result); | ||||
| @@ -257,6 +311,12 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType) | ||||
|         FUNCTION_LOG_PARAM(ENUM, protocolStorageType); | ||||
|     FUNCTION_LOG_END(); | ||||
|  | ||||
|     // Is this a repo remote? | ||||
|     bool isRepo = protocolStorageType == protocolStorageTypeRepo; | ||||
|  | ||||
|     // Get the host index.  Default to 0 if host-id is not set. | ||||
|     unsigned int hostIdx = isRepo ? 0 : protocolHostId() - 1; | ||||
|  | ||||
|     protocolHelperInit(); | ||||
|  | ||||
|     // Allocate the client cache | ||||
| @@ -264,7 +324,7 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType) | ||||
|     { | ||||
|         MEM_CONTEXT_BEGIN(protocolHelper.memContext) | ||||
|         { | ||||
|             // The number of remotes allowed is the greater of allowed repo or db configs + 1 (0 is reserved for connections from | ||||
|             // The number of remotes allowed is the greater of allowed repo or pg configs + 1 (0 is reserved for connections from | ||||
|             // the main process).  Since these are static and only one will be true it presents a problem for coverage.  We think | ||||
|             // that pg remotes will always be greater but we'll protect that assumption with an assertion. | ||||
|             ASSERT(cfgDefOptionIndexTotal(cfgDefOptPgPath) >= cfgDefOptionIndexTotal(cfgDefOptRepoPath)); | ||||
| @@ -294,20 +354,22 @@ protocolRemoteGet(ProtocolStorageType protocolStorageType) | ||||
|     { | ||||
|         MEM_CONTEXT_BEGIN(protocolHelper.memContext) | ||||
|         { | ||||
|             unsigned int optHost = isRepo ? cfgOptRepoHost : cfgOptPgHost + hostIdx; | ||||
|  | ||||
|             // Execute the protocol command | ||||
|             protocolHelperClient->exec = execNew( | ||||
|                 cfgOptionStr(cfgOptCmdSsh), protocolRemoteParam(protocolStorageType, protocolId), | ||||
|                 strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u process on '%s'", protocolId, strPtr(cfgOptionStr(cfgOptRepoHost))), | ||||
|                 strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u process on '%s'", protocolId, strPtr(cfgOptionStr(optHost))), | ||||
|                 (TimeMSec)(cfgOptionDbl(cfgOptProtocolTimeout) * 1000)); | ||||
|             execOpen(protocolHelperClient->exec); | ||||
|  | ||||
|             // Create protocol object | ||||
|             protocolHelperClient->client = protocolClientNew( | ||||
|                 strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u protocol on '%s'", protocolId, strPtr(cfgOptionStr(cfgOptRepoHost))), | ||||
|                 strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u protocol on '%s'", protocolId, strPtr(cfgOptionStr(optHost))), | ||||
|                 PROTOCOL_SERVICE_REMOTE_STR, execIoRead(protocolHelperClient->exec), execIoWrite(protocolHelperClient->exec)); | ||||
|  | ||||
|             // Get cipher options from the remote if none are locally configured | ||||
|             if (strEq(cfgOptionStr(cfgOptRepoCipherType), CIPHER_TYPE_NONE_STR)) | ||||
|             if (isRepo && strEq(cfgOptionStr(cfgOptRepoCipherType), CIPHER_TYPE_NONE_STR)) | ||||
|             { | ||||
|                 // Options to query | ||||
|                 VariantList *param = varLstNew(); | ||||
|   | ||||
| @@ -33,6 +33,8 @@ ProtocolClient *protocolRemoteGet(ProtocolStorageType protocolStorageType); | ||||
| /*********************************************************************************************************************************** | ||||
| Getters | ||||
| ***********************************************************************************************************************************/ | ||||
| bool pgIsLocal(void); | ||||
| unsigned int protocolHostId(void); | ||||
| bool repoIsLocal(void); | ||||
|  | ||||
| /*********************************************************************************************************************************** | ||||
|   | ||||
| @@ -138,6 +138,34 @@ storageLocalWrite(void) | ||||
|  | ||||
|     FUNCTION_TEST_RETURN(storageHelper.storageLocalWrite); | ||||
| } | ||||
| /*********************************************************************************************************************************** | ||||
| Get the pg storage | ||||
| ***********************************************************************************************************************************/ | ||||
| static Storage * | ||||
| storagePgGet(bool write) | ||||
| { | ||||
|     FUNCTION_TEST_BEGIN(); | ||||
|         FUNCTION_TEST_PARAM(BOOL, write); | ||||
|     FUNCTION_TEST_END(); | ||||
|  | ||||
|     Storage *result = NULL; | ||||
|  | ||||
|     // Use remote storage | ||||
|     if (!pgIsLocal()) | ||||
|     { | ||||
|         result = storageRemoteNew( | ||||
|             STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, write, NULL, | ||||
|             protocolRemoteGet(protocolStorageTypePg), cfgOptionUInt(cfgOptCompressLevelNetwork)); | ||||
|     } | ||||
|     // Use Posix storage | ||||
|     else | ||||
|     { | ||||
|         result = storagePosixNew( | ||||
|             cfgOptionStr(cfgOptPgPath + protocolHostId() - 1), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, write, NULL); | ||||
|     } | ||||
|  | ||||
|     FUNCTION_TEST_RETURN(result); | ||||
| } | ||||
|  | ||||
| /*********************************************************************************************************************************** | ||||
| Get ready-only PostgreSQL storage | ||||
| @@ -153,8 +181,7 @@ storagePg(void) | ||||
|  | ||||
|         MEM_CONTEXT_BEGIN(storageHelper.memContext) | ||||
|         { | ||||
|             storageHelper.storagePg = storagePosixNew( | ||||
|                 cfgOptionStr(cfgOptPgPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL); | ||||
|             storageHelper.storagePg = storagePgGet(false); | ||||
|         } | ||||
|         MEM_CONTEXT_END(); | ||||
|     } | ||||
| @@ -176,8 +203,7 @@ storagePgWrite(void) | ||||
|  | ||||
|         MEM_CONTEXT_BEGIN(storageHelper.memContext) | ||||
|         { | ||||
|             storageHelper.storagePgWrite = storagePosixNew( | ||||
|                 cfgOptionStr(cfgOptPgPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL); | ||||
|             storageHelper.storagePgWrite = storagePgGet(true); | ||||
|         } | ||||
|         MEM_CONTEXT_END(); | ||||
|     } | ||||
|   | ||||
| @@ -14,6 +14,7 @@ Remote Storage Protocol Handler | ||||
| #include "common/log.h" | ||||
| #include "common/memContext.h" | ||||
| #include "common/regExp.h" | ||||
| #include "config/config.h" | ||||
| #include "storage/remote/protocol.h" | ||||
| #include "storage/helper.h" | ||||
| #include "storage/storage.intern.h" | ||||
| @@ -99,8 +100,8 @@ storageRemoteProtocol(const String *command, const VariantList *paramList, Proto | ||||
|  | ||||
|     ASSERT(command != NULL); | ||||
|  | ||||
|     // Determine which storage should be used (??? for now this is only repo) | ||||
|     const Storage *storage = storageRepo(); | ||||
|     // Determine which storage should be used | ||||
|     const Storage *storage = strEqZ(cfgOptionStr(cfgOptType), "backup") ? storageRepo() : storagePg(); | ||||
|     StorageInterface interface = storageInterface(storage); | ||||
|     void *driver = storageDriver(storage); | ||||
|  | ||||
|   | ||||
| @@ -66,7 +66,7 @@ testRun(void) | ||||
|         strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL); | ||||
|  | ||||
|     // ***************************************************************************************************************************** | ||||
|     if (testBegin("repoIsLocal()")) | ||||
|     if (testBegin("repoIsLocal() and pgIsLocal()")) | ||||
|     { | ||||
|         StringList *argList = strLstNew(); | ||||
|         strLstAddZ(argList, "pgbackrest"); | ||||
| @@ -85,6 +85,32 @@ testRun(void) | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_RESULT_BOOL(repoIsLocal(), false, "repo is remote"); | ||||
|  | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|         strLstAddZ(argList, "pgbackrest"); | ||||
|         strLstAddZ(argList, "--stanza=test1"); | ||||
|         strLstAddZ(argList, "--pg1-path=/path/to"); | ||||
|         strLstAddZ(argList, "--repo1-retention-full=1"); | ||||
|         strLstAddZ(argList, "backup"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_RESULT_BOOL(pgIsLocal(), true, "pg is local"); | ||||
|  | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|         strLstAddZ(argList, "pgbackrest"); | ||||
|         strLstAddZ(argList, "--stanza=test1"); | ||||
|         strLstAddZ(argList, "--pg7-path=/path/to"); | ||||
|         strLstAddZ(argList, "--pg7-host=test1"); | ||||
|         strLstAddZ(argList, "--host-id=7"); | ||||
|         strLstAddZ(argList, "--command=backup"); | ||||
|         strLstAddZ(argList, "--type=db"); | ||||
|         strLstAddZ(argList, "--process=0"); | ||||
|         strLstAddZ(argList, "local"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_RESULT_BOOL(pgIsLocal(), false, "pg is remote"); | ||||
|     } | ||||
|  | ||||
|     // ***************************************************************************************************************************** | ||||
| @@ -172,7 +198,7 @@ testRun(void) | ||||
|         strLstAddZ(argList, "--command=archive-get"); | ||||
|         strLstAddZ(argList, "--process=3"); | ||||
|         strLstAddZ(argList, "--host-id=1"); | ||||
|         strLstAddZ(argList, "--type=db"); | ||||
|         strLstAddZ(argList, "--type=backup"); | ||||
|         strLstAddZ(argList, "--repo1-host=repo-host"); | ||||
|         strLstAddZ(argList, "local"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
| @@ -184,7 +210,74 @@ testRun(void) | ||||
|                     "-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|pgbackrest@repo-host" | ||||
|                         "|pgbackrest --c --command=archive-get --log-level-file=off --log-level-stderr=error --process=3" | ||||
|                         " --stanza=test1 --type=backup remote")), | ||||
|             "remote protocol params for local"); | ||||
|             "remote protocol params for backup local"); | ||||
|  | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|         strLstAddZ(argList, "pgbackrest"); | ||||
|         strLstAddZ(argList, "--stanza=test1"); | ||||
|         strLstAddZ(argList, "--pg1-path=/path/to/1"); | ||||
|         strLstAddZ(argList, "--pg1-host=pg1-host"); | ||||
|         strLstAddZ(argList, "--repo1-retention-full=1"); | ||||
|         strLstAddZ(argList, "backup"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_RESULT_STR( | ||||
|             strPtr(strLstJoin(protocolRemoteParam(protocolStorageTypePg, 1), "|")), | ||||
|             strPtr( | ||||
|                 strNew( | ||||
|                     "-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|postgres@pg1-host" | ||||
|                         "|pgbackrest --c --command=backup --log-level-file=off --log-level-stderr=error --pg1-path=/path/to/1" | ||||
|                         " --process=1 --stanza=test1 --type=db remote")), | ||||
|             "remote protocol params for db backup"); | ||||
|  | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|         strLstAddZ(argList, "pgbackrest"); | ||||
|         strLstAddZ(argList, "--stanza=test1"); | ||||
|         strLstAddZ(argList, "--command=backup"); | ||||
|         strLstAddZ(argList, "--process=4"); | ||||
|         strLstAddZ(argList, "--host-id=2"); | ||||
|         strLstAddZ(argList, "--pg1-path=/path/to/1"); | ||||
|         strLstAddZ(argList, "--pg2-path=/path/to/2"); | ||||
|         strLstAddZ(argList, "--pg2-host=pg2-host"); | ||||
|         strLstAddZ(argList, "--type=db"); | ||||
|         strLstAddZ(argList, "local"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_RESULT_STR( | ||||
|             strPtr(strLstJoin(protocolRemoteParam(protocolStorageTypePg, 1), "|")), | ||||
|             strPtr( | ||||
|                 strNew( | ||||
|                     "-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|postgres@pg2-host" | ||||
|                         "|pgbackrest --c --command=backup --log-level-file=off --log-level-stderr=error --pg1-path=/path/to/2" | ||||
|                         " --process=4 --stanza=test1 --type=db remote")), | ||||
|             "remote protocol params for db local"); | ||||
|  | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|         strLstAddZ(argList, "pgbackrest"); | ||||
|         strLstAddZ(argList, "--stanza=test1"); | ||||
|         strLstAddZ(argList, "--command=backup"); | ||||
|         strLstAddZ(argList, "--process=4"); | ||||
|         strLstAddZ(argList, "--host-id=3"); | ||||
|         strLstAddZ(argList, "--pg1-path=/path/to/1"); | ||||
|         strLstAddZ(argList, "--pg3-path=/path/to/3"); | ||||
|         strLstAddZ(argList, "--pg3-host=pg3-host"); | ||||
|         strLstAddZ(argList, "--pg3-socket-path=/socket3"); | ||||
|         strLstAddZ(argList, "--pg3-port=3333"); | ||||
|         strLstAddZ(argList, "--type=db"); | ||||
|         strLstAddZ(argList, "local"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_RESULT_STR( | ||||
|             strPtr(strLstJoin(protocolRemoteParam(protocolStorageTypePg, 1), "|")), | ||||
|             strPtr( | ||||
|                 strNew( | ||||
|                     "-o|LogLevel=error|-o|Compression=no|-o|PasswordAuthentication=no|postgres@pg3-host" | ||||
|                         "|pgbackrest --c --command=backup --log-level-file=off --log-level-stderr=error --pg1-path=/path/to/3" | ||||
|                         " --pg1-port=3333 --pg1-socket-path=/socket3 --process=4 --stanza=test1 --type=db remote")), | ||||
|             "remote protocol params for db local"); | ||||
|     } | ||||
|  | ||||
|     // ***************************************************************************************************************************** | ||||
| @@ -724,6 +817,23 @@ testRun(void) | ||||
|         TEST_ASSIGN(client, protocolRemoteGet(protocolStorageTypeRepo), "get remote protocol"); | ||||
|         TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoCipherPass)), "dcba", "check cipher pass after"); | ||||
|  | ||||
|         TEST_RESULT_VOID(protocolFree(), "free remote protocol objects"); | ||||
|  | ||||
|         // Start db protocol | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|         strLstAddZ(argList, "/usr/bin/pgbackrest"); | ||||
|         strLstAddZ(argList, "--stanza=db"); | ||||
|         strLstAddZ(argList, "--protocol-timeout=10"); | ||||
|         strLstAddZ(argList, "--repo1-retention-full=1"); | ||||
|         strLstAddZ(argList, "--pg1-host=localhost"); | ||||
|         strLstAdd(argList, strNewFmt("--pg1-host-user=%s", testUser())); | ||||
|         strLstAdd(argList, strNewFmt("--pg1-path=%s", testPath())); | ||||
|         strLstAddZ(argList, "backup"); | ||||
|         harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|         TEST_ASSIGN(client, protocolRemoteGet(protocolStorageTypePg), "get remote protocol"); | ||||
|  | ||||
|         // Start local protocol | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         argList = strLstNew(); | ||||
|   | ||||
| @@ -32,6 +32,16 @@ testRun(void) | ||||
|     strLstAddZ(argList, "info"); | ||||
|     harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); | ||||
|  | ||||
|     // Set type since we'll be running local and remote tests here | ||||
|     cfgOptionSet(cfgOptType, cfgSourceParam, VARSTRDEF("backup")); | ||||
|     cfgOptionValidSet(cfgOptType, true); | ||||
|  | ||||
|     // Set pg settings so we can run both db and backup remotes | ||||
|     cfgOptionSet(cfgOptPgHost, cfgSourceParam, VARSTRDEF("localhost")); | ||||
|     cfgOptionValidSet(cfgOptPgHost, true); | ||||
|     cfgOptionSet(cfgOptPgPath, cfgSourceParam, VARSTR(strNewFmt("%s/pg", testPath()))); | ||||
|     cfgOptionValidSet(cfgOptPgPath, true); | ||||
|  | ||||
|     // Start a protocol server to test the remote protocol | ||||
|     Buffer *serverRead = bufNew(8192); | ||||
|     Buffer *serverWrite = bufNew(8192); | ||||
| @@ -68,12 +78,13 @@ testRun(void) | ||||
|         TEST_RESULT_BOOL(storageRemoteProtocol(strNew(BOGUS_STR), varLstNew(), server), false, "invalid function"); | ||||
|     } | ||||
|  | ||||
|     // Do these tests against a db remote for coverage | ||||
|     // ***************************************************************************************************************************** | ||||
|     if (testBegin("storageExists()")) | ||||
|     { | ||||
|         Storage *storageRemote = NULL; | ||||
|         TEST_ASSIGN(storageRemote, storageRepoGet(strNew(STORAGE_TYPE_POSIX), false), "get remote repo storage"); | ||||
|         storagePathCreateNP(storageTest, strNew("repo")); | ||||
|         TEST_ASSIGN(storageRemote, storagePgGet(false), "get remote pg storage"); | ||||
|         storagePathCreateNP(storageTest, strNew("pg")); | ||||
|  | ||||
|         TEST_RESULT_BOOL(storageExistsNP(storageRemote, strNew("test.txt")), false, "file does not exist"); | ||||
|  | ||||
| @@ -82,6 +93,9 @@ testRun(void) | ||||
|  | ||||
|         // Check protocol function directly | ||||
|         // ------------------------------------------------------------------------------------------------------------------------- | ||||
|         cfgOptionSet(cfgOptType, cfgSourceParam, VARSTRDEF("db")); | ||||
|         cfgOptionValidSet(cfgOptType, true); | ||||
|  | ||||
|         VariantList *paramList = varLstNew(); | ||||
|         varLstAdd(paramList, varNewStr(strNew("test.txt"))); | ||||
|  | ||||
| @@ -90,6 +104,9 @@ testRun(void) | ||||
|         TEST_RESULT_STR(strPtr(strNewBuf(serverWrite)), "{\"out\":true}\n", "check result"); | ||||
|  | ||||
|         bufUsedSet(serverWrite, 0); | ||||
|  | ||||
|         cfgOptionSet(cfgOptType, cfgSourceParam, VARSTRDEF("db")); | ||||
|         cfgOptionValidSet(cfgOptType, true); | ||||
|     } | ||||
|  | ||||
|     // ***************************************************************************************************************************** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user