1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Convert BackupType enum to StringId.

Allows removal of backupType()/backupTypeStr() and improves debug logging of the enum.

Move BackupType enum and string constants to info/infoBackup.h so they are available to more modules. Also convert InfoBackup to use BackupType instead of a String.
This commit is contained in:
David Steele
2021-05-03 12:15:39 -04:00
committed by GitHub
parent 568dc0ba0c
commit 87df6d7a58
17 changed files with 129 additions and 182 deletions

View File

@ -99,6 +99,9 @@
<commit subject="Convert ArchivePushFileIoType enum to StringId."/>
<commit subject="Update IoClient/IoSession to use StringIds."/>
<commit subject="Convert InfoPgType enum to StringId."/>
<commit subject="Convert BackupType enum to StringId.">
<github-pull-request id="1385"/>
</commit>
<release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/>

View File

@ -43,7 +43,7 @@ static String *
backupLabelFormat(BackupType type, const String *backupLabelPrior, time_t timestamp)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, type);
FUNCTION_LOG_PARAM(STRING_ID, type);
FUNCTION_LOG_PARAM(STRING, backupLabelPrior);
FUNCTION_LOG_PARAM(TIME, timestamp);
FUNCTION_LOG_END();
@ -80,7 +80,7 @@ static String *
backupLabelCreate(BackupType type, const String *backupLabelPrior, time_t timestamp)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ENUM, type);
FUNCTION_LOG_PARAM(STRING_ID, type);
FUNCTION_LOG_PARAM(STRING, backupLabelPrior);
FUNCTION_LOG_PARAM(TIME, timestamp);
FUNCTION_LOG_END();
@ -365,7 +365,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
Manifest *result = NULL;
// No incremental if backup type is full
BackupType type = backupType(cfgOptionStr(cfgOptType));
BackupType type = (BackupType)cfgOptionStrId(cfgOptType);
if (type != backupTypeFull)
{
@ -380,7 +380,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
InfoBackupData backupPrior = infoBackupData(infoBackup, backupIdx);
// The prior backup for a diff must be full
if (type == backupTypeDiff && backupType(backupPrior.backupType) != backupTypeFull)
if (type == backupTypeDiff && backupPrior.backupType != backupTypeFull)
continue;
// The backups must come from the same cluster ??? This should enable delta instead
@ -466,7 +466,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
else
{
LOG_WARN_FMT("no prior backup exists, %s backup has been changed to full", strZ(cfgOptionDisplay(cfgOptType)));
cfgOptionSet(cfgOptType, cfgSourceParam, VARSTR(backupTypeStr(backupTypeFull)));
cfgOptionSet(cfgOptType, cfgSourceParam, VARSTR(strIdToStr(backupTypeFull)));
}
}
MEM_CONTEXT_TEMP_END();
@ -499,7 +499,7 @@ backupBuildIncr(const InfoBackup *infoBackup, Manifest *manifest, Manifest *mani
manifestMove(manifestPrior, MEM_CONTEXT_TEMP());
// Build incremental manifest
manifestBuildIncr(manifest, manifestPrior, backupType(cfgOptionStr(cfgOptType)), archiveStart);
manifestBuildIncr(manifest, manifestPrior, (BackupType)cfgOptionStrId(cfgOptType), archiveStart);
// Set the cipher subpass from prior manifest since we want a single subpass for the entire backup set
manifestCipherSubPassSet(manifest, manifestCipherSubPass(manifestPrior));
@ -720,11 +720,11 @@ backupResumeFind(const Manifest *manifest, const String *cipherPassBackup)
strZ(manifestData(manifest)->backrestVersion), strZ(manifestResumeData->backrestVersion));
}
// Check backup type because new backup label must be the same type as resume backup label
else if (manifestResumeData->backupType != backupType(cfgOptionStr(cfgOptType)))
else if (manifestResumeData->backupType != cfgOptionStrId(cfgOptType))
{
reason = strNewFmt(
"new backup type '%s' does not match resumable backup type '%s'",
strZ(cfgOptionDisplay(cfgOptType)), strZ(backupTypeStr(manifestResumeData->backupType)));
strZ(cfgOptionDisplay(cfgOptType)), strZ(strIdToStr(manifestResumeData->backupType)));
}
// Check prior backup label ??? Do we really care about the prior backup label?
else if (!strEq(manifestResumeData->backupLabelPrior, manifestData(manifest)->backupLabelPrior))
@ -1711,7 +1711,7 @@ backupProcess(BackupData *backupData, Manifest *manifest, const String *lsnStart
}
}
LOG_INFO_FMT("%s backup size = %s", strZ(backupTypeStr(backupType)), strZ(strSizeFormat(sizeTotal)));
LOG_INFO_FMT("%s backup size = %s", strZ(strIdToStr(backupType)), strZ(strSizeFormat(sizeTotal)));
}
MEM_CONTEXT_TEMP_END();
@ -1991,7 +1991,8 @@ cmdBackup(void)
{
manifestBackupLabelSet(
manifest,
backupLabelCreate(backupType(cfgOptionStr(cfgOptType)), manifestData(manifest)->backupLabelPrior, timestampStart));
backupLabelCreate(
(BackupType)cfgOptionStrId(cfgOptType), manifestData(manifest)->backupLabelPrior, timestampStart));
}
// Save the manifest before processing starts

