mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Add temporary mem context to removeExpiredBackup().
This was not really a leak since memory was being freed by the calling function, but this function does enough work to deserve its own memory context. Also fixed a doubled semicolon.
This commit is contained in:
parent
9314be36b1
commit
fd295f002b
@ -795,66 +795,71 @@ removeExpiredBackup(InfoBackup *infoBackup, const String *adhocBackupLabel, unsi
|
|||||||
|
|
||||||
ASSERT(infoBackup != NULL);
|
ASSERT(infoBackup != NULL);
|
||||||
|
|
||||||
// Get all the current backups in backup.info - these will not be expired
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
StringList *currentBackupList = strLstSort(infoBackupDataLabelList(infoBackup, NULL), sortOrderDesc);
|
|
||||||
|
|
||||||
// Get all the backups on disk
|
|
||||||
StringList *backupList = strLstSort(
|
|
||||||
storageListP(
|
|
||||||
storageRepoIdx(repoIdx), STORAGE_REPO_BACKUP_STR,
|
|
||||||
.expression = backupRegExpP(.full = true, .differential = true, .incremental = true)),
|
|
||||||
sortOrderDesc);
|
|
||||||
|
|
||||||
// Initialize the index to the latest backup on disk
|
|
||||||
unsigned int backupIdx = 0;
|
|
||||||
|
|
||||||
// Only remove the resumable backup if there is a possibility it is a dependent of the adhoc label being expired
|
|
||||||
if (adhocBackupLabel != NULL)
|
|
||||||
{
|
{
|
||||||
String *manifestFileName = strNewFmt(
|
// Get all the current backups in backup.info - these will not be expired
|
||||||
STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(strLstGet(backupList, backupIdx)));
|
StringList *currentBackupList = strLstSort(infoBackupDataLabelList(infoBackup, NULL), sortOrderDesc);
|
||||||
String *manifestCopyFileName = strNewFmt("%s" INFO_COPY_EXT, strZ(manifestFileName));
|
|
||||||
|
|
||||||
// If the latest backup is resumable (has a backup.manifest.copy but no backup.manifest)
|
// Get all the backups on disk
|
||||||
if (!storageExistsP(storageRepoIdx(repoIdx), manifestFileName) &&
|
StringList *backupList = strLstSort(
|
||||||
storageExistsP(storageRepoIdx(repoIdx), manifestCopyFileName))
|
storageListP(
|
||||||
|
storageRepoIdx(repoIdx), STORAGE_REPO_BACKUP_STR,
|
||||||
|
.expression = backupRegExpP(.full = true, .differential = true, .incremental = true)),
|
||||||
|
sortOrderDesc);
|
||||||
|
|
||||||
|
// Initialize the index to the latest backup on disk
|
||||||
|
unsigned int backupIdx = 0;
|
||||||
|
|
||||||
|
// Only remove the resumable backup if there is a possibility it is a dependent of the adhoc label being expired
|
||||||
|
if (adhocBackupLabel != NULL)
|
||||||
{
|
{
|
||||||
// If the resumable backup is not related to the expired adhoc backup then don't remove it
|
String *manifestFileName = strNewFmt(
|
||||||
if (!strBeginsWith(strLstGet(backupList, backupIdx), strSubN(adhocBackupLabel, 0, 16)))
|
STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(strLstGet(backupList, backupIdx)));
|
||||||
{
|
String *manifestCopyFileName = strNewFmt("%s" INFO_COPY_EXT, strZ(manifestFileName));
|
||||||
backupIdx = 1;
|
|
||||||
}
|
|
||||||
// Else it may be related to the adhoc backup so check if its ancestor still exists
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Manifest *manifestResume = manifestLoadFile(
|
|
||||||
storageRepoIdx(repoIdx), manifestFileName, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
|
|
||||||
infoPgCipherPass(infoBackupPg(infoBackup)));
|
|
||||||
|
|
||||||
// If the ancestor of the resumable backup still exists in backup.info then do not remove the resumable backup
|
// If the latest backup is resumable (has a backup.manifest.copy but no backup.manifest)
|
||||||
if (infoBackupLabelExists(infoBackup, manifestData(manifestResume)->backupLabelPrior))
|
if (!storageExistsP(storageRepoIdx(repoIdx), manifestFileName) &&
|
||||||
|
storageExistsP(storageRepoIdx(repoIdx), manifestCopyFileName))
|
||||||
|
{
|
||||||
|
// If the resumable backup is not related to the expired adhoc backup then don't remove it
|
||||||
|
if (!strBeginsWith(strLstGet(backupList, backupIdx), strSubN(adhocBackupLabel, 0, 16)))
|
||||||
|
{
|
||||||
backupIdx = 1;
|
backupIdx = 1;
|
||||||
|
}
|
||||||
|
// Else it may be related to the adhoc backup so check if its ancestor still exists
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Manifest *manifestResume = manifestLoadFile(
|
||||||
|
storageRepoIdx(repoIdx), manifestFileName, cfgOptionIdxStrId(cfgOptRepoCipherType, repoIdx),
|
||||||
|
infoPgCipherPass(infoBackupPg(infoBackup)));
|
||||||
|
|
||||||
|
// If the ancestor of the resumable backup still exists in backup.info then do not remove the resumable backup
|
||||||
|
if (infoBackupLabelExists(infoBackup, manifestData(manifestResume)->backupLabelPrior))
|
||||||
|
backupIdx = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Remove non-current backups from disk
|
// Remove non-current backups from disk
|
||||||
for (; backupIdx < strLstSize(backupList); backupIdx++)
|
for (; backupIdx < strLstSize(backupList); backupIdx++)
|
||||||
{
|
|
||||||
if (!strLstExists(currentBackupList, strLstGet(backupList, backupIdx)))
|
|
||||||
{
|
{
|
||||||
LOG_INFO_FMT(
|
if (!strLstExists(currentBackupList, strLstGet(backupList, backupIdx)))
|
||||||
"%s: remove expired backup %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(strLstGet(backupList, backupIdx)));
|
|
||||||
|
|
||||||
// Execute the real expiration and deletion only if the dry-run mode is disabled
|
|
||||||
if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun))
|
|
||||||
{
|
{
|
||||||
storagePathRemoveP(
|
LOG_INFO_FMT(
|
||||||
storageRepoIdxWrite(repoIdx), strNewFmt(STORAGE_REPO_BACKUP "/%s", strZ(strLstGet(backupList, backupIdx))),
|
"%s: remove expired backup %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
|
||||||
.recurse = true);
|
strZ(strLstGet(backupList, backupIdx)));
|
||||||
|
|
||||||
|
// Execute the real expiration and deletion only if the dry-run mode is disabled
|
||||||
|
if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun))
|
||||||
|
{
|
||||||
|
storagePathRemoveP(
|
||||||
|
storageRepoIdxWrite(repoIdx), strNewFmt(STORAGE_REPO_BACKUP "/%s", strZ(strLstGet(backupList, backupIdx))),
|
||||||
|
.recurse = true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN_VOID();
|
FUNCTION_LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
@ -1065,7 +1070,7 @@ cmdExpire(void)
|
|||||||
CATCH_ANY()
|
CATCH_ANY()
|
||||||
{
|
{
|
||||||
LOG_ERROR_FMT(errorTypeCode(errorType()), "%s: %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorMessage());
|
LOG_ERROR_FMT(errorTypeCode(errorType()), "%s: %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorMessage());
|
||||||
errorTotal++;;
|
errorTotal++;
|
||||||
}
|
}
|
||||||
TRY_END();
|
TRY_END();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user