1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +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"/> <github-pull-request id="1898"/>
</commit> </commit>
<commit subject="Pass filters to remote storage as a handler array."/> <commit subject="Pass filters to remote storage as a handler array."/>
<commit subject="Add backupFileRepoPathP()."/>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-contributor id="david.steele"/> <release-item-contributor id="david.steele"/>

View File

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

View File

@ -16,6 +16,30 @@ Constants
#define DATE_TIME_REGEX "[0-9]{8}\\-[0-9]{6}" #define DATE_TIME_REGEX "[0-9]{8}\\-[0-9]{6}"
#define BACKUP_LINK_LATEST "latest" #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 * String *
backupLabelFormat(BackupType type, const String *backupLabelPrior, time_t timestamp) 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 <stdbool.h>
#include <time.h> #include <time.h>
#include "common/compress/helper.h"
#include "common/type/string.h" #include "common/type/string.h"
#include "info/infoBackup.h" #include "info/infoBackup.h"
@ -18,6 +19,19 @@ Backup constants
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions 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 // Format a backup label from a type and timestamp with an optional prior label
String *backupLabelFormat(BackupType type, const String *backupLabelPrior, time_t timestamp); 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); 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) if (file.bundleId != 0)
{ {
pckWriteStrP(param, strNewFmt("%s" MANIFEST_PATH_BUNDLE "/%" PRIu64, strZ(repoPath), file.bundleId));
bundleId = file.bundleId; bundleId = file.bundleId;
reference = file.reference; reference = file.reference;
} }
else else
{
pckWriteStrP(
param,
strNewFmt(
"%s%s%s", strZ(repoPath), strZ(file.name),
strZ(compressExtStr(manifestData(jobData->manifest)->backupOptionCompressType))));
fileName = file.name; 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, jobData->repoIdx);
pckWriteU32P(param, manifestData(jobData->manifest)->backupOptionCompressType); pckWriteU32P(param, manifestData(jobData->manifest)->backupOptionCompressType);
pckWriteTimeP(param, manifestData(jobData->manifest)->backupTimestampCopyStart); pckWriteTimeP(param, manifestData(jobData->manifest)->backupTimestampCopyStart);