pgbackrest.git / summary / log / commit / refs

commit    65d22e43257d46ff6523ffbdb3af59e30deeaea5
Author:   Reid Thompson <1116827+jreidthompson@users.noreply.github.com>
Commit:   GitHub <noreply@github.com>
Date:     Fri May 06 15:11:36 2022 +0000

    Add verify output and verbose options.
    
    These options allow the user to control how the verify results will be output to the console and log.


doc/xml/release.xml | 15 + src/build/config/config.yaml | 14 +- src/build/help/help.xml | 25 +- src/command/verify/verify.c | 184 +++++--- src/config/config.auto.h | 6 +- src/config/parse.auto.c | 47 ++ test/define.yaml | 2 +- test/src/module/command/helpTest.c | 1 + test/src/module/command/verifyTest.c | 816 +++++++++++++++++++++++++++++------ 9 files changed, 907 insertions(+), 203 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 708381280..254772c8e 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -72,6 +72,21 @@ <p>Backup file bundling for improved small file support.</p> </release-item> + <release-item> + <commit subject="Add verify output and verbose options."> + <github-pull-request id="1607"/> + </commit> + + <release-item-contributor-list> + <release-item-contributor id="cynthia.shang"/> + <release-item-contributor id="reid.thompson"/> + <release-item-reviewer id="david.steele"/> + <release-item-reviewer id="stefan.fercot"/> + </release-item-contributor-list> + + <p>Verify command to validate the contents of a repository.</p> + </release-item> + <release-item> <commit subject="Remove dependency on pg_database.datlastsysoid."> <github-pull-request id="1735"/> diff --git a/src/build/config/config.yaml b/src/build/config/config.yaml index 0448dd7eb..af80af99b 100644 --- a/src/build/config/config.yaml +++ b/src/build/config/config.yaml @@ -151,7 +151,6 @@ command: command-role: local: {} remote: {} - internal: true version: log-file: false @@ -306,6 +305,11 @@ option: command: info: {} repo-ls: {} + verify: + default: none + allow-list: + - none + - text allow-list: - text - json @@ -453,6 +457,14 @@ option: command-role: main: {} + verbose: + type: boolean + default: false + command: + verify: {} + command-role: + main: {} + # Command-line only local/remote options #--------------------------------------------------------------------------------------------------------------------------------- exec-id: diff --git a/src/build/help/help.xml b/src/build/help/help.xml index 6bd3b5e2a..b2ba1c253 100644 --- a/src/build/help/help.xml +++ b/src/build/help/help.xml @@ -2411,10 +2411,10 @@ <!-- OPERATION - VERIFY COMMAND --> <command id="verify" name="Verify"> - <summary>Verify the contents of the repository.</summary> + <summary>Verify contents of the repository.</summary> <text> - <p>Verify will attempt to determine if the backups and archives in the repository are valid.</p> + <p>Verify determines if the backups and archives in the repository are valid.</p> </text> <option-list> @@ -2428,6 +2428,27 @@ <example>20150131-153358F_20150131-153401I</example> </option> + + <!-- ======================================================================================================= --> + <option id="output" name="Output"> + <summary>Output type.</summary> + + <text> <p>Output may be none (default) or text. Requesting text generates ouput to stdout.</p> + </text> + + <example>text</example> + </option> + + <!-- ======================================================================================================= --> + <option id="verbose" name="Verbose"> + <summary>Verbose output.</summary> + + <text> + <p>Verbose defaults to false, providing a minimal response with important information about errors in the repository. Specifying true provides more information about what was successfully verified.</p> + </text> + + <example>y</example> + </option> </option-list> </command> diff --git a/src/command/verify/verify.c b/src/command/verify/verify.c index f76ebad32..09106179b 100644 --- a/src/command/verify/verify.c +++ b/src/command/verify/verify.c @@ -1,7 +1,7 @@ /*********************************************************************************************************************************** Verify Command -Verify the contents of the repository. +Verify contents of the repository. ***********************************************************************************************************************************/ #include "build.auto.h" @@ -13,6 +13,7 @@ Verify the contents of the repository. #include "command/check/common.h" #include "command/verify/file.h" #include "command/verify/protocol.h" +#include "command/verify/verify.h" #include "common/compress/helper.h" #include "common/crypto/cipherBlock.h" #include "common/debug.h" @@ -29,6 +30,12 @@ Verify the contents of the repository. #include "protocol/parallel.h" #include "storage/helper.h" +/*********************************************************************************************************************************** +Constants +***********************************************************************************************************************************/ +#define VERIFY_STATUS_OK "ok" +#define VERIFY_STATUS_ERROR "error" + /*********************************************************************************************************************************** Data Types and Structures ***********************************************************************************************************************************/ @@ -233,7 +240,7 @@ verifyInfoFile(const String *pathFileName, bool keepFile, const String *cipherPa if (result.errorCode == errorTypeCode(&ChecksumError)) strCat(errorMsg, strNewFmt(" %s", strZ(pathFileName))); - LOG_WARN(strZ(errorMsg)); + LOG_DETAIL(strZ(errorMsg)); } TRY_END(); } @@ -273,7 +280,7 @@ verifyArchiveInfoFile(void) // If the info and info.copy checksums don't match each other than one (or both) of the files could be corrupt so // log a warning but must trust main if (!strEq(verifyArchiveInfo.checksum, verifyArchiveInfoCopy.checksum)) - LOG_WARN("archive.info.copy does not match archive.info"); + LOG_DETAIL("archive.info.copy does not match archive.info"); } } else @@ -326,7 +333,7 @@ verifyBackupInfoFile(void) // If the info and info.copy checksums don't match each other than one (or both) of the files could be corrupt so // log a warning but must trust main if (!strEq(verifyBackupInfo.checksum, verifyBackupInfoCopy.checksum)) - LOG_WARN("backup.info.copy does not match backup.info"); + LOG_DETAIL("backup.info.copy does not match backup.info"); } } else @@ -393,7 +400,7 @@ verifyManifestFile( // If the manifest and manifest.copy checksums don't match each other than one (or both) of the files could be // corrupt so log a warning but trust main if (!strEq(verifyManifestInfo.checksum, verifyManifestInfoCopy.checksum)) - LOG_WARN_FMT("backup '%s' manifest.copy does not match manifest", strZ(backupResult->backupLabel)); + LOG_DETAIL_FMT("backup '%s' manifest.copy does not match manifest", strZ(backupResult->backupLabel)); } } else @@ -411,7 +418,7 @@ verifyManifestFile( // If loaded successfully, then return the copy as usable if (verifyManifestInfoCopy.errorCode == 0) { - LOG_WARN_FMT("%s/backup.manifest is missing or unusable, using copy", strZ(backupResult->backupLabel)); + LOG_DETAIL_FMT("%s/backup.manifest is missing or unusable, using copy", strZ(backupResult->backupLabel)); result = verifyManifestInfoCopy.manifest; } @@ -420,7 +427,7 @@ verifyManifestFile( { backupResult->status = backupMissingManifest; - LOG_WARN_FMT("manifest missing for '%s' - backup may have expired", strZ(backupResult->backupLabel)); + LOG_DETAIL_FMT("manifest missing for '%s' - backup may have expired", strZ(backupResult->backupLabel)); } } else @@ -453,8 +460,7 @@ verifyManifestFile( // If the PG data is not found in the backup.info history, then error and reset the result if (!found) { - LOG_ERROR_FMT( - errorTypeCode(&FileInvalidError), + LOG_INFO_FMT( "'%s' may not be recoverable - PG data (id %u, version %s, system-id %" PRIu64 ") is not in the backup.info" " history, skipping", strZ(backupResult->backupLabel), manData->pgId, strZ(pgVersionToStr(manData->pgVersion)), manData->pgSystemId); @@ -562,9 +568,7 @@ verifyCreateArchiveIdRange(VerifyArchiveResult *archiveIdResult, StringList *wal // PostgreSQL will ignore it if (archiveIdResult->pgWalInfo.version <= PG_VERSION_92 && strEndsWithZ(walSegment, "FF")) { - LOG_ERROR_FMT( - errorTypeCode(&FileInvalidError), "invalid WAL '%s' for '%s' exists, skipping", strZ(walSegment), - strZ(archiveIdResult->archiveId)); + LOG_INFO_FMT("invalid WAL '%s' for '%s' exists, skipping", strZ(walSegment), strZ(archiveIdResult->archiveId)); (*jobErrorTotal)++; @@ -578,9 +582,7 @@ verifyCreateArchiveIdRange(VerifyArchiveResult *archiveIdResult, StringList *wal { if (strEq(walSegment, strSubN(strLstGet(walFileList, walFileIdx + 1), 0, WAL_SEGMENT_NAME_SIZE))) { - LOG_ERROR_FMT( - errorTypeCode(&FileInvalidError), "duplicate WAL '%s' for '%s' exists, skipping", strZ(walSegment), - strZ(archiveIdResult->archiveId)); + LOG_INFO_FMT("duplicate WAL '%s' for '%s' exists, skipping", strZ(walSegment), strZ(archiveIdResult->archiveId)); (*jobErrorTotal)++; @@ -783,7 +785,7 @@ verifyArchive(VerifyJobData *const jobData) else { // No valid WAL to process (may be only duplicates or nothing in WAL path) - remove WAL path from the list - LOG_WARN_FMT( + LOG_DETAIL_FMT( "path '%s/%s' does not contain any valid WAL to be processed", strZ(archiveResult->archiveId), strZ(walPath)); strLstRemoveIdx(jobData->walPathList, 0); @@ -806,7 +808,7 @@ verifyArchive(VerifyJobData *const jobData) else { // Log that no WAL paths exist in the archive Id dir - remove the archive Id from the list (nothing to process) - LOG_WARN_FMT("archive path '%s' is empty", strZ(strLstGet(jobData->archiveIdList, 0))); + LOG_DETAIL_FMT("archive path '%s' is empty", strZ(strLstGet(jobData->archiveIdList, 0))); strLstRemoveIdx(jobData->archiveIdList, 0); } } @@ -836,7 +838,8 @@ verifyBackup(VerifyJobData *const jobData) // If result list is empty or the last processed is not equal to the backup being processed, then initialize the backup // data and results if (lstEmpty(jobData->backupResultList) || - !strEq(((VerifyBackupResult *)lstGetLast(jobData->backupResultList))->backupLabel, strLstGet(jobData->backupList, 0))) + !strEq( + ((VerifyBackupResult *)lstGetLast(jobData->backupResultList))->backupLabel, strLstGet(jobData->backupList, 0))) { MEM_CONTEXT_BEGIN(lstMemContext(jobData->backupResultList)) { @@ -1045,9 +1048,7 @@ verifyBackup(VerifyJobData *const jobData) { // Nothing to process so report an error, free the manifest, set the status, and remove the backup from processing // list - LOG_ERROR_FMT( - errorTypeCode(&FileInvalidError), "backup '%s' manifest does not contain any target files to verify", - strZ(backupResult->backupLabel)); + LOG_INFO_FMT("backup '%s' manifest does not contain any target files to verify", strZ(backupResult->backupLabel)); jobData->jobErrorTotal++; @@ -1157,8 +1158,7 @@ verifyLogInvalidResult(const String *fileType, VerifyResult verifyResult, unsign FUNCTION_TEST_RETURN(UINT, 0); } - LOG_ERROR_PID_FMT( - processId, errorTypeCode(&FileInvalidError), "%s '%s'", verifyErrorMsg(verifyResult), strZ(filePathName)); + LOG_INFO_PID_FMT(processId, "%s '%s'", verifyErrorMsg(verifyResult), strZ(filePathName)); FUNCTION_TEST_RETURN(UINT, 1); } @@ -1224,9 +1224,7 @@ verifySetBackupCheckArchive( if (!strEmpty(missingFromHistory)) { - LOG_ERROR_FMT( - errorTypeCode(&ArchiveMismatchError), "archiveIds '%s' are not in the archive.info history list", - strZ(missingFromHistory)); + LOG_INFO_FMT("archiveIds '%s' are not in the archive.info history list", strZ(missingFromHistory)); (*jobErrorTotal)++; } @@ -1275,33 +1273,74 @@ verifyAddInvalidWalFile(List *walRangeList, VerifyResult fileResult, const Strin FUNCTION_TEST_RETURN_VOID(); } +/*********************************************************************************************************************************** +Create file errors string +***********************************************************************************************************************************/ +static String * +verifyCreateFileErrorsStr( + const unsigned int errMissing, const unsigned int errChecksum, const unsigned int errSize, const unsigned int errOther, + const bool verboseText) +{ + FUNCTION_TEST_BEGIN(); + FUNCTION_TEST_PARAM(UINT, errMissing); // Number of files missing + FUNCTION_TEST_PARAM(UINT, errChecksum); // Number of files with checksum errors + FUNCTION_TEST_PARAM(UINT, errSize); // Number of files with invalid size + FUNCTION_TEST_PARAM(UINT, errOther); // Number of files with other errors + FUNCTION_TEST_PARAM(BOOL, verboseText); // Is verbose output requested + FUNCTION_TEST_END(); + + String *result = strNew(); + + MEM_CONTEXT_TEMP_BEGIN() + { + // List all if verbose text, otherwise only list if type has errors + strCatFmt( + result, "\n %s%s%s%s", + verboseText || errMissing ? strZ(strNewFmt("missing: %u, ", errMissing)) : "", + verboseText || errChecksum ? strZ(strNewFmt("checksum invalid: %u, ", errChecksum)) : "", + verboseText || errSize ? strZ(strNewFmt("size invalid: %u, ", errSize)) : "", + verboseText || errOther ? strZ(strNewFmt("other: %u", errOther)) : ""); + + // Clean up trailing comma when necessary + if (strEndsWithZ(result, ", ")) + strTrunc(result, (int)strSize(result) - 2); + } + MEM_CONTEXT_TEMP_END(); + + FUNCTION_TEST_RETURN(STRING, result); +} + /*********************************************************************************************************************************** Render the results of the verify command ***********************************************************************************************************************************/ static String * -verifyRender(List *archiveIdResultList, List *backupResultList) +verifyRender(const List *const archiveIdResultList, const List *const backupResultList, const bool verboseText) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(LIST, archiveIdResultList); // Result list for all archive Ids in the repo FUNCTION_TEST_PARAM(LIST, backupResultList); // Result list for all backups in the repo + FUNCTION_TEST_PARAM(BOOL, verboseText); // Is verbose output requested? FUNCTION_TEST_END(); ASSERT(archiveIdResultList != NULL); ASSERT(backupResultList != NULL); - String *result = strCatZ(strNew(), "Results:"); + String *result = strNew(); // Render archive results - if (lstEmpty(archiveIdResultList)) + if (verboseText && lstEmpty(archiveIdResultList)) strCatZ(result, "\n archiveId: none found"); else { for (unsigned int archiveIdx = 0; archiveIdx < lstSize(archiveIdResultList); archiveIdx++) { VerifyArchiveResult *archiveIdResult = lstGet(archiveIdResultList, archiveIdx); - strCatFmt( - result, "\n archiveId: %s, total WAL checked: %u, total valid WAL: %u", strZ(archiveIdResult->archiveId), - archiveIdResult->totalWalFile, archiveIdResult->totalValidWal); + if (verboseText || archiveIdResult->totalWalFile - archiveIdResult->totalValidWal != 0) + { + strCatFmt( + result, "\n archiveId: %s, total WAL checked: %u, total valid WAL: %u", strZ(archiveIdResult->archiveId), + archiveIdResult->totalWalFile, archiveIdResult->totalValidWal); + } if (archiveIdResult->totalWalFile > 0) { @@ -1337,15 +1376,15 @@ verifyRender(List *archiveIdResultList, List *backupResultList) } } - strCatFmt( - result, "\n missing: %u, checksum invalid: %u, size invalid: %u, other: %u", errMissing, errChecksum, - errSize, errOther); + // Create/append file errors string + if (verboseText || errMissing + errChecksum + errSize + errOther > 0) + strCat(result, verifyCreateFileErrorsStr(errMissing, errChecksum, errSize, errOther, verboseText)); } } } // Render backup results - if (lstEmpty(backupResultList)) + if (verboseText && lstEmpty(backupResultList)) strCatZ(result, "\n backup: none found"); else { @@ -1377,9 +1416,12 @@ verifyRender(List *archiveIdResultList, List *backupResultList) } } - strCatFmt( - result, "\n backup: %s, status: %s, total files checked: %u, total valid files: %u", - strZ(backupResult->backupLabel), status, backupResult->totalFileVerify, backupResult->totalFileValid); + if (verboseText || (strcmp(status, "valid") != 0 && strcmp(status, "in-progress") != 0)) + { + strCatFmt( + result, "\n backup: %s, status: %s, total files checked: %u, total valid files: %u", + strZ(backupResult->backupLabel), status, backupResult->totalFileVerify, backupResult->totalFileValid); + } if (backupResult->totalFileVerify > 0) { @@ -1402,9 +1444,9 @@ verifyRender(List *archiveIdResultList, List *backupResultList) errOther++; } - strCatFmt( - result, "\n missing: %u, checksum invalid: %u, size invalid: %u, other: %u", errMissing, errChecksum, - errSize, errOther); + // Create/append file errors string + if (verboseText || errMissing + errChecksum + errSize + errOther > 0) + strCat(result, verifyCreateFileErrorsStr(errMissing, errChecksum, errSize, errOther, verboseText)); } } } @@ -1416,16 +1458,17 @@ verifyRender(List *archiveIdResultList, List *backupResultList) Process the verify command ***********************************************************************************************************************************/ static String * -verifyProcess(unsigned int *errorTotal) +verifyProcess(const bool verboseText) { FUNCTION_LOG_BEGIN(logLevelDebug); - FUNCTION_TEST_PARAM_P(UINT, errorTotal); // Pointer to overall job error total + FUNCTION_TEST_PARAM(BOOL, verboseText); // Is verbose output requested? FUNCTION_LOG_END(); - String *result = NULL; + String *const result = strNew(); MEM_CONTEXT_TEMP_BEGIN() { + unsigned int errorTotal = 0; String *resultStr = strNew(); // Get the repo storage in case it is remote and encryption settings need to be pulled down @@ -1437,8 +1480,8 @@ verifyProcess(unsigned int *errorTotal) // If a usable backup.info file is not found, then report an error in the log if (backupInfo == NULL) { - LOG_ERROR(errorTypeCode(&FormatError), "No usable backup.info file"); - (*errorTotal)++; + strCatZ(resultStr, "\n No usable backup.info file"); + errorTotal++; } // Get a usable archive info file @@ -1447,8 +1490,8 @@ verifyProcess(unsigned int *errorTotal) // If a usable archive.info file is not found, then report an error in the log if (archiveInfo == NULL) { - LOG_ERROR(errorTypeCode(&FormatError), "No usable archive.info file"); - (*errorTotal)++; + strCatZ(resultStr, "\n No usable archive.info file"); + errorTotal++; } // If both a usable archive info and backup info file were found, then proceed with verification @@ -1461,14 +1504,14 @@ verifyProcess(unsigned int *errorTotal) } CATCH_ANY() { - LOG_ERROR(errorTypeCode(&FormatError), errorMessage()); - (*errorTotal)++; + strCatFmt(resultStr, "\n%s", errorMessage()); + errorTotal++; } TRY_END(); } // If valid info files, then begin process of checking backups and archives in the repo - if ((*errorTotal) == 0) + if (errorTotal == 0) { // Initialize the job data VerifyJobData jobData = @@ -1503,7 +1546,7 @@ verifyProcess(unsigned int *errorTotal) // Warn if there are no archives or there are no backups in the repo so that the callback need not try to // distinguish between having processed all of the list or if the list was missing in the first place if (strLstEmpty(jobData.archiveIdList) || strLstEmpty(jobData.backupList)) - LOG_WARN_FMT("no %s exist in the repo", strLstEmpty(jobData.archiveIdList) ? "archives" : "backups"); + LOG_DETAIL_FMT("no %s exist in the repo", strLstEmpty(jobData.archiveIdList) ? "archives" : "backups"); // If there are no archives to process, then set the processing flag to skip to processing the backups if (strLstEmpty(jobData.archiveIdList)) @@ -1603,8 +1646,8 @@ verifyProcess(unsigned int *errorTotal) else { // Log a protocol error and increment the jobErrorTotal - LOG_ERROR_PID_FMT( - processId, errorTypeCode(&ProtocolError), + LOG_INFO_PID_FMT( + processId, "%s %s: [%d] %s", verifyErrorMsg(verifyOtherError), strZ(filePathName), protocolParallelJobErrorCode(job), strZ(protocolParallelJobErrorMessage(job))); @@ -1646,19 +1689,21 @@ verifyProcess(unsigned int *errorTotal) // ??? Need to do the final reconciliation - checking backup required WAL against, valid WAL // Report results - resultStr = verifyRender(jobData.archiveIdResultList, jobData.backupResultList); + resultStr = verifyRender(jobData.archiveIdResultList, jobData.backupResultList, verboseText); } else - LOG_WARN("no archives or backups exist in the repo"); + strCatZ(resultStr, "\n no archives or backups exist in the repo"); - (*errorTotal) += jobData.jobErrorTotal; + errorTotal += jobData.jobErrorTotal; } - MEM_CONTEXT_PRIOR_BEGIN() + // If verbose output or errors then output results + if (verboseText || errorTotal > 0) { - result = strDup(resultStr); + strCatFmt( + result, "stanza: %s\nstatus: %s%s", strZ(cfgOptionStr(cfgOptStanza)), + errorTotal > 0 ? VERIFY_STATUS_ERROR : VERIFY_STATUS_OK, strZ(resultStr)); } - MEM_CONTEXT_PRIOR_END(); } MEM_CONTEXT_TEMP_END(); @@ -1673,16 +1718,21 @@ cmdVerify(void) MEM_CONTEXT_TEMP_BEGIN() { - unsigned int errorTotal = 0; - String *result = verifyProcess(&errorTotal); + const String *const result = verifyProcess(cfgOptionBool(cfgOptVerbose)); // Output results if any - if (strSize(result) > 0) + if (!strEmpty(result)) + { + // Log results LOG_INFO_FMT("%s", strZ(result)); - // Throw an error if any encountered - if (errorTotal > 0) - THROW_FMT(RuntimeError, "%u fatal errors encountered, see log for details", errorTotal); + // Output to console when requested + if (cfgOptionStrId(cfgOptOutput) == CFGOPTVAL_OUTPUT_TEXT) + { + ioFdWriteOneStr(STDOUT_FILENO, result); + ioFdWriteOneStr(STDOUT_FILENO, LF_STR); + } + } } MEM_CONTEXT_TEMP_END(); diff --git a/src/config/config.auto.h b/src/config/config.auto.h index b01e4d096..1d041eea3 100644 --- a/src/config/config.auto.h +++ b/src/config/config.auto.h @@ -126,8 +126,9 @@ Option constants #define CFGOPT_TLS_SERVER_KEY_FILE "tls-server-key-file" #define CFGOPT_TLS_SERVER_PORT "tls-server-port" #define CFGOPT_TYPE "type" +#define CFGOPT_VERBOSE "verbose" -#define CFG_OPTION_TOTAL 154 +#define CFG_OPTION_TOTAL 155 /*********************************************************************************************************************************** Option value constants @@ -195,6 +196,8 @@ Option value constants #define CFGOPTVAL_OUTPUT_JSON STRID5("json", 0x73e6a0) #define CFGOPTVAL_OUTPUT_JSON_Z "json" +#define CFGOPTVAL_OUTPUT_NONE STRID5("none", 0x2b9ee0) +#define CFGOPTVAL_OUTPUT_NONE_Z "none" #define CFGOPTVAL_OUTPUT_TEXT STRID5("text", 0xa60b40) #define CFGOPTVAL_OUTPUT_TEXT_Z "text" @@ -507,6 +510,7 @@ typedef enum cfgOptTlsServerKeyFile, cfgOptTlsServerPort, cfgOptType, + cfgOptVerbose, } ConfigOption; #endif diff --git a/src/config/parse.auto.c b/src/config/parse.auto.c index 4534b8053..89c2f0a64 100644 --- a/src/config/parse.auto.c +++ b/src/config/parse.auto.c @@ -3068,10 +3068,31 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] = ( PARSE_RULE_OPTION_COMMAND(cfgCmdInfo) PARSE_RULE_OPTION_COMMAND(cfgCmdRepoLs) + PARSE_RULE_OPTION_COMMAND(cfgCmdVerify) ), PARSE_RULE_OPTIONAL ( + PARSE_RULE_OPTIONAL_GROUP + ( + PARSE_RULE_FILTER_CMD + ( + PARSE_RULE_VAL_CMD(cfgCmdVerify), + ), + + PARSE_RULE_OPTIONAL_ALLOW_LIST + ( + PARSE_RULE_VAL_STRID(parseRuleValStrIdNone), + PARSE_RULE_VAL_STRID(parseRuleValStrIdText), + ), + + PARSE_RULE_OPTIONAL_DEFAULT + ( + PARSE_RULE_VAL_STRID(parseRuleValStrIdNone), + PARSE_RULE_VAL_STR(parseRuleValStrQT_none_QT), + ), + ), + PARSE_RULE_OPTIONAL_GROUP ( PARSE_RULE_OPTIONAL_ALLOW_LIST @@ -8948,6 +8969,31 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] = ), ), ), + + // ----------------------------------------------------------------------------------------------------------------------------- + PARSE_RULE_OPTION + ( + PARSE_RULE_OPTION_NAME("verbose"), + PARSE_RULE_OPTION_TYPE(cfgOptTypeBoolean), + PARSE_RULE_OPTION_REQUIRED(true), + PARSE_RULE_OPTION_SECTION(cfgSectionCommandLine), + + PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST + ( + PARSE_RULE_OPTION_COMMAND(cfgCmdVerify) + ), + + PARSE_RULE_OPTIONAL + ( + PARSE_RULE_OPTIONAL_GROUP + ( + PARSE_RULE_OPTIONAL_DEFAULT + ( + PARSE_RULE_VAL_BOOL_FALSE, + ), + ), + ), + ), }; /*********************************************************************************************************************************** @@ -9342,6 +9388,7 @@ static const uint8_t optionResolveOrder[] = cfgOptTlsServerKeyFile, cfgOptTlsServerPort, cfgOptType, + cfgOptVerbose, cfgOptArchiveCheck, cfgOptArchiveCopy, cfgOptArchiveModeCheck, diff --git a/test/define.yaml b/test/define.yaml index 012107cf8..1979c20bd 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -836,7 +836,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: verify - total: 8 + total: 12 coverage: - command/verify/file diff --git a/test/src/module/command/helpTest.c b/test/src/module/command/helpTest.c index 51ca18a6b..5e0e1ffaf 100644 --- a/test/src/module/command/helpTest.c +++ b/test/src/module/command/helpTest.c @@ -69,6 +69,7 @@ testRun(void) " stanza-upgrade Upgrade a stanza.\n" " start Allow pgBackRest processes to run.\n" " stop Stop pgBackRest processes from running.\n" + " verify Verify contents of the repository.\n" " version Get version.\n" "\n" "Use 'pgbackrest help [command]' for more information.\n", diff --git a/test/src/module/command/verifyTest.c b/test/src/module/command/verifyTest.c index fcd2d9910..8a9b9f1db 100644 --- a/test/src/module/command/verifyTest.c +++ b/test/src/module/command/verifyTest.c @@ -1,5 +1,5 @@ /*********************************************************************************************************************************** -Test Stanza Commands +Test Verify Command ***********************************************************************************************************************************/ #include "common/io/bufferRead.h" #include "postgres/interface.h" @@ -21,6 +21,9 @@ testRun(void) { FUNCTION_HARNESS_VOID(); + // Create storage + Storage *storageTest = storagePosixNewP(TEST_PATH_STR, .write = true); + // Install local command handler shim static const ProtocolServerHandler testLocalHandlerList[] = {PROTOCOL_SERVER_HANDLER_VERIFY_LIST}; hrnProtocolLocalShimInstall(testLocalHandlerList, LENGTH_OF(testLocalHandlerList)); @@ -247,14 +250,16 @@ testRun(void) TEST_MANIFEST_PATH_DEFAULT, .comment = "manifest db section mismatch"); + harnessLogLevelSet(logLevelDetail); + backupResult.status = backupValid; TEST_ASSIGN(manifest, verifyManifestFile(&backupResult, NULL, false, infoPg, &jobErrorTotal), "verify manifest"); TEST_RESULT_PTR(manifest, NULL, "manifest not set - pg version mismatch"); TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid"); TEST_RESULT_LOG( - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest.copy'" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest.copy'" " for read\n" - "P00 ERROR: [028]: '20181119-152138F' may not be recoverable - PG data (id 1, version 9.2, system-id " + "P00 INFO: '20181119-152138F' may not be recoverable - PG data (id 1, version 9.2, system-id " HRN_PG_SYSTEMID_94_Z ") is not in the backup.info history, skipping"); //-------------------------------------------------------------------------------------------------------------------------- @@ -287,10 +292,10 @@ testRun(void) TEST_RESULT_PTR(manifest, NULL, "manifest not set - pg system-id mismatch"); TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid"); TEST_RESULT_LOG( - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n" - "P00 WARN: 20181119-152138F/backup.manifest is missing or unusable, using copy\n" - "P00 ERROR: [028]: '20181119-152138F' may not be recoverable - PG data (id 1, version 9.4, system-id 0) is " - "not in the backup.info history, skipping"); + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n" + "P00 DETAIL: 20181119-152138F/backup.manifest is missing or unusable, using copy\n" + "P00 INFO: '20181119-152138F' may not be recoverable - PG data (id 1, version 9.4, system-id 0) is not in the " + "backup.info history, skipping"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("rerun copy test with db-id invalid"); @@ -321,9 +326,9 @@ testRun(void) TEST_RESULT_PTR(manifest, NULL, "manifest not set - pg db-id mismatch"); TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid"); TEST_RESULT_LOG( - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n" - "P00 WARN: 20181119-152138F/backup.manifest is missing or unusable, using copy\n" - "P00 ERROR: [028]: '20181119-152138F' may not be recoverable - PG data (id 0, version 9.4, system-id " + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n" + "P00 DETAIL: 20181119-152138F/backup.manifest is missing or unusable, using copy\n" + "P00 INFO: '20181119-152138F' may not be recoverable - PG data (id 0, version 9.4, system-id " HRN_PG_SYSTEMID_94_Z ") is not in the backup.info history, skipping"); //-------------------------------------------------------------------------------------------------------------------------- @@ -338,8 +343,8 @@ testRun(void) TEST_ASSIGN(manifest, verifyManifestFile(&backupResult, NULL, false, infoPg, &jobErrorTotal), "verify manifest"); TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid"); TEST_RESULT_LOG( - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n" - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n" + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " "<REPO:BACKUP>/20181119-152138F/backup.manifest.copy"); //-------------------------------------------------------------------------------------------------------------------------- @@ -353,9 +358,9 @@ testRun(void) TEST_RESULT_PTR(manifest, NULL, "manifest not set"); TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid"); TEST_RESULT_LOG( - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " "<REPO:BACKUP>/20181119-152138F/backup.manifest\n" - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " "<REPO:BACKUP>/20181119-152138F/backup.manifest.copy"); // Write a valid manifest with a manifest copy that is invalid @@ -378,7 +383,9 @@ testRun(void) TEST_ASSIGN(manifest, verifyManifestFile(&backupResult, NULL, true, infoPg, &jobErrorTotal), "verify manifest"); TEST_RESULT_PTR_NE(manifest, NULL, "manifest set"); TEST_RESULT_UINT(backupResult.status, backupValid, "manifest usable"); - TEST_RESULT_LOG("P00 WARN: backup '20181119-152138F' manifest.copy does not match manifest"); + TEST_RESULT_LOG("P00 DETAIL: backup '20181119-152138F' manifest.copy does not match manifest"); + + harnessLogLevelReset(); } // ***************************************************************************************************************************** @@ -426,7 +433,7 @@ testRun(void) TEST_RESULT_UINT(errTotal, 1, "duplicate WAL error"); TEST_RESULT_UINT(strLstSize(walFileList), 0, "all WAL removed from WAL file list"); TEST_RESULT_UINT(lstSize(archiveIdResult->walRangeList), 0, "no range"); - TEST_RESULT_LOG("P00 ERROR: [028]: duplicate WAL '000000020000000200000000' for '9.4-1' exists, skipping"); + TEST_RESULT_LOG("P00 INFO: duplicate WAL '000000020000000200000000' for '9.4-1' exists, skipping"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("FF Wal not skipped > 9.2, duplicates at beginning and end of list are removed"); @@ -453,8 +460,8 @@ testRun(void) TEST_RESULT_STR_Z(walRangeResult->start, "0000000200000001000000FD", "start range"); TEST_RESULT_STR_Z(walRangeResult->stop, "000000020000000200000000", "stop range"); TEST_RESULT_LOG( - "P00 ERROR: [028]: duplicate WAL '000000020000000100000000' for '9.4-1' exists, skipping\n" - "P00 ERROR: [028]: duplicate WAL '000000020000000200000001' for '9.4-1' exists, skipping"); + "P00 INFO: duplicate WAL '000000020000000100000000' for '9.4-1' exists, skipping\n" + "P00 INFO: duplicate WAL '000000020000000200000001' for '9.4-1' exists, skipping"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("FF Wal skipped <= 9.2, duplicates in middle of list removed"); @@ -484,8 +491,8 @@ testRun(void) TEST_RESULT_STR_Z(walRangeResult->stop, "000000020000000200000002", "stop range"); TEST_RESULT_LOG( - "P00 ERROR: [028]: invalid WAL '0000000200000001000000FF' for '9.2-1' exists, skipping\n" - "P00 ERROR: [028]: duplicate WAL '000000020000000200000001' for '9.2-1' exists, skipping"); + "P00 INFO: invalid WAL '0000000200000001000000FF' for '9.2-1' exists, skipping\n" + "P00 INFO: duplicate WAL '000000020000000200000001' for '9.2-1' exists, skipping"); TEST_RESULT_STRLST_Z( walFileList, @@ -645,7 +652,7 @@ testRun(void) "archive.info multi-history"); InfoPg *pgHistory = infoArchivePg(archiveInfo); - StringList *backupList= strLstNew(); + StringList *backupList = strLstNew(); strLstAddZ(backupList, "20181119-152138F"); strLstAddZ(backupList, "20181119-152900F"); StringList *archiveIdList = strLstComparatorSet(strLstNew(), archiveIdComparator); @@ -662,7 +669,7 @@ testRun(void) verifySetBackupCheckArchive(backupList, backupInfo, archiveIdList, pgHistory, &errTotal), "20181119-153000F", "current backup, missing archive"); TEST_RESULT_UINT(errTotal, 1, "error logged"); - TEST_RESULT_LOG("P00 ERROR: [044]: archiveIds '12-3' are not in the archive.info history list"); + TEST_RESULT_LOG("P00 INFO: archiveIds '12-3' are not in the archive.info history list"); errTotal = 0; strLstAddZ(archiveIdList, "13-4"); @@ -670,7 +677,7 @@ testRun(void) verifySetBackupCheckArchive(backupList, backupInfo, archiveIdList, pgHistory, &errTotal), "20181119-153000F", "test multiple archiveIds on disk not in archive.info"); TEST_RESULT_UINT(errTotal, 1, "error logged"); - TEST_RESULT_LOG("P00 ERROR: [044]: archiveIds '12-3, 13-4' are not in the archive.info history list"); + TEST_RESULT_LOG("P00 INFO: archiveIds '12-3, 13-4' are not in the archive.info history list"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("verifyLogInvalidResult() - missing file"); @@ -701,12 +708,11 @@ testRun(void) lstAdd(archiveIdResult.walRangeList, &walRange); lstAdd(archiveIdResultList, &archiveIdResult); + TEST_RESULT_STR_Z( - verifyRender(archiveIdResultList, backupResultList), - "Results:\n" - " archiveId: 9.6-1, total WAL checked: 1, total valid WAL: 0\n" - " missing: 0, checksum invalid: 0, size invalid: 0, other: 0\n" - " backup: none found", "archive: no invalid file list"); + verifyRender(archiveIdResultList, backupResultList, cfgOptionBool(cfgOptVerbose)), + "\n" + " archiveId: 9.6-1, total WAL checked: 1, total valid WAL: 0", "archive: no invalid file list"); VerifyInvalidFile invalidFile = { @@ -726,12 +732,12 @@ testRun(void) lstAdd(backupResultList, &backupResult); TEST_RESULT_STR_Z( - verifyRender(archiveIdResultList, backupResultList), - "Results:\n" + verifyRender(archiveIdResultList, backupResultList, cfgOptionBool(cfgOptVerbose)), + "\n" " archiveId: 9.6-1, total WAL checked: 1, total valid WAL: 0\n" - " missing: 1, checksum invalid: 0, size invalid: 0, other: 0\n" + " missing: 1\n" " backup: test-backup-label, status: invalid, total files checked: 1, total valid files: 0\n" - " missing: 1, checksum invalid: 0, size invalid: 0, other: 0", "archive file missing, backup file missing"); + " missing: 1", "archive file missing, backup file missing, no text, no verbose"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("verifyAddInvalidWalFile() - file missing (coverage test)"); @@ -751,15 +757,33 @@ testRun(void) TEST_TITLE("backup.info invalid checksum, neither backup copy nor archive infos exist"); HRN_STORAGE_PUT_Z(storageRepoWrite(), INFO_BACKUP_PATH_FILE, TEST_INVALID_BACKREST_INFO, .comment = "invalid backup.info"); - TEST_ERROR(cmdVerify(), RuntimeError, "2 fatal errors encountered, see log for details"); + + harnessLogLevelSet(logLevelDetail); + + // Redirect stdout to a file + int stdoutSave = dup(STDOUT_FILENO); + const String *stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS' " "<REPO:BACKUP>/backup.info\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info.copy' for read\n" - "P00 ERROR: [029]: No usable backup.info file\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info' for read\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info.copy' for read\n" - "P00 ERROR: [029]: No usable archive.info file"); + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info.copy' for read\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info' for read\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info.copy' for read\n" + "P00 INFO: stanza: db\n" + " status: error\n" + " No usable backup.info file\n" + " No usable archive.info file"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("backup.info invalid checksum, backup.info.copy valid, archive.info not exist, archive copy checksum invalid"); @@ -778,14 +802,30 @@ testRun(void) "[db:history]\n" TEST_BACKUP_DB1_HISTORY, .comment = "valid backup.info.copy"); - TEST_ERROR(cmdVerify(), RuntimeError, "1 fatal errors encountered, see log for details"); + + // Redirect stdout to a file + stdoutSave = dup(STDOUT_FILENO); + stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS'" + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS'" " <REPO:BACKUP>/backup.info\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info' for read\n" - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS'" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info' for read\n" + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS'" " <REPO:ARCHIVE>/archive.info.copy\n" - "P00 ERROR: [029]: No usable archive.info file"); + "P00 INFO: stanza: db\n" + " status: error\n" + " No usable archive.info file"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("backup.info and copy valid but checksum mismatch, archive.info checksum invalid, archive.info copy valid"); @@ -796,14 +836,30 @@ testRun(void) storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, TEST_INVALID_BACKREST_INFO, .comment = "invalid archive.info"); HRN_INFO_PUT( storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, TEST_ARCHIVE_INFO_BASE, .comment = "valid archive.info.copy"); - TEST_ERROR(cmdVerify(), RuntimeError, "1 fatal errors encountered, see log for details"); + + // Redirect stdout to a file + stdoutSave = dup(STDOUT_FILENO); + stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P00 WARN: backup.info.copy does not match backup.info\n" - "P00 WARN: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS'" + "P00 DETAIL: backup.info.copy does not match backup.info\n" + "P00 DETAIL: invalid checksum, actual 'e056f784a995841fd4e2802b809299b8db6803a2' but expected 'BOGUS'" " <REPO:ARCHIVE>/archive.info\n" - "P00 ERROR: [029]: backup info file and archive info file do not match\n" - " archive: id = 1, version = 9.4, system-id = " HRN_PG_SYSTEMID_94_Z "\n" - " backup : id = 2, version = 11, system-id = " HRN_PG_SYSTEMID_11_Z "\n" + "P00 INFO: stanza: db\n" + " status: error\n" + " backup info file and archive info file do not match\n" + " archive: id = 1, version = 9.4, system-id = 10000000000000090400\n" + " backup : id = 2, version = 11, system-id = 10000000000000110000\n" " HINT: this may be a symptom of repository corruption!"); //-------------------------------------------------------------------------------------------------------------------------- @@ -816,8 +872,7 @@ testRun(void) storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, .comment = "valid archive.info"); TEST_RESULT_VOID(cmdVerify(), "usable backup and archive info files"); TEST_RESULT_LOG( - "P00 WARN: archive.info.copy does not match archive.info\n" - "P00 WARN: no archives or backups exist in the repo"); + "P00 DETAIL: archive.info.copy does not match archive.info"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("backup.info valid, copy invalid, archive.info valid, copy invalid"); @@ -826,22 +881,42 @@ testRun(void) HRN_STORAGE_REMOVE(storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, .comment = "remove archive.info.copy"); TEST_RESULT_VOID(cmdVerify(), "usable backup and archive info files"); TEST_RESULT_LOG( - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info.copy' for read\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info.copy' for read\n" - "P00 WARN: no archives or backups exist in the repo"); + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info.copy' for read\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/archive/db/archive.info.copy' for read"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("backup.info and copy missing, archive.info and copy valid"); + hrnCfgArgRawZ(argList, cfgOptVerbose, "y"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + HRN_STORAGE_REMOVE(storageRepoWrite(), INFO_BACKUP_PATH_FILE); HRN_INFO_PUT( storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, .comment = "valid and matching archive.info.copy"); - TEST_ERROR(cmdVerify(), RuntimeError, "1 fatal errors encountered, see log for details"); + + // Redirect stdout to a file + stdoutSave = dup(STDOUT_FILENO); + stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info' for read\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info.copy' for read\n" - "P00 ERROR: [029]: No usable backup.info file"); + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info' for read\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/backup.info.copy' for read\n" + "P00 INFO: stanza: db\n" + " status: error\n" + " No usable backup.info file"); + + harnessLogLevelReset(); } // ***************************************************************************************************************************** @@ -943,15 +1018,27 @@ testRun(void) // Set log detail level to capture ranges (there should be none) harnessLogLevelSet(logLevelDetail); - TEST_ERROR(cmdVerify(), RuntimeError, "1 fatal errors encountered, see log for details"); + // Redirect stdout to a file + int stdoutSave = dup(STDOUT_FILENO); + const String *stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P00 WARN: no backups exist in the repo\n" - "P00 ERROR: [028]: duplicate WAL '000000020000000700000FFE' for '11-2' exists, skipping\n" - "P00 WARN: path '11-2/0000000200000007' does not contain any valid WAL to be processed\n" - "P00 INFO: Results:\n" - " archiveId: 11-2, total WAL checked: 2, total valid WAL: 0\n" - " missing: 0, checksum invalid: 0, size invalid: 0, other: 0\n" - " backup: none found"); + "P00 DETAIL: no backups exist in the repo\n" + "P00 INFO: duplicate WAL '000000020000000700000FFE' for '11-2' exists, skipping\n" + "P00 DETAIL: path '11-2/0000000200000007' does not contain any valid WAL to be processed\n" + "P00 INFO: stanza: db\n" + " status: error\n" + " archiveId: 11-2, total WAL checked: 2, total valid WAL: 0"); harnessLogLevelReset(); @@ -985,26 +1072,66 @@ testRun(void) harnessLogLevelSet(logLevelDetail); // Test verifyProcess directly - unsigned int errorTotal = 0; TEST_RESULT_STR_Z( - verifyProcess(&errorTotal), - "Results:\n" - " archiveId: 9.4-1, total WAL checked: 0, total valid WAL: 0\n" + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: error\n" " archiveId: 11-2, total WAL checked: 4, total valid WAL: 2\n" - " missing: 0, checksum invalid: 1, size invalid: 1, other: 0\n" - " backup: none found", - "verifyProcess() results"); - TEST_RESULT_UINT(errorTotal, 2, "errors"); + " checksum invalid: 1, size invalid: 1", "verifyProcess() no text, no verbose"); TEST_RESULT_LOG( - "P00 WARN: no backups exist in the repo\n" - "P00 WARN: archive path '9.4-1' is empty\n" - "P00 WARN: path '11-2/0000000100000000' does not contain any valid WAL to be processed\n" - "P01 ERROR: [028]: invalid checksum " + "P00 DETAIL: no backups exist in the repo\n" + "P00 DETAIL: archive path '9.4-1' is empty\n" + "P00 DETAIL: path '11-2/0000000100000000' does not contain any valid WAL to be processed\n" + "P01 INFO: invalid checksum " "'11-2/0000000200000007/000000020000000700000FFD-a6e1a64f0813352bc2e97f116a1800377e17d2e4.gz'\n" - "P01 ERROR: [028]: invalid size " + "P01 INFO: invalid size " "'11-2/0000000200000007/000000020000000700000FFF-ee161f898c9012dd0c28b3fd1e7140b9cf411306'\n" "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000700000FFD, wal stop: 000000020000000800000000"); + harnessLogLevelReset(); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("no text output, verbose, with verify failures"); + + hrnCfgArgRawZ(argList, cfgOptVerbose, "y"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Verify text output, verbose, with verify failures + TEST_RESULT_STR_Z( + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: error\n" + " archiveId: 9.4-1, total WAL checked: 0, total valid WAL: 0\n" + " archiveId: 11-2, total WAL checked: 4, total valid WAL: 2\n" + " missing: 0, checksum invalid: 1, size invalid: 1, other: 0\n" + " backup: none found" , "verbose, with failures"); + TEST_RESULT_LOG( + "P01 INFO: invalid checksum " + "'11-2/0000000200000007/000000020000000700000FFD-a6e1a64f0813352bc2e97f116a1800377e17d2e4.gz'\n" + "P01 INFO: invalid size " + "'11-2/0000000200000007/000000020000000700000FFF-ee161f898c9012dd0c28b3fd1e7140b9cf411306'"); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("text output, verbose, with verify failures"); + + hrnCfgArgRawZ(argList, cfgOptOutput, "text"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Verify text output, verbose, with verify failures + TEST_RESULT_STR_Z( + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: error\n" + " archiveId: 9.4-1, total WAL checked: 0, total valid WAL: 0\n" + " archiveId: 11-2, total WAL checked: 4, total valid WAL: 2\n" + " missing: 0, checksum invalid: 1, size invalid: 1, other: 0\n" + " backup: none found", "verify text output, verbose, with verify failures"); + TEST_RESULT_LOG( + "P01 INFO: invalid checksum " + "'11-2/0000000200000007/000000020000000700000FFD-a6e1a64f0813352bc2e97f116a1800377e17d2e4.gz'\n" + "P01 INFO: invalid size " + "'11-2/0000000200000007/000000020000000700000FFF-ee161f898c9012dd0c28b3fd1e7140b9cf411306'"); + //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("valid info files, start next timeline"); @@ -1028,12 +1155,39 @@ testRun(void) // Set log level to errors only harnessLogLevelSet(logLevelError); - TEST_ERROR(cmdVerify(), RuntimeError, "2 fatal errors encountered, see log for details"); - TEST_RESULT_LOG( - "P01 ERROR: [028]: invalid checksum " - "'11-2/0000000200000007/000000020000000700000FFD-a6e1a64f0813352bc2e97f116a1800377e17d2e4.gz'\n" - "P01 ERROR: [028]: invalid size " - "'11-2/0000000200000007/000000020000000700000FFF-ee161f898c9012dd0c28b3fd1e7140b9cf411306'"); + TEST_RESULT_BOOL(cfgOptionBool(cfgOptVerbose), false, "verbose is false"); + TEST_RESULT_BOOL((cfgOptionStrId(cfgOptOutput) == CFGOPTVAL_OUTPUT_TEXT), false, "text is false"); + + // Redirect stdout to a file + stdoutSave = dup(STDOUT_FILENO); + stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); + TEST_RESULT_LOG(""); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("none output, with verify failures"); + + hrnCfgArgRawZ(argList, cfgOptOutput, "none"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Verify none output + TEST_RESULT_STR_Z( + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: error\n" + " archiveId: 11-2, total WAL checked: 7, total valid WAL: 5\n" + " checksum invalid: 1, size invalid: 1", "verify none output"); + TEST_RESULT_LOG(""); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("valid info files - various archive/backup errors"); @@ -1160,52 +1314,104 @@ testRun(void) // Set log level to capture ranges harnessLogLevelSet(logLevelDetail); - TEST_ERROR(cmdVerify(), RuntimeError, "7 fatal errors encountered, see log for details"); + TEST_RESULT_BOOL(cfgOptionBool(cfgOptVerbose), false, "verbose is false"); + TEST_RESULT_BOOL((cfgOptionStrId(cfgOptOutput) == CFGOPTVAL_OUTPUT_TEXT), false, "text is false"); + + // Redirect stdout to a file + stdoutSave = dup(STDOUT_FILENO); + stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P00 WARN: archive path '9.4-1' is empty\n" - "P00 WARN: path '11-2/0000000100000000' does not contain any valid WAL to be processed\n" - "P01 ERROR: [028]: invalid checksum " + "P00 DETAIL: archive path '9.4-1' is empty\n" + "P00 DETAIL: path '11-2/0000000100000000' does not contain any valid WAL to be processed\n" + "P01 INFO: invalid checksum " "'11-2/0000000200000007/000000020000000700000FFD-a6e1a64f0813352bc2e97f116a1800377e17d2e4.gz'\n" - "P01 ERROR: [028]: invalid size " + "P01 INFO: invalid size " "'11-2/0000000200000007/000000020000000700000FFF-ee161f898c9012dd0c28b3fd1e7140b9cf411306'\n" - "P01 ERROR: [039]: invalid result " + "P01 INFO: invalid result " "11-2/0000000200000008/000000020000000800000003-656817043007aa2100c44c712bcb456db705dab9: [41] raised from " "local-1 shim protocol: unable to open file '" TEST_PATH "/repo/archive/db/" "11-2/0000000200000008/000000020000000800000003-656817043007aa2100c44c712bcb456db705dab9' for read:" " [13] Permission denied\n" " [FileOpenError] on retry after 0ms\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152800F/backup.manifest' for read\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152800F/backup.manifest.copy'" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152800F/backup.manifest' for read\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152800F/backup.manifest.copy'" " for read\n" - "P00 WARN: manifest missing for '20181119-152800F' - backup may have expired\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152810F/backup.manifest.copy'" + "P00 DETAIL: manifest missing for '20181119-152800F' - backup may have expired\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152810F/backup.manifest.copy'" " for read\n" - "P00 ERROR: [028]: backup '20181119-152810F' manifest does not contain any target files to verify\n" - "P01 ERROR: [028]: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" - "P01 ERROR: [028]: file missing '20181119-152900F_20181119-152909D/pg_data/testmissing'\n" - "P00 WARN: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-153000F/backup.manifest' for read\n" + "P00 INFO: backup '20181119-152810F' manifest does not contain any target files to verify\n" + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P01 INFO: file missing '20181119-152900F_20181119-152909D/pg_data/testmissing'\n" + "P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-153000F/backup.manifest' for read\n" "P00 INFO: backup '20181119-153000F' appears to be in progress, skipping\n" - "P01 ERROR: [039]: invalid result UNPROCESSEDBACKUP/pg_data/testother: [41] raised from local-1 shim protocol:" + "P01 INFO: invalid result UNPROCESSEDBACKUP/pg_data/testother: [41] raised from local-1 shim protocol:" " unable to open file '" TEST_PATH "/repo/backup/db/UNPROCESSEDBACKUP/pg_data/testother' for read: [13]" " Permission denied\n" " [FileOpenError] on retry after 0ms\n" "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000700000FFD, wal stop: 000000020000000800000000\n" "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000800000002, wal stop: 000000020000000800000003\n" "P00 DETAIL: archiveId: 11-2, wal start: 000000030000000000000000, wal stop: 000000030000000000000001\n" - "P00 INFO: Results:\n" - " archiveId: 9.4-1, total WAL checked: 0, total valid WAL: 0\n" + "P00 INFO: stanza: db\n" + " status: error\n" " archiveId: 11-2, total WAL checked: 8, total valid WAL: 5\n" - " missing: 0, checksum invalid: 1, size invalid: 1, other: 1\n" + " checksum invalid: 1, size invalid: 1, other: 1\n" " backup: 20181119-152800F, status: manifest missing, total files checked: 0, total valid files: 0\n" " backup: 20181119-152810F, status: invalid, total files checked: 0, total valid files: 0\n" " backup: 20181119-152900F, status: invalid, total files checked: 3, total valid files: 2\n" - " missing: 0, checksum invalid: 1, size invalid: 0, other: 0\n" - " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 5, " - "total valid files: 2\n" - " missing: 1, checksum invalid: 1, size invalid: 0, other: 1\n" - " backup: 20181119-153000F, status: in-progress, total files checked: 0, total valid files: 0"); + " checksum invalid: 1\n" + " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 5," + " total valid files: 2\n" + " missing: 1, checksum invalid: 1, other: 1"); harnessLogLevelReset(); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("text output, not verbose, with verify failures"); + + hrnCfgArgRawZ(argList, cfgOptOutput, "text"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Verify text output, not verbose, with failures + TEST_RESULT_STR_Z( + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: error\n" + " archiveId: 11-2, total WAL checked: 8, total valid WAL: 5\n" + " checksum invalid: 1, size invalid: 1, other: 1\n" + " backup: 20181119-152800F, status: manifest missing, total files checked: 0, total valid files: 0\n" + " backup: 20181119-152810F, status: invalid, total files checked: 0, total valid files: 0\n" + " backup: 20181119-152900F, status: invalid, total files checked: 3, total valid files: 2\n" + " checksum invalid: 1\n" + " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 5, total valid files: 2\n" + " missing: 1, checksum invalid: 1, other: 1", "verify text output, not verbose, with verify failures"); + TEST_RESULT_LOG( + "P01 INFO: invalid checksum " + "'11-2/0000000200000007/000000020000000700000FFD-a6e1a64f0813352bc2e97f116a1800377e17d2e4.gz'\n" + "P01 INFO: invalid size " + "'11-2/0000000200000007/000000020000000700000FFF-ee161f898c9012dd0c28b3fd1e7140b9cf411306'\n" + "P01 INFO: invalid result " + "11-2/0000000200000008/000000020000000800000003-656817043007aa2100c44c712bcb456db705dab9: [41] raised from " + "local-1 shim protocol: unable to open file '" TEST_PATH "/repo/archive/db/" + "11-2/0000000200000008/000000020000000800000003-656817043007aa2100c44c712bcb456db705dab9' for read:" + " [13] Permission denied\n" + "P00 INFO: backup '20181119-152810F' manifest does not contain any target files to verify\n" + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P01 INFO: file missing '20181119-152900F_20181119-152909D/pg_data/testmissing'\n" + "P00 INFO: backup '20181119-153000F' appears to be in progress, skipping\n" + "P01 INFO: invalid result UNPROCESSEDBACKUP/pg_data/testother: [41] raised from local-1 shim protocol:" + " unable to open file '" TEST_PATH "/repo/backup/db/UNPROCESSEDBACKUP/pg_data/testother' for read: [13]" + " Permission denied"); } // ***************************************************************************************************************************** @@ -1305,26 +1511,38 @@ testRun(void) storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F_20181119-152909D/" BACKUP_MANIFEST_FILE, TEST_MANIFEST_DIFF_DB1, .comment = "valid manifest - diff"); HRN_INFO_PUT( - storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F_20181119-152909D/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, TEST_MANIFEST_DIFF_DB1, .comment = "valid manifest copy - diff"); + storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F_20181119-152909D/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, + TEST_MANIFEST_DIFF_DB1, .comment = "valid manifest copy - diff"); // Put the file referenced by both backups into the full backup HRN_STORAGE_PUT_Z(storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F/pg_data/PG_VERSION", fileContents); - TEST_ERROR(cmdVerify(), RuntimeError, "2 fatal errors encountered, see log for details"); + // Redirect stdout to a file + int stdoutSave = dup(STDOUT_FILENO); + const String *stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); // The error for the referenced file is logged twice because it is checked again by the second backup since the first backup // verification had not yet completed before the second backup verification began TEST_RESULT_LOG( - "P00 WARN: no archives exist in the repo\n" - "P01 ERROR: [028]: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" - "P01 ERROR: [028]: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" - "P00 INFO: Results:\n" - " archiveId: none found\n" + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P00 INFO: stanza: db\n" + " status: error\n" " backup: 20181119-152900F, status: invalid, total files checked: 1, total valid files: 0\n" - " missing: 0, checksum invalid: 1, size invalid: 0, other: 0\n" - " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 1, total valid files: 0" - "\n" - " missing: 0, checksum invalid: 1, size invalid: 0, other: 0"); + " checksum invalid: 1\n" + " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 1," + " total valid files: 0\n" + " checksum invalid: 1"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("valid backup, prior backup verification complete - referenced file not checked"); @@ -1428,21 +1646,357 @@ testRun(void) strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-2/0000000200000000/000000020000000000000001-%s", walBufferSha1)), walBuffer, .comment = "valid WAL"); - TEST_ERROR(cmdVerify(), RuntimeError, "3 fatal errors encountered, see log for details"); + // Redirect stdout to a file + stdoutSave = dup(STDOUT_FILENO); + stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), "", .remove = true); TEST_RESULT_LOG( - "P01 ERROR: [028]: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" - "P01 ERROR: [028]: invalid size '20181119-152900F/pg_data/base/1/555_init'\n" - "P01 ERROR: [028]: file missing '20181119-152900F/pg_data/base/1/555_init.1'\n" - "P00 INFO: Results:\n" - " archiveId: 11-2, total WAL checked: 1, total valid WAL: 1\n" - " missing: 0, checksum invalid: 0, size invalid: 0, other: 0\n" + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P01 INFO: invalid size '20181119-152900F/pg_data/base/1/555_init'\n" + "P01 INFO: file missing '20181119-152900F/pg_data/base/1/555_init.1'\n" + "P00 INFO: stanza: db\n" + " status: error\n" " backup: 20181119-152900F, status: invalid, total files checked: 3, total valid files: 0\n" - " missing: 1, checksum invalid: 1, size invalid: 1, other: 0\n" - " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 1, total valid files: 0\n" + " missing: 1, checksum invalid: 1, size invalid: 1\n" + " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 1," + " total valid files: 0\n" + " checksum invalid: 1"); + } + // ***************************************************************************************************************************** + if (testBegin("cmdVerify() verbose text")) + { + // Load Parameters + StringList *argList = strLstDup(argListBase); + hrnCfgArgRawZ(argList, cfgOptOutput, "text"); + hrnCfgArgRawZ(argList, cfgOptVerbose, "y"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + #define TEST_BACKUP_DB1_CURRENT_FULL3_DIFF1 \ + "20181119-152900F_20181119-152909D={" \ + "\"backrest-format\":5,\"backrest-version\":\"2.08dev\"," \ + "\"backup-archive-start\":\"000000010000000000000006\",\"backup-archive-stop\":\"000000010000000000000007\"," \ + "\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186," \ + "\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900," \ + "\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\"," \ + "\"db-id\":1,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false," \ + "\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n" + + #define TEST_BACKUP_DB2_CURRENT_FULL1 \ + "20201119-163000F={" \ + "\"backrest-format\":5,\"backrest-version\":\"2.08dev\"," \ + "\"backup-archive-start\":\"000000020000000000000001\",\"backup-archive-stop\":\"000000020000000000000001\"," \ + "\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186," \ + "\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900," \ + "\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\"," \ + "\"db-id\":2,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false," \ + "\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n" + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("prior backup verification incomplete - referenced file checked verbose, text output"); + + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, .comment = "valid archive.info"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, + .comment = "valid archive.info.copy"); + + #define TEST_BACKUP_INFO \ + "[backup:current]\n" \ + TEST_BACKUP_DB1_CURRENT_FULL3 \ + TEST_BACKUP_DB1_CURRENT_FULL3_DIFF1 \ + TEST_BACKUP_DB2_CURRENT_FULL1 \ + "\n" \ + "[db]\n" \ + TEST_BACKUP_DB2_11 \ + "\n" \ + "[db:history]\n" \ + TEST_BACKUP_DB1_HISTORY \ + "\n" \ + TEST_BACKUP_DB2_HISTORY + + HRN_INFO_PUT(storageRepoWrite(), INFO_BACKUP_PATH_FILE, TEST_BACKUP_INFO); + HRN_INFO_PUT(storageRepoWrite(), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, TEST_BACKUP_INFO); + + // Create valid full backup for DB1 + #define TEST_MANIFEST_FULL_DB1 \ + TEST_MANIFEST_HEADER \ + TEST_MANIFEST_DB_94 \ + TEST_MANIFEST_OPTION_ALL \ + TEST_MANIFEST_TARGET \ + TEST_MANIFEST_DB \ + TEST_MANIFEST_FILE \ + TEST_MANIFEST_FILE_DEFAULT \ + TEST_MANIFEST_LINK \ + TEST_MANIFEST_LINK_DEFAULT \ + TEST_MANIFEST_PATH \ + TEST_MANIFEST_PATH_DEFAULT + + // Write manifests for full backup + HRN_INFO_PUT( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F/" BACKUP_MANIFEST_FILE, TEST_MANIFEST_FULL_DB1, + .comment = "valid manifest - full"); + HRN_INFO_PUT( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, TEST_MANIFEST_FULL_DB1, + .comment = "valid manifest copy - full"); + + // Create valid diff backup for DB1 + #define TEST_MANIFEST_DIFF_DB1 \ + TEST_MANIFEST_HEADER \ + TEST_MANIFEST_DB_94 \ + TEST_MANIFEST_OPTION_ALL \ + TEST_MANIFEST_TARGET \ + TEST_MANIFEST_DB \ + "\n" \ + "[target:file]\n" \ + "pg_data/PG_VERSION={\"checksum\":\"184473f470864e067ee3a22e64b47b0a1c356f29\",\"reference\":\"20181119-152900F\"" \ + ",\"size\":4,\"timestamp\":1565282114}\n" \ + TEST_MANIFEST_FILE_DEFAULT \ + TEST_MANIFEST_LINK \ + TEST_MANIFEST_LINK_DEFAULT \ + TEST_MANIFEST_PATH \ + TEST_MANIFEST_PATH_DEFAULT + + // Write manifests for diff backup + HRN_INFO_PUT( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F_20181119-152909D/" BACKUP_MANIFEST_FILE, + TEST_MANIFEST_DIFF_DB1, .comment = "valid manifest - diff"); + HRN_INFO_PUT( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F_20181119-152909D/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, + TEST_MANIFEST_DIFF_DB1, .comment = "valid manifest copy - diff"); + + // Put the file referenced by both backups into the full backup + HRN_STORAGE_PUT_Z(storageRepoWrite(), STORAGE_REPO_BACKUP "/20181119-152900F/pg_data/PG_VERSION", fileContents); + + // Redirect stdout to a file + int stdoutSave = dup(STDOUT_FILENO); + const String *stdoutFile = STRDEF(TEST_PATH "/stdout.info"); + + THROW_ON_SYS_ERROR(freopen(strZ(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout"); + + // Not in a test wrapper to avoid writing to stdout + cmdVerify(); + + // Restore normal stdout + dup2(stdoutSave, STDOUT_FILENO); + + // Check output of verify command stored in file + TEST_STORAGE_GET(storageTest, strZ(stdoutFile), + "stanza: db\n" + "status: error\n" + " archiveId: none found\n" + " backup: 20181119-152900F, status: invalid, total files checked: 1, total valid files: 0\n" + " missing: 0, checksum invalid: 1, size invalid: 0, other: 0\n" + " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 1, total valid files: 0\n" + " missing: 0, checksum invalid: 1, size invalid: 0, other: 0\n", .remove = true); + // The error for the referenced file is logged twice because it is checked again by the second backup since the first backup + // verification had not yet completed before the second backup verification began + TEST_RESULT_LOG( + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P01 INFO: invalid checksum '20181119-152900F/pg_data/PG_VERSION'\n" + "P00 INFO: stanza: db\n" + " status: error\n" + " archiveId: none found\n" + " backup: 20181119-152900F, status: invalid, total files checked: 1, total valid files: 0\n" " missing: 0, checksum invalid: 1, size invalid: 0, other: 0\n" - " backup: 20201119-163000F, status: valid, total files checked: 2, total valid files: 2\n" - " missing: 0, checksum invalid: 0, size invalid: 0, other: 0"); + " backup: 20181119-152900F_20181119-152909D, status: invalid, total files checked: 1," + " total valid files: 0\n" + " missing: 0, checksum invalid: 1, size invalid: 0, other: 0"); + } + + // ***************************************************************************************************************************** + if (testBegin("verifyProcess(), none output, not verbose, no failures")) + { + //-------------------------------------------------------------------------------------------------------------------------- + // Load Parameters with multi-repo + StringList *argList = strLstDup(argListBase); + hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 4, TEST_PATH "/repo4"); + hrnCfgArgRawZ(argList, cfgOptOutput, "none"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Store valid archive/backup info files + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, .comment = "valid archive.info"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, + .comment = "valid archive.info.copy"); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("none output, not verbose, with no verify failures"); + + #define TEST_NO_CURRENT_BACKUP \ + "[db]\n" \ + TEST_BACKUP_DB2_11 \ + "\n" \ + "[db:history]\n" \ + TEST_BACKUP_DB1_HISTORY \ + "\n" \ + TEST_BACKUP_DB2_HISTORY + + HRN_INFO_PUT(storageRepoWrite(), INFO_BACKUP_PATH_FILE, TEST_NO_CURRENT_BACKUP, .comment = "no current backups"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, TEST_NO_CURRENT_BACKUP, .comment = "no current backups copy"); + + // Create WAL file with just header info and small WAL size + Buffer *walBuffer = bufNew((size_t)(1024 * 1024)); + bufUsedSet(walBuffer, bufSize(walBuffer)); + memset(bufPtr(walBuffer), 0, bufSize(walBuffer)); + hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer); + const char *walBufferSha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer))); + + HRN_STORAGE_PUT( + storageRepoIdxWrite(0), + strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-2/0000000200000007/000000020000000700000FFE-%s", walBufferSha1)), walBuffer, + .comment = "valid WAL"); + + harnessLogLevelSet(logLevelDetail); + + // Verify text output with no verify errors + TEST_RESULT_STR_Z(verifyProcess(cfgOptionBool(cfgOptVerbose)), "", "verify none output, not verbose, with no failures"); + TEST_RESULT_LOG( + "P00 DETAIL: no backups exist in the repo\n" + "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000700000FFE, wal stop: 000000020000000700000FFE"); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("none output, verbose, with no verify failures"); + + hrnCfgArgRawZ(argList, cfgOptVerbose, "y"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + TEST_RESULT_STR_Z( + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: ok\n" + " archiveId: 11-2, total WAL checked: 1, total valid WAL: 1\n" + " missing: 0, checksum invalid: 0, size invalid: 0, other: 0\n" + " backup: none found", + "verify none output, verbose, with no failures"); + TEST_RESULT_LOG( + "P00 DETAIL: no backups exist in the repo\n" + "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000700000FFE, wal stop: 000000020000000700000FFE"); + } + + // ***************************************************************************************************************************** + if (testBegin("verifyProcess(), text")) + { + //-------------------------------------------------------------------------------------------------------------------------- + // Load Parameters with multi-repo + StringList *argList = strLstDup(argListBase); + hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 4, TEST_PATH "/repo4"); + hrnCfgArgRawZ(argList, cfgOptOutput, "text"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Store valid archive/backup info files + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, .comment = "valid archive.info"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, + .comment = "valid archive.info.copy"); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("text output, not verbose, with no verify failures"); + + #define TEST_NO_CURRENT_BACKUP \ + "[db]\n" \ + TEST_BACKUP_DB2_11 \ + "\n" \ + "[db:history]\n" \ + TEST_BACKUP_DB1_HISTORY \ + "\n" \ + TEST_BACKUP_DB2_HISTORY + + HRN_INFO_PUT(storageRepoWrite(), INFO_BACKUP_PATH_FILE, TEST_NO_CURRENT_BACKUP, .comment = "no current backups"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, TEST_NO_CURRENT_BACKUP, .comment = "no current backups copy"); + + // Create WAL file with just header info and small WAL size + Buffer *walBuffer = bufNew((size_t)(1024 * 1024)); + bufUsedSet(walBuffer, bufSize(walBuffer)); + memset(bufPtr(walBuffer), 0, bufSize(walBuffer)); + hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer); + const char *walBufferSha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer))); + + HRN_STORAGE_PUT( + storageRepoIdxWrite(0), + strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-2/0000000200000007/000000020000000700000FFE-%s", walBufferSha1)), walBuffer, + .comment = "valid WAL"); + + harnessLogLevelSet(logLevelDetail); + + // Verify text output with no verify errors + TEST_RESULT_STR_Z(verifyProcess(cfgOptionBool(cfgOptVerbose)), "", "verify text output, not verbose, with no failures"); + TEST_RESULT_LOG( + "P00 DETAIL: no backups exist in the repo\n" + "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000700000FFE, wal stop: 000000020000000700000FFE"); + } + + // ***************************************************************************************************************************** + if (testBegin("verifyProcess(), text, verbose")) + { + //-------------------------------------------------------------------------------------------------------------------------- + // Load Parameters with multi-repo + StringList *argList = strLstDup(argListBase); + hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 4, TEST_PATH "/repo4"); + hrnCfgArgRawZ(argList, cfgOptOutput, "text"); + hrnCfgArgRawZ(argList, cfgOptVerbose, "y"); + HRN_CFG_LOAD(cfgCmdVerify, argList); + + // Store valid archive/backup info files + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, .comment = "valid archive.info"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, TEST_ARCHIVE_INFO_MULTI_HISTORY_BASE, + .comment = "valid archive.info.copy"); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("text output, verbose with no verify failures"); + + #define TEST_NO_CURRENT_BACKUP \ + "[db]\n" \ + TEST_BACKUP_DB2_11 \ + "\n" \ + "[db:history]\n" \ + TEST_BACKUP_DB1_HISTORY \ + "\n" \ + TEST_BACKUP_DB2_HISTORY + + HRN_INFO_PUT(storageRepoWrite(), INFO_BACKUP_PATH_FILE, TEST_NO_CURRENT_BACKUP, .comment = "no current backups"); + HRN_INFO_PUT( + storageRepoWrite(), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, TEST_NO_CURRENT_BACKUP, .comment = "no current backups copy"); + + // Create WAL file with just header info and small WAL size + Buffer *walBuffer = bufNew((size_t)(1024 * 1024)); + bufUsedSet(walBuffer, bufSize(walBuffer)); + memset(bufPtr(walBuffer), 0, bufSize(walBuffer)); + hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer); + const char *walBufferSha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer))); + + HRN_STORAGE_PUT( + storageRepoIdxWrite(0), + strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-2/0000000200000007/000000020000000700000FFE-%s", walBufferSha1)), walBuffer, + .comment = "valid WAL"); + + harnessLogLevelSet(logLevelDetail); + + // Verify text output with no verify errors + TEST_RESULT_STR_Z( + verifyProcess(cfgOptionBool(cfgOptVerbose)), + "stanza: db\n" + "status: ok\n" + " archiveId: 11-2, total WAL checked: 1, total valid WAL: 1\n" + " missing: 0, checksum invalid: 0, size invalid: 0, other: 0\n" + " backup: none found", "verify text output, verbose, with no failures"); + TEST_RESULT_LOG( + "P00 DETAIL: no backups exist in the repo\n" + "P00 DETAIL: archiveId: 11-2, wal start: 000000020000000700000FFE, wal stop: 000000020000000700000FFE"); } FUNCTION_HARNESS_RETURN_VOID(); [parent: f405fc6ae281]