View File

@ -16,10 +16,6 @@ Constants
#define DATE_TIME_REGEX "[0-9]{8}\\-[0-9]{6}"
#define BACKUP_LINK_LATEST "latest"
STRING_EXTERN(BACKUP_TYPE_FULL_STR, BACKUP_TYPE_FULL);
STRING_EXTERN(BACKUP_TYPE_DIFF_STR, BACKUP_TYPE_DIFF);
STRING_EXTERN(BACKUP_TYPE_INCR_STR, BACKUP_TYPE_INCR);
/**********************************************************************************************************************************/
String *
backupRegExp(BackupRegExpParam param)
@ -85,58 +81,6 @@ backupRegExp(BackupRegExpParam param)
FUNCTION_LOG_RETURN(STRING, result);
}
/**********************************************************************************************************************************/
BackupType
backupType(const String *type)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, type);
FUNCTION_TEST_END();
ASSERT(type != NULL);
BackupType result;
if (strEq(type, BACKUP_TYPE_FULL_STR))
result = backupTypeFull;
else if (strEq(type, BACKUP_TYPE_DIFF_STR))
result = backupTypeDiff;
else if (strEq(type, BACKUP_TYPE_INCR_STR))
result = backupTypeIncr;
else
THROW_FMT(AssertError, "invalid backup type '%s'", strZ(type));
FUNCTION_TEST_RETURN(result);
}
const String *backupTypeStr(BackupType type)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, type);
FUNCTION_TEST_END();
ASSERT(type <= backupTypeIncr);
const String *result = NULL;
switch (type)
{
case backupTypeFull:
result = BACKUP_TYPE_FULL_STR;
break;
case backupTypeDiff:
result = BACKUP_TYPE_DIFF_STR;
break;
case backupTypeIncr:
result = BACKUP_TYPE_INCR_STR;
break;
}
FUNCTION_TEST_RETURN(result);
}
/**********************************************************************************************************************************/
void
backupLinkLatest(const String *backupLabel, unsigned int repoIdx)

View File

@ -13,23 +13,6 @@ Backup constants
***********************************************************************************************************************************/
#define BACKUP_PATH_HISTORY "backup.history"
/***********************************************************************************************************************************
Backup type enum and constants
***********************************************************************************************************************************/
typedef enum
{
backupTypeFull,
backupTypeDiff,
backupTypeIncr,
} BackupType;
#define BACKUP_TYPE_FULL "full"
STRING_DECLARE(BACKUP_TYPE_FULL_STR);
#define BACKUP_TYPE_DIFF "diff"
STRING_DECLARE(BACKUP_TYPE_DIFF_STR);
#define BACKUP_TYPE_INCR "incr"
STRING_DECLARE(BACKUP_TYPE_INCR_STR);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
@ -47,10 +30,6 @@ typedef struct BackupRegExpParam
String *backupRegExp(BackupRegExpParam param);
// Convert text backup type to an enum and back
BackupType backupType(const String *type);
const String *backupTypeStr(BackupType type);
// Create a symlink to the specified backup (if symlinks are supported)
void backupLinkLatest(const String *backupLabel, unsigned int repoIdx);

