1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Add backupFileRepoPathP().

The path for a backup file in the repository was being generated in four different places, so move the logic to a function.
This commit is contained in:
David Steele 2022-10-18 17:39:59 +13:00
parent fee38c2c7c
commit 5fceee88a9
5 changed files with 59 additions and 23 deletions

View File

@ -91,6 +91,7 @@
<github-pull-request id="1898"/>
</commit>
<commit subject="Pass filters to remote storage as a handler array."/>
<commit subject="Add backupFileRepoPathP()."/>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>

View File

@ -941,9 +941,9 @@ backupFilePut(BackupData *backupData, Manifest *manifest, const String *name, ti
StorageWrite *write = storageNewWriteP(
storageRepoWrite(),
strNewFmt(
STORAGE_REPO_BACKUP "/%s/%s%s", strZ(manifestData(manifest)->backupLabel), strZ(manifestName),
strZ(compressExtStr(compressType))),
backupFileRepoPathP(
manifestData(manifest)->backupLabel, .manifestName = manifestName,
.compressType = compressTypeEnum(cfgOptionStrId(cfgOptCompressType))),
.compressible = true);
IoFilterGroup *filterGroup = ioWriteFilterGroup(storageWriteIo(write));
@ -1706,20 +1706,23 @@ static ProtocolParallelJob *backupJobCallback(void *data, unsigned int clientIdx
{
param = protocolCommandParam(command);
String *const repoFile = strCatFmt(strNew(), STORAGE_REPO_BACKUP "/%s/", strZ(jobData->backupLabel));
if (bundle && file.size <= jobData->bundleLimit)
strCatFmt(repoFile, MANIFEST_PATH_BUNDLE "/%" PRIu64, jobData->bundleId);
{
pckWriteStrP(param, backupFileRepoPathP(jobData->backupLabel, .bundleId = jobData->bundleId));
}
else
{
CHECK(AssertError, fileTotal == 0, "cannot bundle file");
strCatFmt(repoFile, "%s%s", strZ(file.name), strZ(compressExtStr(jobData->compressType)));
pckWriteStrP(
param,
backupFileRepoPathP(
jobData->backupLabel, .manifestName = file.name, .compressType = jobData->compressType));
fileName = file.name;
bundle = false;
}
pckWriteStrP(param, repoFile);
pckWriteU32P(param, jobData->compressType);
pckWriteI32P(param, jobData->compressLevel);
pckWriteU64P(param, jobData->cipherSubPass == NULL ? cipherTypeNone : cipherTypeAes256Cbc);
@ -2093,9 +2096,9 @@ backupArchiveCheckCopy(const BackupData *const backupData, Manifest *const manif
read,
storageNewWriteP(
storageRepoWrite(),
strNewFmt(
STORAGE_REPO_BACKUP "/%s/%s%s", strZ(manifestData(manifest)->backupLabel), strZ(manifestName),
strZ(compressExtStr(compressTypeEnum(cfgOptionStrId(cfgOptCompressType)))))));
backupFileRepoPathP(
manifestData(manifest)->backupLabel, .manifestName = manifestName,
.compressType = compressTypeEnum(cfgOptionStrId(cfgOptCompressType)))));
// Add to manifest
ManifestFile file =

View File

@ -16,6 +16,30 @@ Constants
#define DATE_TIME_REGEX "[0-9]{8}\\-[0-9]{6}"
#define BACKUP_LINK_LATEST "latest"
/**********************************************************************************************************************************/
String *
backupFileRepoPath(const String *const backupLabel, const BackupFileRepoPathParam param)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, backupLabel);
FUNCTION_TEST_PARAM(STRING, param.manifestName);
FUNCTION_TEST_PARAM(UINT64, param.bundleId);
FUNCTION_TEST_PARAM(ENUM, param.compressType);
FUNCTION_TEST_END();
ASSERT(backupLabel != NULL);
ASSERT(param.bundleId != 0 || param.manifestName != NULL);
String *const result = strCatFmt(strNew(), STORAGE_REPO_BACKUP "/%s/", strZ(backupLabel));
if (param.bundleId != 0)
strCatFmt(result, MANIFEST_PATH_BUNDLE "/%" PRIu64, param.bundleId);
else
strCatFmt(result, "%s%s", strZ(param.manifestName), strZ(compressExtStr(param.compressType)));
FUNCTION_TEST_RETURN(STRING, result);
}
/**********************************************************************************************************************************/
String *
backupLabelFormat(BackupType type, const String *backupLabelPrior, time_t timestamp)

View File

@ -7,6 +7,7 @@ Common Functions and Definitions for Backup and Expire Commands
#include <stdbool.h>
#include <time.h>
#include "common/compress/helper.h"
#include "common/type/string.h"
#include "info/infoBackup.h"
@ -18,6 +19,19 @@ Backup constants
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Determine the path/file where the file is backed up in the repo
typedef struct BackupFileRepoPathParam
{
const String *manifestName; // File name in manifest
uint64_t bundleId; // Is the file bundled?
CompressType compressType; // Is the file compressed?
} BackupFileRepoPathParam;
#define backupFileRepoPathP(backupLabel, ...) \
backupFileRepoPath(backupLabel, (BackupFileRepoPathParam){__VA_ARGS__})
String *backupFileRepoPath(const String *backupLabel, BackupFileRepoPathParam param);
// Format a backup label from a type and timestamp with an optional prior label
String *backupLabelFormat(BackupType type, const String *backupLabelPrior, time_t timestamp);

View File

@ -2305,26 +2305,20 @@ static ProtocolParallelJob *restoreJobCallback(void *data, unsigned int clientId
{
param = protocolCommandParam(command);
const String *const repoPath = strNewFmt(
STORAGE_REPO_BACKUP "/%s/",
strZ(file.reference != NULL ? file.reference : manifestData(jobData->manifest)->backupLabel));
if (file.bundleId != 0)
{
pckWriteStrP(param, strNewFmt("%s" MANIFEST_PATH_BUNDLE "/%" PRIu64, strZ(repoPath), file.bundleId));
bundleId = file.bundleId;
reference = file.reference;
}
else
{
pckWriteStrP(
param,
strNewFmt(
"%s%s%s", strZ(repoPath), strZ(file.name),
strZ(compressExtStr(manifestData(jobData->manifest)->backupOptionCompressType))));
fileName = file.name;
}
pckWriteStrP(
param,
backupFileRepoPathP(
file.reference != NULL ? file.reference : manifestData(jobData->manifest)->backupLabel,
.manifestName = file.name, .bundleId = file.bundleId,
.compressType = manifestData(jobData->manifest)->backupOptionCompressType));
pckWriteU32P(param, jobData->repoIdx);
pckWriteU32P(param, manifestData(jobData->manifest)->backupOptionCompressType);
pckWriteTimeP(param, manifestData(jobData->manifest)->backupTimestampCopyStart);