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 10:26:48 +02:00
|
|
|
import { MaskedInput, Dialog, FormGroup, TextInput } from '@cloudron/pankow';
|
2025-08-06 16:26:00 +02:00
|
|
|
import { prettyBinarySize } from '@cloudron/pankow/utils';
|
2025-09-26 09:46:07 +02:00
|
|
|
import { s3like } 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('');
|
|
|
|
|
const mountOptionUsername = ref('');
|
|
|
|
|
const mountOptionPassword = ref('');
|
|
|
|
|
const mountOptionUser = ref('');
|
|
|
|
|
const mountOptionPrivateKey = ref('');
|
|
|
|
|
|
2025-08-06 16:26:00 +02:00
|
|
|
async function onSubmit() {
|
2025-08-06 16:40:06 +02:00
|
|
|
busy.value = true;
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
// TODO maybe deal with gcs??
|
|
|
|
|
if (s3like(provider.value) && (accessKeyId.value !== site.value.config.accessKeyId || secretAccessKey.value)) {
|
|
|
|
|
const [error] = await backupSitesModel.setConfig(site.value.id, {
|
|
|
|
|
accessKeyId: accessKeyId.value,
|
|
|
|
|
secretAccessKey: secretAccessKey.value,
|
|
|
|
|
});
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
} else if (provider.value === 'cifs' && (mountOptionUsername.value !== site.value.config.mountOptions.username || mountOptionPassword.value)) {
|
|
|
|
|
const [error] = await backupSitesModel.setConfig(site.value.id, {
|
|
|
|
|
mountOptions: {
|
|
|
|
|
username: mountOptionUsername.value,
|
|
|
|
|
password: mountOptionPassword.value,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
} else if (provider.value === 'sshfs' && (mountOptionUser.value !== site.value.config.mountOptions.user || mountOptionPrivateKey.value)) {
|
|
|
|
|
const [error] = await backupSitesModel.setConfig(site.value.id, {
|
|
|
|
|
mountOptions: {
|
|
|
|
|
user: mountOptionUser.value,
|
|
|
|
|
privateKey: mountOptionPrivateKey.value,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
busy.value = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
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') {
|
|
|
|
|
mountOptionUsername.value = t.config.mountOptions.username;
|
|
|
|
|
mountOptionPassword.value = null;
|
|
|
|
|
} else if (provider.value === 'sshfs') {
|
|
|
|
|
mountOptionUser.value = t.config.mountOptions.user;
|
|
|
|
|
mountOptionPrivateKey.value = null;
|
|
|
|
|
}
|
|
|
|
|
|
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-08-10 19:36:37 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-10-08 20:40:37 +02:00
|
|
|
<FormGroup v-if="provider === 'sshfs'">
|
|
|
|
|
<label for="mountOptionUserInput">{{ $t('backups.configureBackupStorage.user') }}</label>
|
|
|
|
|
<TextInput id="mountOptionUserInput" v-model="mountOptionUser" required />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup v-if="provider === 'sshfs'">
|
|
|
|
|
<label for="mountOptionPrivateKeyInput">{{ $t('backups.configureBackupStorage.privateKey') }}</label>
|
|
|
|
|
<MaskedInput id="mountOptionPrivateKeyInput" :multiline="true" v-model="mountOptionPrivateKey" required/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup v-if="provider === 'cifs'">
|
|
|
|
|
<label for="mountOptionUsernameInput">{{ $t('backups.configureBackupStorage.username') }} ({{ provider }})</label>
|
|
|
|
|
<TextInput id="mountOptionUsernameInput" v-model="mountOptionUsername" required />
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup v-if="provider === 'cifs'">
|
|
|
|
|
<label for="mountOptionPasswordInput">{{ $t('backups.configureBackupStorage.password') }} ({{ provider }})</label>
|
|
|
|
|
<MaskedInput id="mountOptionPasswordInput" v-model="mountOptionPassword" required />
|
|
|
|
|
</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>
|