backup cleaner: better error messages

This commit is contained in:
Girish Ramakrishnan
2023-01-31 10:56:37 +01:00
parent af7a5d2182
commit ebd970d3f4

View File

@@ -36,7 +36,7 @@ function applyBackupRetentionPolicy(allBackups, policy, referencedBackupIds) {
if ((now - backup.creationTime) < 48*60*60*1000) backup.keepReason = 'creating';
else backup.discardReason = 'creating-too-long';
} else if (referencedBackupIds.includes(backup.id)) {
backup.keepReason = 'reference';
backup.keepReason = 'referenced';
} else if ((backup.preserveSecs === -1) || ((now - backup.creationTime) < (backup.preserveSecs * 1000))) {
backup.keepReason = 'preserveSecs';
} else if ((now - backup.creationTime < policy.keepWithinSecs * 1000) || policy.keepWithinSecs < 0) {
@@ -60,7 +60,7 @@ function applyBackupRetentionPolicy(allBackups, policy, referencedBackupIds) {
let lastPeriod = null, keptSoFar = 0;
for (const backup of allBackups) {
if (backup.discardReason) continue; // already discarded for some reason
if (backup.keepReason && backup.keepReason !== 'reference') continue; // kept for some other reason
if (backup.keepReason && backup.keepReason !== 'referenced') continue; // kept for some other reason
const period = moment(backup.creationTime).format(KEEP_FORMATS[format]);
if (period === lastPeriod) continue; // already kept for this period
@@ -76,7 +76,7 @@ function applyBackupRetentionPolicy(allBackups, policy, referencedBackupIds) {
}
for (const backup of allBackups) {
debug(`applyBackupRetentionPolicy: ${backup.id} ${backup.type} ${backup.keepReason || backup.discardReason || 'unprocessed'}`);
debug(`applyBackupRetentionPolicy: ${backup.remotePath} keep/discard: ${backup.keepReason || backup.discardReason || 'unprocessed'}`);
}
}
@@ -97,13 +97,13 @@ async function removeBackup(backupConfig, backup, progressCallback) {
}
if (removeError) {
debug('removeBackup: error removing backup %j : %s', backup, removeError.message);
debug(`removeBackup: error removing backup ${removeError.message}`);
return;
}
// prune empty directory if possible
const [pruneError] = await safe(storage.api(backupConfig.provider).remove(backupConfig, path.dirname(backupFilePath)));
if (pruneError) debug('removeBackup: unable to prune backup directory %s : %s', path.dirname(backupFilePath), pruneError.message);
if (pruneError) debug(`removeBackup: unable to prune backup directory ${path.dirname(backupFilePath)}: ${pruneError.message}`);
const [delError] = await safe(backups.del(backup.id));
if (delError) debug(`removeBackup: error removing ${backup.id} from database`, delError);
@@ -197,7 +197,7 @@ async function cleanupBoxBackups(backupConfig, progressCallback) {
return { removedBoxBackupPaths, referencedBackupIds };
}
// cleans up the database by checking if backup existsing in the remote
// cleans up the database by checking if backup exists in the remote
async function cleanupMissingBackups(backupConfig, progressCallback) {
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof progressCallback, 'function');