backups: remove any old mount point configuration

This commit is contained in:
Girish Ramakrishnan
2021-07-09 16:15:58 -07:00
parent 17a70fdefd
commit 7f4d039e11

View File

@@ -399,6 +399,15 @@ function mountOptionsChanged(currentConfig, backupConfig) {
|| !_.isEqual(currentConfig.mountOptions, backupConfig.mountOptions);
}
function mountObject(backupConfig) {
return {
name: 'backup',
hostPath: backupConfig.mountPoint,
mountType: backupConfig.provider,
mountOptions: backupConfig.mountOptions
};
}
function setBackupConfig(backupConfig, callback) {
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof callback, 'function');
@@ -412,25 +421,13 @@ function setBackupConfig(backupConfig, callback) {
error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
if (error) return callback(error);
const newMount = {
name: 'backup',
hostPath: backupConfig.mountPoint,
mountType: backupConfig.provider,
mountOptions: backupConfig.mountOptions
};
[error] = await safe(mounts.tryAddMount(newMount, { timeout: 10 })); // 10 seconds
[error] = await safe(mounts.tryAddMount(mountObject(backupConfig), { timeout: 10 })); // 10 seconds
if (error) {
if (backups.isMountProvider(oldConfig.provider)) { // put back the old mount configuration
debug('setBackupConfig: rolling back to previous mount configuration');
await safe(mounts.tryAddMount({
name: 'backup',
hostPath: oldConfig.mountPoint,
mountType: oldConfig.provider,
mountOptions: oldConfig.mountOptions
}, { timeout: 10 }));
await safe(mounts.tryAddMount(mountObject(oldConfig), { timeout: 10 }));
}
return callback(error);
@@ -454,6 +451,11 @@ function setBackupConfig(backupConfig, callback) {
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), async function (error) {
if (error) return callback(error);
if (backups.isMountProvider(oldConfig.provider) && !backups.isMountProvider(backupConfig.provider)) {
debug('setBackupConfig: removing old backup mount point');
await safe(mounts.removeMount(mountObject(oldConfig)));
}
notifyChange(exports.BACKUP_CONFIG_KEY, backupConfig);
backups.configureCollectd(backupConfig, callback);