2025-08-06 16:26:00 +02:00
|
|
|
<script setup>
|
|
|
|
|
|
2025-08-07 21:00:25 +02:00
|
|
|
import { ref, useTemplateRef } from 'vue';
|
2025-10-09 11:58:16 +02:00
|
|
|
import { MaskedInput, Dialog, FormGroup, TextInput, Checkbox } from '@cloudron/pankow';
|
2025-08-06 16:26:00 +02:00
|
|
|
import { prettyBinarySize } from '@cloudron/pankow/utils';
|
2025-10-09 11:58:16 +02:00
|
|
|
import { s3like, regionName } from '../utils.js';
|
2025-09-12 09:48:37 +02:00
|
|
|
import BackupSitesModel from '../models/BackupSitesModel.js';
|
2025-08-06 16:26:00 +02:00
|
|
|
import SystemModel from '../models/SystemModel.js';
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits([ 'success' ]);
|
|
|
|
|
|
2025-09-12 09:48:37 +02:00
|
|
|
const backupSitesModel = BackupSitesModel.create();
|
2025-08-06 16:26:00 +02:00
|
|
|
const systemModel = SystemModel.create();
|
|
|
|
|
|
2025-08-06 16:40:06 +02:00
|
|
|
const minMemoryLimit = ref(1024 * 1024 * 1024); // 1 GB
|
|
|
|
|
const maxMemoryLimit = ref(minMemoryLimit.value); // set later
|
|
|
|
|
|
2025-08-06 16:26:00 +02:00
|
|
|
const dialog = useTemplateRef('dialog');
|
2025-09-12 09:48:37 +02:00
|
|
|
const site = ref({});
|
2025-10-08 20:40:37 +02:00
|
|
|
const provider = ref('');
|
2025-08-06 16:26:00 +02:00
|
|
|
const formError = ref({});
|
|
|
|
|
const busy = ref(false);
|
2025-08-10 19:36:37 +02:00
|
|
|
const name = ref('');
|
2025-09-24 17:22:10 +02:00
|
|
|
const enableForUpdates = ref(false);
|
2025-08-06 16:40:06 +02:00
|
|
|
const memoryLimit = ref(0);
|
|
|
|
|
const uploadPartSize = ref(0);
|
|
|
|
|
const syncConcurrency = ref(0);
|
|
|
|
|
const downloadConcurrency = ref(0);
|
|
|
|
|
const copyConcurrency = ref(0);
|
2025-08-06 16:26:00 +02:00
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
const accessKeyId = ref('');
|
|
|
|
|
const secretAccessKey = ref('');
|
2025-10-09 11:58:16 +02:00
|
|
|
const mountOptionsUsername = ref('');
|
|
|
|
|
const mountOptionsPassword = ref('');
|
|
|
|
|
const mountOptionsUser = ref('');
|
|
|
|
|
const mountOptionsPrivateKey = ref('');
|
2025-10-08 20:40:37 +02:00
|
|
|
|
2025-08-06 16:26:00 +02:00
|
|
|
async function onSubmit() {
|
2025-08-06 16:40:06 +02:00
|
|
|
busy.value = true;
|
|
|
|
|
|
2025-09-12 09:48:37 +02:00
|
|
|
let [error] = await backupSitesModel.setName(site.value.id, name.value);
|
2025-08-10 19:36:37 +02:00
|
|
|
if (error) {
|
2025-10-09 12:09:13 +02:00
|
|
|
if (error.status === 400) formError.value.name = error.body.message;
|
|
|
|
|
else formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
|
2025-08-10 19:36:37 +02:00
|
|
|
busy.value = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-09 12:20:55 +02:00
|
|
|
const data = site.value.config;
|
2025-10-09 11:58:16 +02:00
|
|
|
|
|
|
|
|
// TODO maybe deal with gcs??
|
2025-10-09 12:05:10 +02:00
|
|
|
if (s3like(provider.value)) {
|
2025-10-09 12:20:55 +02:00
|
|
|
data.accessKeyId = accessKeyId.value;
|
|
|
|
|
if (secretAccessKey.value) data.secretAccessKey = secretAccessKey.value;
|
2025-10-09 11:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (provider.value === 'cifs') {
|
|
|
|
|
data.mountOptions.username = mountOptionsUsername.value;
|
|
|
|
|
if (mountOptionsPassword.value) data.mountOptions.password = mountOptionsPassword.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (provider.value === 'sshfs') {
|
|
|
|
|
data.mountOptions.user = mountOptionsUser.value;
|
|
|
|
|
if (mountOptionsPrivateKey.value) data.mountOptions.privateKey = mountOptionsPrivateKey.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only call if anything has changed
|
|
|
|
|
if (Object.keys(data).length) {
|
|
|
|
|
const [error] = await backupSitesModel.setConfig(site.value.id, data);
|
|
|
|
|
if (error) {
|
|
|
|
|
if (error.status === 400) {
|
|
|
|
|
// if (error.body.message.indexOf('password') === 0) formError.value.generic = 'Username or password is wrong';
|
|
|
|
|
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
} else {
|
|
|
|
|
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
busy.value = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-06 16:40:06 +02:00
|
|
|
const limits = {
|
|
|
|
|
memoryLimit: parseInt(memoryLimit.value),
|
|
|
|
|
uploadPartSize: parseInt(uploadPartSize.value),
|
|
|
|
|
syncConcurrency: parseInt(syncConcurrency.value),
|
|
|
|
|
downloadConcurrency: parseInt(downloadConcurrency.value),
|
|
|
|
|
copyConcurrency: parseInt(copyConcurrency.value),
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-12 09:48:37 +02:00
|
|
|
[error] = await backupSitesModel.setLimits(site.value.id, limits);
|
2025-08-06 16:40:06 +02:00
|
|
|
if (error) {
|
|
|
|
|
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
busy.value = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-06 16:26:00 +02:00
|
|
|
emit('success');
|
|
|
|
|
dialog.value.close();
|
2025-08-06 16:40:06 +02:00
|
|
|
busy.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2025-08-06 16:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
async open(t) {
|
2025-10-08 15:44:58 +02:00
|
|
|
t = JSON.parse(JSON.stringify(t)); // make a copy
|
2025-08-06 16:26:00 +02:00
|
|
|
formError.value = {};
|
|
|
|
|
busy.value = false;
|
2025-09-12 09:48:37 +02:00
|
|
|
site.value = t;
|
2025-10-08 20:40:37 +02:00
|
|
|
provider.value = t.provider;
|
2025-08-06 16:26:00 +02:00
|
|
|
|
2025-08-10 19:36:37 +02:00
|
|
|
name.value = t.name || '';
|
2025-09-24 17:22:10 +02:00
|
|
|
enableForUpdates.value = !!t.enableForUpdates;
|
2025-08-06 16:40:06 +02:00
|
|
|
memoryLimit.value = t.limits.memoryLimit || 1024 * 1024 * 1024; // 1 GB
|
|
|
|
|
uploadPartSize.value = t.limits.uploadPartSize || 10 * 1024 * 1024;
|
|
|
|
|
syncConcurrency.value = t.limits.syncConcurrency || 10;
|
|
|
|
|
downloadConcurrency.value = t.limits.downloadConcurrency || 10;
|
|
|
|
|
copyConcurrency.value = t.limits.copyConcurrency || 10;
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
if (s3like(provider.value)) {
|
|
|
|
|
accessKeyId.value = t.config.accessKeyId;
|
|
|
|
|
secretAccessKey.value = null;
|
|
|
|
|
} else if (provider.value === 'cifs') {
|
2025-10-09 11:58:16 +02:00
|
|
|
mountOptionsUsername.value = t.config.mountOptions.username;
|
|
|
|
|
mountOptionsPassword.value = null;
|
2025-10-08 20:40:37 +02:00
|
|
|
} else if (provider.value === 'sshfs') {
|
2025-10-09 11:58:16 +02:00
|
|
|
mountOptionsUser.value = t.config.mountOptions.user;
|
|
|
|
|
mountOptionsPrivateKey.value = null;
|
2025-10-08 20:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-06 16:40:06 +02:00
|
|
|
await getMemory();
|
2025-08-06 16:26:00 +02:00
|
|
|
|
|
|
|
|
dialog.value.open();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Dialog ref="dialog"
|
|
|
|
|
:title="$t('backups.configureBackupStorage.title')"
|
|
|
|
|
:reject-label="$t('main.dialog.close')"
|
2025-09-23 12:15:27 +02:00
|
|
|
:reject-active="!busy"
|
2025-08-06 16:26:00 +02:00
|
|
|
reject-style="secondary"
|
|
|
|
|
:confirm-label="$t('main.dialog.save')"
|
2025-09-23 12:15:27 +02:00
|
|
|
:confirm-busy="busy"
|
2025-08-06 16:26:00 +02:00
|
|
|
confirm-style="primary"
|
|
|
|
|
@confirm="onSubmit()"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<div>
|
2025-08-10 19:36:37 +02:00
|
|
|
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form">
|
|
|
|
|
<fieldset :disabled="busy">
|
|
|
|
|
<input style="display: none;" type="submit"/>
|
|
|
|
|
|
|
|
|
|
<FormGroup>
|
2025-09-24 16:52:51 +02:00
|
|
|
<label for="backupSiteNameInput">{{ $t('backups.configureBackupStorage.name') }}</label>
|
|
|
|
|
<TextInput id="backupSiteNameInput" v-model="name" required/>
|
2025-10-09 12:09:13 +02:00
|
|
|
<div class="error-label" v-if="formError.name">{{ formError.name }}</div>
|
2025-08-10 19:36:37 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-09 12:09:13 +02:00
|
|
|
<div class="error-label" v-if="formError.generic">{{ formError.generic }}</div>
|
|
|
|
|
|
2025-10-09 11:58:16 +02:00
|
|
|
<FormGroup v-if="site.provider && site.config">
|
|
|
|
|
<label><i v-if="site.encrypted" class="fa-solid fa-lock"></i> Storage: <b>{{ site.provider }} ({{ site.format }}) </b></label>
|
|
|
|
|
<div>
|
|
|
|
|
<span v-if="site.provider === 'filesystem'">{{ site.config.backupDir }}{{ (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
<span v-else-if="site.provider === 'disk' || site.provider === 'ext4' || site.provider === 'xfs' || site.provider === 'mountpoint'">{{ site.config.mountOptions.diskPath || site.config.mountPoint }}{{ (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
<span v-else-if="site.provider === 'cifs' || site.provider === 'nfs' || site.provider === 'sshfs'">{{ site.config.mountOptions.host }}:{{ site.config.mountOptions.remoteDir }}{{ (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
<span v-else-if="site.provider === 's3'">{{ site.config.region + ' ' + site.config.bucket + (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
<span v-else-if="site.provider === 'minio'">{{ site.config.endpoint + ' ' + site.config.bucket + (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
<span v-else-if="site.provider === 'gcs'">{{ site.config.endpoint + ' ' + site.config.bucket + (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
<span v-else>{{ regionName(site.provider, site.config.endpoint) + ' ' + site.config.bucket + (site.config.prefix ? `/${site.config.prefix}` : '') }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
<FormGroup v-if="provider === 'sshfs'">
|
2025-10-09 11:58:16 +02:00
|
|
|
<label for="mountOptionsUserInput">{{ $t('backups.configureBackupStorage.user') }}</label>
|
|
|
|
|
<TextInput id="mountOptionsUserInput" v-model="mountOptionsUser" required />
|
2025-10-08 20:40:37 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup v-if="provider === 'sshfs'">
|
2025-10-09 11:58:16 +02:00
|
|
|
<label for="mountOptionsPrivateKeyInput">{{ $t('backups.configureBackupStorage.privateKey') }}</label>
|
|
|
|
|
<MaskedInput id="mountOptionsPrivateKeyInput" :multiline="true" v-model="mountOptionsPrivateKey" required/>
|
2025-10-08 20:40:37 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup v-if="provider === 'cifs'">
|
2025-10-09 11:58:16 +02:00
|
|
|
<label for="mountOptionsUsernameInput">{{ $t('backups.configureBackupStorage.username') }} ({{ provider }})</label>
|
|
|
|
|
<TextInput id="mountOptionsUsernameInput" v-model="mountOptionsUsername" required />
|
2025-10-08 20:40:37 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup v-if="provider === 'cifs'">
|
2025-10-09 11:58:16 +02:00
|
|
|
<label for="mountOptionsPasswordInput">{{ $t('backups.configureBackupStorage.password') }} ({{ provider }})</label>
|
|
|
|
|
<MaskedInput id="mountOptionsPasswordInput" v-model="mountOptionsPassword" required />
|
2025-10-08 20:40:37 +02:00
|
|
|
</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="secretAccessKeyInput">{{ $t('backups.configureBackupStorage.s3SecretAccessKey') }}</label>
|
|
|
|
|
<MaskedInput id="secretAccessKeyInput" v-model="secretAccessKey" required />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-08-10 19:36:37 +02:00
|
|
|
<FormGroup>
|
|
|
|
|
<label for="memoryLimitInput">{{ $t('backups.configureBackupStorage.memoryLimit') }}: <b>{{ prettyBinarySize(memoryLimit, '1024 MB') }}</b></label>
|
|
|
|
|
<div class="small">{{ $t('backups.configureBackupStorage.memoryLimitDescription') }}</div>
|
|
|
|
|
<input type="range" id="memoryLimitInput" v-model="memoryLimit" :step="256*1024*1024" :min="minMemoryLimit" :max="maxMemoryLimit" />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
<FormGroup v-if="s3like(provider)">
|
2025-08-10 19:36:37 +02:00
|
|
|
<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>
|
|
|
|
|
|
2025-09-26 09:46:07 +02:00
|
|
|
<FormGroup v-if="site.format === 'rsync'">
|
2025-08-10 19:36:37 +02:00
|
|
|
<label for="syncConcurrencyInput">{{ $t('backups.configureBackupStorage.uploadConcurrency') }}: <b>{{ syncConcurrency }}</b></label>
|
|
|
|
|
<div class="small">{{ $t('backups.configureBackupStorage.uploadConcurrencyDescription') }}</div>
|
|
|
|
|
<input type="range" id="syncConcurrencyInput" v-model="syncConcurrency" step="10" min="10" max="200" />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
<FormGroup v-if="site.format === 'rsync' && (s3like(provider) || provider === 'gcs')">
|
2025-08-10 19:36:37 +02:00
|
|
|
<label for="downloadConcurrencyInput">{{ $t('backups.configureBackupStorage.downloadConcurrency') }}: <b>{{ downloadConcurrency }}</b></label>
|
|
|
|
|
<div class="small">{{ $t('backups.configureBackupStorage.downloadConcurrencyDescription') }}</div>
|
|
|
|
|
<input type="range" id="downloadConcurrencyInput" v-model="downloadConcurrency" step="10" min="10" max="200" />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
<FormGroup v-if="site.format === 'rsync' && (s3like(provider) || provider === 'gcs')">
|
2025-08-10 19:36:37 +02:00
|
|
|
<label for="copyConcurrencyInput">{{ $t('backups.configureBackupStorage.copyConcurrency') }}: <b>{{ copyConcurrency }}</b></label>
|
|
|
|
|
<div class="small">{{ $t('backups.configureBackupStorage.copyConcurrencyDescription') }}
|
2025-10-08 20:40:37 +02:00
|
|
|
<span v-show="provider === 'digitalocean-spaces'">{{ $t('backups.configureBackupStorage.copyConcurrencyDigitalOceanNote') }}</span>
|
2025-08-10 19:36:37 +02:00
|
|
|
</div>
|
|
|
|
|
<input type="range" id="copyConcurrencyInput" v-model="copyConcurrency" step="10" min="10" max="500" />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
2025-08-06 16:26:00 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</template>
|