rework backup root

notes:
* backup root cannot come from backend. for dynamic mounts backend cannot know where it is mounted
* backupConfig is 3 parts - format / mount / password . there is also this rootPath (which should not be in db)
* password should be stored separately in settings at some point
* format has to be passed along everywhere because we allow restore from  same backupConfig but different format. we do this by saving the format in the backups table

fixes #819
This commit is contained in:
Girish Ramakrishnan
2023-08-15 20:24:54 +05:30
parent da49a69562
commit aa8c23c8b3
14 changed files with 94 additions and 154 deletions
+7 -16
View File
@@ -20,7 +20,6 @@ const assert = require('assert'),
fs = require('fs'),
mail = require('./mail.js'),
mailServer = require('./mailserver.js'),
mounts = require('./mounts.js'),
network = require('./network.js'),
platform = require('./platform.js'),
reverseProxy = require('./reverseproxy.js'),
@@ -190,6 +189,7 @@ async function restoreTask(backupConfig, remotePath, ipv4Config, options, auditS
}
await dashboard.setLocation(location.domain, auditSource);
delete backupConfig.rootPath;
await backups.setConfig(backupConfig);
await eventlog.add(eventlog.ACTION_RESTORE, auditSource, { remotePath });
@@ -202,7 +202,7 @@ async function restoreTask(backupConfig, remotePath, ipv4Config, options, auditS
}
async function restore(backupConfig, remotePath, version, ipv4Config, options, auditSource) {
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof backupConfig, 'object'); // format, storage, password
assert.strictEqual(typeof remotePath, 'string');
assert.strictEqual(typeof version, 'string');
assert.strictEqual(typeof ipv4Config, 'object');
@@ -220,21 +220,12 @@ async function restore(backupConfig, remotePath, version, ipv4Config, options, a
const activated = await users.isActivated();
if (activated) throw new BoxError(BoxError.CONFLICT, 'Already activated. Restore with a fresh Cloudron installation.');
if (mounts.isManagedProvider(backupConfig.provider)) {
const error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
if (error) throw error;
let error = backups.validateFormat(backupConfig.format);
if (error) throw error;
const newMount = {
name: 'backup',
hostPath: paths.MANAGED_BACKUP_MOUNT_DIR,
mountType: backupConfig.provider,
mountOptions: backupConfig.mountOptions
};
await mounts.tryAddMount(newMount, { timeout: 10 }); // 10 seconds
}
let error = await backups.testStorage(backupConfig);
await backups.setupStorage(backupConfig, paths.MANAGED_BACKUP_MOUNT_DIR);
backupConfig.rootPath = backups.getRootPath(backupConfig, paths.MANAGED_BACKUP_MOUNT_DIR);
error = await backups.testStorage(backupConfig);
if (error) throw error;
if ('password' in backupConfig) {