pgbackrest.git / summary / log / commit / refs
commit 00fa22131a3e1069e324fe9c239a225091d5063c
Author: David Steele <david@pgbackrest.org>
Commit: GitHub <noreply@github.com>
Date: Fri Oct 30 17:57:08 2026 +0000
Generate a manifest key for each backup set in repository format 6.
Before format 6, backup.info stores one key that encrypts every manifest for the life of the stanza. Each manifest stores the key for the files in its backup set, so the key in backup.info opens every backup in the repository.
At format 6, an encrypted full backup generates a manifest key and stores it in backup.info by the label of the full backup. The key encrypts the manifests of the full backup and of every differential and incremental backup based on it. backup.info is saved with the new key before the manifest is written so a resumed backup or a reconstructed backup.info can read the manifest.
The key for a manifest is determined by the backup label, which begins with the label of its full backup. Backups made before a stanza was upgraded to format 6 have no key of their own and use the single key in backup.info as before. A stanza created at format 6 has no such key.
The manifest command now resolves the default --set=latest to the newest backup in backup.info rather than following the latest link and rejects a --set that is not a backup label. The info command reports a --set that is not a backup label as not found.
repo-get finds the label from the path of the backup, the name of a history manifest, or the destination of the latest link. With --ignore-missing on an encrypted repository it checks for a missing file before finding the passphrase.
verify skips the newest backup as in progress when backup.info does not contain a key for it, since the backup may have started after verify loaded backup.info. Any other backup without a key is reported as invalid.
Keys are not yet removed from backup.info when a backup set expires or an incomplete full backup is removed.
doc/xml/release/2020s/2027/2.61.0.xml | 3 +
src/command/backup/backup.c | 17 ++++-
src/command/backup/common.c | 5 --
src/command/backup/common.h | 1 +
src/command/backup/complete.c.inc | 6 +-
src/command/backup/incr.c.inc | 2 +-
src/command/backup/resume.c.inc | 15 +++--
src/command/expire/expire.c | 3 +-
src/command/info/info.c | 8 ++-
src/command/manifest/manifest.c | 20 +++++-
src/command/repo/get.c | 44 +++++++++++--
src/command/restore/select.c.inc | 10 ++-
src/command/stanza/create.c | 7 +-
src/command/verify/verify.c | 114 ++++++++++++++++++++-------------
src/common/format/cipherSpecMap.c | 23 ++++++-
src/common/format/cipherSpecMap.h | 3 +
src/info/infoBackup.c | 63 +++++++++++++++++-
src/info/infoBackup.h | 10 ++-
test/src/harness/backup.c | 13 ++--
test/src/harness/config.h | 2 +-
test/src/module/command/backupTest.c | 58 +++++++++++++----
test/src/module/command/manifestTest.c | 12 ++++
test/src/module/command/repoTest.c | 64 +++++++++++++++++-
test/src/module/command/stanzaTest.c | 2 +-
test/src/module/command/verifyTest.c | 40 ++++++++++--
test/src/module/info/infoBackupTest.c | 22 +++++++
26 files changed, 456 insertions(+), 111 deletions(-)
diff --git a/doc/xml/release/2020s/2027/2.61.0.xml b/doc/xml/release/2020s/2027/2.61.0.xml
index a840eed73..3b72d419b 100644
--- a/doc/xml/release/2020s/2027/2.61.0.xml
+++ b/doc/xml/release/2020s/2027/2.61.0.xml
@@ -12,6 +12,9 @@
<commit subject="Require a generated repository passphrase for new format 6 stanzas.">
<github-pull-request id="2880"/>
</commit>
+ <commit subject="Generate a manifest key for each backup set in repository format 6.">
+ <github-pull-request id="2882"/>
+ </commit>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>
diff --git a/src/command/backup/backup.c b/src/command/backup/backup.c
index b697af85a..ffaba6569 100644
--- a/src/command/backup/backup.c
+++ b/src/command/backup/backup.c
@@ -20,6 +20,7 @@ Backup Command
#include "common/crypto/cipherBlock.h"
#include "common/debug.h"
#include "common/format/cipherBlockFormat.h"
+#include "common/format/format.h"
#include "common/io/filter/size.h"
#include "common/log.h"
#include "common/regExp.h"
@@ -212,7 +213,6 @@ cmdBackup(void)
// Load backup.info
InfoBackup *const infoBackup = infoBackupLoadFileReconstruct(storageRepo(), INFO_BACKUP_PATH_FILE_STR, cfgCipherSpecMain());
const InfoPgData infoPg = infoPgDataCurrent(infoBackupPg(infoBackup));
- const CipherSpec *const cipherSpecManifest = infoBackupCipherSpec(infoBackup);
// Get pg storage and database objects
BackupData *const backupData = backupInit(infoBackup);
@@ -249,14 +249,27 @@ cmdBackup(void)
cfgOptionSet(cfgOptDelta, cfgSourceParam, BOOL_TRUE_VAR);
// Resume a backup when possible
- if (!backupResume(manifest, cipherSpecManifest))
+ if (!backupResume(manifest, infoBackup))
{
manifestBackupLabelSet(
manifest,
backupLabelCreate(
(BackupType)cfgOptionStrId(cfgOptType), manifestData(manifest)->backupLabelPrior, timestampStart));
+
+ // Format >= 6 stores a manifest key for a new backup set in backup.info before a manifest is encrypted with it
+ if (manifestFormat(manifest) >= REPOSITORY_FORMAT_6 && manifestData(manifest)->backupType == backupTypeFull &&
+ cfgOptionStrId(cfgOptRepoCipherType) != cipherTypeNone)
+ {
+ infoBackupCipherSpecAdd(
+ infoBackup, manifestData(manifest)->backupLabel,
+ cipherSpecGen(cfgOptionStrId(cfgOptRepoCipherType), manifestFormat(manifest)));
+ infoBackupSaveFile(infoBackup, storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR, cfgCipherSpecMain());
+ }
}
+ // Key for the manifest of the backup
+ const CipherSpec *const cipherSpecManifest = infoBackupCipherSpecManifest(infoBackup, manifestData(manifest)->backupLabel);
+
// Save the manifest before processing starts
backupManifestSaveCopy(manifest, cipherSpecManifest, false);
diff --git a/src/command/backup/common.c b/src/command/backup/common.c
index 3a8d4e486..8702a5dd9 100644
--- a/src/command/backup/common.c
+++ b/src/command/backup/common.c
@@ -10,11 +10,6 @@ Common Functions and Definitions for Backup and Expire Commands
#include "common/log.h"
#include "storage/helper.h"
-/***********************************************************************************************************************************
-Constants
-***********************************************************************************************************************************/
-#define BACKUP_LINK_LATEST "latest"
-
/**********************************************************************************************************************************/
FN_EXTERN String *
backupFileRepoPath(const String *const backupLabel, const BackupFileRepoPathParam param)
diff --git a/src/command/backup/common.h b/src/command/backup/common.h
index 56322b1a8..0b4cee219 100644
--- a/src/command/backup/common.h
+++ b/src/command/backup/common.h
@@ -14,6 +14,7 @@ Common Functions and Definitions for Backup and Expire Commands
/***********************************************************************************************************************************
Backup constants
***********************************************************************************************************************************/
+#define BACKUP_LINK_LATEST "latest"
#define BACKUP_PATH_HISTORY "backup.history"
#define BACKUP_BLOCK_INCR_EXT ".pgbi"
diff --git a/src/command/backup/complete.c.inc b/src/command/backup/complete.c.inc
index 5f4fce6da..6140d9721 100644
--- a/src/command/backup/complete.c.inc
+++ b/src/command/backup/complete.c.inc
@@ -181,12 +181,13 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
MEM_CONTEXT_TEMP_BEGIN()
{
const String *const backupLabel = manifestData(manifest)->backupLabel;
+ const CipherSpec *const cipherSpecManifest = infoBackupCipherSpecManifest(infoBackup, backupLabel);
// Validation and final save of the backup manifest. Validate in strict mode to catch as many potential issues as possible.
// -------------------------------------------------------------------------------------------------------------------------
manifestValidate(manifest, true);
- backupManifestSaveCopy(manifest, infoBackupCipherSpec(infoBackup), true);
+ backupManifestSaveCopy(manifest, cipherSpecManifest, true);
storageCopy(
storageNewReadP(
@@ -207,8 +208,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
ioFilterGroupAdd(ioWriteFilterGroup(storageWriteIo(manifestWrite)), compressFilterP(compressTypeGz, 9));
- cipherBlockFilterGroupAdd(
- ioWriteFilterGroup(storageWriteIo(manifestWrite)), cipherModeEncrypt, infoBackupCipherSpec(infoBackup));
+ cipherBlockFilterGroupAdd(ioWriteFilterGroup(storageWriteIo(manifestWrite)), cipherModeEncrypt, cipherSpecManifest);
manifestSave(manifest, storageWriteIo(manifestWrite));
diff --git a/src/command/backup/incr.c.inc b/src/command/backup/incr.c.inc
index c59698b07..8441f0257 100644
--- a/src/command/backup/incr.c.inc
+++ b/src/command/backup/incr.c.inc
@@ -52,7 +52,7 @@ backupBuildIncrPrior(const InfoBackup *const infoBackup)
{
result = manifestLoadFile(
storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabelPrior)),
- infoBackupCipherSpec(infoBackup));
+ infoBackupCipherSpecManifest(infoBackup, backupLabelPrior));
const ManifestData *const manifestPriorData = manifestData(result);
LOG_INFO_FMT(
diff --git a/src/command/backup/resume.c.inc b/src/command/backup/resume.c.inc
index 4e911b842..c799f950d 100644
--- a/src/command/backup/resume.c.inc
+++ b/src/command/backup/resume.c.inc
@@ -169,14 +169,15 @@ backupResumeClean(
// Helper to find a resumable backup
static const Manifest *
-backupResumeFind(const Manifest *const manifest, const CipherSpec *const cipherSpecManifest)
+backupResumeFind(const Manifest *const manifest, const InfoBackup *const infoBackup)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(MANIFEST, manifest);
- FUNCTION_LOG_PARAM(CIPHER_SPEC, cipherSpecManifest);
+ FUNCTION_LOG_PARAM(INFO_BACKUP, infoBackup);
FUNCTION_LOG_END();
ASSERT(manifest != NULL);
+ ASSERT(infoBackup != NULL);
Manifest *result = NULL;
@@ -217,7 +218,8 @@ backupResumeFind(const Manifest *const manifest, const CipherSpec *const cipherS
{
TRY_BEGIN()
{
- manifestResume = manifestLoadFile(storageRepo(), manifestFile, cipherSpecManifest);
+ manifestResume = manifestLoadFile(
+ storageRepo(), manifestFile, infoBackupCipherSpecManifest(infoBackup, backupLabel));
}
CATCH_ANY()
{
@@ -303,20 +305,21 @@ backupResumeFind(const Manifest *const manifest, const CipherSpec *const cipherS
}
static bool
-backupResume(Manifest *const manifest, const CipherSpec *const cipherSpecManifest)
+backupResume(Manifest *const manifest, const InfoBackup *const infoBackup)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(MANIFEST, manifest);
- FUNCTION_LOG_PARAM(CIPHER_SPEC, cipherSpecManifest);
+ FUNCTION_LOG_PARAM(INFO_BACKUP, infoBackup);
FUNCTION_LOG_END();
ASSERT(manifest != NULL);
+ ASSERT(infoBackup != NULL);
bool result = false;
MEM_CONTEXT_TEMP_BEGIN()
{
- const Manifest *const manifestResume = backupResumeFind(manifest, cipherSpecManifest);
+ const Manifest *const manifestResume = backupResumeFind(manifest, infoBackup);
// If a resumable backup was found set the label and cipher subpass
if (manifestResume)
diff --git a/src/command/expire/expire.c b/src/command/expire/expire.c
index f96e4e047..28894f4d8 100644
--- a/src/command/expire/expire.c
+++ b/src/command/expire/expire.c
@@ -954,7 +954,8 @@ removeExpiredBackup(const InfoBackup *const infoBackup, const String *const adho
if (adhocBackupLabel != NULL && strBeginsWith(strLstGet(backupList, 0), strSubN(adhocBackupLabel, 0, 16)))
{
const Manifest *const manifestResume = manifestLoadFile(
- storageRepoIdx(repoIdx), manifestFileName, infoBackupCipherSpec(infoBackup));
+ storageRepoIdx(repoIdx), manifestFileName,
+ infoBackupCipherSpecManifest(infoBackup, strLstGet(backupList, 0)));
// If the ancestor of the resumable backup no longer exists in backup.info then it can be removed
if (!infoBackupLabelExists(infoBackup, manifestData(manifestResume)->backupLabelPrior))
diff --git a/src/command/info/info.c b/src/command/info/info.c
index 50be72ef1..2cacf0dbb 100644
--- a/src/command/info/info.c
+++ b/src/command/info/info.c
@@ -9,6 +9,7 @@ Info Command
#include <unistd.h>
#include "command/archive/common.h"
+#include "command/backup/common.h"
#include "command/info/info.h"
#include "command/lock.h"
#include "common/crypto/common.h"
@@ -1508,7 +1509,7 @@ infoUpdateStanza(
{
stanzaRepo->repoList[repoIdx].manifest = manifestLoadFile(
storage, strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)),
- infoBackupCipherSpec(stanzaRepo->repoList[repoIdx].backupInfo));
+ infoBackupCipherSpecManifest(stanzaRepo->repoList[repoIdx].backupInfo, backupLabel));
}
}
}
@@ -1610,8 +1611,9 @@ infoRender(void)
// Get the repo storage in case it is remote and encryption settings need to be pulled down
const Storage *const storageRepo = storageRepoIdx(repoIdx);
- // If a backup set was specified, see if the manifest exists
- if (backupLabel != NULL)
+ // If a backup label was specified, see if the manifest exists
+ if (backupLabel != NULL &&
+ regExpMatchOne(backupRegExpP(.full = true, .differential = true, .incremental = true), backupLabel))
{
// If the backup exists on this repo, set the global indicator that we found it on at least one repo and
// set the exists label for later loading of the manifest
diff --git a/src/command/manifest/manifest.c b/src/command/manifest/manifest.c
index ee937841b..f6f73d5d5 100644
--- a/src/command/manifest/manifest.c
+++ b/src/command/manifest/manifest.c
@@ -6,6 +6,7 @@ Manifest Command
#include <unistd.h>
#include "command/backup/blockMap.h"
+#include "command/backup/common.h"
#include "command/manifest/manifest.h"
#include "command/restore/blockChecksum.h"
#include "common/crypto/cipherBlock.h"
@@ -13,6 +14,7 @@ Manifest Command
#include "common/io/fdWrite.h"
#include "common/io/io.h"
#include "common/log.h"
+#include "common/regExp.h"
#include "common/type/json.h"
#include "config/config.h"
#include "info/manifest/manifest.h"
@@ -443,10 +445,24 @@ cmdManifestRender(void)
// Load backup.info and cipher
const InfoBackup *const infoBackup = infoBackupLoadFile(storageRepo(), INFO_BACKUP_PATH_FILE_STR, cfgCipherSpecMain());
+ // The latest backup is the newest in backup.info
+ const String *backupLabel = cfgOptionStr(cfgOptSet);
+
+ if (strEqZ(backupLabel, BACKUP_LINK_LATEST))
+ {
+ if (infoBackupDataTotal(infoBackup) == 0)
+ THROW(BackupSetInvalidError, "no backup set found");
+
+ backupLabel = infoBackupData(infoBackup, infoBackupDataTotal(infoBackup) - 1).backupLabel;
+ }
+ // Else error when the set is not a backup label
+ else if (!regExpMatchOne(backupRegExpP(.full = true, .differential = true, .incremental = true), backupLabel))
+ THROW_FMT(BackupSetInvalidError, "backup set %s is not valid", strZ(backupLabel));
+
// Load manifest
const Manifest *const manifest = manifestLoadFile(
- storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(cfgOptionStr(cfgOptSet))),
- infoBackupCipherSpec(infoBackup));
+ storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)),
+ infoBackupCipherSpecManifest(infoBackup, backupLabel));
// Manifest info
const ManifestData *const data = manifestData(manifest);
diff --git a/src/command/repo/get.c b/src/command/repo/get.c
index ec20a79af..47d0e9b9a 100644
--- a/src/command/repo/get.c
+++ b/src/command/repo/get.c
@@ -14,6 +14,7 @@ Repository Get Command
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
+#include "common/regExp.h"
#include "config/config.h"
#include "storage/helper.h"
@@ -52,12 +53,19 @@ storageGetProcess(IoWrite *const destination)
// Is the file an info file, i.e. one that has a header in front of its content?
bool fileIsInfo = false;
+ // Is the file missing?
+ bool missing = false;
+
// Add decryption if needed
if (!cfgOptionBool(cfgOptRaw))
{
const CipherType repoCipherType = cfgOptionStrId(cfgOptRepoCipherType);
- if (repoCipherType != cipherTypeNone)
+ // Check for a missing file before finding the passphrase when missing files are ignored
+ if (repoCipherType != cipherTypeNone && cfgOptionBool(cfgOptIgnoreMissing))
+ missing = !storageExistsP(storageRepo(), file);
+
+ if (repoCipherType != cipherTypeNone && !missing)
{
// Determine the passphrase using the following pattern:
//
@@ -69,6 +77,8 @@ storageGetProcess(IoWrite *const destination)
// / backup / stanza / set / (backup passphrase)
// / backup / stanza / backup.history / (manifest passphrase)
//
+ // Format >= 6 stores a manifest passphrase for each backup set by label.
+ //
// Nothing should be stored at the top level of the repo except the backup/archive paths. The backup/archive paths
// should contain only stanza paths.
// -----------------------------------------------------------------------------------------------------------------
@@ -115,15 +125,37 @@ storageGetProcess(IoWrite *const destination)
if (!strEndsWithZ(file, INFO_BACKUP_FILE) && !strEndsWithZ(file, INFO_BACKUP_FILE INFO_COPY_EXT))
{
- // Find the manifest passphrase
+ // Find the manifest passphrase by the label of the backup
const InfoBackup *const info = infoBackupLoadFile(
storageRepo(), strNewFmt(STORAGE_PATH_BACKUP "/%s/%s", strZ(stanza), INFO_BACKUP_FILE),
cfgCipherSpecMain());
- const CipherSpec *const cipherSpecManifest = infoBackupCipherSpec(info);
+ const String *backupLabel = strLstGet(filePathSplitLst, 2);
+ const bool history = strEq(backupLabel, STRDEF(BACKUP_PATH_HISTORY));
+
+ // Get the label from the name of the history manifest
+ if (history)
+ {
+ backupLabel = strBase(file);
+ }
+ // Else get the label from the destination of the latest link
+ else if (strEq(backupLabel, STRDEF(BACKUP_LINK_LATEST)))
+ {
+ const StorageInfo latestInfo = storageInfoP(
+ storageRepo(), strNewFmt(STORAGE_PATH_BACKUP "/%s/" BACKUP_LINK_LATEST, strZ(stanza)),
+ .level = storageInfoLevelDetail, .ignoreMissing = true);
+
+ if (latestInfo.type == storageTypeLink)
+ backupLabel = latestInfo.linkDestination;
+ }
+
+ const CipherSpec *const cipherSpecManifest =
+ regExpMatchOne(
+ backupRegExpP(.full = true, .differential = true, .incremental = true, .noAnchorEnd = true),
+ backupLabel) ?
+ infoBackupCipherSpecManifest(info, backupLabel) : infoBackupCipherSpec(info);
// Find the backup passphrase if not a manifest
- if (!strEq(strLstGet(filePathSplitLst, 2), STRDEF(BACKUP_PATH_HISTORY)) &&
- !strEndsWithZ(file, BACKUP_MANIFEST_FILE) &&
+ if (!history && !strEndsWithZ(file, BACKUP_MANIFEST_FILE) &&
!strEndsWithZ(file, BACKUP_MANIFEST_FILE INFO_COPY_EXT))
{
const Manifest *const manifest = manifestLoadFile(
@@ -163,7 +195,7 @@ storageGetProcess(IoWrite *const destination)
}
// Open source
- if (ioReadOpen(source))
+ if (!missing && ioReadOpen(source))
{
// Open the destination file now that we know the source exists and is readable
ioWriteOpen(destination);
diff --git a/src/command/restore/select.c.inc b/src/command/restore/select.c.inc
index fb4c5de54..a72c6a85a 100644
--- a/src/command/restore/select.c.inc
+++ b/src/command/restore/select.c.inc
@@ -156,7 +156,9 @@ restoreBackupSet(void)
{
found = true;
- result = restoreBackupData(backupData.backupLabel, repoIdx, infoBackupCipherSpec(infoBackup));
+ result = restoreBackupData(
+ backupData.backupLabel, repoIdx,
+ infoBackupCipherSpecManifest(infoBackup, backupData.backupLabel));
break;
}
}
@@ -183,7 +185,8 @@ restoreBackupSet(void)
strZ(latestBackup.backupLabel));
}
- result = restoreBackupData(latestBackup.backupLabel, repoIdx, infoBackupCipherSpec(infoBackup));
+ result = restoreBackupData(
+ latestBackup.backupLabel, repoIdx, infoBackupCipherSpecManifest(infoBackup, latestBackup.backupLabel));
break;
}
}
@@ -194,7 +197,8 @@ restoreBackupSet(void)
{
if (strEq(infoBackupData(infoBackup, backupIdx).backupLabel, backupSetRequested))
{
- result = restoreBackupData(backupSetRequested, repoIdx, infoBackupCipherSpec(infoBackup));
+ result = restoreBackupData(
+ backupSetRequested, repoIdx, infoBackupCipherSpecManifest(infoBackup, backupSetRequested));
break;
}
}
diff --git a/src/command/stanza/create.c b/src/command/stanza/create.c
index 3eddf76c8..d5b6b7bf2 100644
--- a/src/command/stanza/create.c
+++ b/src/command/stanza/create.c
@@ -217,9 +217,10 @@ cmdStanzaCreate(void)
infoArchiveSaveFile(infoArchive, storageRepoWriteStanza, INFO_ARCHIVE_PATH_FILE_STR, cfgCipherSpecMainIdx(repoIdx));
- // If the repo is encrypted, generate a cipher passphrase for encrypting subsequent manifests
- const CipherSpec *const cipherSpecManifest = cipherSpecGen(
- cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), format);
+ // If the repo is encrypted, generate a cipher passphrase for encrypting subsequent manifests. Format >= 6 adds a
+ // key for each backup set when the full backup is created.
+ const CipherSpec *const cipherSpecManifest =
+ format < REPOSITORY_FORMAT_6 ? cipherSpecGen(cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx), format) : NULL;
// Create and save backup info
infoBackup = infoBackupNew(
diff --git a/src/command/verify/verify.c b/src/command/verify/verify.c
index 5e38e6114..eeb777114 100644
--- a/src/command/verify/verify.c
+++ b/src/command/verify/verify.c
@@ -124,7 +124,7 @@ typedef struct VerifyJobData
String *currentBackup; // In progress backup, if any
const InfoPg *pgHistory; // Database history list
bool backupProcessing; // Are we processing WAL or are we processing backups
- const CipherSpec *cipherSpecManifest; // Cipher spec for reading backup manifests
+ const InfoBackup *infoBackup; // Backup info with the keys for reading backup manifests
const CipherSpecMap *cipherSpecArchive; // Cipher keys for reading WAL files
unsigned int jobErrorTotal; // Total errors that occurred during the job execution
List *archiveIdResultList; // Archive results
@@ -349,12 +349,12 @@ Get the manifest file
***********************************************************************************************************************************/
static Manifest *
verifyManifestFile(
- VerifyBackupResult *const backupResult, const CipherSpec *const cipherSpecManifest, bool currentBackup,
+ VerifyBackupResult *const backupResult, const InfoBackup *const infoBackup, bool currentBackup,
const InfoPg *const pgHistory, unsigned int *const jobErrorTotal)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM_P(VERIFY_BACKUP_RESULT, backupResult); // The result set for the backup being processed
- FUNCTION_LOG_PARAM(CIPHER_SPEC, cipherSpecManifest); // Cipher spec to access the manifest file
+ FUNCTION_LOG_PARAM(INFO_BACKUP, infoBackup); // Backup info with the keys for reading backup manifests
FUNCTION_LOG_PARAM(BOOL, currentBackup); // Is this possibly a backup currently in progress?
FUNCTION_LOG_PARAM(INFO_PG, pgHistory); // Database history
FUNCTION_LOG_PARAM_P(UINT, jobErrorTotal); // Pointer to the overall job error total
@@ -366,64 +366,90 @@ verifyManifestFile(
{
const String *const fileName = strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupResult->backupLabel));
- // Get the main manifest file
- const VerifyInfoFile verifyManifestInfo = verifyInfoFile(fileName, true, cipherSpecManifest);
+ // Key for the manifest, NULL when backup.info has no key for the backup
+ const CipherSpec *cipherSpecManifest = NULL;
- // If the main file did not error, then report on the copy's status and check checksums
- if (verifyManifestInfo.errorCode == 0)
+ TRY_BEGIN()
{
- result = verifyManifestInfo.manifest;
-
- // The current in-progress backup is only notional until the main file is checked because the backup may have
- // completed by the time the main manifest is checked here. So having a main manifest file means this backup is not
- // (or is no longer) the currentBackup.
- currentBackup = false;
-
- // Attempt to load the copy and report on it's status but don't keep it in memory
- const VerifyInfoFile verifyManifestInfoCopy = verifyInfoFile(
- strNewFmt("%s%s", strZ(fileName), INFO_COPY_EXT), false, cipherSpecManifest);
+ cipherSpecManifest = infoBackupCipherSpecManifest(infoBackup, backupResult->backupLabel);
+ }
+ CATCH(CryptoError)
+ {
+ LOG_DETAIL(errorMessage());
+ }
+ TRY_END();
- // If the copy loaded successfully, then check the checksums
- if (verifyManifestInfoCopy.errorCode == 0)
+ // If there is no key then skip a backup that may be in progress
+ if (cipherSpecManifest == NULL)
+ {
+ if (currentBackup)
{
- // 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_DETAIL_FMT("backup '%s' manifest.copy does not match manifest", strZ(backupResult->backupLabel));
+ backupResult->status = backupInProgress;
+
+ LOG_INFO_FMT("backup '%s' appears to be in progress, skipping", strZ(backupResult->backupLabel));
}
}
else
{
- // If this might be an in-progress backup and the main manifest is simply missing, it is assumed the backup is an
- // actual in-progress backup and verification is skipped, otherwise, if the main is not simply missing, or this is not
- // an in-progress backup then attempt to load the copy.
- if (!(currentBackup && verifyManifestInfo.errorCode == errorTypeCode(&FileMissingError)))
+ // Get the main manifest file
+ const VerifyInfoFile verifyManifestInfo = verifyInfoFile(fileName, true, cipherSpecManifest);
+
+ // If the main file did not error, then report on the copy's status and check checksums
+ if (verifyManifestInfo.errorCode == 0)
{
+ result = verifyManifestInfo.manifest;
+
+ // The current in-progress backup is only notional until the main file is checked because the backup may have
+ // completed by the time the main manifest is checked here. So having a main manifest file means this backup is not
+ // (or is no longer) the currentBackup.
currentBackup = false;
+ // Attempt to load the copy and report on it's status but don't keep it in memory
const VerifyInfoFile verifyManifestInfoCopy = verifyInfoFile(
- strNewFmt("%s%s", strZ(fileName), INFO_COPY_EXT), true, cipherSpecManifest);
+ strNewFmt("%s%s", strZ(fileName), INFO_COPY_EXT), false, cipherSpecManifest);
- // If loaded successfully, then return the copy as usable
+ // If the copy loaded successfully, then check the checksums
if (verifyManifestInfoCopy.errorCode == 0)
{
- LOG_DETAIL_FMT("%s/backup.manifest is missing or unusable, using copy", strZ(backupResult->backupLabel));
-
- result = verifyManifestInfoCopy.manifest;
- }
- else if (verifyManifestInfo.errorCode == errorTypeCode(&FileMissingError) &&
- verifyManifestInfoCopy.errorCode == errorTypeCode(&FileMissingError))
- {
- backupResult->status = backupMissingManifest;
-
- LOG_DETAIL_FMT("manifest missing for '%s' - backup may have expired", strZ(backupResult->backupLabel));
+ // 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_DETAIL_FMT("backup '%s' manifest.copy does not match manifest", strZ(backupResult->backupLabel));
}
}
else
{
- backupResult->status = backupInProgress;
+ // If this might be an in-progress backup and the main manifest is simply missing, it is assumed the backup is an
+ // actual in-progress backup and verification is skipped, otherwise, if the main is not simply missing, or this is
+ // not an in-progress backup then attempt to load the copy.
+ if (!(currentBackup && verifyManifestInfo.errorCode == errorTypeCode(&FileMissingError)))
+ {
+ currentBackup = false;
- LOG_INFO_FMT("backup '%s' appears to be in progress, skipping", strZ(backupResult->backupLabel));
+ const VerifyInfoFile verifyManifestInfoCopy = verifyInfoFile(
+ strNewFmt("%s%s", strZ(fileName), INFO_COPY_EXT), true, cipherSpecManifest);
+
+ // If loaded successfully, then return the copy as usable
+ if (verifyManifestInfoCopy.errorCode == 0)
+ {
+ LOG_DETAIL_FMT("%s/backup.manifest is missing or unusable, using copy", strZ(backupResult->backupLabel));
+
+ result = verifyManifestInfoCopy.manifest;
+ }
+ else if (verifyManifestInfo.errorCode == errorTypeCode(&FileMissingError) &&
+ verifyManifestInfoCopy.errorCode == errorTypeCode(&FileMissingError))
+ {
+ backupResult->status = backupMissingManifest;
+
+ LOG_DETAIL_FMT("manifest missing for '%s' - backup may have expired", strZ(backupResult->backupLabel));
+ }
+ }
+ else
+ {
+ backupResult->status = backupInProgress;
+
+ LOG_INFO_FMT("backup '%s' appears to be in progress, skipping", strZ(backupResult->backupLabel));
+ }
}
}
@@ -639,7 +665,7 @@ verifyBackupSet(VerifyJobData *const jobData, const String *const backupLabel)
{
const Manifest *const manifest = manifestLoadFile(
storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)),
- jobData->cipherSpecManifest);
+ infoBackupCipherSpecManifest(jobData->infoBackup, backupLabel));
// Check files for block incremental
bool hasBlockIncr = false;
@@ -958,7 +984,7 @@ verifyBackup(VerifyJobData *const jobData)
// Get a usable backup manifest file
Manifest *const manifest = verifyManifestFile(
- backupResult, jobData->cipherSpecManifest, inProgressBackup, jobData->pgHistory, &jobData->jobErrorTotal);
+ backupResult, jobData->infoBackup, inProgressBackup, jobData->pgHistory, &jobData->jobErrorTotal);
// If a usable backup.manifest file is not found
if (manifest == NULL)
@@ -1623,7 +1649,7 @@ verifyProcess(const bool verboseText)
.walPathList = NULL,
.walFileList = strLstNew(),
.pgHistory = infoArchivePg(archiveInfo),
- .cipherSpecManifest = infoBackupCipherSpec(backupInfo),
+ .infoBackup = backupInfo,
.cipherSpecArchive = infoArchiveCipherSpecMap(archiveInfo),
.archiveIdResultList = lstNewP(sizeof(VerifyArchiveResult), .comparator = archiveIdComparator),
.backupResultList = lstNewP(sizeof(VerifyBackupResult), .comparator = lstComparatorStr),
diff --git a/src/common/format/cipherSpecMap.c b/src/common/format/cipherSpecMap.c
index 801c50cba..325fd1080 100644
--- a/src/common/format/cipherSpecMap.c
+++ b/src/common/format/cipherSpecMap.c
@@ -76,7 +76,7 @@ cipherSpecMapNewPack(PackRead *const packRead)
/**********************************************************************************************************************************/
FN_EXTERN const CipherSpec *
-cipherSpecMapGet(const CipherSpecMap *const this, const String *const id)
+cipherSpecMapFind(const CipherSpecMap *const this, const String *const id)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(CIPHER_SPEC_MAP, this);
@@ -88,11 +88,28 @@ cipherSpecMapGet(const CipherSpecMap *const this, const String *const id)
const CipherSpecMapItem *const item = lstFind(this->pub.list, &id);
+ FUNCTION_TEST_RETURN_CONST(CIPHER_SPEC, item == NULL ? NULL : item->cipherSpec);
+}
+
+/**********************************************************************************************************************************/
+FN_EXTERN const CipherSpec *
+cipherSpecMapGet(const CipherSpecMap *const this, const String *const id)
+{
+ FUNCTION_TEST_BEGIN();
+ FUNCTION_TEST_PARAM(CIPHER_SPEC_MAP, this);
+ FUNCTION_TEST_PARAM(STRING, id);
+ FUNCTION_TEST_END();
+
+ ASSERT(this != NULL);
+ ASSERT(id != NULL);
+
+ const CipherSpec *const result = cipherSpecMapFind(this, id);
+
// Error when request key was not found
- if (item == NULL)
+ if (result == NULL)
THROW_FMT(CryptoError, "unable to find cipher key '%s'", strZ(id));
- FUNCTION_TEST_RETURN_CONST(CIPHER_SPEC, item->cipherSpec);
+ FUNCTION_TEST_RETURN_CONST(CIPHER_SPEC, result);
}
/**********************************************************************************************************************************/
diff --git a/src/common/format/cipherSpecMap.h b/src/common/format/cipherSpecMap.h
index 75de0021c..8bdb3b203 100644
--- a/src/common/format/cipherSpecMap.h
+++ b/src/common/format/cipherSpecMap.h
@@ -64,6 +64,9 @@ cipherSpecMapGetIdx(const CipherSpecMap *const this, const unsigned int idx)
return lstGet(THIS_PUB(CipherSpecMap)->list, idx);
}
+// Key by id, NULL when the id is not found
+FN_EXTERN const CipherSpec *cipherSpecMapFind(const CipherSpecMap *this, const String *id);
+
// Key by id. Errors when the id is not found.
FN_EXTERN const CipherSpec *cipherSpecMapGet(const CipherSpecMap *this, const String *id);
diff --git a/src/info/infoBackup.c b/src/info/infoBackup.c
index 8594845c2..547429ee6 100644
--- a/src/info/infoBackup.c
+++ b/src/info/infoBackup.c
@@ -11,6 +11,7 @@ Backup Info Handler
#include "command/backup/common.h"
#include "common/debug.h"
#include "common/format/cipherBlockFormat.h"
+#include "common/format/format.h"
#include "common/ini.h"
#include "common/io/bufferWrite.h"
#include "common/io/io.h"
@@ -408,6 +409,65 @@ infoBackupFormatSet(InfoBackup *const this, const unsigned int format)
FUNCTION_LOG_RETURN_VOID();
}
+/**********************************************************************************************************************************/
+FN_EXTERN const CipherSpec *
+infoBackupCipherSpecManifest(const InfoBackup *const this, const String *const backupLabel)
+{
+ FUNCTION_TEST_BEGIN();
+ FUNCTION_TEST_PARAM(INFO_BACKUP, this);
+ FUNCTION_TEST_PARAM(STRING, backupLabel);
+ FUNCTION_TEST_END();
+
+ ASSERT(this != NULL);
+ ASSERT(backupLabel != NULL);
+ ASSERT(strSize(backupLabel) > DATE_TIME_LEN);
+
+ const CipherSpec *result;
+
+ MEM_CONTEXT_TEMP_BEGIN()
+ {
+ const CipherSpecMap *const cipherSpecMap = infoCipherSpecMap(infoPgInfo(infoBackupPg(this)));
+
+ // Key of the backup set by the label of the full backup
+ result = cipherSpecMapFind(cipherSpecMap, strSubN(backupLabel, 0, DATE_TIME_LEN + 1));
+
+ // Else the shared key
+ if (result == NULL)
+ {
+ // Error when there are keys but no shared key
+ if (cipherSpecMapSize(cipherSpecMap) > 0 && cipherSpecMapFind(cipherSpecMap, CIPHER_SPEC_MAP_ID_DEFAULT_STR) == NULL)
+ THROW_FMT(CryptoError, "unable to find key for backup set '%s'", strZ(backupLabel));
+
+ result = infoBackupCipherSpec(this);
+ }
+ }
+ MEM_CONTEXT_TEMP_END();
+
+ FUNCTION_TEST_RETURN_CONST(CIPHER_SPEC, result);
+}
+
+/**********************************************************************************************************************************/
+FN_EXTERN void
+infoBackupCipherSpecAdd(InfoBackup *const this, const String *const backupLabel, const CipherSpec *const cipherSpec)
+{
+ FUNCTION_LOG_BEGIN(logLevelDebug);
+ FUNCTION_LOG_PARAM(INFO_BACKUP, this);
+ FUNCTION_LOG_PARAM(STRING, backupLabel);
+ FUNCTION_LOG_PARAM(CIPHER_SPEC, cipherSpec);
+ FUNCTION_LOG_END();
+
+ ASSERT(this != NULL);
+ ASSERT(infoBackupFormat(this) >= REPOSITORY_FORMAT_6);
+ ASSERT(backupLabel != NULL);
+ ASSERT(strSize(backupLabel) == DATE_TIME_LEN + 1);
+ ASSERT(cipherSpec != NULL);
+
+ infoCipherSpecAdd(infoPgInfo(infoBackupPg(this)), backupLabel, cipherSpec);
+ this->pub.updated = true;
+
+ FUNCTION_LOG_RETURN_VOID();
+}
+
/**********************************************************************************************************************************/
FN_EXTERN InfoBackupData
infoBackupData(const InfoBackup *const this, const unsigned int backupDataIdx)
@@ -881,7 +941,8 @@ infoBackupLoadFileReconstruct(
if (storageExistsP(storage, manifestFileName))
{
bool found = false;
- const Manifest *const manifest = manifestLoadFile(storage, manifestFileName, infoBackupCipherSpec(infoBackup));
+ const Manifest *const manifest = manifestLoadFile(
+ storage, manifestFileName, infoBackupCipherSpecManifest(infoBackup, backupLabel));
const ManifestData *const manData = manifestData(manifest);
// If the pg data for the manifest exists in the history, then add it to current, but if something doesn't match
diff --git a/src/info/infoBackup.h b/src/info/infoBackup.h
index 78fd2e26c..d77fb5d44 100644
--- a/src/info/infoBackup.h
+++ b/src/info/infoBackup.h
@@ -104,13 +104,18 @@ infoBackupPg(const InfoBackup *const this)
FN_EXTERN InfoBackup *infoBackupPgSet(InfoBackup *this, unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalogVersion);
-// Cipher spec for dependent files
+// Cipher spec shared by the manifests of backup sets created before format 6, none when there are no keys
FN_INLINE_ALWAYS const CipherSpec *
infoBackupCipherSpec(const InfoBackup *const this)
{
return infoPgCipherSpec(infoBackupPg(this));
}
+// Cipher spec for the manifest of a backup. A backup set created at format >= 6 has a manifest key of its own, stored by the label
+// of the full backup. Earlier backup sets use the shared key. Errors when there are keys but no key for the backup set and no
+// shared key.
+FN_EXTERN const CipherSpec *infoBackupCipherSpecManifest(const InfoBackup *this, const String *backupLabel);
+
// Repository format
FN_INLINE_ALWAYS unsigned int
infoBackupFormat(const InfoBackup *const this)
@@ -149,6 +154,9 @@ infoBackupDataTotal(const InfoBackup *const this)
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
+// Add the key of a new backup set by the label of its full backup
+FN_EXTERN void infoBackupCipherSpecAdd(InfoBackup *this, const String *backupLabel, const CipherSpec *cipherSpec);
+
// Add backup to the current list
FN_EXTERN void infoBackupDataAdd(InfoBackup *this, const Manifest *manifest);
diff --git a/test/src/harness/backup.c b/test/src/harness/backup.c
index 4d08a96de..37069bc4d 100644
--- a/test/src/harness/backup.c
+++ b/test/src/harness/backup.c
@@ -7,9 +7,9 @@ Harness for Creating Test Backups
#include "command/backup/backup.h"
#include "common/compress/helper.h"
-#include "common/crypto/cipherBlock.h"
#include "common/crypto/common.h"
#include "common/crypto/hash.h"
+#include "common/format/cipherBlockFormat.h"
#include "config/config.h"
#include "info/infoArchive.h"
#include "info/manifest/manifest.h"
@@ -240,9 +240,14 @@ hrnBackupPqScript(const unsigned int pgVersion, const time_t backupTimeStart, Hr
if (param.walCompressType != compressTypeNone)
ioFilterGroupAdd(ioWriteFilterGroup(storageWriteIo(write)), compressFilterP(param.walCompressType, 1));
- // Encrypt with the archive passphrase, which is what archive-push writes WAL with
- cipherBlockFilterGroupAdd(
- ioWriteFilterGroup(storageWriteIo(write)), cipherModeEncrypt, infoArchiveCipherSpec(infoArchive));
+ // Encrypt with the current archive key the way archive-push writes WAL. Format >= 6 also stores the key id.
+ const CipherSpecMap *const cipherSpecMap = infoArchiveCipherSpecMap(infoArchive);
+ const String *const cipherId = cipherSpecMapIdCurrent(cipherSpecMap);
+
+ cipherBlockFormatFilterGroupWriteAddP(
+ ioWriteFilterGroup(storageWriteIo(write)),
+ cipherId == NULL ? infoArchiveCipherSpec(infoArchive) : cipherSpecMapGet(cipherSpecMap, cipherId),
+ infoArchiveFormat(infoArchive), .keyId = cipherId);
storagePutP(write, walBuffer);
}
diff --git a/test/src/harness/config.h b/test/src/harness/config.h
index 3dd5e88c2..02d37421c 100644
--- a/test/src/harness/config.h
+++ b/test/src/harness/config.h
@@ -14,7 +14,7 @@ Prefix for environment variables
/***********************************************************************************************************************************
Config option constants
***********************************************************************************************************************************/
-#define TEST_CIPHER_PASS "xmainx"
+#define TEST_CIPHER_PASS "FORTESTINGONLY+cN4MjV7ZH7mtqP44dL9PgGxJKUMk="
#define TEST_CIPHER_PASS_ARCHIVE "xarchivex"
// Archive pass encoded as base64 for format 6
diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c
index 2e9bd9879..e7d7ca54a 100644
--- a/test/src/module/command/backupTest.c
+++ b/test/src/module/command/backupTest.c
@@ -424,8 +424,13 @@ testBackupValidate(const Storage *const storage, const String *const path, const
// -------------------------------------------------------------------------------------------------------------------------
const InfoBackup *const infoBackup = infoBackupLoadFile(
storageRepo(), INFO_BACKUP_PATH_FILE_STR, param.cipherSpecMain == NULL ? cipherSpecNewNone() : param.cipherSpecMain);
+
+ // The label of the backup is the destination when the path is a link
+ const StorageInfo pathInfo = storageInfoP(storage, path);
+ const String *const backupLabel = strBase(pathInfo.type == storageTypeLink ? pathInfo.linkDestination : path);
+
Manifest *manifest = manifestLoadFile(
- storage, strNewFmt("%s/" BACKUP_MANIFEST_FILE, strZ(path)), infoBackupCipherSpec(infoBackup));
+ storage, strNewFmt("%s/" BACKUP_MANIFEST_FILE, strZ(path)), infoBackupCipherSpecManifest(infoBackup, backupLabel));
// Build list of files in the manifest
StringList *const manifestFileList = strLstNew();
@@ -1732,12 +1737,15 @@ testRun(void)
hrnCfgArgRawBool(argList, cfgOptCompress, false);
HRN_CFG_LOAD(cfgCmdBackup, argList);
+ const InfoBackup *const infoBackup = infoBackupNew(
+ PG_VERSION_12, HRN_PG_SYSTEMID_12, hrnPgCatalogVersion(PG_VERSION_12), REPOSITORY_FORMAT_DEFAULT, NULL);
+
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cannot resume when manifest and copy are missing");
HRN_STORAGE_PATH_CREATE(storageRepoWrite(), STORAGE_REPO_BACKUP "/20191003-105320F");
- TEST_RESULT_PTR(backupResumeFind((Manifest *)1, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind((Manifest *)1, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed: partially deleted by prior resume or invalid");
@@ -1751,7 +1759,7 @@ testRun(void)
HRN_STORAGE_PUT_EMPTY(storageRepoWrite(), STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT);
- TEST_RESULT_PTR(backupResumeFind((Manifest *)1, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind((Manifest *)1, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG("P00 INFO: backup '20191003-105320F' cannot be resumed: resume is disabled");
@@ -1775,7 +1783,7 @@ testRun(void)
HRN_STORAGE_PUT_Z(storageRepoWrite(), STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, "X");
- TEST_RESULT_PTR(backupResumeFind(manifest, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind(manifest, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed: unable to read"
@@ -1807,7 +1815,7 @@ testRun(void)
storageNewWriteP(
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
- TEST_RESULT_PTR(backupResumeFind(manifest, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind(manifest, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed:"
@@ -1828,7 +1836,7 @@ testRun(void)
storageNewWriteP(
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
- TEST_RESULT_PTR(backupResumeFind(manifest, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind(manifest, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed:"
@@ -1850,7 +1858,7 @@ testRun(void)
storageNewWriteP(
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
- TEST_RESULT_PTR(backupResumeFind(manifest, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind(manifest, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed:"
@@ -1872,7 +1880,7 @@ testRun(void)
storageNewWriteP(
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
- TEST_RESULT_PTR(backupResumeFind(manifest, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind(manifest, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed:"
@@ -1893,7 +1901,7 @@ testRun(void)
storageNewWriteP(
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
- TEST_RESULT_PTR(backupResumeFind(manifest, cipherSpecNewNone()), NULL, "find resumable backup");
+ TEST_RESULT_PTR(backupResumeFind(manifest, infoBackup), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed:"
@@ -4008,12 +4016,13 @@ testRun(void)
backupTimeStart = BACKUP_EPOCH + 3200000;
{
- // Create encrypted stanza
+ // Create encrypted stanza at format 6
StringList *argList = strLstNew();
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath);
hrnCfgArgRaw(argList, cfgOptPgPath, pg1Path);
hrnCfgArgRawBool(argList, cfgOptOnline, false);
+ hrnCfgArgRawZ(argList, cfgOptRepoFormat, "6");
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, "aes-256-cbc");
hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
HRN_CFG_LOAD(cfgCmdStanzaCreate, argList);
@@ -4092,14 +4101,15 @@ testRun(void)
// History manifest has no passphrase for the files
const InfoBackup *const infoBackup = infoBackupLoadFile(storageRepo(), INFO_BACKUP_PATH_FILE_STR, TEST_CIPHER_SPEC);
+ const CipherSpec *const cipherSpecManifest = infoBackupCipherSpecManifest(infoBackup, STRDEF("20191108-080000F"));
StorageRead *const read = storageNewReadP(
storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/" BACKUP_PATH_HISTORY "/2019/20191108-080000F.manifest.gz"));
- cipherBlockFilterGroupAdd(ioReadFilterGroup(storageReadIo(read)), cipherModeDecrypt, infoBackupCipherSpec(infoBackup));
+ cipherBlockFilterGroupAdd(ioReadFilterGroup(storageReadIo(read)), cipherModeDecrypt, cipherSpecManifest);
ioFilterGroupAdd(ioReadFilterGroup(storageReadIo(read)), decompressFilterP(compressTypeGz));
TEST_RESULT_UINT(
- cipherSpecType(manifestCipherSpec(manifestNewLoad(storageReadIo(read), infoBackupCipherSpec(infoBackup)))),
- cipherTypeNone, "history manifest has no file passphrase");
+ cipherSpecType(manifestCipherSpec(manifestNewLoad(storageReadIo(read), cipherSpecManifest))), cipherTypeNone,
+ "history manifest has no file passphrase");
}
// -------------------------------------------------------------------------------------------------------------------------
@@ -4435,6 +4445,28 @@ testRun(void)
"pg_data={\"path\":\"" TEST_PATH "/pg1\",\"type\":\"path\"}\n",
"compare file list");
}
+
+ // -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("backup set keys");
+ {
+ const InfoBackup *const infoBackup = infoBackupLoadFile(storageRepo(), INFO_BACKUP_PATH_FILE_STR, TEST_CIPHER_SPEC);
+ const CipherSpecMap *const cipherSpecMap = infoCipherSpecMap(infoPgInfo(infoBackupPg(infoBackup)));
+
+ TEST_RESULT_UINT(cipherSpecMapSize(cipherSpecMap), 2, "manifest key for each full backup");
+ TEST_RESULT_STR_Z(cipherSpecMapGetIdx(cipherSpecMap, 0)->id, "20191108-080000F", "first backup set key id");
+ TEST_RESULT_STR_Z(cipherSpecMapGetIdx(cipherSpecMap, 1)->id, "20191111-192000F", "second backup set key id");
+
+ const String *const backupLabel = STRDEF("20191108-080000F_20191111-052640I");
+ const CipherSpec *const cipherSpecManifest = infoBackupCipherSpecManifest(infoBackup, backupLabel);
+
+ const Manifest *const manifest = manifestLoadFile(
+ storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)), cipherSpecManifest);
+
+ TEST_RESULT_UINT(cipherSpecType(manifestCipherSpec(manifest)), cipherTypeAes256Cbc, "manifest stores file key");
+ TEST_RESULT_BOOL(
+ bufEq(cipherSpecPass(manifestCipherSpec(manifest)), cipherSpecPass(cipherSpecManifest)), false,
+ "file key is not manifest key");
+ }
}
FUNCTION_HARNESS_RETURN_VOID();
diff --git a/test/src/module/command/manifestTest.c b/test/src/module/command/manifestTest.c
index fa7a56f02..ef86dc14a 100644
--- a/test/src/module/command/manifestTest.c
+++ b/test/src/module/command/manifestTest.c
@@ -103,6 +103,18 @@ testRun(void)
hrnBackupPqScriptP(PG_VERSION_14, backupTimeStart, .noArchiveCheck = true, .noWal = true);
TEST_RESULT_VOID(hrnCmdBackup(), "backup repo1");
+ // No backup on repo2 for the manifest command to render
+ StringList *argListManifest = strLstDup(argListCommon);
+ hrnCfgArgRawZ(argListManifest, cfgOptRepo, "2");
+ HRN_CFG_LOAD(cfgCmdManifest, argListManifest);
+
+ TEST_ERROR(cmdManifestRender(), BackupSetInvalidError, "no backup set found");
+
+ hrnCfgArgRawZ(argListManifest, cfgOptSet, "bogus");
+ HRN_CFG_LOAD(cfgCmdManifest, argListManifest);
+
+ TEST_ERROR(cmdManifestRender(), BackupSetInvalidError, "backup set bogus is not valid");
+
// Backup to repo2
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
HRN_CFG_LOAD(cfgCmdBackup, argList);
diff --git a/test/src/module/command/repoTest.c b/test/src/module/command/repoTest.c
index 8c7617c81..066eb1070 100644
--- a/test/src/module/command/repoTest.c
+++ b/test/src/module/command/repoTest.c
@@ -423,7 +423,7 @@ testRun(void)
storageFixture, STORAGE_PATH_BACKUP "/test/latest/" BACKUP_MANIFEST_FILE ".copy", manifestFileBuffer,
.cipherSpec = TEST_CIPHER_SPEC_PASS("custom"));
HRN_STORAGE_PUT(
- storageFixture, STORAGE_PATH_BACKUP "/test/backup.history/2020/label.manifest.gz", manifestFileBuffer,
+ storageFixture, STORAGE_PATH_BACKUP "/test/backup.history/2020/20200101-000000F.manifest.gz", manifestFileBuffer,
.cipherSpec = TEST_CIPHER_SPEC_PASS("custom"));
HRN_STORAGE_PUT(
storageFixture, STORAGE_PATH_BACKUP "/test/latest/pg_data/backup_label", backupLabelBuffer,
@@ -698,7 +698,7 @@ testRun(void)
argList = strLstNew();
hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
- strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/backup.history/2020/label.manifest.gz");
+ strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/backup.history/2020/20200101-000000F.manifest.gz");
HRN_CFG_LOAD(cfgCmdRepoGet, argList);
writeBuffer = bufNew(0);
@@ -718,6 +718,66 @@ testRun(void)
TEST_RESULT_INT(storageGetProcess(ioBufferWriteNew(writeBuffer)), 0, "get");
TEST_RESULT_BOOL(bufEq(writeBuffer, backupLabelBuffer), true, "get matches put");
+ // -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("get encrypted format 6 backup.manifest");
+
+ // Format 6 backup.info with a manifest key for the backup set
+ HRN_INFO_PUT(
+ storageFixture, STORAGE_PATH_BACKUP "/test/" INFO_BACKUP_FILE,
+ "[cipher]\n"
+ "cipher-pass={\"20200102-000000F\":{\"digest\":\"sha256\",\"key\":\"Y3VzdG9tNw==\"}}\n"
+ "\n"
+ "[db]\n"
+ "db-catalog-version=201909212\n"
+ "db-control-version=1201\n"
+ "db-id=1\n"
+ "db-system-id=6846378200844646865\n"
+ "db-version=\"12\"\n"
+ "\n"
+ "[db:history]\n"
+ "1={\"db-catalog-version\":201909212,\"db-control-version\":1201,\"db-system-id\":6846378200844646865"
+ ",\"db-version\":\"12\"}",
+ .format = REPOSITORY_FORMAT_6, .header = true, .cipherSpec = TEST_CIPHER_SPEC);
+ HRN_STORAGE_PUT(
+ storageFixture, STORAGE_PATH_BACKUP "/test/20200102-000000F/" BACKUP_MANIFEST_FILE, manifestFileBuffer,
+ .cipherSpec = cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF("custom7"), .digest = hashTypeSha256));
+
+ argList = strLstNew();
+ hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
+ hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
+ strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/20200102-000000F/" BACKUP_MANIFEST_FILE);
+ HRN_CFG_LOAD(cfgCmdRepoGet, argList);
+
+ writeBuffer = bufNew(0);
+ TEST_RESULT_INT(storageGetProcess(ioBufferWriteNew(writeBuffer)), 0, "get by label");
+ TEST_RESULT_BOOL(bufEq(writeBuffer, manifestFileBuffer), true, "get matches put");
+
+ const String *const latestLink = storagePathP(storageFixture, STRDEF(STORAGE_PATH_BACKUP "/test/latest"));
+
+ HRN_STORAGE_PATH_REMOVE(storageFixture, STORAGE_PATH_BACKUP "/test/latest", .recurse = true);
+ TEST_RESULT_VOID(storageLinkCreateP(storageFixture, STRDEF("20200102-000000F"), latestLink), "latest link");
+
+ argList = strLstNew();
+ hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
+ hrnCfgArgRawStrId(argList, cfgOptRepoCipherType, cipherTypeAes256Cbc);
+ strLstAddZ(argList, STORAGE_PATH_BACKUP "/test/latest/" BACKUP_MANIFEST_FILE);
+ HRN_CFG_LOAD(cfgCmdRepoGet, argList);
+
+ writeBuffer = bufNew(0);
+ TEST_RESULT_INT(storageGetProcess(ioBufferWriteNew(writeBuffer)), 0, "get through latest link");
+ TEST_RESULT_BOOL(bufEq(writeBuffer, manifestFileBuffer), true, "get matches put");
+
+ hrnCfgArgRawBool(argList, cfgOptIgnoreMissing, true);
+ HRN_CFG_LOAD(cfgCmdRepoGet, argList);
+
+ writeBuffer = bufNew(0);
+ TEST_RESULT_INT(storageGetProcess(ioBufferWriteNew(writeBuffer)), 0, "get through latest link with ignore missing");
+ TEST_RESULT_BOOL(bufEq(writeBuffer, manifestFileBuffer), true, "get matches put");
+
+ HRN_STORAGE_REMOVE(storageFixture, STORAGE_PATH_BACKUP "/test/latest");
+
+ TEST_RESULT_INT(storageGetProcess(ioBufferWriteNew(bufNew(0))), 1, "get missing latest link");
+
// -------------------------------------------------------------------------------------------------------------------------
// Reset env
hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 1);
diff --git a/test/src/module/command/stanzaTest.c b/test/src/module/command/stanzaTest.c
index 6db4ccad2..9db628022 100644
--- a/test/src/module/command/stanzaTest.c
+++ b/test/src/module/command/stanzaTest.c
@@ -317,7 +317,7 @@ testRun(void)
storageRepoIdx(3), INFO_BACKUP_PATH_FILE_STR,
cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF(TEST_CIPHER_PASS_FMT6))),
"load backup info from encrypted repo4");
- TEST_RESULT_UINT(cipherSpecType(infoBackupCipherSpec(infoBackup)), cipherTypeAes256Cbc, "cipher sub set");
+ TEST_RESULT_UINT(cipherSpecMapSize(infoCipherSpecMap(infoPgInfo(infoBackupPg(infoBackup)))), 0, "no backup keys");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cmdStanzaCreate missing files - multi-repo and encryption");
diff --git a/test/src/module/command/verifyTest.c b/test/src/module/command/verifyTest.c
index a43e803a5..11a300ba9 100644
--- a/test/src/module/command/verifyTest.c
+++ b/test/src/module/command/verifyTest.c
@@ -242,6 +242,9 @@ testRun(void)
infoArchivePg(infoArchiveNewLoad(ioBufferReadNew(harnessInfoChecksumZ(TEST_ARCHIVE_INFO_BASE)), cipherSpecNewNone())),
"infoPg from archive.info");
+ const InfoBackup *const infoBackup = infoBackupNew(
+ PG_VERSION_96, HRN_PG_SYSTEMID_96, hrnPgCatalogVersion(PG_VERSION_96), REPOSITORY_FORMAT_DEFAULT, NULL);
+
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("manifest.copy exists, no manifest main, manifest db version not in history, not current db");
@@ -270,7 +273,7 @@ testRun(void)
backupResult.status = backupValid;
TEST_ASSIGN(
- manifest, verifyManifestFile(&backupResult, cipherSpecNewNone(), false, infoPg, &jobErrorTotal), "verify manifest");
+ manifest, verifyManifestFile(&backupResult, infoBackup, 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(
@@ -306,7 +309,7 @@ testRun(void)
backupResult.status = backupValid;
TEST_ASSIGN(
- manifest, verifyManifestFile(&backupResult, cipherSpecNewNone(), false, infoPg, &jobErrorTotal), "verify manifest");
+ manifest, verifyManifestFile(&backupResult, infoBackup, false, infoPg, &jobErrorTotal), "verify manifest");
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(
@@ -341,7 +344,7 @@ testRun(void)
backupResult.status = backupValid;
TEST_ASSIGN(
- manifest, verifyManifestFile(&backupResult, cipherSpecNewNone(), false, infoPg, &jobErrorTotal), "verify manifest");
+ manifest, verifyManifestFile(&backupResult, infoBackup, false, infoPg, &jobErrorTotal), "verify manifest");
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(
@@ -360,7 +363,7 @@ testRun(void)
INFO_COPY_EXT, TEST_INVALID_BACKREST_INFO, .comment = "invalid manifest copy");
TEST_ASSIGN(
- manifest, verifyManifestFile(&backupResult, cipherSpecNewNone(), false, infoPg, &jobErrorTotal), "verify manifest");
+ manifest, verifyManifestFile(&backupResult, infoBackup, false, infoPg, &jobErrorTotal), "verify manifest");
TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid");
TEST_RESULT_LOG(
"P00 DETAIL: unable to open missing file '" TEST_PATH "/repo/backup/db/20181119-152138F/backup.manifest' for read\n"
@@ -375,7 +378,7 @@ testRun(void)
TEST_INVALID_BACKREST_INFO, .comment = "invalid manifest");
TEST_ASSIGN(
- manifest, verifyManifestFile(&backupResult, cipherSpecNewNone(), true, infoPg, &jobErrorTotal), "verify manifest");
+ manifest, verifyManifestFile(&backupResult, infoBackup, true, infoPg, &jobErrorTotal), "verify manifest");
TEST_RESULT_PTR(manifest, NULL, "manifest not set");
TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid");
TEST_RESULT_LOG(
@@ -402,11 +405,36 @@ testRun(void)
backupResult.status = backupValid;
TEST_ASSIGN(
- manifest, verifyManifestFile(&backupResult, cipherSpecNewNone(), true, infoPg, &jobErrorTotal), "verify manifest");
+ manifest, verifyManifestFile(&backupResult, infoBackup, 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 DETAIL: backup '20181119-152138F' manifest.copy does not match manifest");
+ // -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("no key for the backup set");
+
+ InfoBackup *const infoBackupKey = infoBackupNew(
+ PG_VERSION_96, HRN_PG_SYSTEMID_96, hrnPgCatalogVersion(PG_VERSION_96), REPOSITORY_FORMAT_6, NULL);
+ infoBackupCipherSpecAdd(
+ infoBackupKey, STRDEF("20181119-152000F"),
+ cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF("setkey"), .digest = hashTypeSha256));
+
+ backupResult.status = backupValid;
+ TEST_ASSIGN(
+ manifest, verifyManifestFile(&backupResult, infoBackupKey, true, infoPg, &jobErrorTotal), "verify manifest");
+ TEST_RESULT_PTR(manifest, NULL, "manifest not set");
+ TEST_RESULT_UINT(backupResult.status, backupInProgress, "backup in progress");
+ TEST_RESULT_LOG(
+ "P00 DETAIL: unable to find key for backup set '20181119-152138F'\n"
+ "P00 INFO: backup '20181119-152138F' appears to be in progress, skipping");
+
+ backupResult.status = backupValid;
+ TEST_ASSIGN(
+ manifest, verifyManifestFile(&backupResult, infoBackupKey, false, infoPg, &jobErrorTotal), "verify manifest");
+ TEST_RESULT_PTR(manifest, NULL, "manifest not set");
+ TEST_RESULT_UINT(backupResult.status, backupInvalid, "manifest unusable - backup invalid");
+ TEST_RESULT_LOG("P00 DETAIL: unable to find key for backup set '20181119-152138F'");
+
harnessLogLevelReset();
}
diff --git a/test/src/module/info/infoBackupTest.c b/test/src/module/info/infoBackupTest.c
index a905d3ee5..a376ee05a 100644
--- a/test/src/module/info/infoBackupTest.c
+++ b/test/src/module/info/infoBackupTest.c
@@ -81,6 +81,16 @@ testRun(void)
TEST_RESULT_UINT(infoBackupFormat(infoBackup), REPOSITORY_FORMAT_6, "format updated");
TEST_RESULT_BOOL(infoBackup->pub.updated, true, "updated after format set");
+ // Backup set key with no shared key
+ TEST_RESULT_VOID(
+ infoBackupCipherSpecAdd(
+ infoBackup, STRDEF("20261017-120000F"),
+ cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF("setkey"), .digest = hashTypeSha256)),
+ "add backup set key");
+ TEST_ERROR(
+ infoBackupCipherSpecManifest(infoBackup, STRDEF("20261016-120000F")), CryptoError,
+ "unable to find key for backup set '20261016-120000F'");
+
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("check cipher pass");
@@ -116,6 +126,18 @@ testRun(void)
"zWa/6Xtp-IVZC5444yXB+cgFDFl7MxGlgkZSaoPvTGirhPygu4jOKOXf9LO4vjfO", "cipher sub set");
TEST_RESULT_INT(infoPgDataTotal(infoBackupPg(infoBackup)), 1, "history set");
+ TEST_RESULT_VOID(
+ infoBackupCipherSpecAdd(
+ infoBackup, STRDEF("20261017-120000F"),
+ cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF("setkey"), .digest = hashTypeSha256)),
+ "add backup set key");
+ TEST_RESULT_STR_Z(
+ strNewBuf(cipherSpecPass(infoBackupCipherSpecManifest(infoBackup, STRDEF("20261017-120000F_20261018-120000I")))),
+ "setkey", "backup set key");
+ TEST_RESULT_STR_Z(
+ strNewBuf(cipherSpecPass(infoBackupCipherSpecManifest(infoBackup, STRDEF("20261016-120000F")))),
+ "zWa/6Xtp-IVZC5444yXB+cgFDFl7MxGlgkZSaoPvTGirhPygu4jOKOXf9LO4vjfO", "shared key");
+
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("add pg info");
[parent: 840ffebf23a3]