pg.ddx.io  pgbackrest/pgbackrest GitHub issues and pull requests  
help / color / mirror / Atom feed
From: pgstef (@pgstef) <noreply+pgstef@github.com>
To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>
Subject: Re: [pgbackrest/pgbackrest] PR #2915: Add a minimum repository format for options.
Date: Tue, 10 Nov 2026 13:57:47 +0000
Message-ID: <gh-pgbackrest-pgbackrest-2915-r5843019410@github.com> (raw)
In-Reply-To: <gh-pgbackrest-pgbackrest-2915@github.com>
References: <gh-pgbackrest-pgbackrest-2915@github.com>

The overall approach looks good to me! I noticed two minor things worth considering:

**1. Archive key rotation format check**

If I read it correctly, the format check previously used `archive.info`, but now relies on `backup.info` through `cfgRepoFormatSet()`. After an interrupted `stanza-upgrade`, it's possible to have `archive.info` at format 6 while `backup.info` is still at format 5, since `archive.info` is saved first.

In that case, archive key rotation would be skipped even though the archive format supports it. Depending on how `repo-cipher-rotate` is configured, this could happen silently (default), produce a misleading warning (config/env), or fail the expire operation (command line).

This would be a rare situation that `stanza-upgrade` can repair, but perhaps we should preserve the archive-specific format check in `expireArchiveCipherRotate()`?

I was able to reproduce this on the PR with the following test, added after the "new key is current" check in the existing rotation tests. It reuses `argList`, `backupInfoContent`, and `timeRotate`, and passes as-is, confirming that the archive key is not rotated:
```c
// backup.info back to format 5 (archive.info saved first by stanza-upgrade, backup.info save interrupted)
HRN_INFO_PUT(storageRepoIdxWrite(1), INFO_BACKUP_PATH_FILE, strZ(backupInfoContent), .cipherSpec = TEST_CIPHER_SPEC);
HRN_INFO_PUT(
    storageRepoIdxWrite(1), INFO_ARCHIVE_PATH_FILE, TEST_ARCHIVE_INFO_FORMAT_6(timeRotate - 31 * SEC_PER_DAY),
    .format = REPOSITORY_FORMAT_6, .header = true, .cipherSpec = TEST_CIPHER_SPEC);

// Command-line repo2-cipher-rotate (argList)
HRN_CFG_LOAD(cfgCmdExpire, argList);

TEST_ERROR(cmdExpire(), CommandError, CFGCMD_EXPIRE " command encountered 1 error(s), check the log file for details");
TEST_RESULT_LOG(
    "P00   WARN: backup '20181119-152850F_20181119-152252D' missing manifest removed from backup.info\n"
    "P00  ERROR: [031]: repo2: option 'repo2-cipher-rotate' requires repository format 6 or higher");

TEST_ASSIGN(
    infoArchive, infoArchiveLoadFile(storageRepoIdx(1), INFO_ARCHIVE_PATH_FILE_STR, TEST_CIPHER_SPEC), "load archive info");
TEST_RESULT_STR_Z(cipherSpecMapIdCurrent(infoArchiveCipherSpecMap(infoArchive)), "1", "cmdline: key NOT rotated");

// Env-var repo2-cipher-rotate (config/env source)
StringList *argListEnv = strLstDup(argListAvoidWarn);
hrnCfgArgRawZ(argListEnv, cfgOptRepo, "2");
hrnCfgArgKeyRawZ(argListEnv, cfgOptRepoPath, 2, TEST_PATH "/repo2");
hrnCfgArgKeyRawZ(argListEnv, cfgOptRepoRetentionFull, 2, "1");
hrnCfgArgKeyRawStrId(argListEnv, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
hrnCfgEnvKeyRawZ(cfgOptRepoCipherRotate, 2, "30d");
HRN_CFG_LOAD(cfgCmdExpire, argListEnv);

TEST_RESULT_VOID(cmdExpire(), "expire with env rotate");
TEST_RESULT_LOG(
    "P00   WARN: backup '20181119-152850F_20181119-152252D' missing manifest removed from backup.info\n"
    "P00   WARN: option 'repo2-cipher-rotate' requires repository format 6 or higher\n"
    "P00 DETAIL: repo2: 12-2 archive retention on backup 20181119-152850F, start = 000000010000000000000002\n"
    "P00   INFO: repo2: 12-2 no archive to remove");
hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherRotate, 2);

TEST_ASSIGN(
    infoArchive, infoArchiveLoadFile(storageRepoIdx(1), INFO_ARCHIVE_PATH_FILE_STR, TEST_CIPHER_SPEC), "load archive info");
TEST_RESULT_STR_Z(cipherSpecMapIdCurrent(infoArchiveCipherSpecMap(infoArchive)), "1", "env: key NOT rotated");
```

**2. Remote parameter regression test**

The existing "remote pg server, backup params for remote" test already catches the regression fixed by `ea62757d0`, but only because `cfgOptionIdxTest()` checks the repository format before checking whether the option is set.

Would it be worth adding a test with an encrypted repository and `repo1-cipher-rotate` explicitly configured? This would make the regression coverage more explicit and help protect the fix if that ordering changes in the future.

Something like the following, after the existing test in `protocolTest.c` (passes with the fix):

```c
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("remote pg server, backup params for remote with repo-cipher-rotate");

argList = strLstNew();
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
hrnCfgArgRawZ(argList, cfgOptPgPath, "/path/to/1");
hrnCfgArgRawZ(argList, cfgOptPgHost, "pg1-host");
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherType, 1, "aes-256-cbc");
hrnCfgArgKeyRawZ(argList, cfgOptRepoCipherRotate, 1, "30d");
hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionFull, 1, "1");
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 1, TEST_CIPHER_PASS);
HRN_CFG_LOAD(cfgCmdBackup, argList, .noStd = true);
hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 1);

// Repo format is not known, but repo-cipher-rotate is not valid on the remote
TEST_RESULT_STRLST_Z(
    protocolRemoteParamSsh(protocolStorageTypePg, 0),
    "-o\nLogLevel=error\n-o\nCompression=no\n-o\nPasswordAuthentication=no\npostgres@pg1-host\n"
    TEST_PROJECT_EXE " --exec-id=1-test --lock=test1-backup-1.lock --log-level-console=off --log-level-file=off"
    " --log-level-stderr=error --pg1-path=/path/to/1 --process=0 --remote-type=pg --stanza=test1 backup:remote\n",
    "check config");
```

view thread (11+ messages)  latest in thread

Message-ID: <gh-pgbackrest-pgbackrest-2915-r5843019410@github.com>
Permalink:  ../gh-pgbackrest-pgbackrest-2915-r5843019410@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox