rename backupTargets to backupSites
This commit is contained in:
+14
-14
@@ -153,7 +153,7 @@ const appTaskManager = require('./apptaskmanager.js'),
|
||||
archives = require('./archives.js'),
|
||||
assert = require('node:assert'),
|
||||
backups = require('./backups.js'),
|
||||
backupTargets = require('./backuptargets.js'),
|
||||
backupSites = require('./backupsites.js'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
constants = require('./constants.js'),
|
||||
crypto = require('node:crypto'),
|
||||
@@ -1258,12 +1258,12 @@ async function scheduleTask(appId, installationState, taskId, auditSource) {
|
||||
assert.strictEqual(typeof taskId, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
const backupTarget = await backupTargets.getPrimary();
|
||||
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 = backupTarget.limits?.memoryLimit ? Math.max(backupTarget.limits.memoryLimit/1024/1024, 400) : 400;
|
||||
memoryLimit = backupSite.limits?.memoryLimit ? Math.max(backupSite.limits.memoryLimit/1024/1024, 400) : 400;
|
||||
} else if (installationState === exports.ISTATE_PENDING_DATA_DIR_MIGRATION) {
|
||||
memoryLimit = 1024; // cp takes more memory than we think
|
||||
}
|
||||
@@ -2360,7 +2360,7 @@ async function importApp(app, data, auditSource) {
|
||||
let restoreConfig;
|
||||
|
||||
if (data.remotePath) { // if not provided, we import in-place
|
||||
const backupTarget = await backupTargets.createPseudo({
|
||||
const backupSite = await backupSites.createPseudo({
|
||||
id: `appimport-${app.id}`,
|
||||
provider: data.provider,
|
||||
config: data.config,
|
||||
@@ -2369,7 +2369,7 @@ async function importApp(app, data, auditSource) {
|
||||
encryptedFilenames: data.encryptedFilenames ?? false
|
||||
});
|
||||
|
||||
restoreConfig = { remotePath: data.remotePath, backupTarget };
|
||||
restoreConfig = { remotePath: data.remotePath, backupSite };
|
||||
} else { // inPlace
|
||||
restoreConfig = { inPlace: true };
|
||||
}
|
||||
@@ -2399,8 +2399,8 @@ async function exportApp(app, data, auditSource) {
|
||||
|
||||
if (!canBackupApp(app)) throw new BoxError(BoxError.BAD_STATE, 'App cannot be backed up in this state');
|
||||
|
||||
const backupTarget = await backupTargets.getPrimary();
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ appId, backupTarget.id, { snapshotOnly: true } ]);
|
||||
const backupSite = await backupSites.getPrimary();
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ appId, backupSite.id, { snapshotOnly: true } ]);
|
||||
safe(tasks.startTask(taskId, {}), { debug }); // background
|
||||
return { taskId };
|
||||
}
|
||||
@@ -2774,11 +2774,11 @@ async function backup(app, auditSource) {
|
||||
|
||||
if (!canBackupApp(app)) throw new BoxError(BoxError.BAD_STATE, 'App cannot be backed up in this state');
|
||||
|
||||
const backupTarget = await backupTargets.getPrimary();
|
||||
const backupSite = await backupSites.getPrimary();
|
||||
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ app.id, backupTarget.id, { snapshotOnly: false } ]);
|
||||
const taskId = await tasks.add(`${tasks.TASK_APP_BACKUP_PREFIX}${app.id}`, [ app.id, backupSite.id, { snapshotOnly: false } ]);
|
||||
|
||||
const memoryLimit = backupTarget.limits?.memoryLimit ? Math.max(backupTarget.limits.memoryLimit/1024/1024, 1024) : 1024;
|
||||
const memoryLimit = backupSite.limits?.memoryLimit ? Math.max(backupSite.limits.memoryLimit/1024/1024, 1024) : 1024;
|
||||
|
||||
// background
|
||||
tasks.startTask(taskId, { timeout: 24 * 60 * 60 * 1000 /* 24 hours */, nice: 15, memoryLimit, oomScoreAdjust: -999 })
|
||||
@@ -2827,12 +2827,12 @@ async function getBackupDownloadStream(app, backupId) {
|
||||
if (backup.identifier !== app.id) throw new BoxError(BoxError.NOT_FOUND, 'Backup not found'); // some other app's backup
|
||||
if (backup.format !== 'tgz') throw new BoxError(BoxError.BAD_STATE, 'only tgz backups can be downloaded');
|
||||
|
||||
const backupTarget = await backupTargets.get(backup.targetId);
|
||||
if (!backupTarget) throw new BoxError(BoxError.NOT_FOUND, 'Backup target not found'); // not possible
|
||||
const backupSite = await backupSites.get(backup.siteId);
|
||||
if (!backupSite) throw new BoxError(BoxError.NOT_FOUND, 'Backup site not found'); // not possible
|
||||
|
||||
const ps = new PassThrough();
|
||||
|
||||
const stream = await backupTargets.storageApi(backupTarget).download(backupTarget.config, backup.remotePath);
|
||||
const stream = await backupSites.storageApi(backupSite).download(backupSite.config, backup.remotePath);
|
||||
stream.on('error', function(error) {
|
||||
debug(`getBackupDownloadStream: read stream error: ${error.message}`);
|
||||
ps.emit('error', new BoxError(BoxError.EXTERNAL_ERROR, error));
|
||||
@@ -2859,7 +2859,7 @@ async function restoreApps(apps, options, auditSource) {
|
||||
let installationState, restoreConfig;
|
||||
if (!error && result.length) {
|
||||
installationState = exports.ISTATE_PENDING_RESTORE;
|
||||
restoreConfig = { remotePath: result[0].remotePath, backupTarget: options.backupTarget };
|
||||
restoreConfig = { remotePath: result[0].remotePath, backupSite: options.backupSite };
|
||||
} else {
|
||||
installationState = exports.ISTATE_PENDING_INSTALL;
|
||||
restoreConfig = null;
|
||||
|
||||
Reference in New Issue
Block a user