backuptarget: pseudo target for import and restore
This commit is contained in:
@@ -254,10 +254,11 @@ async function setup(config) {
|
||||
debug('setup: removing old storage configuration');
|
||||
if (!mounts.isManagedProvider(config.provider)) return;
|
||||
|
||||
await safe(mounts.removeMount(paths.MANAGED_BACKUP_MOUNT_DIR), { debug }); // ignore error
|
||||
const mountPath = path.join(paths.MANAGED_BACKUP_MOUNT_DIR, config.id);
|
||||
await safe(mounts.removeMount(mountPath), { debug }); // ignore error
|
||||
|
||||
debug('setup: setting up new storage configuration');
|
||||
await setupManagedMount(config.provider, config.mountOptions, paths.MANAGED_BACKUP_MOUNT_DIR);
|
||||
await setupManagedMount(config.provider, config.mountOptions, mountPath);
|
||||
}
|
||||
|
||||
async function teardown(config) {
|
||||
@@ -265,7 +266,8 @@ async function teardown(config) {
|
||||
|
||||
if (!mounts.isManagedProvider(config.provider)) return;
|
||||
|
||||
await safe(mounts.removeMount(paths.MANAGED_BACKUP_MOUNT_DIR), { debug }); // ignore error
|
||||
const mountPath = path.join(paths.MANAGED_BACKUP_MOUNT_DIR, config.id);
|
||||
await safe(mounts.removeMount(mountPath), { debug }); // ignore error
|
||||
}
|
||||
|
||||
async function verifyConfig({ id, provider, config }) {
|
||||
@@ -277,7 +279,9 @@ async function verifyConfig({ id, provider, config }) {
|
||||
if ('chown' in config && typeof config.chown !== 'boolean') throw new BoxError(BoxError.BAD_FIELD, 'chown must be boolean');
|
||||
if ('preserveAttributes' in config && typeof config.preserveAttributes !== 'boolean') throw new BoxError(BoxError.BAD_FIELD, 'preserveAttributes must be boolean');
|
||||
|
||||
let rootPath, testMountObject;
|
||||
const managedMountValidationPath = path.join(paths.MANAGED_BACKUP_MOUNT_DIR, `${id}-validation`);
|
||||
|
||||
let rootPath;
|
||||
if (provider === mounts.MOUNT_TYPE_FILESYSTEM) {
|
||||
if (!config.backupFolder || typeof config.backupFolder !== 'string') throw new BoxError(BoxError.BAD_FIELD, 'backupFolder must be non-empty string');
|
||||
const error = validateDestPath(config.backupFolder);
|
||||
@@ -296,8 +300,8 @@ async function verifyConfig({ id, provider, config }) {
|
||||
const error = mounts.validateMountOptions(provider, config.mountOptions);
|
||||
if (error) throw error;
|
||||
|
||||
testMountObject = await setupManagedMount(provider, config.mountOptions, '/mnt/backup-storage-validation'); // this validates mountOptions
|
||||
rootPath = path.join('/mnt/backup-storage-validation', config.prefix);
|
||||
await setupManagedMount(provider, config.mountOptions, managedMountValidationPath);
|
||||
rootPath = path.join(managedMountValidationPath, config.prefix);
|
||||
} else if (provider === mounts.MOUNT_TYPE_MOUNTPOINT) {
|
||||
if (!config.mountPoint || typeof config.mountPoint !== 'string') throw new BoxError(BoxError.BAD_FIELD, 'mountPoint must be non-empty string');
|
||||
const error = validateDestPath(config.mountPoint);
|
||||
@@ -324,7 +328,7 @@ async function verifyConfig({ id, provider, config }) {
|
||||
throw new BoxError(BoxError.BAD_FIELD, `Unable to remove test file as 'yellowtent' user in ${rootPath}: ${safe.error.message}. Check dir/mount permissions`);
|
||||
}
|
||||
|
||||
if (testMountObject) await mounts.removeMount('/mnt/backup-storage-validation');
|
||||
if (mounts.isManagedProvider(provider)) await mounts.removeMount(managedMountValidationPath);
|
||||
|
||||
const newConfig = _.pick(config, ['noHardlinks', 'chown', 'preserveAttributes', 'backupFolder', 'prefix', 'mountOptions', 'mountPoint']);
|
||||
return { provider, id, ...newConfig };
|
||||
|
||||
Reference in New Issue
Block a user