View File

@ -332,7 +332,7 @@ expireTimeBasedBackup(InfoBackup *infoBackup, const time_t minTimestamp, unsigne
(strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", ")));
}
if (strEqZ(cfgOptionIdxStr(cfgOptRepoRetentionArchiveType, repoIdx), CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_FULL) &&
if (cfgOptionIdxStrId(cfgOptRepoRetentionArchiveType, repoIdx) == backupTypeFull &&
!cfgOptionIdxTest(cfgOptRepoRetentionArchive, repoIdx) && numFullExpired > 0)
{
cfgOptionIdxSet(
@ -380,7 +380,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
MEM_CONTEXT_TEMP_BEGIN()
{
// Get the retention options. repo-archive-retention-type always has a value as it defaults to "full"
const String *archiveRetentionType = cfgOptionIdxStr(cfgOptRepoRetentionArchiveType, repoIdx);
const BackupType archiveRetentionType = (BackupType)cfgOptionIdxStrId(cfgOptRepoRetentionArchiveType, repoIdx);
unsigned int archiveRetention = cfgOptionIdxTest(
cfgOptRepoRetentionArchive, repoIdx) ? cfgOptionIdxUInt(cfgOptRepoRetentionArchive, repoIdx) : 0;
@ -406,21 +406,24 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
// remaining non-expired backups, from newest to oldest, based on the type.
StringList *globalBackupRetentionList = NULL;
if (strCmp(archiveRetentionType, STRDEF(CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_FULL)) == 0)
switch (archiveRetentionType)
{
case backupTypeFull:
globalBackupRetentionList = strLstSort(
infoBackupDataLabelList(infoBackup, backupRegExpP(.full = true)), sortOrderDesc);
}
else if (strCmp(archiveRetentionType, STRDEF(CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_DIFF)) == 0)
{
break;
case backupTypeDiff:
globalBackupRetentionList = strLstSort(
infoBackupDataLabelList(infoBackup, backupRegExpP(.full = true, .differential = true)), sortOrderDesc);
}
else
{ // Incrementals can depend on Full or Diff so get a list of all incrementals
break;
case backupTypeIncr:
// Incrementals can depend on Full or Diff so get a list of all incrementals
globalBackupRetentionList = strLstSort(
infoBackupDataLabelList(infoBackup, backupRegExpP(.full = true, .differential = true, .incremental = true)),
sortOrderDesc);
break;
}
// Expire archives. If no backups were found or the number of backups found is not enough to satify archive retention

View File

@ -398,7 +398,7 @@ backupListAdd(
// main keys
kvPut(varKv(backupInfo), BACKUP_KEY_LABEL_VAR, VARSTR(backupData->backupLabel));
kvPut(varKv(backupInfo), BACKUP_KEY_TYPE_VAR, VARSTR(backupData->backupType));
kvPut(varKv(backupInfo), BACKUP_KEY_TYPE_VAR, VARSTR(strIdToStr(backupData->backupType)));
kvPut(
varKv(backupInfo), BACKUP_KEY_PRIOR_VAR,
(backupData->backupPrior != NULL ? VARSTR(backupData->backupPrior) : NULL));

View File

@ -13,6 +13,10 @@ strIdFromStr("mytest0123a") will return the StringId 0x7de75c51315464d5. Using t
strIdToStr(0x7de75c51315464d5) which returns "mytest0123+" where the plus at the end signals that the original string was equal to
or longer than the maximum allowed.
When assigning a StringId to an enum, it will be necessary to cast the StringId to the enum type if the enum contains all 32-bit
values, since some compilers will complain about the implicit conversion without a cast. The enum will be 32-bit if all values of
the enum are <= 0xffffffff.
See strIdGenerate() for information on StringId constants.
***********************************************************************************************************************************/
#ifndef COMMON_TYPE_STRINGID_H

View File

@ -47,10 +47,6 @@ Constants
Constants for configuration options.
***********************************************************************************************************************************/
#define CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_DIFF "diff"
#define CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_FULL "full"
#define CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_INCR "incr"
#define CFGOPTVAL_TMP_REPO_RETENTION_FULL_TYPE_COUNT "count"
#define CFGOPTVAL_TMP_REPO_RETENTION_FULL_TYPE_TIME "time"

View File

@ -19,6 +19,7 @@ Configuration Load
#include "config/config.intern.h"
#include "config/load.h"
#include "config/parse.h"
#include "info/infoBackup.h"
#include "storage/cifs/storage.h"
#include "storage/posix/storage.h"
#include "storage/helper.h"
@ -198,11 +199,11 @@ cfgLoadUpdateOption(void)
// For each possible repo, check and adjust the settings as appropriate
for (unsigned int optionIdx = 0; optionIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); optionIdx++)
{
const String *archiveRetentionType = cfgOptionIdxStr(cfgOptRepoRetentionArchiveType, optionIdx);
const BackupType archiveRetentionType = (BackupType)cfgOptionIdxStrId(cfgOptRepoRetentionArchiveType, optionIdx);
const String *msgArchiveOff = strNewFmt(
"WAL segments will not be expired: option '%s=%s' but", cfgOptionIdxName(cfgOptRepoRetentionArchiveType, optionIdx),
strZ(archiveRetentionType));
strZ(strIdToStr(archiveRetentionType)));
// If the archive retention is not explicitly set then determine what it should be defaulted to
if (!cfgOptionIdxTest(cfgOptRepoRetentionArchive, optionIdx))
@ -210,7 +211,9 @@ cfgLoadUpdateOption(void)
// If repo-retention-archive-type is default (full), then if repo-retention-full is set, set the
// repo-retention-archive to this value when retention-full-type is 'count', else ignore archiving. If
// retention-full-type is 'time' then the the expire command will default the archive retention accordingly.
if (strEqZ(archiveRetentionType, CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_FULL))
switch (archiveRetentionType)
{
case backupTypeFull:
{
if (strEqZ(
cfgOptionIdxStr(cfgOptRepoRetentionFullType, optionIdx),
@ -220,8 +223,11 @@ cfgLoadUpdateOption(void)
cfgOptionIdxSet(cfgOptRepoRetentionArchive, optionIdx, cfgSourceDefault,
VARUINT(cfgOptionIdxUInt(cfgOptRepoRetentionFull, optionIdx)));
}
break;
}
else if (strEqZ(archiveRetentionType, CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_DIFF))
case backupTypeDiff:
{
// if repo-retention-diff is set then user must have set it
if (cfgOptionIdxTest(cfgOptRepoRetentionDiff, optionIdx))
@ -236,14 +242,15 @@ cfgLoadUpdateOption(void)
cfgOptionIdxName(cfgOptRepoRetentionArchive, optionIdx),
cfgOptionIdxName(cfgOptRepoRetentionDiff, optionIdx));
}
}
else
{
CHECK(strEqZ(archiveRetentionType, CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_INCR));
break;
}
case backupTypeIncr:
LOG_WARN_FMT(
"%s option '%s' is not set", strZ(msgArchiveOff),
cfgOptionIdxName(cfgOptRepoRetentionArchive, optionIdx));
break;
}
}
else
@ -251,14 +258,14 @@ cfgLoadUpdateOption(void)
// If repo-retention-archive is set then check repo-retention-archive-type and issue a warning if the
// corresponding setting is UNDEF since UNDEF means backups will not be expired but they should be in the
// practice of setting this value even though expiring the archive itself is OK and will be performed.
if ((strEqZ(archiveRetentionType, CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_DIFF)) &&
(!cfgOptionIdxTest(cfgOptRepoRetentionDiff, optionIdx)))
if (archiveRetentionType == backupTypeDiff && !cfgOptionIdxTest(cfgOptRepoRetentionDiff, optionIdx))
{
LOG_WARN_FMT("option '%s' is not set for '%s=%s'\n"
LOG_WARN_FMT(
"option '%s' is not set for '%s=%s'\n"
"HINT: to retain differential backups indefinitely (without warning), set option '%s' to the maximum.",
cfgOptionIdxName(cfgOptRepoRetentionDiff, optionIdx),
cfgOptionIdxName(cfgOptRepoRetentionArchiveType, optionIdx),
CFGOPTVAL_TMP_REPO_RETENTION_ARCHIVE_TYPE_DIFF,
strZ(strIdToStr(backupTypeDiff)),
cfgOptionIdxName(cfgOptRepoRetentionDiff, optionIdx));
}
}

View File

@ -154,7 +154,7 @@ infoBackupLoadCallback(void *data, const String *section, const String *key, con
// When reading timestamps, read as uint64 to ensure always positive value (guarantee no backups before 1970)
.backupTimestampStart = (time_t)varUInt64(kvGet(backupKv, INFO_BACKUP_KEY_BACKUP_TIMESTAMP_START_VAR)),
.backupTimestampStop= (time_t)varUInt64(kvGet(backupKv, INFO_BACKUP_KEY_BACKUP_TIMESTAMP_STOP_VAR)),
.backupType = varStrForce(kvGet(backupKv, INFO_BACKUP_KEY_BACKUP_TYPE_VAR)),
.backupType = (BackupType)strIdFromStr(stringIdBit5, varStr(kvGet(backupKv, INFO_BACKUP_KEY_BACKUP_TYPE_VAR))),
// Possible NULL values
.backupArchiveStart = strDup(varStr(kvGet(backupKv, INFO_BACKUP_KEY_BACKUP_ARCHIVE_START_VAR))),
@ -174,6 +174,10 @@ infoBackupLoadCallback(void *data, const String *section, const String *key, con
.optionOnline = varBool(kvGet(backupKv, INFO_BACKUP_KEY_OPT_ONLINE_VAR)),
};
ASSERT(
infoBackupData.backupType == backupTypeFull || infoBackupData.backupType == backupTypeDiff ||
infoBackupData.backupType == backupTypeIncr);
// Add the backup data to the list
lstAdd(infoBackup->pub.backup, &infoBackupData);
}
@ -255,7 +259,7 @@ infoBackupSaveCallback(void *data, const String *sectionNext, InfoSave *infoSave
// When storing time_t treat as signed int to avoid casting
kvPut(backupDataKv, INFO_BACKUP_KEY_BACKUP_TIMESTAMP_START_VAR, VARINT64(backupData.backupTimestampStart));
kvPut(backupDataKv, INFO_BACKUP_KEY_BACKUP_TIMESTAMP_STOP_VAR, VARINT64(backupData.backupTimestampStop));
kvPut(backupDataKv, INFO_BACKUP_KEY_BACKUP_TYPE_VAR, VARSTR(backupData.backupType));
kvPut(backupDataKv, INFO_BACKUP_KEY_BACKUP_TYPE_VAR, VARSTR(strIdToStr(backupData.backupType)));
kvPut(backupDataKv, INFO_BACKUP_KEY_OPT_ARCHIVE_CHECK_VAR, VARBOOL(backupData.optionArchiveCheck));
kvPut(backupDataKv, INFO_BACKUP_KEY_OPT_ARCHIVE_COPY_VAR, VARBOOL(backupData.optionArchiveCopy));
@ -377,7 +381,7 @@ infoBackupDataAdd(const InfoBackup *this, const Manifest *manifest)
.backupPgId = manData->pgId,
.backupTimestampStart = manData->backupTimestampStart,
.backupTimestampStop= manData->backupTimestampStop,
.backupType = backupTypeStr(manData->backupType),
.backupType = manData->backupType,
.backupArchiveStart = strDup(manData->archiveStart),
.backupArchiveStop = strDup(manData->archiveStop),

View File

@ -4,11 +4,23 @@ Backup Info Handler
#ifndef INFO_INFOBACKUP_H
#define INFO_INFOBACKUP_H
#include "common/type/stringId.h"
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
typedef struct InfoBackup InfoBackup;
/***********************************************************************************************************************************
Backup type enum
***********************************************************************************************************************************/
typedef enum
{
backupTypeFull = STRID5("full", 0x632a60),
backupTypeDiff = STRID5("diff", 0x319240),
backupTypeIncr = STRID5("incr", 0x90dc90),
} BackupType;
#include "common/type/object.h"
#include "common/type/string.h"
#include "common/type/stringList.h"
@ -45,7 +57,7 @@ typedef struct InfoBackupData
StringList *backupReference;
time_t backupTimestampStart;
time_t backupTimestampStop;
const String *backupType;
BackupType backupType;
bool optionArchiveCheck;
bool optionArchiveCopy;
bool optionBackupStandby;

View File

@ -868,6 +868,7 @@ manifestNewBuild(
this->pub.data.backrestVersion = strNew(PROJECT_VERSION);
this->pub.data.pgVersion = pgVersion;
this->pub.data.pgCatalogVersion = pgCatalogVersion;
this->pub.data.backupType = backupTypeFull;
this->pub.data.backupOptionOnline = online;
this->pub.data.backupOptionChecksumPage = varNewBool(checksumPage);
@ -1113,7 +1114,7 @@ manifestBuildIncr(Manifest *this, const Manifest *manifestPrior, BackupType type
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(MANIFEST, this);
FUNCTION_LOG_PARAM(MANIFEST, manifestPrior);
FUNCTION_LOG_PARAM(ENUM, type);
FUNCTION_LOG_PARAM(STRING_ID, type);
FUNCTION_LOG_PARAM(STRING, archiveStart);
FUNCTION_LOG_END();
@ -1658,7 +1659,12 @@ manifestLoadCallback(void *callbackData, const String *section, const String *ke
else if (strEq(key, MANIFEST_KEY_BACKUP_TIMESTAMP_STOP_STR))
manifest->pub.data.backupTimestampStop = (time_t)varUInt64(value);
else if (strEq(key, MANIFEST_KEY_BACKUP_TYPE_STR))
manifest->pub.data.backupType = backupType(varStr(value));
{
manifest->pub.data.backupType = (BackupType)strIdFromStr(stringIdBit5, varStr(value));
ASSERT(
manifest->pub.data.backupType == backupTypeFull || manifest->pub.data.backupType == backupTypeDiff ||
manifest->pub.data.backupType == backupTypeIncr);
}
}
MEM_CONTEXT_END();
}
@ -1920,7 +1926,7 @@ manifestSaveCallback(void *callbackData, const String *sectionNext, InfoSave *in
jsonFromInt64(manifest->pub.data.backupTimestampStop));
infoSaveValue(
infoSaveData, MANIFEST_SECTION_BACKUP_STR, MANIFEST_KEY_BACKUP_TYPE_STR,
jsonFromStr(backupTypeStr(manifest->pub.data.backupType)));
jsonFromStr(strIdToStr(manifest->pub.data.backupType)));
}
// -----------------------------------------------------------------------------------------------------------------------------

View File

@ -34,6 +34,7 @@ typedef struct Manifest Manifest;
#include "common/crypto/hash.h"
#include "common/type/object.h"
#include "info/info.h"
#include "info/infoBackup.h"
#include "storage/storage.h"
/***********************************************************************************************************************************

View File

@ -768,7 +768,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: backup-common
total: 3
total: 2
coverage:
- command/backup/common

View File

@ -311,18 +311,5 @@ testRun(void)
TEST_ERROR(ioWrite(write, buffer), AssertError, "should not be possible to see two misaligned pages in a row");
}
// *****************************************************************************************************************************
if (testBegin("backupType() and backupTypeStr()"))
{
TEST_RESULT_UINT(backupType(strNew("full")), backupTypeFull, "backup type full");
TEST_RESULT_UINT(backupType(strNew("diff")), backupTypeDiff, "backup type diff");
TEST_RESULT_UINT(backupType(strNew("incr")), backupTypeIncr, "backup type incr");
TEST_ERROR(backupType(strNew("bogus")), AssertError, "invalid backup type 'bogus'");
TEST_RESULT_STR_Z(backupTypeStr(backupTypeFull), "full", "backup type str full");
TEST_RESULT_STR_Z(backupTypeStr(backupTypeDiff), "diff", "backup type str diff");
TEST_RESULT_STR_Z(backupTypeStr(backupTypeIncr), "incr", "backup type str incr");
}
FUNCTION_HARNESS_RETURN_VOID();
}

View File

@ -1240,7 +1240,7 @@ testRun(void)
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRawZ(argList, cfgOptPgPath, "/pg");
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_FULL);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeFull);
strLstAddZ(argList, "--no-" CFGOPT_COMPRESS);
harnessCfgLoad(cfgCmdBackup, argList);
@ -1512,7 +1512,7 @@ testRun(void)
strLstAddZ(argList, "--no-" CFGOPT_ONLINE);
strLstAddZ(argList, "--" CFGOPT_COMPRESS);
hrnCfgArgRawBool(argList, cfgOptRepoHardlink, true);
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_DIFF);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeDiff);
harnessCfgLoad(cfgCmdBackup, argList);
TEST_ERROR(cmdBackup(), FileMissingError, "no files have changed since the last backup - this seems unlikely");
@ -1533,7 +1533,7 @@ testRun(void)
strLstAddZ(argList, "--no-" CFGOPT_ONLINE);
strLstAddZ(argList, "--no-" CFGOPT_COMPRESS);
strLstAddZ(argList, "--" CFGOPT_CHECKSUM_PAGE);
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_INCR);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeIncr);
harnessCfgLoad(cfgCmdBackup, argList);
storagePutP(storageNewWriteP(storagePgWrite(), PG_FILE_PGVERSION_STR), BUFSTRDEF("VER"));
@ -1560,7 +1560,7 @@ testRun(void)
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--no-" CFGOPT_ONLINE);
strLstAddZ(argList, "--no-" CFGOPT_COMPRESS);
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_DIFF);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeDiff);
harnessCfgLoad(cfgCmdBackup, argList);
sleepMSec(MSEC_PER_SEC - (timeMSec() % MSEC_PER_SEC));
@ -1598,7 +1598,7 @@ testRun(void)
// With repo2 the only repo configured, ensure it is chosen by confirming diff is changed to full due to no prior backups
hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionFull, 2, "1");
hrnCfgArgRawZ(argList, cfgOptType, BACKUP_TYPE_DIFF);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeDiff);
harnessCfgLoad(cfgCmdBackup, argList);
TEST_RESULT_VOID(cmdBackup(), "backup");
@ -1706,7 +1706,7 @@ testRun(void)
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_FULL);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeFull);
strLstAddZ(argList, "--" CFGOPT_STOP_AUTO);
strLstAddZ(argList, "--no-" CFGOPT_COMPRESS);
strLstAddZ(argList, "--no-" CFGOPT_ARCHIVE_CHECK);
@ -1803,7 +1803,7 @@ testRun(void)
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_FULL);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeFull);
strLstAddZ(argList, "--" CFGOPT_STOP_AUTO);
hrnCfgArgRawBool(argList, cfgOptRepoHardlink, true);
strLstAddZ(argList, "--" CFGOPT_ARCHIVE_COPY);
@ -1993,7 +1993,7 @@ testRun(void)
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_DIFF);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeDiff);
strLstAddZ(argList, "--no-" CFGOPT_COMPRESS);
strLstAddZ(argList, "--" CFGOPT_STOP_AUTO);
hrnCfgArgRawBool(argList, cfgOptRepoHardlink, true);
@ -2322,7 +2322,7 @@ testRun(void)
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_FULL);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeFull);
hrnCfgArgRawBool(argList, cfgOptRepoHardlink, true);
strLstAddZ(argList, "--" CFGOPT_MANIFEST_SAVE_THRESHOLD "=1");
strLstAddZ(argList, "--" CFGOPT_ARCHIVE_COPY);
@ -2513,7 +2513,7 @@ testRun(void)
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_INCR);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeIncr);
hrnCfgArgRawBool(argList, cfgOptRepoHardlink, true);
harnessCfgLoad(cfgCmdBackup, argList);
@ -2551,7 +2551,7 @@ testRun(void)
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, "--" CFGOPT_TYPE "=" BACKUP_TYPE_INCR);
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeIncr);
strLstAddZ(argList, "--" CFGOPT_DELTA);
hrnCfgArgRawBool(argList, cfgOptRepoHardlink, true);
harnessCfgLoad(cfgCmdBackup, argList);

View File

@ -150,7 +150,7 @@ testRun(void)
InfoBackupData backupData = infoBackupData(infoBackup, 0);
TEST_RESULT_STR_Z(backupData.backupLabel, "20161219-212741F", "full backup label");
TEST_RESULT_STR_Z(backupData.backupType, "full", " backup type full");
TEST_RESULT_UINT(backupData.backupType, backupTypeFull, " backup type full");
TEST_RESULT_INT(backupData.backrestFormat, 5, " backrest format");
TEST_RESULT_STR_Z(backupData.backrestVersion, "2.04", " backrest version");
TEST_RESULT_STR_Z(backupData.backupArchiveStart, "00000007000000000000001C", " archive start");
@ -167,7 +167,7 @@ testRun(void)
InfoBackupData *backupDataPtr = infoBackupDataByLabel(infoBackup, STRDEF("20161219-212741F_20161219-212803D"));
TEST_RESULT_STR_Z(backupDataPtr->backupLabel, "20161219-212741F_20161219-212803D", "diff backup label");
TEST_RESULT_STR_Z(backupDataPtr->backupType, "diff", " backup type diff");
TEST_RESULT_UINT(backupDataPtr->backupType, backupTypeDiff, " backup type diff");
TEST_RESULT_UINT(backupDataPtr->backupInfoRepoSize, 3159811, " repo size");
TEST_RESULT_UINT(backupDataPtr->backupInfoRepoSizeDelta, 15765, " repo delta");
TEST_RESULT_UINT(backupDataPtr->backupInfoSize, 26897030, " backup size");
@ -183,7 +183,7 @@ testRun(void)
TEST_RESULT_STR_Z(backupData.backupLabel, "20161219-212741F_20161219-212918I", "incr backup label");
TEST_RESULT_STR(backupData.backupArchiveStart, NULL, " archive start NULL");
TEST_RESULT_STR(backupData.backupArchiveStop, NULL, " archive stop NULL");
TEST_RESULT_STR_Z(backupData.backupType, "incr", " backup type incr");
TEST_RESULT_UINT(backupData.backupType, backupTypeIncr, " backup type incr");
TEST_RESULT_STR_Z(backupData.backupPrior, "20161219-212741F", " backup prior exists");
TEST_RESULT_BOOL(
(strLstSize(backupData.backupReference) == 2 && strLstExists(backupData.backupReference, STRDEF("20161219-212741F")) &&
@ -317,7 +317,7 @@ testRun(void)
TEST_RESULT_INT(backupData.backupPgId, 1, "pg id");
TEST_RESULT_STR(backupData.backupArchiveStart, NULL, "archive start NULL");
TEST_RESULT_STR(backupData.backupArchiveStop, NULL, "archive stop NULL");
TEST_RESULT_STR_Z(backupData.backupType, "full", "backup type set");
TEST_RESULT_UINT(backupData.backupType, backupTypeFull, "backup type set");
TEST_RESULT_STR(backupData.backupPrior, NULL, "no backup prior");
TEST_RESULT_PTR(backupData.backupReference, NULL, "no backup reference");
TEST_RESULT_INT(backupData.backupTimestampStart, 1565282140, "timestamp start");
@ -424,7 +424,7 @@ testRun(void)
TEST_RESULT_STR_Z(backupData.backrestVersion, PROJECT_VERSION, "backuprest version");
TEST_RESULT_STR_Z(backupData.backupArchiveStart, "000000030000028500000089", "archive start set");
TEST_RESULT_STR_Z(backupData.backupArchiveStop, "000000030000028500000090", "archive stop set");
TEST_RESULT_STR_Z(backupData.backupType, "diff", "backup type set");
TEST_RESULT_UINT(backupData.backupType, backupTypeDiff, "backup type set");
TEST_RESULT_STR_Z(backupData.backupPrior, "20190818-084502F", "backup prior set");
TEST_RESULT_STRLST_Z(
backupData.backupReference,