implement in-place import and custom backup config

This commit is contained in:
Girish Ramakrishnan
2019-12-04 18:54:25 -08:00
parent 80b890101b
commit 1b563854a7
4 changed files with 54 additions and 17 deletions
+25 -13
View File
@@ -1450,28 +1450,40 @@ function importApp(appId, data, auditSource, callback) {
get(appId, function (error, app) {
if (error) return callback(error);
error = validateBackupFormat(data.backupFormat);
// all fields are optional
data.backupId = data.backupId || null;
data.backupFormat = data.backupFormat || null;
data.backupConfig = data.backupConfig || null;
const { backupId, backupFormat, backupConfig } = data;
error = backupFormat ? validateBackupFormat(backupFormat) : null;
if (error) return callback(error);
error = checkAppState(app, exports.ISTATE_PENDING_RESTORE);
if (error) return callback(error);
// TODO: check if the file exists in the storage backend
const restoreConfig = { backupId: data.backupId, backupFormat: data.backupFormat, oldManifest: app.manifest };
// TODO: make this smarter to do a read-only test and check if the file exists in the storage backend
const testBackupConfig = backupConfig ? backups.testConfig.bind(null, backupConfig) : (next) => next();
const task = {
args: {
restoreConfig,
overwriteDns: true
},
values: {}
};
addTask(appId, exports.ISTATE_PENDING_RESTORE, task, function (error, result) {
testBackupConfig(function (error) {
if (error) return callback(error);
eventlog.add(eventlog.ACTION_APP_RESTORE, auditSource, { app: app, backupId: data.backupId, fromManifest: app.manifest, toManifest: app.manifest, taskId: result.taskId });
const restoreConfig = { backupId, backupFormat, backupConfig, oldManifest: app.manifest };
callback(null, { taskId: result.taskId });
const task = {
args: {
restoreConfig,
overwriteDns: true
},
values: {}
};
addTask(appId, exports.ISTATE_PENDING_RESTORE, task, function (error, result) {
if (error) return callback(error);
eventlog.add(eventlog.ACTION_APP_RESTORE, auditSource, { app: app, backupId, fromManifest: app.manifest, toManifest: app.manifest, taskId: result.taskId });
callback(null, { taskId: result.taskId });
});
});
});
}