1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-10-30 23:37:45 +02:00

Error on db history mismatch when expiring.

Amend commit 434cd832 to error when the db history in archive.info and backup.info do not match.

The Perl code would attempt to reconcile the history by matching on system id and version but we are not planning to migrate that code to C.  It's possible that there are users with mismatches but if so they should have been getting errors from info for the last six months.  It's easy enough to manually fix these files if there are any mismatches in the field.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang
2019-06-24 11:59:44 -04:00
committed by David Steele
parent 039e515a31
commit b498188f01
6 changed files with 320 additions and 65 deletions

View File

@@ -330,8 +330,27 @@ removeExpiredArchive(InfoBackup *infoBackup)
strLstAdd(globalBackupArchiveRetentionList, strLstGet(globalBackupRetentionList, idx));
}
// From newest to oldest, confirm the pgVersion and pgSystemId from the archive.info history id match that of the
// same history id of the backup.info and if not, there is a mismatch between the info files so do not continue.
// NOTE: If the archive.info file was reconstructed and contains history 4: version 10, sys-id 456 and history 3:
// version 9.6, sys-id 123, but backup.info contains history 4 and 3 (identical to archive.info) but also 2 and 1
// then an error will not be thrown since only archive 4 and 3 would have existed and the others expired so
// nothing really to do.
for (unsigned int infoPgIdx = 0; infoPgIdx < infoPgDataTotal(infoArchivePgData); infoPgIdx++)
{
InfoPgData archiveInfoPgHistory = infoPgData(infoArchivePgData, infoPgIdx);
InfoPgData backupInfoPgHistory = infoPgData(infoBackupPg(infoBackup), infoPgIdx);
if (archiveInfoPgHistory.id != backupInfoPgHistory.id ||
archiveInfoPgHistory.systemId != backupInfoPgHistory.systemId ||
archiveInfoPgHistory.version != backupInfoPgHistory.version)
{
THROW(FormatError, "archive expiration cannot continue - archive and backup history lists do not match");
}
}
// Loop through the archive.info history from oldest to newest and if there is a corresponding directory on disk
// then remove WAL that are not part of retention
// then remove WAL that are not part of retention as long as the db:history id verion/system-id matches backup.info
for (unsigned int pgIdx = infoPgDataTotal(infoArchivePgData) - 1; (int)pgIdx >= 0; pgIdx--)
{
String *archiveId = infoPgArchiveId(infoArchivePgData, pgIdx);
@@ -342,7 +361,7 @@ removeExpiredArchive(InfoBackup *infoBackup)
for (unsigned int archiveIdx = 0; archiveIdx < strLstSize(listArchiveDisk); archiveIdx++)
{
// Is there an archive directory for this archvieId?
// Is there an archive directory for this archvieId? If not, move on to the next.
if (strCmp(archiveId, strLstGet(listArchiveDisk, archiveIdx)) != 0)
continue;

View File

@@ -695,7 +695,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: expire
total: 6
total: 7
coverage:
command/expire/expire: full

View File

@@ -535,31 +535,8 @@ P00 INFO: full backup size = 48MB
P00 INFO: new backup label = [BACKUP-FULL-1]
P00 INFO: backup command end: completed successfully
P00 INFO: expire command begin
P00 INFO: full backup total < 2 - using oldest full backup for 9.3-1 archive retention
P00 INFO: expire command end: completed successfully
+ supplemental file: [TEST_PATH]/db-master/pgbackrest.conf
----------------------------------------------------------
[db]
pg1-path=[TEST_PATH]/db-master/db/base
[global]
compress-level=3
db-timeout=45
lock-path=[TEST_PATH]/db-master/lock
log-level-console=detail
log-level-file=trace
log-level-stderr=off
log-path=[TEST_PATH]/db-master/log
log-subprocess=y
log-timestamp=n
protocol-timeout=60
repo1-path=[TEST_PATH]/db-master/repo
spool-path=[TEST_PATH]/db-master/spool
[global:backup]
archive-copy=y
start-fast=y
P00 ERROR: [029]: archive expiration cannot continue - archive and backup history lists do not match
P00 INFO: expire command end: aborted with exception [029]
stanza-create db - fail no force to recreate the stanza from backups (db-master host)
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --stanza=db --no-online stanza-create
@@ -631,6 +608,7 @@ stanza-upgrade db - successfully upgrade with XX.Y-Z (db-master host)
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --stanza=db --no-online stanza-upgrade
------------------------------------------------------------------------------------------------------------------------------------
P00 INFO: stanza-upgrade command begin [BACKREST-VERSION]: --compress-level=3 --config=[TEST_PATH]/db-master/pgbackrest.conf --db-timeout=45 --lock-path=[TEST_PATH]/db-master/lock --log-level-console=detail --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/db-master/log --log-subprocess --no-log-timestamp --no-online --pg1-path=[TEST_PATH]/db-master/db/base --protocol-timeout=60 --repo1-path=[TEST_PATH]/db-master/repo --stanza=db
P00 WARN: backup [BACKUP-FULL-1] found in repository added to backup.info
P00 INFO: stanza-upgrade command end: completed successfully
+ supplemental file: [TEST_PATH]/db-master/repo/backup/db/backup.info
@@ -646,13 +624,14 @@ backrest-version="[VERSION-1]"
[db]
db-catalog-version=201510051
db-control-version=942
db-id=2
db-id=3
db-system-id=1000000000000000095
db-version="9.5"
[db:history]
1={"db-catalog-version":201409291,"db-control-version":942,"db-system-id":1000000000000000094,"db-version":"9.4"}
2={"db-catalog-version":201510051,"db-control-version":942,"db-system-id":1000000000000000095,"db-version":"9.5"}
1={"db-catalog-version":201306121,"db-control-version":937,"db-system-id":1000000000000000093,"db-version":"9.3"}
2={"db-catalog-version":201409291,"db-control-version":942,"db-system-id":1000000000000000094,"db-version":"9.4"}
3={"db-catalog-version":201510051,"db-control-version":942,"db-system-id":1000000000000000095,"db-version":"9.5"}
+ supplemental file: [TEST_PATH]/db-master/repo/archive/db/archive.info
-----------------------------------------------------------------------
@@ -669,9 +648,54 @@ db-version="9.5"
[db:history]
1={"db-id":1000000000000000093,"db-version":"9.3"}
2={"db-id":1000000000000000094,"db-version":"9.4"}
3={"db-id":1000000000000000094,"db-version":"10.0"}
3={"db-id":1000000000000000100,"db-version":"10"}
4={"db-id":1000000000000000095,"db-version":"9.5"}
stanza-upgrade db - successfully upgrade - no info file mismatch (db-master host)
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --stanza=db --no-online stanza-upgrade
------------------------------------------------------------------------------------------------------------------------------------
P00 INFO: stanza-upgrade command begin [BACKREST-VERSION]: --compress-level=3 --config=[TEST_PATH]/db-master/pgbackrest.conf --db-timeout=45 --lock-path=[TEST_PATH]/db-master/lock --log-level-console=detail --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/db-master/log --log-subprocess --no-log-timestamp --no-online --pg1-path=[TEST_PATH]/db-master/db/base --protocol-timeout=60 --repo1-path=[TEST_PATH]/db-master/repo --stanza=db
P00 INFO: stanza-upgrade command end: completed successfully
+ supplemental file: [TEST_PATH]/db-master/repo/backup/db/backup.info
---------------------------------------------------------------------
[backrest]
backrest-checksum="[CHECKSUM]"
backrest-format=5
backrest-version="[VERSION-1]"
[backup:current]
[BACKUP-FULL-1]={"backrest-format":5,"backrest-version":"[VERSION-1]","backup-archive-start":null,"backup-archive-stop":null,"backup-info-repo-size":[SIZE],"backup-info-repo-size-delta":[DELTA],"backup-info-size":[SIZE],"backup-info-size-delta":[DELTA],"backup-timestamp-start":[TIMESTAMP],"backup-timestamp-stop":[TIMESTAMP],"backup-type":"full","db-id":1,"option-archive-check":true,"option-archive-copy":true,"option-backup-standby":false,"option-checksum-page":false,"option-compress":true,"option-hardlink":false,"option-online":false}
[db]
db-catalog-version=201510051
db-control-version=942
db-id=3
db-system-id=1000000000000000095
db-version="9.5"
[db:history]
1={"db-catalog-version":201306121,"db-control-version":937,"db-system-id":1000000000000000093,"db-version":"9.3"}
2={"db-catalog-version":201409291,"db-control-version":942,"db-system-id":1000000000000000094,"db-version":"9.4"}
3={"db-catalog-version":201510051,"db-control-version":942,"db-system-id":1000000000000000095,"db-version":"9.5"}
+ supplemental file: [TEST_PATH]/db-master/repo/archive/db/archive.info
-----------------------------------------------------------------------
[backrest]
backrest-checksum="[CHECKSUM]"
backrest-format=5
backrest-version="[VERSION-1]"
[db]
db-id=3
db-system-id=1000000000000000095
db-version="9.5"
[db:history]
1={"db-id":1000000000000000093,"db-version":"9.3"}
2={"db-id":1000000000000000094,"db-version":"9.4"}
3={"db-id":1000000000000000095,"db-version":"9.5"}
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --log-level-console=warn --archive-push-queue-max=33554432 --stanza=db archive-push [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
------------------------------------------------------------------------------------------------------------------------------------
@@ -690,6 +714,7 @@ P00 INFO: full backup size = 48MB
P00 INFO: new backup label = [BACKUP-FULL-2]
P00 INFO: backup command end: completed successfully
P00 INFO: expire command begin
P00 INFO: remove archive path: [TEST_PATH]/db-master/repo/archive/db/9.4-2
P00 INFO: expire command end: completed successfully
+ supplemental file: [TEST_PATH]/db-master/pgbackrest.conf
@@ -725,15 +750,15 @@ info all stanzas - db upgraded - db-1 and db-2 listed (db-master host)
"database" : {
"id" : 1
},
"id" : "9.4-2",
"max" : "000000010000000100000001",
"min" : "000000010000000100000001"
"id" : "9.3-1",
"max" : "000000010000000100000002",
"min" : "000000010000000100000002"
},
{
"database" : {
"id" : 2
"id" : 3
},
"id" : "9.5-4",
"id" : "9.5-3",
"max" : "000000010000000100000001",
"min" : "000000010000000100000001"
}
@@ -778,7 +803,7 @@ info all stanzas - db upgraded - db-1 and db-2 listed (db-master host)
"version" : "[VERSION-1]"
},
"database" : {
"id" : 2
"id" : 3
},
"info" : {
"delta" : [DELTA],
@@ -802,11 +827,16 @@ info all stanzas - db upgraded - db-1 and db-2 listed (db-master host)
"db" : [
{
"id" : 1,
"system-id" : 1000000000000000093,
"version" : "9.3"
},
{
"id" : 2,
"system-id" : 1000000000000000094,
"version" : "9.4"
},
{
"id" : 2,
"id" : 3,
"system-id" : 1000000000000000095,
"version" : "9.5"
}

View File

@@ -428,7 +428,7 @@ db-version="9.4"
1={"db-id":1000000000000000093,"db-version":"9.3"}
2={"db-id":1000000000000000094,"db-version":"9.4"}
stanza-upgrade db - successfully upgrade with XX.Y-Z (backup host)
stanza-upgrade db - successfully upgrade - no info file mismatch (backup host)
> [CONTAINER-EXEC] backup [BACKREST-BIN] --config=[TEST_PATH]/backup/pgbackrest.conf --stanza=db --no-online stanza-upgrade
------------------------------------------------------------------------------------------------------------------------------------
P00 INFO: stanza-upgrade command begin [BACKREST-VERSION]: --compress-level=3 --compress-level-network=1 --config=[TEST_PATH]/backup/pgbackrest.conf --db-timeout=45 --lock-path=[TEST_PATH]/backup/lock --log-level-console=detail --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/backup/log --log-subprocess --no-log-timestamp --no-online --pg1-host=db-master --pg1-host-cmd=[BACKREST-BIN] --pg1-host-config=[TEST_PATH]/db-master/pgbackrest.conf --pg1-host-user=[USER-1] --pg1-path=[TEST_PATH]/db-master/db/base --protocol-timeout=60 --repo1-cipher-pass=<redacted> --repo1-cipher-type=aes-256-cbc --repo1-path=/ --repo1-s3-bucket=pgbackrest-dev --repo1-s3-endpoint=s3.amazonaws.com --repo1-s3-key=<redacted> --repo1-s3-key-secret=<redacted> --repo1-s3-region=us-east-1 --no-repo1-s3-verify-tls --repo1-type=s3 --stanza=db
@@ -470,15 +470,14 @@ backrest-version="[VERSION-1]"
cipher-pass=[CIPHER-PASS-2]
[db]
db-id=4
db-id=3
db-system-id=1000000000000000095
db-version="9.5"
[db:history]
1={"db-id":1000000000000000093,"db-version":"9.3"}
2={"db-id":1000000000000000094,"db-version":"9.4"}
3={"db-id":1000000000000000094,"db-version":"10.0"}
4={"db-id":1000000000000000095,"db-version":"9.5"}
3={"db-id":1000000000000000095,"db-version":"9.5"}
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --log-level-console=warn --archive-push-queue-max=33554432 --stanza=db archive-push [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
------------------------------------------------------------------------------------------------------------------------------------
@@ -579,7 +578,7 @@ info all stanzas - db upgraded - db-1 and db-2 listed (db-master host)
"database" : {
"id" : 3
},
"id" : "9.5-4",
"id" : "9.5-3",
"max" : "000000010000000100000001",
"min" : "000000010000000100000001"
}

View File

@@ -292,6 +292,8 @@ sub run
# Remove the archive info file and force reconstruction
if (!$bEncrypt)
{
forceStorageMove(storageRepo(), $strArchiveInfoFile, $strArchiveInfoOldFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strArchiveInfoCopyFile, $strArchiveInfoCopyOldFile, {bRecurse => false});
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
@@ -303,6 +305,8 @@ sub run
#--------------------------------------------------------------------------------------------------------------------------
if (!$bEncrypt)
{
forceStorageMove(storageRepo(), $strBackupInfoFile, $strBackupInfoOldFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strBackupInfoCopyFile, $strBackupInfoCopyOldFile, {bRecurse => false});
forceStorageRemove(storageRepo(), $strBackupInfoFile);
forceStorageRemove(storageRepo(), $strBackupInfoCopyFile);
@@ -310,13 +314,15 @@ sub run
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE)});
}
# Confirm successful backup at db-1 although archive at db-2
# Confirm successful backup at db-1 although archive at db-2 and format error thrown by expire (if not encrypted) since
# archive.info history and backup.info history are mismatched
#--------------------------------------------------------------------------------------------------------------------------
# Create the tablespace directory and perform a backup
storageTest()->pathCreate($oHostDbMaster->dbBasePath() . '/' . DB_PATH_PGTBLSPC);
$oHostBackup->backup(
'full', 'create first full backup ',
{strOptionalParam => '--repo1-retention-full=2 --no-' . cfgOptionName(CFGOPT_ONLINE)}, false);
{iExpectedExitStatus => $bEncrypt ? undef : ERROR_FORMAT,
strOptionalParam => '--repo1-retention-full=2 --no-' . cfgOptionName(CFGOPT_ONLINE)}, false);
# Stanza Create fails when not using force - no backup.info but backup exists
#--------------------------------------------------------------------------------------------------------------------------
@@ -340,31 +346,45 @@ sub run
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE) . ' --' . cfgOptionName(CFGOPT_FORCE),
iExpectedExitStatus => $bEncrypt ? ERROR_FILE_MISSING : undef});
# Encrypted info files could not be reconstructed above so just copy them back
if ($bEncrypt)
{
forceStorageMove(storageRepo(), $strBackupInfoOldFile, $strBackupInfoFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strBackupInfoCopyOldFile, $strBackupInfoCopyFile, {bRecurse => false});
}
# Test archive dir version XX.Y-Z ensuring sort order of db ids is reconstructed correctly from the directory db-id value
#--------------------------------------------------------------------------------------------------------------------------
# Create the 10.0-3 directory and copy a WAL file to it (something that has a different system id)
forceStorageMode(storageRepo(), STORAGE_REPO_ARCHIVE, '770');
storageRepo()->pathCreate(STORAGE_REPO_ARCHIVE . '/10.0-3/0000000100000001', {bCreateParent => true});
storageRepo()->put(
storageRepo()->openWrite(
STORAGE_REPO_ARCHIVE . '/10.0-3/0000000100000001/000000010000000100000001',
{strCipherPass => $oHostBackup->cipherPassArchive()}),
$self->walGenerateContent(PG_VERSION_94));
forceStorageOwner(storageRepo(), STORAGE_REPO_ARCHIVE . '/10.0-3', $oHostBackup->userGet(), {bRecurse => true});
# Copy old backup.info files back to avoid history mismatch
forceStorageMove(storageRepo(), $strBackupInfoOldFile, $strBackupInfoFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strBackupInfoCopyOldFile, $strBackupInfoCopyFile, {bRecurse => false});
# Copy pg_control for 9.5
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_95);
forceStorageMode(storageDb(), $oHostDbMaster->dbBasePath() . '/' . DB_FILE_PGCONTROL, '600');
# Test archive dir version XX.Y-Z ensuring sort order of db ids is reconstructed correctly from the directory db-id value.
# Not testing with encryption since unnecessary and copying files around in this case is burdensome.
#--------------------------------------------------------------------------------------------------------------------------
if (!$bEncrypt)
{
# Create the 10-3 directory and copy a WAL file to it (with a different system id than what it will be upgraded to)
forceStorageMode(storageRepo(), STORAGE_REPO_ARCHIVE, '770');
storageRepo()->pathCreate(STORAGE_REPO_ARCHIVE . '/10-3/0000000100000001', {bCreateParent => true});
storageRepo()->put(
storageRepo()->openWrite(
STORAGE_REPO_ARCHIVE . '/10-3/0000000100000001/000000010000000100000001',
{strCipherPass => $oHostBackup->cipherPassArchive()}),
$self->walGenerateContent(PG_VERSION_10));
forceStorageOwner(storageRepo(), STORAGE_REPO_ARCHIVE . '/10-3', $oHostBackup->userGet(), {bRecurse => true});
# Make sure the archive.info has the history in the db-id order such that 10 is before 9.5.
$oHostBackup->stanzaUpgrade(
'successfully upgrade with XX.Y-Z',
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
# Remove the 10-3 directory and copy old archive.info file back. Recreate so archive.info and backup.info files match.
forceStorageRemove(storageRepo(), STORAGE_REPO_ARCHIVE . '/10-3', {bRecurse => true});
forceStorageRemove(storageRepo(), $strArchiveInfoFile);
forceStorageRemove(storageRepo(), $strArchiveInfoCopyFile);
forceStorageMove(storageRepo(), $strArchiveInfoOldFile, $strArchiveInfoFile, {bRecurse => false});
forceStorageMove(storageRepo(), $strArchiveInfoCopyOldFile, $strArchiveInfoCopyFile, {bRecurse => false});
}
$oHostBackup->stanzaUpgrade(
'successfully upgrade with XX.Y-Z', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
'successfully upgrade - no info file mismatch',
{strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
# Push a WAL and create a backup in the new DB to confirm diff changed to full and info command displays the JSON correctly
#--------------------------------------------------------------------------------------------------------------------------

View File

@@ -838,6 +838,193 @@ testRun(void)
harnessLogLevelReset();
}
// *****************************************************************************************************************************
if (testBegin("info files mismatch"))
{
// Load Parameters
StringList *argList = strLstDup(argListBase);
strLstAddZ(argList, "--repo1-retention-full=2");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
// archive.info has only current db with different db history id as backup.info
//--------------------------------------------------------------------------------------------------------------------------
storagePutNP(storageNewWriteNP(storageTest, backupInfoFileName),
harnessInfoChecksumZ(
"[backup:current]\n"
"20181119-152138F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
"\"backup-archive-start\":\"000000010000000000000002\",\"backup-archive-stop\":\"000000010000000000000002\","
"\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186,"
"\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900,"
"\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\","
"\"db-id\":1,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false,"
"\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n"
"20181119-152800F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
"\"backup-archive-start\":\"000000010000000000000004\",\"backup-archive-stop\":\"000000010000000000000004\","
"\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186,"
"\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900,"
"\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\","
"\"db-id\":2,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false,"
"\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n"
"20181119-152900F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
"\"backup-archive-start\":\"000000010000000000000006\",\"backup-archive-stop\":\"000000010000000000000006\","
"\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186,"
"\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900,"
"\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\","
"\"db-id\":2,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false,"
"\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n"
"\n"
"[db]\n"
"db-catalog-version=201707211\n"
"db-control-version=1002\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
"db-version=\"10\"\n"
"\n"
"[db:history]\n"
"1={\"db-catalog-version\":201409291,\"db-control-version\":1002,\"db-system-id\":6625592122879095702,"
"\"db-version\":\"10\"}\n"
"2={\"db-catalog-version\":201707211,\"db-control-version\":1002,\"db-system-id\":6626363367545678089,"
"\"db-version\":\"10\"}\n"));
storagePutNP(
storageNewWriteNP(storageTest, archiveInfoFileName),
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"db-system-id=6626363367545678089\n"
"db-version=\"10\"\n"
"\n"
"[db:history]\n"
"1={\"db-id\":6626363367545678089,\"db-version\":\"10\"}"));
// Create 10-1 and 10-2 although 10-2 is not realistic since the archive.info knows nothing about it - it is just to
// confirm that nothing from disk is removed and it will also be used for the next test.
archiveGenerate(storageTest, archiveStanzaPath, 1, 7, "10-1", "0000000100000000");
archiveGenerate(storageTest, archiveStanzaPath, 1, 7, "10-2", "0000000100000000");
TEST_ERROR(cmdExpire(), FormatError, "archive expiration cannot continue - archive and backup history lists do not match");
harnessLogResult("P00 INFO: expire full backup 20181119-152138F");
TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-1", "0000000100000000")), sortOrderAsc), ", ")),
strPtr(archiveExpectList(1, 7, "0000000100000000")),
" none removed from 10-1/0000000100000000");
TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-2", "0000000100000000")), sortOrderAsc), ", ")),
strPtr(archiveExpectList(1, 7, "0000000100000000")),
" none removed from 10-2/0000000100000000");
// archive.info old history db system id not the same as backup.info
//--------------------------------------------------------------------------------------------------------------------------
storagePutNP(
storageNewWriteNP(storageTest, archiveInfoFileName),
harnessInfoChecksumZ(
"[db]\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
"db-version=\"10\"\n"
"\n"
"[db:history]\n"
"1={\"db-id\":6626363367545671234,\"db-version\":\"10\"}\n"
"2={\"db-id\":6626363367545678089,\"db-version\":\"10\"}"));
TEST_ERROR(cmdExpire(), FormatError, "archive expiration cannot continue - archive and backup history lists do not match");
// archive.info old history db version not the same as backup.info
//--------------------------------------------------------------------------------------------------------------------------
storagePutNP(
storageNewWriteNP(storageTest, archiveInfoFileName),
harnessInfoChecksumZ(
"[db]\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
"db-version=\"10\"\n"
"\n"
"[db:history]\n"
"1={\"db-id\":6625592122879095702,\"db-version\":\"9.4\"}\n"
"2={\"db-id\":6626363367545678089,\"db-version\":\"10\"}"));
TEST_ERROR(cmdExpire(), FormatError, "archive expiration cannot continue - archive and backup history lists do not match");
// archive.info has only current db with same db history id as backup.info
//--------------------------------------------------------------------------------------------------------------------------
storagePutNP(storageNewWriteNP(storageTest, backupInfoFileName),
harnessInfoChecksumZ(
"[backup:current]\n"
"20181119-152138F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
"\"backup-archive-start\":\"000000010000000000000002\",\"backup-archive-stop\":\"000000010000000000000002\","
"\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186,"
"\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900,"
"\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\","
"\"db-id\":1,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false,"
"\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n"
"20181119-152800F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
"\"backup-archive-start\":\"000000010000000000000004\",\"backup-archive-stop\":\"000000010000000000000004\","
"\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186,"
"\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900,"
"\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\","
"\"db-id\":2,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false,"
"\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n"
"20181119-152900F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
"\"backup-archive-start\":\"000000010000000000000006\",\"backup-archive-stop\":\"000000010000000000000006\","
"\"backup-info-repo-size\":2369186,\"backup-info-repo-size-delta\":2369186,"
"\"backup-info-size\":20162900,\"backup-info-size-delta\":20162900,"
"\"backup-timestamp-start\":1542640898,\"backup-timestamp-stop\":1542640911,\"backup-type\":\"full\","
"\"db-id\":2,\"option-archive-check\":true,\"option-archive-copy\":false,\"option-backup-standby\":false,"
"\"option-checksum-page\":true,\"option-compress\":true,\"option-hardlink\":false,\"option-online\":true}\n"
"\n"
"[db]\n"
"db-catalog-version=201707211\n"
"db-control-version=1002\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
"db-version=\"10\"\n"
"\n"
"[db:history]\n"
"1={\"db-catalog-version\":201409291,\"db-control-version\":1002,\"db-system-id\":6625592122879095702,"
"\"db-version\":\"10\"}\n"
"2={\"db-catalog-version\":201707211,\"db-control-version\":1002,\"db-system-id\":6626363367545678089,"
"\"db-version\":\"10\"}\n"));
storagePutNP(
storageNewWriteNP(storageTest, archiveInfoFileName),
harnessInfoChecksumZ(
"[db]\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
"db-version=\"10\"\n"
"\n"
"[db:history]\n"
"2={\"db-id\":6626363367545678089,\"db-version\":\"10\"}"));
argList = strLstDup(argListBase);
strLstAddZ(argList, "--repo1-retention-full=1");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
// Here, although backup 20181119-152138F of 10-1 will be expired, the WAL in 10-1 will not since the archive.info
// does not know about that dir. Again, not really realistic since if it is on disk and reconstructed it would have. So
// here we are testing that things on disk that we are not aware of are not touched.
TEST_RESULT_VOID(cmdExpire(), "Expire archive that archive.info is aware of");
harnessLogResult("P00 INFO: expire full backup 20181119-152138F\nP00 INFO: expire full backup 20181119-152800F");
TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-1", "0000000100000000")), sortOrderAsc), ", ")),
strPtr(archiveExpectList(1, 7, "0000000100000000")),
" none removed from 10-1/0000000100000000");
TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-2", "0000000100000000")), sortOrderAsc), ", ")),
strPtr(archiveExpectList(6, 7, "0000000100000000")),
" all prior to 000000010000000000000006 removed from 10-2/0000000100000000");
}
// *****************************************************************************************************************************
if (testBegin("sortArchiveId()"))