backuptarget: pseudo target for import and restore
This commit is contained in:
33
src/apps.js
33
src/apps.js
@@ -165,7 +165,6 @@ const appTaskManager = require('./apptaskmanager.js'),
|
||||
domains = require('./domains.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
fs = require('fs'),
|
||||
hush = require('./hush.js'),
|
||||
Location = require('./location.js'),
|
||||
locks = require('./locks.js'),
|
||||
logs = require('./logs.js'),
|
||||
@@ -2350,30 +2349,22 @@ async function importApp(app, data, auditSource) {
|
||||
|
||||
const appId = app.id;
|
||||
|
||||
const { remotePath, format, encryptionPassword, encryptedFilenames, config } = data;
|
||||
|
||||
let error = checkAppState(app, exports.ISTATE_PENDING_IMPORT);
|
||||
const error = checkAppState(app, exports.ISTATE_PENDING_IMPORT);
|
||||
if (error) throw error;
|
||||
|
||||
let encryption, restoreConfig;
|
||||
let restoreConfig;
|
||||
|
||||
if (data.remotePath) { // if not provided, we import in-place
|
||||
error = backupTargets.validateFormat(format);
|
||||
if (error) throw error;
|
||||
const backupTarget = await backupTargets.createPseudo({
|
||||
id: `appimport-${app.id}`,
|
||||
provider: data.provider,
|
||||
config: data.config,
|
||||
format: data.format,
|
||||
encryptionPassword: data.encryptionPassword,
|
||||
encryptedFilenames: data.encryptedFilenames
|
||||
});
|
||||
|
||||
if (encryptionPassword) {
|
||||
encryption = hush.generateEncryptionKeysSync(encryptionPassword);
|
||||
encryption.encryptedFilenames = !!encryptedFilenames;
|
||||
} else {
|
||||
encryption = null;
|
||||
}
|
||||
|
||||
await backupTargets.setupManagedStorage(config, `/mnt/appimport-${app.id}`); // this validates mountOptions . this is not cleaned up, it's fine
|
||||
config.rootPath = backupTargets.getRootPath(config, `/mnt/appimport-${app.id}`);
|
||||
error = await backupTargets.testStorage(Object.assign({ mountPath: `/mnt/appimport-${app.id}` }, config)); // this validates provider and it's api options. requires mountPath
|
||||
if (error) throw error;
|
||||
|
||||
restoreConfig = { remotePath, backupFormat: format, backupConfig: config };
|
||||
restoreConfig = { remotePath: data.remotePath, backupTarget };
|
||||
} else { // inPlace
|
||||
restoreConfig = { inPlace: true };
|
||||
}
|
||||
@@ -2389,7 +2380,7 @@ async function importApp(app, data, auditSource) {
|
||||
};
|
||||
const taskId = await addTask(appId, exports.ISTATE_PENDING_IMPORT, task, auditSource);
|
||||
|
||||
await eventlog.add(eventlog.ACTION_APP_IMPORT, auditSource, { app: app, remotePath, fromManifest: app.manifest, toManifest: app.manifest, taskId });
|
||||
await eventlog.add(eventlog.ACTION_APP_IMPORT, auditSource, { app, remotePath: data.remotePath, inPlace: data.inPlace, taskId });
|
||||
|
||||
return { taskId };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user