fix the backup tests
This commit is contained in:
+14
-15
@@ -22,14 +22,14 @@ const apps = require('./apps.js'),
|
||||
util = require('util'),
|
||||
_ = require('underscore');
|
||||
|
||||
function applyBackupRetentionPolicy(backups, policy, referencedBackupIds) {
|
||||
assert(Array.isArray(backups));
|
||||
function applyBackupRetentionPolicy(allBackups, policy, referencedBackupIds) {
|
||||
assert(Array.isArray(allBackups));
|
||||
assert.strictEqual(typeof policy, 'object');
|
||||
assert(Array.isArray(referencedBackupIds));
|
||||
|
||||
const now = new Date();
|
||||
|
||||
for (const backup of backups) {
|
||||
for (const backup of allBackups) {
|
||||
if (backup.state === backups.BACKUP_STATE_ERROR) {
|
||||
backup.discardReason = 'error';
|
||||
} else if (backup.state === backups.BACKUP_STATE_CREATING) {
|
||||
@@ -58,7 +58,7 @@ function applyBackupRetentionPolicy(backups, policy, referencedBackupIds) {
|
||||
if (!n) continue; // disabled rule
|
||||
|
||||
let lastPeriod = null, keptSoFar = 0;
|
||||
for (const backup of backups) {
|
||||
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
|
||||
const period = moment(backup.creationTime).format(KEEP_FORMATS[format]);
|
||||
@@ -71,11 +71,11 @@ function applyBackupRetentionPolicy(backups, policy, referencedBackupIds) {
|
||||
}
|
||||
|
||||
if (policy.keepLatest) {
|
||||
let latestNormalBackup = backups.find(b => b.state === backups.BACKUP_STATE_NORMAL);
|
||||
let latestNormalBackup = allBackups.find(b => b.state === backups.BACKUP_STATE_NORMAL);
|
||||
if (latestNormalBackup && !latestNormalBackup.keepReason) latestNormalBackup.keepReason = 'latest';
|
||||
}
|
||||
|
||||
for (const backup of backups) {
|
||||
for (const backup of allBackups) {
|
||||
debug(`applyBackupRetentionPolicy: ${backup.id} ${backup.type} ${backup.keepReason || backup.discardReason || 'unprocessed'}`);
|
||||
}
|
||||
}
|
||||
@@ -279,21 +279,20 @@ function run(progressCallback, callback) {
|
||||
|
||||
progressCallback({ percent: 40, message: 'Cleaning app backups' });
|
||||
|
||||
cleanupAppBackups(backupConfig, referencedAppBackupIds, progressCallback, function (error, removedAppBackupIds) {
|
||||
cleanupAppBackups(backupConfig, referencedAppBackupIds, progressCallback, async function (error, removedAppBackupIds) {
|
||||
if (error) return callback(error);
|
||||
|
||||
progressCallback({ percent: 70, message: 'Cleaning missing backups' });
|
||||
|
||||
cleanupMissingBackups(backupConfig, progressCallback, function (error, missingBackupIds) {
|
||||
const [cleanupMissingBackupsError, missingBackupIds] = await cleanupMissingBackups(backupConfig, progressCallback);
|
||||
if (cleanupMissingBackupsError) return callback(cleanupMissingBackupsError);
|
||||
|
||||
progressCallback({ percent: 90, message: 'Cleaning snapshots' });
|
||||
|
||||
cleanupSnapshots(backupConfig, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
progressCallback({ percent: 90, message: 'Cleaning snapshots' });
|
||||
|
||||
cleanupSnapshots(backupConfig, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, { removedBoxBackupIds, removedAppBackupIds, missingBackupIds });
|
||||
});
|
||||
callback(null, { removedBoxBackupIds, removedAppBackupIds, missingBackupIds });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user