import/restore: automatically detect prefix from the full path
This commit is contained in:
@@ -4,7 +4,7 @@ import { ref, onMounted, useTemplateRef } from 'vue';
|
||||
import { Notification, Button, SingleSelect, FormGroup, PasswordInput, TextInput, Checkbox } from '@cloudron/pankow';
|
||||
import { copyToClipboard } from '@cloudron/pankow/utils';
|
||||
import { REGIONS_CONTABO, REGIONS_VULTR, REGIONS_IONOS, REGIONS_OVH, REGIONS_LINODE, REGIONS_SCALEWAY, REGIONS_WASABI } from '../constants.js';
|
||||
import { redirectIfNeeded, mountlike, s3like } from '../utils.js';
|
||||
import { redirectIfNeeded, mountlike, s3like, parseFullBackupPath } from '../utils.js';
|
||||
import ProvisionModel from '../models/ProvisionModel.js';
|
||||
import BackupProviderForm from '../components/BackupProviderForm.vue';
|
||||
import Whirlpool from '../components/Whirlpool.vue';
|
||||
@@ -27,7 +27,7 @@ const progressMessage = ref('');
|
||||
const taskMinutesActive = ref(0);
|
||||
const provider = ref('');
|
||||
const providerConfig = ref({});
|
||||
const remotePath = ref('');
|
||||
const fullPath = ref('');
|
||||
const format = ref('');
|
||||
const encrypted = ref(false);
|
||||
const encryptionPasswordHint = ref('');
|
||||
@@ -87,21 +87,21 @@ async function onSubmit() {
|
||||
busy.value = true;
|
||||
formError.value = {};
|
||||
|
||||
if (remotePath.value.indexOf('/') === -1) {
|
||||
if (fullPath.value.indexOf('/') === -1) {
|
||||
error.value.generic = 'Backup id must include the directory path';
|
||||
error.value.remotePath = true;
|
||||
busy.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (remotePath.value.indexOf('box') === -1) {
|
||||
if (fullPath.value.indexOf('box') === -1) {
|
||||
error.value.generic = 'Backup id must contain "box"';
|
||||
error.value.remotePath = true;
|
||||
busy.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const version = remotePath.value.match(/_v(\d+.\d+.\d+)/);
|
||||
const version = fullPath.value.match(/_v(\d+.\d+.\d+)/);
|
||||
if (!version) {
|
||||
formError.value.generic = 'Backup id is missing version information';
|
||||
formError.value.remotePath = true;
|
||||
@@ -109,11 +109,12 @@ async function onSubmit() {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = {}; // filled below
|
||||
const config = {};
|
||||
const { prefix, remotePath } = parseFullBackupPath(fullPath.value);
|
||||
|
||||
if (s3like(provider.value)) {
|
||||
config.endpoint = providerConfig.value.endpoint;
|
||||
config.prefix = providerConfig.value.prefix;
|
||||
config.prefix = prefix;
|
||||
config.bucket = providerConfig.value.bucket;
|
||||
config.accessKeyId = providerConfig.value.accessKeyId;
|
||||
config.secretAccessKey = providerConfig.value.secretAccessKey;
|
||||
@@ -160,7 +161,7 @@ async function onSubmit() {
|
||||
config.signatureVersion = 'v4';
|
||||
}
|
||||
} else if (mountlike(provider.value)) {
|
||||
config.prefix = providerConfig.value.prefix;
|
||||
config.prefix = prefix;
|
||||
config.noHardlinks = !providerConfig.value.useHardlinks;
|
||||
config.mountOptions = {};
|
||||
|
||||
@@ -188,12 +189,12 @@ async function onSubmit() {
|
||||
config.preserveAttributes = !!providerConfig.value.preserveAttributes;
|
||||
}
|
||||
} else if (provider.value === 'filesystem') {
|
||||
config.backupDir = providerConfig.value.backupDir;
|
||||
config.backupDir = prefix;
|
||||
config.noHardlinks = !providerConfig.value.useHardlinks;
|
||||
config.preserveAttributes = true;
|
||||
} else if (provider.value === 'gcs') {
|
||||
config.bucket = providerConfig.value.bucket;
|
||||
config.prefix = providerConfig.value.prefix;
|
||||
config.prefix = prefix;
|
||||
config.projectId = providerConfig.value.projectId;
|
||||
config.credentials = providerConfig.value.credentials;
|
||||
}
|
||||
@@ -204,7 +205,7 @@ async function onSubmit() {
|
||||
config,
|
||||
format: format.value,
|
||||
},
|
||||
remotePath: remotePath.value,
|
||||
remotePath,
|
||||
version: version ? version[1] : '',
|
||||
ipv4Config: {
|
||||
provider: ipv4Provider.value,
|
||||
@@ -274,7 +275,7 @@ function onBackupConfigChanged(event) {
|
||||
}
|
||||
|
||||
provider.value = data.provider;
|
||||
remotePath.value = data.config.prefix ? `${data.config.prefix}/${data.remotePath}` : data.remotePath;
|
||||
fullPath.value = data.config.prefix ? `${data.config.prefix}/${data.remotePath}` : data.remotePath;
|
||||
providerConfig.value = data.config;
|
||||
format.value = data.format;
|
||||
encrypted.value = !!data.encrypted;
|
||||
@@ -351,7 +352,7 @@ onMounted(async () => {
|
||||
<!-- remotePath contains the prefix as well -->
|
||||
<FormGroup>
|
||||
<label for="inputRemotePath">{{ $t('app.importBackupDialog.remotePath') }} <sup><a href="https://docs.cloudron.io/backups/#import-app-backup" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
|
||||
<TextInput id="inputRemotePath" v-model="remotePath" required />
|
||||
<TextInput id="inputRemotePath" v-model="fullPath" required />
|
||||
</FormGroup>
|
||||
|
||||
<BackupProviderForm ref="form"
|
||||
|
||||
Reference in New Issue
Block a user