diff --git a/src/mounts.js b/src/mounts.js index 8b8edc322..590ecbc8f 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -163,6 +163,6 @@ async function tryAddMount(volume, options) { const status = await getStatus(volume.mountType, volume.hostPath); if (status.state !== 'active') { // cleanup await removeMount(volume); - throw new BoxError(BoxError.MOUNT_ERROR, `Mount is not active (${status.state}): ${status.message}`); + throw new BoxError(BoxError.MOUNT_ERROR, `Failed to mount (${status.state}): ${status.message}`); } } diff --git a/src/provision.js b/src/provision.js index d57e2688c..44e5d2612 100644 --- a/src/provision.js +++ b/src/provision.js @@ -195,7 +195,7 @@ function restore(backupConfig, backupId, version, sysinfoConfig, options, auditS mountOptions: backupConfig.mountOptions }; - [error] = await safe(mounts.tryAddMount(newMount, null, { times: 20, interval: 500 })); // 10 seconds + [error] = await safe(mounts.tryAddMount(newMount, { timeout: 10 })); // 10 seconds if (error) return callback(error); } diff --git a/src/settings.js b/src/settings.js index 40d9f1b9c..57e5d70ac 100644 --- a/src/settings.js +++ b/src/settings.js @@ -408,29 +408,33 @@ function setBackupConfig(backupConfig, callback) { 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 = { + const 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); + [error] = await safe(mounts.tryAddMount(newMount, { 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 })); + } + + return callback(error); + } } backups.testConfig(backupConfig, async function (error) { @@ -450,11 +454,6 @@ function setBackupConfig(backupConfig, callback) { settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), async 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.removeMount(oldMount)); - } - notifyChange(exports.BACKUP_CONFIG_KEY, backupConfig); backups.configureCollectd(backupConfig, callback); diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 717684350..02b9741b1 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -293,7 +293,7 @@ function testConfig(apiConfig, callback) { const field = apiConfig.provider === PROVIDER_FILESYSTEM ? 'backupFolder' : 'mountPoint'; if (!safe.fs.mkdirSync(path.join(backupPath, 'snapshot'), { recursive: true }) && safe.error.code !== 'EEXIST') { - if (safe.error && safe.error.code === 'EACCES') return callback(new BoxError(BoxError.BAD_FIELD, `Access denied. Run "chown yellowtent:yellowtent ${backupPath}" on the server`, { field })); + if (safe.error && safe.error.code === 'EACCES') return callback(new BoxError(BoxError.BAD_FIELD, `Access denied. Create the directory and run "chown yellowtent:yellowtent ${backupPath}" on the server`, { field })); return callback(new BoxError(BoxError.BAD_FIELD, safe.error.message, { field })); }