Share backup provide form between app import and backup storage configuration

This commit is contained in:
Johannes Zellner
2025-04-29 19:50:28 +02:00
parent a8cb0a0e9c
commit e2659c87f4
3 changed files with 155 additions and 431 deletions

View File

@@ -10,6 +10,7 @@ import { REGIONS_CONTABO, REGIONS_VULTR, REGIONS_IONOS, REGIONS_OVH, REGIONS_LIN
const appsModel = AppsModel.create();
const dialog = useTemplateRef('dialog');
const form = useTemplateRef('form');
const backupConfigInput = useTemplateRef('backupConfigInput');
const appId = ref('');
const busy = ref(false);
@@ -19,6 +20,8 @@ const provider = ref('');
const remotePath = ref('');
async function onSubmit() {
if (!form.value.reportValidity()) return;
formError.value = {};
busy.value = true;
@@ -236,13 +239,19 @@ defineExpose({
<div>
<div>{{ $t('app.importBackupDialog.description') }}</div>
<!-- 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 />
</FormGroup>
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form">
<fieldset :disabled="busy">
<input style="display: none;" type="submit"/>
<BackupProviderForm ref="form" v-model:provider="provider" v-model:provider-config="providerConfig" :form-error="formError" :import-only="true" />
<!-- 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 />
</FormGroup>
<BackupProviderForm ref="form" v-model:provider="provider" v-model:provider-config="providerConfig" :form-error="formError" :import-only="true" />
</fieldset>
</form>
</div>
</Dialog>
</div>

View File

@@ -1,129 +1,57 @@
<script setup>
import { ref, useTemplateRef, onMounted, watch } from 'vue';
import { Button, InputGroup, Dialog, SingleSelect, FormGroup, TextInput, Checkbox, PasswordInput, NumberInput } from 'pankow';
import { prettyBinarySize } from 'pankow/utils';
import { BACKUP_FORMATS, STORAGE_PROVIDERS, REGIONS_CONTABO, REGIONS_VULTR, REGIONS_UPCLOUD, REGIONS_IONOS, REGIONS_OVH, REGIONS_LINODE, REGIONS_SCALEWAY, REGIONS_EXOSCALE, REGIONS_DIGITALOCEAN, REGIONS_HETZNER, REGIONS_WASABI, REGIONS_S3 } from '../constants.js';
import BackupsModel from '../models/BackupsModel.js';
import SystemModel from '../models/SystemModel.js';
import { ref, useTemplateRef } from 'vue';
import { Dialog } from 'pankow';
import { REGIONS_CONTABO, REGIONS_VULTR, REGIONS_IONOS, REGIONS_OVH, REGIONS_LINODE, REGIONS_SCALEWAY, REGIONS_WASABI } from '../constants.js';
import { mountlike, s3like } from '../utils.js';
import BackupProviderForm from './BackupProviderForm.vue';
import BackupsModel from '../models/BackupsModel.js';
const emit = defineEmits([ 'success' ]);
const backupsModel = BackupsModel.create();
const systemModel = SystemModel.create();
const storageProviders = STORAGE_PROVIDERS.concat([
{ name: 'No-op (Only for testing)', value: 'noop' }
]);
const minMemoryLimit = ref(1024 * 1024 * 1024); // 1 GB
const maxMemoryLimit = ref(minMemoryLimit.value); // set later
const dialog = useTemplateRef('dialog');
const form = useTemplateRef('form');
const config = ref({});
const formError = ref({});
const blockDevices = ref([]);
const advancedVisible = ref(false);
const busy = ref(false);
const provider = ref('');
const format = ref('rsync');
const encryptionPassword = ref('');
const encryptedFilenames = ref(false);
const memoryLimit = ref(minMemoryLimit.value);
const uploadPartSize = ref(10*1024*1024);
const syncConcurrency = ref(10);
const downloadConcurrency = ref(10);
const copyConcurrency = ref(10);
const mountPoint = ref('');
const mountOptionHost = ref('');
const mountOptionSeal = ref(false);
const mountOptionRemoteDir = ref('');
const mountOptionUsername = ref('');
const mountOptionPassword = ref('');
const mountOptionDiskPath = ref('');
const mountOptionPort = ref(0);
const mountOptionUser = ref('');
const mountOptionPrivateKey = ref('');
const disk = ref('');
const backupFolder = ref('');
const useHardlinks = ref(false);
const preserveAttributes = ref(false);
const chown = ref(false);
const endpoint = ref('');
const acceptSelfSignedCerts = ref(false);
const bucket = ref('');
const prefix = ref('');
const region = ref('');
const accessKeyId = ref('');
const secretAccessKey = ref('');
const gcsKeyFileName = ref('');
const gcsProjectId = ref('');
const gcsKeyContentJson = ref(null);
function onGcsKeyChange(event) {
delete formError.value.gcs;
const fr = new FileReader();
fr.onload = () => {
// validate input file
try {
const keyJson = JSON.parse(fr.result);
if (!keyJson.project_id) throw new Error('project_id field missing in JSON key file');
if (!keyJson.client_email) throw new Error('client_email field missing in JSON key file');
if (!keyJson.private_key) throw new Error('private_key field missing in JSON key file');
gcsProjectId.value = keyJson.project_id;
gcsKeyContentJson.value = keyJson;
} catch (e) {
if (e.name === 'SyntaxError') formError.value.gcs = 'Invalid JSON';
else formError.value.gcs = e.message;
gcsKeyFileName.value = '';
gcsProjectId.value = '';
gcsKeyContentJson.value = null;
}
};
fr.readAsText(event.target.files[0]);
gcsKeyFileName.value = event.target.files[0].name;
}
const providerConfig = ref({
limits: {},
mountOptions: {},
});
async function onSubmit() {
if (!form.value.reportValidity()) return;
const data = {
provider: provider.value,
format: format.value,
format: providerConfig.value.format,
};
// required for api call to provide all fields
data.chedulePattern = config.value.schedulePattern;
data.etentionPolicy = config.value.retentionPolicy;
data.schedulePattern = config.value.schedulePattern;
data.retentionPolicy = config.value.retentionPolicy;
if (encryptionPassword.value) {
data.encryptedFilenames = encryptedFilenames.value;
data.password = encryptionPassword.value;
if (providerConfig.value.encryptionPassword) {
data.encryptedFilenames = providerConfig.value.encryptedFilenames;
data.password = providerConfig.value.encryptionPassword;
}
if (s3like(data.provider)) {
data.endpoint = endpoint.value;
data.prefix = prefix.value;
data.bucket = bucket.value;
data.accessKeyId = accessKeyId.value;
data.secretAccessKey = secretAccessKey.value;
data.endpoint = providerConfig.value.endpoint;
data.prefix = providerConfig.value.prefix;
data.bucket = providerConfig.value.bucket;
data.accessKeyId = providerConfig.value.accessKeyId;
data.secretAccessKey = providerConfig.value.secretAccessKey;
if (data.provider === 's3') {
data.region = region.value || undefined;
data.region = providerConfig.value.region || undefined;
delete data.endpoint;
} else if (data.provider === 'minio' || data.provider === 's3-v4-compat') {
data.region = region.value || 'us-east-1';
data.acceptSelfSignedCerts = acceptSelfSignedCerts.value;
data.region = providerConfig.value.region || 'us-east-1';
data.acceptSelfSignedCerts = providerConfig.value.acceptSelfSignedCerts;
data.s3ForcePathStyle = true;
} else if (data.provider === 'exoscale-sos') {
data.region = 'us-east-1';
@@ -161,57 +89,57 @@ async function onSubmit() {
data.signatureVersion = 'v4';
}
} else if (mountlike(data.provider)) {
data.prefix = prefix.value;
data.noHardlinks = !useHardlinks.value;
data.prefix = providerConfig.value.prefix;
data.noHardlinks = !providerConfig.value.useHardlinks;
data.mountOptions = {};
if (data.provider === 'cifs' || data.provider === 'sshfs' || data.provider === 'nfs') {
data.mountOptions.host = mountOptionHost.value;
data.mountOptions.remoteDir = mountOptionRemoteDir.value;
data.mountOptions.host = providerConfig.value.mountOptionHost;
data.mountOptions.remoteDir = providerConfig.value.mountOptionRemoteDir;
if (data.provider === 'cifs') {
data.mountOptions.username = mountOptionUsername.value;
data.mountOptions.password = mountOptionPassword.value;
data.mountOptions.seal = !!mountOptionSeal.value;
data.preserveAttributes = !!preserveAttributes.value;
data.mountOptions.username = providerConfig.value.mountOptionUsername;
data.mountOptions.password = providerConfig.value.mountOptionPassword;
data.mountOptions.seal = !!providerConfig.value.mountOptionSeal;
data.preserveAttributes = !!providerConfig.value.preserveAttributes;
} else if (data.provider === 'sshfs') {
data.mountOptions.user = mountOptionUser.value;
data.mountOptions.port = parseInt(mountOptionPort.value);
data.mountOptions.privateKey = mountOptionPrivateKey.value;
data.mountOptions.user = providerConfig.value.mountOptionUser;
data.mountOptions.port = parseInt(providerConfig.value.mountOptionPort);
data.mountOptions.privateKey = providerConfig.value.mountOptionPrivateKey;
data.preserveAttributes = true;
}
} else if (data.provider === 'ext4' || data.provider === 'xfs' || data.provider === 'disk') {
data.mountOptions.diskPath = mountOptionDiskPath.value;
data.mountOptions.diskPath = providerConfig.value.mountOptionDiskPath;
data.preserveAttributes = true;
} else if (data.provider === 'mountpoint') {
data.mountPoint = mountPoint.value;
data.chown = !!chown.value;
data.preserveAttributes = !!preserveAttributes.value;
data.mountPoint = providerConfig.value.mountPoint;
data.chown = !!providerConfig.value.chown;
data.preserveAttributes = !!providerConfig.value.preserveAttributes;
}
} else if (data.provider === 'filesystem') {
data.backupFolder = backupFolder.value;
data.noHardlinks = !useHardlinks.value;
data.backupFolder = providerConfig.value.backupFolder;
data.noHardlinks = !providerConfig.value.useHardlinks;
data.preserveAttributes = true;
} else if (data.provider === 'gcs') {
// TODO we should probably allow to change the config without reuploading a new .json
if (gcsKeyContentJson.value) return;
if (providerConfig.value.gcsKeyContentJson) return;
data.bucket = bucket.value;
data.prefix = prefix.value;
data.projectId = gcsKeyContentJson.value.project_id;
data.bucket = providerConfig.value.bucket;
data.prefix = providerConfig.value.prefix;
data.projectId = providerConfig.value.gcsKeyContentJson.project_id;
data.credentials = {
client_email: gcsKeyContentJson.value.client_email,
private_key: gcsKeyContentJson.value.private_key
client_email: providerConfig.value.gcsKeyContentJson.client_email,
private_key: providerConfig.value.gcsKeyContentJson.private_key
};
}
const limits = {
memoryLimit: parseInt(memoryLimit.value),
syncConcurrency: parseInt(syncConcurrency.value),
copyConcurrency: parseInt(copyConcurrency.value),
downloadConcurrency: parseInt(downloadConcurrency.value),
uploadPartSize: parseInt(uploadPartSize.value),
// deleteConcurrency: parseInt(deleteConcurrency.value),
memoryLimit: parseInt(providerConfig.value.limits.memoryLimit),
syncConcurrency: parseInt(providerConfig.value.limits.syncConcurrency),
copyConcurrency: parseInt(providerConfig.value.limits.copyConcurrency),
downloadConcurrency: parseInt(providerConfig.value.limits.downloadConcurrency),
uploadPartSize: parseInt(providerConfig.value.limits.uploadPartSize),
// deleteConcurrency: parseInt(providerConfig.value.limits.deleteConcurrency),
};
formError.value = {};
@@ -227,50 +155,6 @@ async function onSubmit() {
dialog.value.close();
}
async function getBlockDevices() {
const [error, result] = await systemModel.blockDevices();
if (error) return console.error(error);
// amend label for UI
result.forEach(d => {
d.label = d.path;
// pre-select current if set
if (d.path === mountOptionDiskPath.value || ('/dev/disk/by-uuid/' + d.uuid) === mountOptionDiskPath.value) {
disk.value = d.path;
}
});
// only offer non /, /boot or /home disks
// only offer xfs and ext4 disks
blockDevices.value = result
.filter(d => { return d.mountpoint !== '/' && d.mountpoint !== '/home' && d.mountpoint !== '/boot'; })
.filter(d => { return d.type === 'xfs' || d.type === 'ext4'; });
}
async function getMemory() {
const [error, result] = await systemModel.memory();
if (error) return console.error(error);
maxMemoryLimit.value = Math.ceil(result.memory / (1024*1024*1024)) * 1024 * 1024 * 1024;
}
watch(provider, (newProvider) => {
if (newProvider === 'scaleway-objectstorage') {
// scaleway only supports 1000 parts per object (https://www.scaleway.com/en/docs/s3-multipart-upload/)
if (parseInt(uploadPartSize.value) < 100 * 1024 * 1024) uploadPartSize.value = 100 * 1024 * 1024;
} else if (newProvider === 's3') {
if (parseInt(downloadConcurrency.value) < 30) downloadConcurrency.value = 30;
if (parseInt(syncConcurrency.value) < 20) syncConcurrency.value = 20;
if (parseInt(copyConcurrency.value) < 500) downloadConcurrency.value = 500;
}
});
onMounted(async () => {
await getBlockDevices();
await getMemory();
});
defineExpose({
async open() {
const [error, result] = await backupsModel.getConfig();
@@ -279,39 +163,23 @@ defineExpose({
config.value = result;
formError.value = {};
busy.value = false;
advancedVisible.value = false;
provider.value = result.provider;
format.value = result.format;
backupFolder.value = result.backupFolder;
useHardlinks.value = !result.noHardlinks;
memoryLimit.value = result.limits.memoryLimit || minMemoryLimit.value;
uploadPartSize.value = result.limits.uploadPartSize || (10*1024*1024);
syncConcurrency.value = result.limits.syncConcurrency || 10;
downloadConcurrency.value = result.limits.downloadConcurrency || 10;
copyConcurrency.value = result.limits.copyConcurrency || 10;
encryptionPassword.value = result.password || '';
encryptedFilenames.value = !!result.encryptedFilenames;
mountOptionHost.value = result.mountOptions.hostPath;
mountOptionUsername.value = result.mountOptions.username;
mountOptionPassword.value = result.mountOptions.password;
mountOptionRemoteDir.value = result.mountOptions.remoteDir;
mountOptionSeal.value = result.mountOptions.seal;
mountOptionUser.value = result.mountOptions.user;
mountOptionPrivateKey.value = result.mountOptions.privateKey;
preserveAttributes.value = !!result.preserveAttributes;
chown.value = !!result.chown;
disk.value = result.disk;
mountPoint.value = result.mountPoint;
endpoint.value = result.endpoint;
acceptSelfSignedCerts.value = result.acceptSelfSignedCerts;
bucket.value = result.bucket;
prefix.value = result.prefix;
region.value = result.region;
accessKeyId.value = result.accessKeyId;
secretAccessKey.value = result.secretAccessKey;
gcsProjectId.value = result.projectId || '';
gcsKeyFileName.value = '';
gcsKeyContentJson.value = null;
providerConfig.value = result;
// ensure we have all required child objects
if (!providerConfig.value.mountOptions) providerConfig.value.mountOptions = {};
if (!providerConfig.value.limits) providerConfig.value.limits = {};
// some sane defaults
if (!providerConfig.value.limits.memoryLimit) providerConfig.value.limits.memoryLimit = 1024 * 1024 * 1024; // 1 GB
if (!providerConfig.value.limits.uploadPartSize) providerConfig.value.limits.uploadPartSize = 10 * 1024 * 1024;
if (!providerConfig.value.limits.syncConcurrency) providerConfig.value.limits.syncConcurrency = 10;
if (!providerConfig.value.limits.downloadConcurrency) providerConfig.value.limits.downloadConcurrency = 10;
if (!providerConfig.value.limits.copyConcurrency) providerConfig.value.limits.copyConcurrency = 10;
// needs translation for UI
providerConfig.value.useHardlinks = !result.noHardlinks;
providerConfig.value.encryptionPassword = result.password;
dialog.value.open();
}
@@ -332,229 +200,10 @@ defineExpose({
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form">
<fieldset :disabled="busy">
<input style="display: none;" type="submit"/>
<p class="has-error" v-show="formError.generic">{{ formError.generic }}</p>
<div class="error-label" v-show="formError.generic">{{ formError.generic }}</div>
<FormGroup>
<label for="providerInput">{{ $t('backups.configureBackupStorage.provider') }} <sup><a href="https://docs.cloudron.io/backups/#storage-providers" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
<p class="small text-info" v-show="config.provider !== provider">Backups in the old storage location have to be removed manually.</p>
<SingleSelect id="providerInput" v-model="provider" :options="storageProviders" option-key="value" option-label="name" />
</FormGroup>
<BackupProviderForm v-model:provider="provider" v-model:provider-config="providerConfig" :form-error="formError"/>
<!-- Noop -->
<p class="has-error" v-show="provider === 'noop'">{{ $t('backups.configureBackupStorage.noopNote') }}</p>
<!-- mountpoint -->
<FormGroup v-if="provider === 'mountpoint'">
<label for="mountPointInput">{{ $t('backups.configureBackupStorage.mountPoint') }}</label>
<TextInput id="mountPointInput" v-model="mountPoint" placeholder="/mnt/backups" required/>
<p v-html="$t('backups.configureBackupStorage.mountPointDescription', { providerDocsLink: `https://docs.cloudron.io/backups/#${provider}` })"></p>
</FormGroup>
<!-- CIFS/NFS/SSHFS -->
<FormGroup v-if="provider === 'cifs' || provider === 'nfs' || provider === 'sshfs'">
<label for="mountOptionHostInput">{{ $t('backups.configureBackupStorage.server') }} ({{ provider }})</label>
<TextInput id="mountOptionHostInput" v-model="mountOptionHost" placeholder="Server IP or hostname" required />
</FormGroup>
<!-- CIFS -->
<Checkbox v-if="provider === 'cifs'" v-model="mountOptionSeal" :label="$t('backups.configureBackupStorage.cifsSealSupport')" />
<!-- CIFS/NFS/SSHFS -->
<FormGroup v-if="provider === 'cifs' || provider === 'nfs' || provider === 'sshfs'">
<label for="mountOptionRemoteDirInput">{{ $t('backups.configureBackupStorage.remoteDirectory') }} ({{ provider }})</label>
<TextInput id="mountOptionRemoteDirInput" v-model="mountOptionRemoteDir" placeholder="/share" required />
</FormGroup>
<!-- CIFS -->
<FormGroup v-if="provider === 'cifs'">
<label for="mountOptionUsernameInput">{{ $t('backups.configureBackupStorage.username') }} ({{ provider }})</label>
<TextInput id="mountOptionUsernameInput" v-model="mountOptionUsername" required />
</FormGroup>
<!-- CIFS -->
<FormGroup v-if="provider === 'cifs'">
<label for="mountOptionPasswordInput">{{ $t('backups.configureBackupStorage.password') }} ({{ provider }})</label>
<PasswordInput id="mountOptionPasswordInput" v-model="mountOptionPassword" required />
</FormGroup>
<!-- EXT4/XFS -->
<FormGroup v-if="provider === 'xfs' || provider === 'ext4'">
<label for="mountOptionDiskPathInput">{{ $t('backups.configureBackupStorage.diskPath') }}</label>
<TextInput id="mountOptionDiskPathInput" v-model="mountOptionDiskPath" placeholder="/dev/disk/by-uuid/uuid" required />
</FormGroup>
<!-- Disk -->
<FormGroup v-if="provider === 'disk'">
<label class="control-label">{{ $t('backups.configureBackupStorage.diskPath') }}</label>
<SingleSelect v-model="disk" :options="blockDevices" option-label="label" option-key="path" required />
</FormGroup>
<!-- SSHFS -->
<FormGroup v-if="provider === 'sshfs'">
<label for="mountOptionPortInput">{{ $t('backups.configureBackupStorage.port') }}</label>
<NumberInput v-model="mountOptionPort" id="mountOptionPortInput" required />
</FormGroup>
<!-- SSHFS -->
<FormGroup v-if="provider === 'sshfs'">
<label for="mountOptionUserInput">{{ $t('backups.configureBackupStorage.user') }}</label>
<TextInput id="mountOptionUserInput" v-model="mountOptionUser" required />
</FormGroup>
<!-- SSHFS -->
<FormGroup v-if="provider === 'sshfs'">
<label for="mountOptionPrivateKeyInput">{{ $t('backups.configureBackupStorage.privateKey') }}</label>
<textarea id="mountOptionPrivateKeyInput" v-model="mountOptionPrivateKey" required></textarea>
</FormGroup>
<!-- Filesystem -->
<FormGroup v-if="provider === 'filesystem'">
<label for="backupFolderInput">{{ $t('backups.configureBackupStorage.localDirectory') }}</label>
<TextInput id="backupFolderInput" v-model="backupFolder" placeholder="Directory for backups" required />
</FormGroup>
<!-- Filesystem/SSHFS/CIFS/NFS/EXT4/mountpoint -->
<Checkbox v-if="provider === 'filesystem' || mountlike(provider)" v-model="useHardlinks" :label="$t('backups.configureBackupStorage.hardlinksLabel')"/>
<!-- CIFS/mountpoint -->
<Checkbox v-if="provider === 'mountpoint' || provider === 'cifs'" v-model="preserveAttributes" :label="$t('backups.configureBackupStorage.preserveAttributesLabel')"/>
<!-- mountpoint -->
<Checkbox v-if="provider === 'mountpoint'" v-model="chown" :label="$t('backups.configureBackupStorage.chown')"/>
<!-- S3/Minio/SOS/GCS/UpCloud/B2/R2 -->
<FormGroup v-if="provider === 'minio' || provider === 'upcloud-objectstorage' || provider === 'backblaze-b2' || provider === 'cloudflare-r2' || provider === 's3-v4-compat' || provider === 'idrive-e2'">
<label for="endpointInput">{{ $t('backups.configureBackupStorage.s3Endpoint') }}</label>
<TextInput id="endpointInput" v-model="endpoint" placeholder="URL" required />
</FormGroup>
<Checkbox v-if="provider === 'minio' || provider === 's3-v4-compat'" v-model="acceptSelfSignedCerts" :label="$t('backups.configureBackupStorage.acceptSelfSignedCerts')"/>
<FormGroup v-if="s3like(provider) || provider === 'gcs'">
<label for="bucketInput">{{ $t('backups.configureBackupStorage.bucketName') }}</label>
<TextInput id="bucketInput" v-model="bucket" required />
</FormGroup>
<FormGroup v-if="provider !== 'filesystem' && provider !== 'noop'">
<label for="prefixInput">{{ $t('backups.configureBackupStorage.prefix') }}</label>
<TextInput id="prefixInput" v-model="prefix" placeholder="Prefix for backup file names" />
</FormGroup>
<!-- S3/Minio/SOS/GCS -->
<FormGroup v-if="
provider === 's3' ||
provider === 'digitalocean-spaces' ||
provider === 'hetzner-objectstorage' ||
provider === 'wasabi' ||
provider === 'scaleway-objectstorage' ||
provider === 'linode-objectstorage' ||
provider === 'ovh-objectstorage' ||
provider === 'ionos-objectstorage' ||
provider === 'vultr-objectstorage' ||
provider === 'contabo-objectstorage' ||
provider === 'exoscale-sos'
"
>
<label for="regionInput">{{ $t('backups.configureBackupStorage.region') }}</label>
<SingleSelect id="regionInput" v-if="provider === 's3'" v-model="region" :options="REGIONS_S3" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'digitalocean-spaces'" v-model="endpoint" :options="REGIONS_DIGITALOCEAN" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'hetzner-objectstorage'" v-model="endpoint" :options="REGIONS_HETZNER" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'exoscale-sos'" v-model="endpoint" :options="REGIONS_EXOSCALE" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'wasabi'" v-model="endpoint" :options="REGIONS_WASABI" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'scaleway-objectstorage'" v-model="endpoint" :options="REGIONS_SCALEWAY" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'linode-objectstorage'" v-model="endpoint" :options="REGIONS_LINODE" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'ovh-objectstorage'" v-model="endpoint" :options="REGIONS_OVH" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'ionos-objectstorage'" v-model="endpoint" :options="REGIONS_IONOS" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'vultr-objectstorage'" v-model="endpoint" :options="REGIONS_VULTR" option-label="name" option-key="value" required />
<SingleSelect id="regionInput" v-if="provider === 'contabo-objectstorage'" v-model="endpoint" :options="REGIONS_CONTABO" option-label="name" option-key="value" required />
</FormGroup>
<FormGroup v-if="provider === 's3-v4-compat'">
<label for="s3v4CompatRegionInput">{{ $t('backups.configureBackupStorage.region') }}</label>
<TextInput id="s3v4CompatRegionInput" v-model="region" placeholder="Leave empty to use us-east-1 as default" />
</FormGroup>
<FormGroup v-if="s3like(provider)">
<label for="accessKeyIdInput">{{ $t('backups.configureBackupStorage.s3AccessKeyId') }}</label>
<TextInput id="accessKeyIdInput" v-model="accessKeyId" required />
</FormGroup>
<FormGroup v-if="s3like(provider)">
<label for="accessKeyInput">{{ $t('backups.configureBackupStorage.s3SecretAccessKey') }}</label>
<TextInput id="accessKeyInput" v-model="secretAccessKey" required />
</FormGroup>
<FormGroup v-if="provider === 'gcs'">
<input type="file" id="gcsKeyFileInput" style="display:none" @change="onGcsKeyChange"/>
<label for="gcsKeyInput">{{ $t('backups.configureBackupStorage.gcsServiceKey') }}{{ gcsProjectId ? ` - project: ${gcsProjectId}` : '' }}</label>
<InputGroup>
<TextInput readonly required style="flex-grow: 1" v-model="gcsKeyFileName" placeholder="Service Account Key" onclick="document.getElementById('gcsKeyFileInput').click();"/>
<Button tool icon="fa fa-upload" onclick="document.getElementById('gcsKeyFileInput').click();"/>
</InputGroup>
<div class="has-error" v-show="formError.gcs">{{ formError.gcs }}</div>
</FormGroup>
<FormGroup v-if="provider !== 'noop'">
<label for="formatInput">{{ $t('backups.configureBackupStorage.format') }} <sup><a href="https://docs.cloudron.io/backups/#backup-formats" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
<select class="form-control" id="formatInput" v-model="format">
<option v-for="f in BACKUP_FORMATS" :value="f.value" :key="f.value">{{ f.name }}</option>
</select>
<p class="small text-info" v-show="format !== config.format">{{ $t('backups.configureBackupStorage.formatChangeNote') }}</p>
<p class="small text-info" v-show="format === 'rsync' && (s3like(provider) || provider === 'gcs')">{{ $t('backups.configureBackupStorage.s3LikeNote') }} <sup><a href="https://docs.cloudron.io/backups/#amazon-s3" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></p>
</FormGroup>
<FormGroup v-if="provider !== 'noop'">
<label for="encryptionPassswordInput">{{ $t('backups.configureBackupStorage.encryptionPassword') }} <sup><a href="https://docs.cloudron.io/backups/#encryption" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
<TextInput id="encryptionPassswordInput" v-model="encryptionPassword" :placeholder="$t('backups.configureBackupStorage.encryptionPasswordPlaceholder')" />
<div class="text-small text-danger" v-show="encryptionPassword !== ''">{{ $t('backups.configureBackupStorage.encryptionDescription') }}</div>
</FormGroup>
<Checkbox v-if="format === 'rsync' && encryptionPassword !== ''" v-model="encryptedFilenames" :label="$t('backups.configureBackupStorage.encryptFilenames')"/>
<p class="actionable" @click="advancedVisible = true" v-show="!advancedVisible">{{ $t('backups.configureBackupStorage.advancedSettings') }}</p>
<div v-show="advancedVisible">
<FormGroup>
<label for="memoryLimitInput">{{ $t('backups.configureBackupStorage.memoryLimit') }}: <b>{{ prettyBinarySize(memoryLimit, '1024 MB') }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.memoryLimitDescription') }}</p>
<input type="range" id="memoryLimitInput" v-model="memoryLimit" :step="256*1024*1024" :min="minMemoryLimit" :max="maxMemoryLimit" />
</FormGroup>
<FormGroup v-if="s3like(provider)">
<label for="uploadPartSizeInput">{{ $t('backups.configureBackupStorage.uploadPartSize') }}: <b>{{ prettyBinarySize(uploadPartSize, 'Default (50 MiB)') }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.uploadPartSizeDescription') }}</p>
<input type="range" id="uploadPartSizeInput" v-model="uploadPartSize" list="uploadPartSizeTicks" :step="1024*1024" :min="10*1024*1024" :max="1024*1024*1024" />
<datalist id="uploadPartSizeTicks">
<option :value="1024*1024*10"></option>
<option :value="1024*1024*64"></option>
<option :value="1024*1024*128"></option>
<option :value="1024*1024*256"></option>
<option :value="1024*1024*512"></option>
<option :value="1024*1024*1024"></option>
</datalist>
</FormGroup>
<FormGroup v-if="format === 'rsync' && provider !== 'noop'">
<label for="syncConcurrencyInput">{{ $t('backups.configureBackupStorage.uploadConcurrency') }}: <b>{{ syncConcurrency }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.uploadConcurrencyDescription') }}</p>
<input type="range" id="syncConcurrencyInput" v-model="syncConcurrency" step="10" min="10" max="200" />
</FormGroup>
<FormGroup v-if="format === 'rsync' && (s3like(provider) || provider === 'gcs')">
<label for="downloadConcurrencyInput">{{ $t('backups.configureBackupStorage.downloadConcurrency') }}: <b>{{ downloadConcurrency }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.downloadConcurrencyDescription') }}</p>
<input type="range" id="downloadConcurrencyInput" v-model="downloadConcurrency" step="10" min="10" max="200" />
</FormGroup>
<FormGroup v-if="format === 'rsync' && (s3like(provider) || provider === 'gcs')">
<label for="copyConcurrencyInput">{{ $t('backups.configureBackupStorage.copyConcurrency') }}: <b>{{ copyConcurrency }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.copyConcurrencyDescription') }}
<span v-show="provider === 'digitalocean-spaces'">{{ $t('backups.configureBackupStorage.copyConcurrencyDigitalOceanNote') }}</span>
</p>
<input type="range" id="copyConcurrencyInput" v-model="copyConcurrency" step="10" min="10" max="500" />
</FormGroup>
</div>
</fieldset>
</form>
</div>

View File

@@ -1,8 +1,9 @@
<script setup>
import { ref, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import { Button, InputGroup, SingleSelect, FormGroup, TextInput, Checkbox, PasswordInput, NumberInput } from 'pankow';
import { BACKUP_FORMATS, STORAGE_PROVIDERS, REGIONS_CONTABO, REGIONS_VULTR, REGIONS_UPCLOUD, REGIONS_IONOS, REGIONS_OVH, REGIONS_LINODE, REGIONS_SCALEWAY, REGIONS_EXOSCALE, REGIONS_DIGITALOCEAN, REGIONS_HETZNER, REGIONS_WASABI, REGIONS_S3 } from '../constants.js';
import { prettyBinarySize } from 'pankow/utils';
import { BACKUP_FORMATS, STORAGE_PROVIDERS, REGIONS_CONTABO, REGIONS_VULTR, REGIONS_IONOS, REGIONS_OVH, REGIONS_LINODE, REGIONS_SCALEWAY, REGIONS_EXOSCALE, REGIONS_DIGITALOCEAN, REGIONS_HETZNER, REGIONS_WASABI, REGIONS_S3 } from '../constants.js';
import SystemModel from '../models/SystemModel.js';
import { mountlike, s3like } from '../utils.js';
@@ -28,6 +29,10 @@ const gcsKeyFileName = ref('');
const gcsProjectId = ref('');
const gcsKeyContentJson = ref(null);
const gcsFileParseError = ref('');
const advancedVisible = ref(false);
const minMemoryLimit = ref(1024 * 1024 * 1024); // 1 GB
const maxMemoryLimit = ref(minMemoryLimit.value); // set later
function onGcsKeyChange(event) {
gcsFileParseError.value = '';
@@ -78,7 +83,26 @@ async function getBlockDevices() {
.filter(d => { return d.type === 'xfs' || d.type === 'ext4'; });
}
async function getMemory() {
const [error, result] = await systemModel.memory();
if (error) return console.error(error);
maxMemoryLimit.value = Math.ceil(result.memory / (1024*1024*1024)) * 1024 * 1024 * 1024;
}
watch(provider, (newProvider) => {
if (newProvider === 'scaleway-objectstorage') {
// scaleway only supports 1000 parts per object (https://www.scaleway.com/en/docs/s3-multipart-upload/)
if (parseInt(providerConfig.value.uploadPartSize) < 100 * 1024 * 1024) providerConfig.value.uploadPartSize = 100 * 1024 * 1024;
} else if (newProvider === 's3') {
if (parseInt(providerConfig.value.downloadConcurrency) < 30) providerConfig.value.downloadConcurrency = 30;
if (parseInt(providerConfig.value.syncConcurrency) < 20) providerConfig.value.syncConcurrency = 20;
if (parseInt(providerConfig.value.copyConcurrency) < 500) providerConfig.value.downloadConcurrency = 500;
}
});
onMounted(async () => {
await getMemory();
await getBlockDevices();
});
@@ -258,9 +282,51 @@ onMounted(async () => {
<FormGroup v-if="provider !== 'noop'">
<label for="encryptionPassswordInput">{{ $t('backups.configureBackupStorage.encryptionPassword') }} <sup><a href="https://docs.cloudron.io/backups/#encryption" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
<TextInput id="encryptionPassswordInput" v-model="providerConfig.encryptionPassword" :placeholder="$t('backups.configureBackupStorage.encryptionPasswordPlaceholder')" />
<div class="error-label" v-show="providerConfig.encryptionPassword">{{ $t('backups.configureBackupStorage.encryptionDescription') }}</div>
</FormGroup>
<Checkbox v-if="providerConfig.format === 'rsync' && providerConfig.encryptionPassword" v-model="providerConfig.encryptedFilenames" :label="$t(importOnly ? 'backups.configureBackupStorage.encryptedFilenames' : 'backups.configureBackupStorage.encryptFilenames')"/>
<div class="warning-label" v-show="providerConfig.encryptionPassword && !importOnly">{{ $t('backups.configureBackupStorage.encryptionDescription') }}</div>
<Checkbox v-if="providerConfig.format === 'rsync' && providerConfig.encryptionPassword" v-model="providerConfig.encryptedFilenames" :label="$t('backups.configureBackupStorage.encryptFilenames')"/>
<p class="actionable" @click="advancedVisible = true" v-if="!advancedVisible && !importOnly">{{ $t('backups.configureBackupStorage.advancedSettings') }}</p>
<div v-if="advancedVisible && !importOnly">
<FormGroup>
<label for="memoryLimitInput">{{ $t('backups.configureBackupStorage.memoryLimit') }}: <b>{{ prettyBinarySize(memoryLimit, '1024 MB') }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.memoryLimitDescription') }}</p>
<input type="range" id="memoryLimitInput" v-model="providerConfig.limits.memoryLimit" :step="256*1024*1024" :min="minMemoryLimit" :max="maxMemoryLimit" />
</FormGroup>
<FormGroup v-if="s3like(provider)">
<label for="uploadPartSizeInput">{{ $t('backups.configureBackupStorage.uploadPartSize') }}: <b>{{ prettyBinarySize(providerConfig.limits.uploadPartSize, 'Default (50 MiB)') }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.uploadPartSizeDescription') }}</p>
<input type="range" id="uploadPartSizeInput" v-model="providerConfig.limits.uploadPartSize" list="uploadPartSizeTicks" :step="1024*1024" :min="10*1024*1024" :max="1024*1024*1024" />
<datalist id="uploadPartSizeTicks">
<option :value="1024*1024*10"></option>
<option :value="1024*1024*64"></option>
<option :value="1024*1024*128"></option>
<option :value="1024*1024*256"></option>
<option :value="1024*1024*512"></option>
<option :value="1024*1024*1024"></option>
</datalist>
</FormGroup>
<FormGroup v-if="format === 'rsync' && provider !== 'noop'">
<label for="syncConcurrencyInput">{{ $t('backups.configureBackupStorage.uploadConcurrency') }}: <b>{{ providerConfig.limits.syncConcurrency }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.uploadConcurrencyDescription') }}</p>
<input type="range" id="syncConcurrencyInput" v-model="providerConfig.limits.syncConcurrency" step="10" min="10" max="200" />
</FormGroup>
<FormGroup v-if="format === 'rsync' && (s3like(provider) || provider === 'gcs')">
<label for="downloadConcurrencyInput">{{ $t('backups.configureBackupStorage.downloadConcurrency') }}: <b>{{ providerConfig.limits.downloadConcurrency }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.downloadConcurrencyDescription') }}</p>
<input type="range" id="downloadConcurrencyInput" v-model="providerConfig.limits.downloadConcurrency" step="10" min="10" max="200" />
</FormGroup>
<FormGroup v-if="format === 'rsync' && (s3like(provider) || provider === 'gcs')">
<label for="copyConcurrencyInput">{{ $t('backups.configureBackupStorage.copyConcurrency') }}: <b>{{ providerConfig.limits.copyConcurrency }}</b></label>
<p class="small">{{ $t('backups.configureBackupStorage.copyConcurrencyDescription') }}
<span v-show="provider === 'digitalocean-spaces'">{{ $t('backups.configureBackupStorage.copyConcurrencyDigitalOceanNote') }}</span>
</p>
<input type="range" id="copyConcurrencyInput" v-model="providerConfig.limits.copyConcurrency" step="10" min="10" max="500" />
</FormGroup>
</div>
</div>
</template>