backups: add per site enabledForUpdates flag
previously, we had a singleton 'main' flag to indicate a site can be used for updates. with this new approach, we can get rid of the 'primary' concept. each site can be used for updates or not.
This commit is contained in:
+9
-9
@@ -1258,12 +1258,11 @@ async function scheduleTask(appId, installationState, taskId, auditSource) {
|
||||
assert.strictEqual(typeof taskId, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
const backupSite = await backupSites.getPrimary();
|
||||
|
||||
let memoryLimit = 400;
|
||||
if (installationState === exports.ISTATE_PENDING_CLONE || installationState === exports.ISTATE_PENDING_RESTORE
|
||||
|| installationState === exports.ISTATE_PENDING_IMPORT || installationState === exports.ISTATE_PENDING_UPDATE) {
|
||||
memoryLimit = backupSite.limits?.memoryLimit ? Math.max(backupSite.limits.memoryLimit/1024/1024, 400) : 400;
|
||||
const sites = await backupSites.listByContentForUpdates(appId);
|
||||
memoryLimit = sites.reduce((acc, cur) => cur.limits?.memoryLimit ? Math.max(cur.limits.memoryLimit/1024/1024, acc) : acc, 400);
|
||||
} else if (installationState === exports.ISTATE_PENDING_DATA_DIR_MIGRATION) {
|
||||
memoryLimit = 1024; // cp takes more memory than we think
|
||||
}
|
||||
@@ -2390,17 +2389,16 @@ async function importApp(app, data, auditSource) {
|
||||
return { taskId };
|
||||
}
|
||||
|
||||
async function exportApp(app, data, auditSource) {
|
||||
async function exportApp(app, backupSiteId, auditSource) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
assert.strictEqual(typeof backupSiteId, 'string'); // FIXME: this is not used at all in snapshotOnly mode
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
const appId = app.id;
|
||||
|
||||
if (!canBackupApp(app)) throw new BoxError(BoxError.BAD_STATE, 'App cannot be backed up in this state');
|
||||
|
||||
const backupSite = await backupSites.getPrimary();
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ appId, backupSite.id, { snapshotOnly: true } ]);
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ appId, backupSiteId, { snapshotOnly: true } ]);
|
||||
safe(tasks.startTask(taskId, {}), { debug }); // background
|
||||
return { taskId };
|
||||
}
|
||||
@@ -2768,13 +2766,15 @@ function canBackupApp(app) {
|
||||
app.installationState === exports.ISTATE_PENDING_UPDATE; // called from apptask
|
||||
}
|
||||
|
||||
async function backup(app, auditSource) {
|
||||
async function backup(app, backupSiteId, auditSource) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof backupSiteId, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
if (!canBackupApp(app)) throw new BoxError(BoxError.BAD_STATE, 'App cannot be backed up in this state');
|
||||
|
||||
const backupSite = await backupSites.getPrimary();
|
||||
const backupSite = await backupSites.get(backupSiteId);
|
||||
if (!backupSite) throw new BoxError(BoxError.BAD_FIELD, 'No such backup site');
|
||||
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ app.id, backupSite.id, { snapshotOnly: false } ]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user