backups: fix mounting logic of backup settings and cloudron restore
This commit is contained in:
@@ -393,14 +393,45 @@ function getBackupConfig(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function mountOptionsChanged(currentConfig, backupConfig) {
|
||||
return currentConfig.provider !== backupConfig.provider
|
||||
|| currentConfig.mountPoint !== backupConfig.mountPoint
|
||||
|| !_.isEqual(currentConfig.mountOptions, backupConfig.mountOptions);
|
||||
}
|
||||
|
||||
function setBackupConfig(backupConfig, callback) {
|
||||
assert.strictEqual(typeof backupConfig, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
getBackupConfig(function (error, currentConfig) {
|
||||
getBackupConfig(async function (error, oldConfig) {
|
||||
if (error) return callback(error);
|
||||
|
||||
backups.injectPrivateFields(backupConfig, currentConfig);
|
||||
backups.injectPrivateFields(backupConfig, oldConfig);
|
||||
|
||||
let oldMount = null, newMount = null;
|
||||
if (backups.isMountProvider(oldConfig.provider)) {
|
||||
oldMount = {
|
||||
name: 'backup',
|
||||
hostPath: oldConfig.mountPoint,
|
||||
mountType: oldConfig.provider,
|
||||
mountOptions: oldConfig.mountOptions
|
||||
};
|
||||
}
|
||||
|
||||
if (backups.isMountProvider(backupConfig.provider) && (!backups.isMountProvider(oldConfig.provider) || mountOptionsChanged(oldConfig, backupConfig))) {
|
||||
error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
|
||||
if (error) return callback(error);
|
||||
|
||||
newMount = {
|
||||
name: 'backup',
|
||||
hostPath: backupConfig.mountPoint,
|
||||
mountType: backupConfig.provider,
|
||||
mountOptions: backupConfig.mountOptions
|
||||
};
|
||||
|
||||
[error] = await safe(mounts.tryAddMount(newMount, oldMount, { times: 20, interval: 500 })); // 10 seconds
|
||||
if (error) return callback(error);
|
||||
}
|
||||
|
||||
backups.testConfig(backupConfig, async function (error) {
|
||||
if (error) return callback(error);
|
||||
@@ -411,31 +442,18 @@ function setBackupConfig(backupConfig, callback) {
|
||||
}
|
||||
|
||||
// if any of these changes, we have to clear the cache
|
||||
if ([ 'format', 'provider', 'prefix', 'bucket', 'region', 'endpoint', 'backupFolder', 'mountPoint', 'encryption' ].some(p => backupConfig[p] !== currentConfig[p])) {
|
||||
if ([ 'format', 'provider', 'prefix', 'bucket', 'region', 'endpoint', 'backupFolder', 'mountPoint', 'encryption' ].some(p => backupConfig[p] !== oldConfig[p])) {
|
||||
debug('setBackupConfig: clearing backup cache');
|
||||
backups.cleanupCacheFilesSync();
|
||||
}
|
||||
|
||||
if (backupConfig.provider === 'sshfs' || backupConfig.provider === 'cifs' || backupConfig.provider === 'nfs' || backupConfig.provider === 'ext4') {
|
||||
error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
|
||||
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), async function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
const backupVolume = {
|
||||
name: 'backup',
|
||||
hostPath: backupConfig.mountPoint,
|
||||
mountType: backupConfig.provider,
|
||||
mountOptions: backupConfig.mountOptions
|
||||
};
|
||||
|
||||
[error] = await safe(mounts.writeMountFile(backupVolume));
|
||||
if (error) return callback(error);
|
||||
} else if (currentConfig.provider === 'sshfs' || currentConfig.provider === 'cifs' || currentConfig.provider === 'nfs' || currentConfig.provider === 'ext4') {
|
||||
debug('setBackupConfig: removing old mount configuration');
|
||||
await safe(mounts.removeMountFile(currentConfig.hostPath));
|
||||
}
|
||||
|
||||
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), function (error) {
|
||||
if (error) return callback(error);
|
||||
if (oldMount && (!backups.isMountProvider(backupConfig.provider) || (newMount && newMount.hostPath !== oldMount.hostPath))) {
|
||||
debug('setBackupConfig: removing old mount configuration');
|
||||
await safe(mounts.removeMountFile(oldMount.hostPath));
|
||||
}
|
||||
|
||||
notifyChange(exports.BACKUP_CONFIG_KEY, backupConfig);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user