backupcleaner: backupSite -> site
This commit is contained in:
+23
-23
@@ -202,8 +202,8 @@ async function cleanupBoxBackups(site, progressCallback) {
|
||||
}
|
||||
|
||||
// cleans up the database by checking if backup exists in the remote. this can happen if user had set some bucket policy
|
||||
async function cleanupMissingBackups(backupSite, progressCallback) {
|
||||
assert.strictEqual(typeof backupSite, 'object');
|
||||
async function cleanupMissingBackups(site, progressCallback) {
|
||||
assert.strictEqual(typeof site, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
|
||||
const perPage = 1000;
|
||||
@@ -213,14 +213,14 @@ async function cleanupMissingBackups(backupSite, progressCallback) {
|
||||
|
||||
let page = 1, result = [];
|
||||
do {
|
||||
result = await backups.listByTypePaged(backups.BACKUP_TYPE_BOX, backupSite.id, page, perPage);
|
||||
result = await backups.listByTypePaged(backups.BACKUP_TYPE_BOX, site.id, page, perPage);
|
||||
|
||||
for (const backup of result) {
|
||||
if (backup.state !== backups.BACKUP_STATE_NORMAL) continue; // note: errored and incomplete backups are cleaned up by the backup retention logic
|
||||
|
||||
const ext = backupFormats.api(backupSite.format).getFileExtension(!!backupSite.encryption);
|
||||
const ext = backupFormats.api(site.format).getFileExtension(!!site.encryption);
|
||||
const remotePath = backup.remotePath + (ext ? '' : '/'); // add trailing slash to indicate directory
|
||||
const [existsError, exists] = await safe(backupSites.storageApi(backupSite).exists(backupSite.config, remotePath));
|
||||
const [existsError, exists] = await safe(backupSites.storageApi(site).exists(site.config, remotePath));
|
||||
if (existsError || exists) continue;
|
||||
|
||||
await progressCallback({ message: `Removing missing backup ${backup.remotePath}`});
|
||||
@@ -240,10 +240,10 @@ async function cleanupMissingBackups(backupSite, progressCallback) {
|
||||
}
|
||||
|
||||
// removes the snapshots of apps that have been uninstalled
|
||||
async function removeOldAppSnapshots(backupSite) {
|
||||
assert.strictEqual(typeof backupSite, 'object');
|
||||
async function removeOldAppSnapshots(site) {
|
||||
assert.strictEqual(typeof site, 'object');
|
||||
|
||||
const snapshotInfo = await backupSites.getSnapshotInfo(backupSite);
|
||||
const snapshotInfo = await backupSites.getSnapshotInfo(site);
|
||||
|
||||
const progressCallback = (progress) => { debug(`removeOldAppSnapshots: ${progress.message}`); };
|
||||
|
||||
@@ -253,15 +253,15 @@ async function removeOldAppSnapshots(backupSite) {
|
||||
const app = await apps.get(appId);
|
||||
if (app !== null) continue; // app is still installed
|
||||
|
||||
const ext = backupFormats.api(backupSite.format).getFileExtension(!!backupSite.encryption);
|
||||
const ext = backupFormats.api(site.format).getFileExtension(!!site.encryption);
|
||||
const remotePath = `snapshot/app_${appId}${ext}`;
|
||||
if (ext) {
|
||||
await safe(backupSites.storageApi(backupSite).remove(backupSite.config, remotePath), { debug });
|
||||
await safe(backupSites.storageApi(site).remove(site.config, remotePath), { debug });
|
||||
} else {
|
||||
await safe(backupSites.storageApi(backupSite).removeDir(backupSite.config, remotePath, progressCallback), { debug });
|
||||
await safe(backupSites.storageApi(site).removeDir(site.config, remotePath, progressCallback), { debug });
|
||||
}
|
||||
|
||||
await backupSites.setSnapshotInfo(backupSite, appId, null /* info */);
|
||||
await backupSites.setSnapshotInfo(site, appId, null /* info */);
|
||||
debug(`removeOldAppSnapshots: removed snapshot of app ${appId}`);
|
||||
}
|
||||
|
||||
@@ -272,38 +272,38 @@ async function run(siteId, progressCallback) {
|
||||
assert.strictEqual(typeof siteId, 'string');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
|
||||
const backupSite = await backupSites.get(siteId);
|
||||
if (!backupSite) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Target not found');
|
||||
const site = await backupSites.get(siteId);
|
||||
if (!site) throw new BoxError(BoxError.EXTERNAL_ERROR, 'Target not found');
|
||||
|
||||
debug(`run: retention is ${JSON.stringify(backupSite.retention)}`);
|
||||
debug(`run: retention is ${JSON.stringify(site.retention)}`);
|
||||
|
||||
const status = await backupSites.ensureMounted(backupSite);
|
||||
const status = await backupSites.ensureMounted(site);
|
||||
debug(`run: mount point status is ${JSON.stringify(status)}`);
|
||||
if (status.state !== 'active') throw new BoxError(BoxError.MOUNT_ERROR, `Backup endpoint is not mounted: ${status.message}`);
|
||||
|
||||
if (backupSite.retention.keepWithinSecs < 0) {
|
||||
if (site.retention.keepWithinSecs < 0) {
|
||||
debug('run: keeping all backups');
|
||||
return {};
|
||||
}
|
||||
|
||||
await progressCallback({ percent: 10, message: 'Cleaning box backups' });
|
||||
const { removedBoxBackupPaths, referencedBackupIds } = await cleanupBoxBackups(backupSite, progressCallback); // references is app or mail backup ids
|
||||
const { removedBoxBackupPaths, referencedBackupIds } = await cleanupBoxBackups(site, progressCallback); // references is app or mail backup ids
|
||||
|
||||
await progressCallback({ percent: 20, message: 'Cleaning mail backups' });
|
||||
const removedMailBackupPaths = await cleanupMailBackups(backupSite, referencedBackupIds, progressCallback);
|
||||
const removedMailBackupPaths = await cleanupMailBackups(site, referencedBackupIds, progressCallback);
|
||||
|
||||
await progressCallback({ percent: 40, message: 'Cleaning app backups' });
|
||||
const archivedBackupIds = await archives.listBackupIds();
|
||||
const removedAppBackupPaths = await cleanupAppBackups(backupSite, referencedBackupIds.concat(archivedBackupIds), progressCallback);
|
||||
const removedAppBackupPaths = await cleanupAppBackups(site, referencedBackupIds.concat(archivedBackupIds), progressCallback);
|
||||
|
||||
await progressCallback({ percent: 70, message: 'Checking storage backend and removing stale entries in database' });
|
||||
const missingBackupPaths = await cleanupMissingBackups(backupSite, progressCallback);
|
||||
const missingBackupPaths = await cleanupMissingBackups(site, progressCallback);
|
||||
|
||||
await progressCallback({ percent: 80, message: 'Removing snapshots of uninstalled apps' });
|
||||
await removeOldAppSnapshots(backupSite);
|
||||
await removeOldAppSnapshots(site);
|
||||
|
||||
await progressCallback({ percent: 80, message: 'Cleaning storage artifacts' });
|
||||
await backupSites.storageApi(backupSite).cleanup(backupSite.config, progressCallback);
|
||||
await backupSites.storageApi(site).cleanup(site.config, progressCallback);
|
||||
|
||||
return { removedBoxBackupPaths, removedMailBackupPaths, removedAppBackupPaths, missingBackupPaths };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user