2025-08-06 16:26:00 +02:00
|
|
|
<script setup>
|
|
|
|
|
|
2025-08-07 21:00:25 +02:00
|
|
|
import { ref, useTemplateRef } from 'vue';
|
2025-09-24 18:11:48 +02:00
|
|
|
import { Checkbox, Radiobutton, MultiSelect, 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-24 18:11:48 +02:00
|
|
|
import AppsModel from '../models/AppsModel.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-24 18:11:48 +02:00
|
|
|
const appsModel = AppsModel.create();
|
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-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-09-26 11:51:10 +02:00
|
|
|
const includeExclude = ref('everything'); // or include, exclude
|
2025-09-24 18:11:48 +02:00
|
|
|
const contentOptions = ref([]);
|
|
|
|
|
const contentInclude = ref([]);
|
|
|
|
|
const contentExclude = ref([]);
|
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) {
|
|
|
|
|
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
busy.value = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-24 17:22:10 +02:00
|
|
|
[error] = await backupSitesModel.setEnableForUpdates(site.value.id, enableForUpdates.value);
|
|
|
|
|
if (error) {
|
|
|
|
|
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
busy.value = false;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-24 18:11:48 +02:00
|
|
|
let contents;
|
2025-09-26 11:51:10 +02:00
|
|
|
if (includeExclude.value === 'everything') {
|
|
|
|
|
contents = null;
|
|
|
|
|
} else if (includeExclude.value === 'exclude') {
|
2025-09-24 18:11:48 +02:00
|
|
|
contents = { exclude: contentExclude.value };
|
|
|
|
|
} else if (includeExclude.value === 'include' && contentInclude.value.length) {
|
|
|
|
|
contents = { include: contentInclude.value };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[error] = await backupSitesModel.setContents(site.value.id, contents);
|
|
|
|
|
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) {
|
|
|
|
|
formError.value = {};
|
|
|
|
|
busy.value = false;
|
2025-09-12 09:48:37 +02:00
|
|
|
site.value = t;
|
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;
|
|
|
|
|
|
|
|
|
|
await getMemory();
|
2025-08-06 16:26:00 +02:00
|
|
|
|
2025-09-24 18:11:48 +02:00
|
|
|
const [error, result] = await appsModel.list();
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
contentOptions.value = [{
|
|
|
|
|
id: 'box',
|
|
|
|
|
label: 'Platform',
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
result.forEach(a => {
|
|
|
|
|
contentOptions.value.push({
|
|
|
|
|
id: a.id,
|
|
|
|
|
label: `${a.label || a.fqdn} - ${a.manifest.title}`,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-09-26 11:51:10 +02:00
|
|
|
if (t.contents !== null) {
|
|
|
|
|
if (t.contents.exclude) {
|
|
|
|
|
includeExclude.value = 'exclude';
|
|
|
|
|
contentExclude.value = t.contents.exclude;
|
|
|
|
|
} else if (t.contents.include) {
|
|
|
|
|
contentInclude.value = t.contents.include;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
includeExclude.value = 'everything';
|
2025-09-24 18:11:48 +02:00
|
|
|
}
|
|
|
|
|
|
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-09-24 18:11:48 +02:00
|
|
|
<FormGroup>
|
2025-09-26 11:51:10 +02:00
|
|
|
<label>Backup Contents</label>
|
|
|
|
|
<Radiobutton v-model="includeExclude" value="everything" label="Everything"/>
|
|
|
|
|
<div>
|
|
|
|
|
<Radiobutton v-model="includeExclude" value="exclude" label="Exclude selected"/>
|
|
|
|
|
<MultiSelect v-model="contentExclude" v-if="includeExclude === 'exclude'" :options="contentOptions" :search-threshold="10" option-key="id" style="margin: 6px 0 6px 25px;"/>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<Radiobutton v-model="includeExclude" value="include" label="Include only selected"/>
|
|
|
|
|
<MultiSelect v-model="contentInclude" v-if="includeExclude === 'include'" :options="contentOptions" :search-threshold="10" option-key="id" style="margin: 6px 0 6px 25px;"/>
|
|
|
|
|
</div>
|
2025-09-24 18:11:48 +02:00
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-09-24 17:22:10 +02:00
|
|
|
<Checkbox v-model="enableForUpdates" :label="$t('backups.configureBackupStorage.useForUpdates')" />
|
|
|
|
|
|
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-09-12 09:48:37 +02:00
|
|
|
<FormGroup v-if="s3like(site.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-09-12 09:48:37 +02:00
|
|
|
<FormGroup v-if="site.format === 'rsync' && (s3like(site.provider) || site.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-09-12 09:48:37 +02:00
|
|
|
<FormGroup v-if="site.format === 'rsync' && (s3like(site.provider) || site.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-09-12 09:48:37 +02:00
|
|
|
<span v-show="site.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>
|