backups: move limits and storage into separate keys
This commit is contained in:
@@ -32,6 +32,8 @@ exports = module.exports = {
|
||||
|
||||
getConfig,
|
||||
setConfig,
|
||||
setStorage,
|
||||
setLimits,
|
||||
|
||||
remount,
|
||||
getMountStatus,
|
||||
@@ -414,27 +416,37 @@ async function setPolicy(policy) {
|
||||
}
|
||||
|
||||
async function getConfig() {
|
||||
const value = await settings.getJson(settings.BACKUP_CONFIG_KEY);
|
||||
return value || {
|
||||
provider: 'filesystem',
|
||||
backupFolder: paths.DEFAULT_BACKUP_DIR,
|
||||
format: 'tgz',
|
||||
encryption: null,
|
||||
};
|
||||
const result = await settings.getJson(settings.BACKUP_STORAGE_KEY) || { provider: 'filesystem', backupFolder: paths.DEFAULT_BACKUP_DIR, format: 'tgz', encryption: null };
|
||||
const limits = await settings.getJson(settings.BACKUP_LIMITS_KEY);
|
||||
if (limits) result.limits = limits;
|
||||
return result;
|
||||
}
|
||||
|
||||
async function setConfig(backupConfig) {
|
||||
assert.strictEqual(typeof backupConfig, 'object');
|
||||
|
||||
await settings.setJson(settings.BACKUP_STORAGE_KEY, _.omit(backupConfig, 'limits'));
|
||||
await settings.setJson(settings.BACKUP_LIMITS_KEY, backupConfig.limits || null);
|
||||
}
|
||||
|
||||
async function setLimits(limits) {
|
||||
assert.strictEqual(typeof limits, 'object');
|
||||
|
||||
await settings.setJson(settings.BACKUP_LIMITS_KEY, limits);
|
||||
}
|
||||
|
||||
async function setStorage(storageConfig) {
|
||||
assert.strictEqual(typeof storageConfig, 'object');
|
||||
|
||||
const oldConfig = await getConfig();
|
||||
|
||||
injectPrivateFields(backupConfig, oldConfig);
|
||||
injectPrivateFields(storageConfig, oldConfig);
|
||||
|
||||
if (mounts.isManagedProvider(backupConfig.provider)) {
|
||||
let error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
|
||||
if (mounts.isManagedProvider(storageConfig.provider)) {
|
||||
let error = mounts.validateMountOptions(storageConfig.provider, storageConfig.mountOptions);
|
||||
if (error) throw error;
|
||||
|
||||
[error] = await safe(mounts.tryAddMount(mountObjectFromBackupConfig(backupConfig), { timeout: 10 })); // 10 seconds
|
||||
[error] = await safe(mounts.tryAddMount(mountObjectFromBackupConfig(storageConfig), { timeout: 10 })); // 10 seconds
|
||||
|
||||
if (error) {
|
||||
if (mounts.isManagedProvider(oldConfig.provider)) { // put back the old mount configuration
|
||||
@@ -447,26 +459,23 @@ async function setConfig(backupConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
const error = await testConfig(backupConfig);
|
||||
const error = await testConfig(storageConfig);
|
||||
if (error) throw error;
|
||||
|
||||
if ('password' in backupConfig) { // user set password
|
||||
const error = await validateEncryptionPassword(backupConfig.password);
|
||||
if ('password' in storageConfig) { // user set password
|
||||
const error = await validateEncryptionPassword(storageConfig.password);
|
||||
if (error) throw error;
|
||||
|
||||
backupConfig.encryption = generateEncryptionKeysSync(backupConfig.password);
|
||||
delete backupConfig.password;
|
||||
storageConfig.encryption = generateEncryptionKeysSync(storageConfig.password);
|
||||
delete storageConfig.password;
|
||||
}
|
||||
|
||||
// if any of these changes, we have to clear the cache
|
||||
if (!_.isEqual(_.omit(backupConfig, 'limits'), _.omit(oldConfig, 'limits'))) {
|
||||
debug('setBackupConfig: clearing backup cache');
|
||||
cleanupCacheFilesSync();
|
||||
}
|
||||
debug('setBackupConfig: clearing backup cache');
|
||||
cleanupCacheFilesSync();
|
||||
|
||||
await settings.setJson(settings.BACKUP_CONFIG_KEY, backupConfig);
|
||||
await settings.setJson(settings.BACKUP_STORAGE_KEY, storageConfig);
|
||||
|
||||
if (mounts.isManagedProvider(oldConfig.provider) && !mounts.isManagedProvider(backupConfig.provider)) {
|
||||
if (mounts.isManagedProvider(oldConfig.provider) && !mounts.isManagedProvider(storageConfig.provider)) {
|
||||
debug('setBackupConfig: removing old backup mount point');
|
||||
await safe(mounts.removeMount(mountObjectFromBackupConfig(oldConfig)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user