backup target: create snapshot and cache files per target
snapshot file tracks the snapshot directory. when app gets deleted, the cleaner will remove the upstream snapshot directory when it runs. cache files are used in rsync logic to track what was uploading into snapshot in the previous run without needing to rescan upstream.
This commit is contained in:
+13
-19
@@ -18,7 +18,6 @@ const apps = require('./apps.js'),
|
||||
debug = require('debug')('box:backupcleaner'),
|
||||
moment = require('moment'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
storage = require('./storage.js');
|
||||
|
||||
@@ -243,35 +242,30 @@ async function cleanupMissingBackups(target, progressCallback) {
|
||||
}
|
||||
|
||||
// removes the snapshots of apps that have been uninstalled
|
||||
async function cleanupSnapshots(backupTarget) {
|
||||
async function removeOldAppSnapshots(backupTarget) {
|
||||
assert.strictEqual(typeof backupTarget, 'object');
|
||||
|
||||
const contents = safe.fs.readFileSync(paths.SNAPSHOT_INFO_FILE, 'utf8');
|
||||
const info = safe.JSON.parse(contents);
|
||||
if (!info) return;
|
||||
const snapshotInfo = await backupTargets.getSnapshotInfo(backupTarget);
|
||||
|
||||
const progressCallback = (progress) => { debug(`cleanupSnapshots: ${progress.message}`); };
|
||||
const progressCallback = (progress) => { debug(`removeOldAppSnapshots: ${progress.message}`); };
|
||||
|
||||
for (const appId of Object.keys(info)) {
|
||||
for (const appId of Object.keys(snapshotInfo)) {
|
||||
if (appId === 'box' || appId === 'mail') continue;
|
||||
|
||||
const app = await apps.get(appId);
|
||||
if (app) continue; // app is still installed
|
||||
if (app !== null) continue; // app is still installed
|
||||
|
||||
if (info[appId].format ==='tgz') {
|
||||
await safe(storage.api(backupTarget.provider).remove(backupTarget.config, backupFormat.api(info[appId].format).getBackupFilePath(backupTarget, `snapshot/app_${appId}`)), { debug });
|
||||
if (snapshotInfo[appId].format ==='tgz') {
|
||||
await safe(storage.api(backupTarget.provider).remove(backupTarget.config, backupFormat.api(snapshotInfo[appId].format).getBackupFilePath(backupTarget, `snapshot/app_${appId}`)), { debug });
|
||||
} else {
|
||||
await safe(storage.api(backupTarget.provider).removeDir(backupTarget.config, backupFormat.api(info[appId].format).getBackupFilePath(backupTarget, `snapshot/app_${appId}`), progressCallback), { debug });
|
||||
await safe(storage.api(backupTarget.provider).removeDir(backupTarget.config, backupFormat.api(snapshotInfo[appId].format).getBackupFilePath(backupTarget, `snapshot/app_${appId}`), progressCallback), { debug });
|
||||
}
|
||||
|
||||
safe.fs.unlinkSync(path.join(paths.BACKUP_INFO_DIR, `${appId}.sync.cache`));
|
||||
safe.fs.unlinkSync(path.join(paths.BACKUP_INFO_DIR, `${appId}.sync.cache.new`));
|
||||
|
||||
await safe(backupTargets.setSnapshotInfo(appId, null /* info */), { debug });
|
||||
debug(`cleanupSnapshots: cleaned up snapshot of app ${appId}`);
|
||||
await backupTargets.setSnapshotInfo(backupTarget, appId, null /* info */);
|
||||
debug(`removeOldAppSnapshots: removed snapshot of app ${appId}`);
|
||||
}
|
||||
|
||||
debug('cleanupSnapshots: done');
|
||||
debug('removeOldAppSnapshots: done');
|
||||
}
|
||||
|
||||
async function run(targetId, progressCallback) {
|
||||
@@ -305,8 +299,8 @@ async function run(targetId, progressCallback) {
|
||||
await progressCallback({ percent: 70, message: 'Checking storage backend and removing stale entries in database' });
|
||||
const missingBackupPaths = await cleanupMissingBackups(backupTarget, progressCallback);
|
||||
|
||||
await progressCallback({ percent: 80, message: 'Cleaning snapshots' });
|
||||
await cleanupSnapshots(backupTarget);
|
||||
await progressCallback({ percent: 80, message: 'Removing snapshots of uninstalled apps' });
|
||||
await removeOldAppSnapshots(backupTarget);
|
||||
|
||||
await progressCallback({ percent: 80, message: 'Cleaning storage artifacts' });
|
||||
await storage.api(backupTarget.provider).cleanup(backupTarget.config, progressCallback);
|
||||
|
||||
Reference in New Issue
Block a user