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

Update expire command to use C backup.info reconstruct.

This was still being done in Perl until the C Manifest object was available.
This commit is contained in:
Cynthia Shang 2019-10-08 17:30:33 -04:00 committed by David Steele
parent 4e4d1f414a
commit ecae5e34e5
5 changed files with 64 additions and 18 deletions

View File

@ -154,13 +154,6 @@ sub main
new pgBackRest::Backup::Backup()->process();
}
# Process expire command
# ----------------------------------------------------------------------------------------------------------------------
elsif (cfgCommandTest(CFGCMD_EXPIRE))
{
new pgBackRest::Backup::Info(storageRepo()->pathGet(STORAGE_REPO_BACKUP));
}
}
return 1;

View File

@ -63,7 +63,7 @@ expireBackup(InfoBackup *infoBackup, String *removeBackupLabel, String *backupEx
storageRemoveNP(
storageRepoWrite(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, strPtr(removeBackupLabel)));
// Remove the backup from the info file
// Remove the backup from the info object
infoBackupDataDelete(infoBackup, removeBackupLabel);
if (strSize(backupExpired) == 0)
@ -632,7 +632,7 @@ cmdExpire(void)
storageRepo();
// Load the backup.info
InfoBackup *infoBackup = infoBackupLoadFile(
InfoBackup *infoBackup = infoBackupLoadFileReconstruct(
storageRepo(), INFO_BACKUP_PATH_FILE_STR, cipherType(cfgOptionStr(cfgOptRepoCipherType)),
cfgOptionStr(cfgOptRepoCipherPass));

View File

@ -124,7 +124,6 @@ main(int argListSize, const char *argList[])
cmdBegin(true);
// Run expire
perlExec();
cmdExpire();
break;

View File

@ -8321,11 +8321,6 @@ static const EmbeddedModule embeddedModule[] =
"\n"
"new pgBackRest::Backup::Backup()->process();\n"
"}\n"
"\n\n\n"
"elsif (cfgCommandTest(CFGCMD_EXPIRE))\n"
"{\n"
"new pgBackRest::Backup::Info(storageRepo()->pathGet(STORAGE_REPO_BACKUP));\n"
"}\n"
"}\n"
"\n"
"return 1;\n"

View File

@ -723,11 +723,36 @@ testRun(void)
strLstAddZ(argList, "--repo1-retention-archive-type=diff");
harnessCfgLoad(cfgCmdExpire, argList);
// Write backup.manifest so infoBackup reconstruct produces same results as backup.info on disk
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152138F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152800F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152800F_20181119-152152D/" BACKUP_MANIFEST_FILE,
strPtr(backupStanzaPath))), BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152800F_20181119-152155I/" BACKUP_MANIFEST_FILE,
strPtr(backupStanzaPath))), BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152800F_20181119-152252D/" BACKUP_MANIFEST_FILE,
strPtr(backupStanzaPath))), BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152900F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152900F_20181119-152500I/" BACKUP_MANIFEST_FILE,
strPtr(backupStanzaPath))), BUFSTRDEF("tmp"));
TEST_RESULT_VOID(cmdExpire(), "expire last backup in archive sub path and remove sub path");
TEST_RESULT_BOOL(
storagePathExistsNP(storageTest, strNewFmt("%s/%s", strPtr(archiveStanzaPath), "9.4-1/0000000100000000")),
false, " archive sub path removed");
harnessLogResult("P00 INFO: expire full backup 20181119-152138F");
harnessLogResult(
"P00 INFO: expire full backup 20181119-152138F\n"
"P00 INFO: remove expired backup 20181119-152138F");
//--------------------------------------------------------------------------------------------------------------------------
argList = strLstDup(argListAvoidWarn);
@ -742,6 +767,10 @@ testRun(void)
harnessLogResult(strPtr(strNewFmt(
"P00 INFO: expire full backup set: 20181119-152800F, 20181119-152800F_20181119-152152D, "
"20181119-152800F_20181119-152155I, 20181119-152800F_20181119-152252D\n"
"P00 INFO: remove expired backup 20181119-152800F_20181119-152252D\n"
"P00 INFO: remove expired backup 20181119-152800F_20181119-152155I\n"
"P00 INFO: remove expired backup 20181119-152800F_20181119-152152D\n"
"P00 INFO: remove expired backup 20181119-152800F\n"
"P00 INFO: remove archive path: %s/%s/9.4-1", testPath(), strPtr(archiveStanzaPath))));
TEST_ASSIGN(infoBackup, infoBackupLoadFile(storageTest, backupInfoFileName, cipherTypeNone, NULL), " get backup.info");
@ -890,6 +919,18 @@ testRun(void)
"2={\"db-catalog-version\":201707211,\"db-control-version\":1002,\"db-system-id\":6626363367545678089,"
"\"db-version\":\"10\"}\n"));
// Write backup.manifest so infoBackup reconstruct produces same results as backup.info on disk and removeExpiredBackup
// will find backup directories to remove
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152138F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152800F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152900F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, archiveInfoFileName),
harnessInfoChecksumZ(
@ -907,7 +948,9 @@ testRun(void)
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");
harnessLogResult(
"P00 INFO: expire full backup 20181119-152138F\n"
"P00 INFO: remove expired backup 20181119-152138F");
TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-1", "0000000100000000")), sortOrderAsc), ", ")),
@ -994,6 +1037,18 @@ testRun(void)
"2={\"db-catalog-version\":201707211,\"db-control-version\":1002,\"db-system-id\":6626363367545678089,"
"\"db-version\":\"10\"}\n"));
// Write backup.manifest so infoBackup reconstruct produces same results as backup.info on disk and removeExpiredBackup
// will find backup directories to remove
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152138F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152800F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, strNewFmt("%s/20181119-152900F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
BUFSTRDEF("tmp"));
storagePutNP(
storageNewWriteNP(storageTest, archiveInfoFileName),
harnessInfoChecksumZ(
@ -1014,7 +1069,11 @@ testRun(void)
// 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");
harnessLogResult(
"P00 INFO: expire full backup 20181119-152138F\n"
"P00 INFO: expire full backup 20181119-152800F\n"
"P00 INFO: remove expired backup 20181119-152800F\n"
"P00 INFO: remove expired backup 20181119-152138F");
TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-1", "0000000100000000")), sortOrderAsc), ", ")),