Make basic backup target add and edit work
This commit is contained in:
@@ -1,210 +0,0 @@
|
||||
<script setup>
|
||||
|
||||
import { ref, useTemplateRef } from 'vue';
|
||||
import { Dialog } from '@cloudron/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 dialog = useTemplateRef('dialog');
|
||||
const form = useTemplateRef('form');
|
||||
const config = ref({});
|
||||
const formError = ref({});
|
||||
const busy = ref(false);
|
||||
const provider = ref('');
|
||||
const oldProvider = ref('');
|
||||
const oldFormat = ref('');
|
||||
const providerConfig = ref({
|
||||
limits: {},
|
||||
mountOptions: {},
|
||||
prefix: '',
|
||||
});
|
||||
|
||||
async function onSubmit() {
|
||||
if (!form.value.reportValidity()) return;
|
||||
|
||||
const data = {
|
||||
provider: provider.value,
|
||||
format: providerConfig.value.format,
|
||||
};
|
||||
|
||||
// required for api call to provide all fields
|
||||
data.schedulePattern = config.value.schedulePattern;
|
||||
data.retentionPolicy = config.value.retentionPolicy;
|
||||
|
||||
if (providerConfig.value.encryptionPassword) {
|
||||
data.encryptedFilenames = providerConfig.value.encryptedFilenames;
|
||||
data.password = providerConfig.value.encryptionPassword;
|
||||
}
|
||||
|
||||
if (s3like(data.provider)) {
|
||||
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 = providerConfig.value.region || undefined;
|
||||
delete data.endpoint;
|
||||
} else if (data.provider === 'minio' || data.provider === 's3-v4-compat') {
|
||||
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';
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'wasabi') {
|
||||
data.region = REGIONS_WASABI.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'scaleway-objectstorage') {
|
||||
data.region = REGIONS_SCALEWAY.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'linode-objectstorage') {
|
||||
data.region = REGIONS_LINODE.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'ovh-objectstorage') {
|
||||
data.region = REGIONS_OVH.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'ionos-objectstorage') {
|
||||
data.region = REGIONS_IONOS.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'vultr-objectstorage') {
|
||||
data.region = REGIONS_VULTR.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'contabo-objectstorage') {
|
||||
data.region = REGIONS_CONTABO.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
data.s3ForcePathStyle = true;
|
||||
} else if (data.provider === 'upcloud-objectstorage') { // the UI sets region and endpoint
|
||||
const m = /^.*\.(.*)\.upcloudobjects.com$/.exec(data.endpoint);
|
||||
data.region = m ? m[1] : 'us-east-1'; // let it fail in validation phase if m is not valid
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (data.provider === 'digitalocean-spaces') {
|
||||
data.region = 'us-east-1';
|
||||
} else if (data.provider === 'hetzner-objectstorage') {
|
||||
data.region = 'us-east-1';
|
||||
data.signatureVersion = 'v4';
|
||||
}
|
||||
} else if (mountlike(data.provider)) {
|
||||
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 = providerConfig.value.mountOptionHost;
|
||||
data.mountOptions.remoteDir = providerConfig.value.mountOptionRemoteDir;
|
||||
|
||||
if (data.provider === 'cifs') {
|
||||
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 = 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 = providerConfig.value.mountOptionDiskPath;
|
||||
data.preserveAttributes = true;
|
||||
} else if (data.provider === 'mountpoint') {
|
||||
data.mountPoint = providerConfig.value.mountPoint;
|
||||
data.chown = !!providerConfig.value.chown;
|
||||
data.preserveAttributes = !!providerConfig.value.preserveAttributes;
|
||||
}
|
||||
} else if (data.provider === 'filesystem') {
|
||||
data.backupFolder = providerConfig.value.backupFolder;
|
||||
data.noHardlinks = !providerConfig.value.useHardlinks;
|
||||
data.preserveAttributes = true;
|
||||
} else if (data.provider === 'gcs') {
|
||||
data.bucket = providerConfig.value.bucket;
|
||||
data.prefix = providerConfig.value.prefix;
|
||||
data.projectId = providerConfig.value.projectId;
|
||||
data.credentials = providerConfig.value.credentials;
|
||||
}
|
||||
|
||||
const limits = {
|
||||
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 = {};
|
||||
busy.value = true;
|
||||
const [error] = await backupsModel.setConfig(data, limits);
|
||||
if (error) {
|
||||
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
emit('success');
|
||||
dialog.value.close();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
async open() {
|
||||
const [error, result] = await backupsModel.getConfig();
|
||||
if (error) return console.error(error);
|
||||
|
||||
config.value = result;
|
||||
formError.value = {};
|
||||
busy.value = false;
|
||||
oldProvider.value = result.provider;
|
||||
provider.value = result.provider;
|
||||
providerConfig.value = result;
|
||||
oldFormat.value = result.format;
|
||||
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog ref="dialog"
|
||||
:title="$t('backups.configureBackupStorage.title')"
|
||||
:confirm-label="$t('main.dialog.save')"
|
||||
:confirm-busy="busy"
|
||||
:reject-label="busy ? null :$t('main.dialog.cancel')"
|
||||
reject-style="secondary"
|
||||
@confirm="onSubmit()"
|
||||
>
|
||||
<div>
|
||||
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form">
|
||||
<fieldset :disabled="busy">
|
||||
<input style="display: none;" type="submit"/>
|
||||
<div class="warning-label" v-show="oldProvider !== provider || oldFormat !== providerConfig.format">{{ $t('backups.configureBackupStorage.formatChangeNote') }}</div>
|
||||
|
||||
<BackupProviderForm v-model:provider="provider" v-model:provider-config="providerConfig" :form-error="formError"/>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -304,6 +304,8 @@ onMounted(async () => {
|
||||
<Button tool :menu="taskLogsMenu" :disabled="!taskLogsMenu.length">{{ $t('main.action.logs') }}</Button>
|
||||
</template>
|
||||
|
||||
<p v-html="$t('backups.schedule.description')"></p>
|
||||
|
||||
<TableView :columns="columns" :model="backups" :busy="busy">
|
||||
<template #preserveSecs="backup">
|
||||
<i class="fas fa-archive" v-show="backup.preserveSecs === -1" v-tooltip="$t('backups.listing.tooltipPreservedBackup')"></i>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
import { Button, InputGroup, SingleSelect, FormGroup, TextInput, Checkbox, PasswordInput, NumberInput } from '@cloudron/pankow';
|
||||
import { prettyBinarySize } from '@cloudron/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 ProvisionModel from '../models/ProvisionModel.js';
|
||||
import SystemModel from '../models/SystemModel.js';
|
||||
@@ -37,10 +36,6 @@ const blockDevices = ref([]);
|
||||
const disk = ref('');
|
||||
const gcsKeyFileName = ref('');
|
||||
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 = '';
|
||||
@@ -101,18 +96,6 @@ async function getBlockDevices() {
|
||||
.filter(d => { return d.type === 'xfs' || d.type === 'ext4'; });
|
||||
}
|
||||
|
||||
async function getMemory() {
|
||||
if (props.provisioning) {
|
||||
maxMemoryLimit.value = 4 * 1024 * 1024 * 1024;
|
||||
return;
|
||||
}
|
||||
|
||||
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/)
|
||||
@@ -125,7 +108,6 @@ watch(provider, (newProvider) => {
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await getMemory();
|
||||
await getBlockDevices();
|
||||
});
|
||||
|
||||
@@ -306,48 +288,5 @@ onMounted(async () => {
|
||||
</FormGroup>
|
||||
<div class="warning-label" v-show="encryptionPassword && !importOnly">{{ $t('backups.configureBackupStorage.encryptionDescription') }}</div>
|
||||
<Checkbox v-if="format === 'rsync' && encryptionPassword" v-model="encryptedFilenames" :label="$t(importOnly ? 'backups.configureBackupStorage.encryptedFilenames' : '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>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.memoryLimitDescription') }}</div>
|
||||
<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>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.uploadConcurrencyDescription') }}</div>
|
||||
<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>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.downloadConcurrencyDescription') }}</div>
|
||||
<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>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.copyConcurrencyDescription') }}
|
||||
<span v-show="provider === 'digitalocean-spaces'">{{ $t('backups.configureBackupStorage.copyConcurrencyDigitalOceanNote') }}</span>
|
||||
</div>
|
||||
<input type="range" id="copyConcurrencyInput" v-model="providerConfig.limits.copyConcurrency" step="10" min="10" max="500" />
|
||||
</FormGroup>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
<script setup>
|
||||
|
||||
import { ref, useTemplateRef } from 'vue';
|
||||
import { Dialog, FormGroup, TextInput, MultiSelect } from '@cloudron/pankow';
|
||||
import { prettyBinarySize } from '@cloudron/pankow/utils';
|
||||
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 BackupTargetsModel from '../models/BackupTargetsModel.js';
|
||||
import SystemModel from '../models/SystemModel.js';
|
||||
|
||||
const emit = defineEmits([ 'success' ]);
|
||||
|
||||
const backupTargetsModel = BackupTargetsModel.create();
|
||||
const systemModel = SystemModel.create();
|
||||
|
||||
const dialog = useTemplateRef('dialog');
|
||||
const form = useTemplateRef('form');
|
||||
const target = ref({});
|
||||
const label = ref('');
|
||||
const encrypted = ref(false);
|
||||
const encryptedFilenames = ref(false);
|
||||
const formError = ref({});
|
||||
const busy = ref(false);
|
||||
const provider = ref('');
|
||||
const providerConfig = ref({
|
||||
mountOptions: {},
|
||||
prefix: '',
|
||||
});
|
||||
const isPrimary = ref(false);
|
||||
const limits = ref({});
|
||||
const format = ref('');
|
||||
const retention = ref({
|
||||
keepWithinSecs: 0
|
||||
});
|
||||
|
||||
const configureDays = ref([]);
|
||||
const configureHours = ref([]);
|
||||
const configureRetention = ref('');
|
||||
|
||||
const minMemoryLimit = ref(1024 * 1024 * 1024); // 1 GB
|
||||
const maxMemoryLimit = ref(minMemoryLimit.value); // set later
|
||||
|
||||
const backupRetentions = [
|
||||
{ name: '2 days', id: { keepWithinSecs: 2 * 24 * 60 * 60 }},
|
||||
{ name: '1 week', id: { keepWithinSecs: 7 * 24 * 60 * 60 }}, // default
|
||||
{ name: '1 month', id: { keepWithinSecs: 30 * 24 * 60 * 60 }},
|
||||
{ name: '3 months', id: { keepWithinSecs: 3 * 30 * 24 * 60 * 60 }},
|
||||
{ name: '2 daily, 4 weekly', id: { keepDaily: 2, keepWeekly: 4 }},
|
||||
{ name: '3 daily, 4 weekly, 6 monthly', id: { keepDaily: 3, keepWeekly: 4, keepMonthly: 6 }},
|
||||
{ name: '7 daily, 4 weekly, 12 monthly', id: { keepDaily: 7, keepWeekly: 4, keepMonthly: 12 }},
|
||||
{ name: 'Forever', id: { keepWithinSecs: -1 }}
|
||||
];
|
||||
|
||||
// values correspond to cron days
|
||||
const cronDays = [
|
||||
{ id: 0, name: 'Sunday' },
|
||||
{ id: 1, name: 'Monday' },
|
||||
{ id: 2, name: 'Tuesday' },
|
||||
{ id: 3, name: 'Wednesday' },
|
||||
{ id: 4, name: 'Thursday' },
|
||||
{ id: 5, name: 'Friday' },
|
||||
{ id: 6, name: 'Saturday' },
|
||||
];
|
||||
|
||||
// generates 24h time sets (instead of american 12h) to avoid having to translate everything to locales eg. 12:00
|
||||
const cronHours = Array.from({ length: 24 }).map(function (v, i) { return { id: i, name: (i < 10 ? '0' : '') + i + ':00' }; });
|
||||
|
||||
function isScheduleValid() {
|
||||
return !!configureDays.value.length && !!configureHours.value.length;
|
||||
}
|
||||
|
||||
async function onSubmitAdd() {
|
||||
if (!form.value.reportValidity() || !isScheduleValid()) return;
|
||||
|
||||
// build schedule pattern
|
||||
let daysPattern;
|
||||
if (configureDays.value.length === 7) daysPattern = '*';
|
||||
else daysPattern = configureDays.value;
|
||||
|
||||
let hoursPattern;
|
||||
if (configureHours.value.length === 24) hoursPattern = '*';
|
||||
else hoursPattern = configureHours.value;
|
||||
|
||||
const schedulePattern = `00 00 ${hoursPattern} * * ${daysPattern}`;
|
||||
|
||||
// build provider config
|
||||
const data = {};
|
||||
if (s3like(provider.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 (provider.value === 's3') {
|
||||
data.region = providerConfig.value.region || undefined;
|
||||
delete data.endpoint;
|
||||
} else if (provider.value === 'minio' || provider.value === 's3-v4-compat') {
|
||||
data.region = providerConfig.value.region || 'us-east-1';
|
||||
data.acceptSelfSignedCerts = providerConfig.value.acceptSelfSignedCerts;
|
||||
data.s3ForcePathStyle = true;
|
||||
} else if (provider.value === 'exoscale-sos') {
|
||||
data.region = 'us-east-1';
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'wasabi') {
|
||||
data.region = REGIONS_WASABI.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'scaleway-objectstorage') {
|
||||
data.region = REGIONS_SCALEWAY.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'linode-objectstorage') {
|
||||
data.region = REGIONS_LINODE.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'ovh-objectstorage') {
|
||||
data.region = REGIONS_OVH.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'ionos-objectstorage') {
|
||||
data.region = REGIONS_IONOS.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'vultr-objectstorage') {
|
||||
data.region = REGIONS_VULTR.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'contabo-objectstorage') {
|
||||
data.region = REGIONS_CONTABO.find(function (x) { return x.value === data.endpoint; }).region;
|
||||
data.signatureVersion = 'v4';
|
||||
data.s3ForcePathStyle = true;
|
||||
} else if (provider.value === 'upcloud-objectstorage') { // the UI sets region and endpoint
|
||||
const m = /^.*\.(.*)\.upcloudobjects.com$/.exec(data.endpoint);
|
||||
data.region = m ? m[1] : 'us-east-1'; // let it fail in validation phase if m is not valid
|
||||
data.signatureVersion = 'v4';
|
||||
} else if (provider.value === 'digitalocean-spaces') {
|
||||
data.region = 'us-east-1';
|
||||
} else if (provider.value === 'hetzner-objectstorage') {
|
||||
data.region = 'us-east-1';
|
||||
data.signatureVersion = 'v4';
|
||||
}
|
||||
} else if (mountlike(provider.value)) {
|
||||
data.prefix = providerConfig.value.prefix;
|
||||
data.noHardlinks = !providerConfig.value.useHardlinks;
|
||||
data.mountOptions = {};
|
||||
|
||||
if (provider.value === 'cifs' || provider.value === 'sshfs' || provider.value === 'nfs') {
|
||||
data.mountOptions.host = providerConfig.value.mountOptionHost;
|
||||
data.mountOptions.remoteDir = providerConfig.value.mountOptionRemoteDir;
|
||||
|
||||
if (provider.value === 'cifs') {
|
||||
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 (provider.value === 'sshfs') {
|
||||
data.mountOptions.user = providerConfig.value.mountOptionUser;
|
||||
data.mountOptions.port = parseInt(providerConfig.value.mountOptionPort);
|
||||
data.mountOptions.privateKey = providerConfig.value.mountOptionPrivateKey;
|
||||
data.preserveAttributes = true;
|
||||
}
|
||||
} else if (provider.value === 'ext4' || provider.value === 'xfs' || provider.value === 'disk') {
|
||||
data.mountOptions.diskPath = providerConfig.value.mountOptionDiskPath;
|
||||
data.preserveAttributes = true;
|
||||
} else if (provider.value === 'mountpoint') {
|
||||
data.mountPoint = providerConfig.value.mountPoint;
|
||||
data.chown = !!providerConfig.value.chown;
|
||||
data.preserveAttributes = !!providerConfig.value.preserveAttributes;
|
||||
}
|
||||
} else if (provider.value === 'filesystem') {
|
||||
data.backupFolder = providerConfig.value.backupFolder;
|
||||
data.noHardlinks = !providerConfig.value.useHardlinks;
|
||||
data.preserveAttributes = true;
|
||||
} else if (provider.value === 'gcs') {
|
||||
data.bucket = providerConfig.value.bucket;
|
||||
data.prefix = providerConfig.value.prefix;
|
||||
data.projectId = providerConfig.value.projectId;
|
||||
data.credentials = providerConfig.value.credentials;
|
||||
}
|
||||
|
||||
// build limits
|
||||
const limitsConfig = {
|
||||
memoryLimit: parseInt(limits.value.memoryLimit),
|
||||
syncConcurrency: parseInt(limits.value.syncConcurrency),
|
||||
copyConcurrency: parseInt(limits.value.copyConcurrency),
|
||||
downloadConcurrency: parseInt(limits.value.downloadConcurrency),
|
||||
uploadPartSize: parseInt(limits.value.uploadPartSize),
|
||||
// deleteConcurrency: parseInt(providerConfig.value.limits.deleteConcurrency),
|
||||
};
|
||||
|
||||
const encryptionPassword = providerConfig.value.encryptionPassword || null;
|
||||
const encryptedFilenames = providerConfig.value.encryptionPassword ? providerConfig.value.encryptedFilenames : null;
|
||||
|
||||
formError.value = {};
|
||||
busy.value = true;
|
||||
const [error, targetId] = await backupTargetsModel.add(label.value, format.value, provider.value, data, schedulePattern, retention.value, limitsConfig, encryptionPassword, encryptedFilenames);
|
||||
if (error) {
|
||||
formError.value.generic = error.body ? error.body.message : 'Internal error';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
if (isPrimary.value) {
|
||||
const [error] = await backupTargetsModel.setPrimary(targetId);
|
||||
if (error) {
|
||||
formError.value.generic = 'Failed to set primary backup target';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
emit('success');
|
||||
dialog.value.close();
|
||||
}
|
||||
|
||||
async function onSubmitEdit() {
|
||||
// TODO set config (eg. provider config passwords)
|
||||
// TODO set label somehow?
|
||||
|
||||
// schedule
|
||||
let daysPattern;
|
||||
if (configureDays.value.length === 7) daysPattern = '*';
|
||||
else daysPattern = configureDays.value;
|
||||
|
||||
let hoursPattern;
|
||||
if (configureHours.value.length === 24) hoursPattern = '*';
|
||||
else hoursPattern = configureHours.value;
|
||||
|
||||
const schedulePattern = `00 00 ${hoursPattern} * * ${daysPattern}`;
|
||||
let [error] = await backupTargetsModel.setSchedule(target.value.id, schedulePattern);
|
||||
if (error) {
|
||||
formError.value.generic = 'Failed to set schdule';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
// retention
|
||||
[error] = await backupTargetsModel.setRetention(target.value.id, retention.value);
|
||||
if (error) {
|
||||
formError.value.generic = 'Failed to set retention';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
// limits
|
||||
const limitsConfig = {
|
||||
memoryLimit: parseInt(limits.value.memoryLimit),
|
||||
syncConcurrency: parseInt(limits.value.syncConcurrency),
|
||||
copyConcurrency: parseInt(limits.value.copyConcurrency),
|
||||
downloadConcurrency: parseInt(limits.value.downloadConcurrency),
|
||||
uploadPartSize: parseInt(limits.value.uploadPartSize),
|
||||
// deleteConcurrency: parseInt(providerConfig.value.limits.deleteConcurrency),
|
||||
};
|
||||
|
||||
[error] = await backupTargetsModel.setLimits(target.value.id, limitsConfig);
|
||||
if (error) {
|
||||
formError.value.generic = 'Failed to set limits';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
// primary
|
||||
if (isPrimary.value) {
|
||||
const [error] = await backupTargetsModel.setPrimary(target.value.id);
|
||||
if (error) {
|
||||
formError.value.generic = 'Failed to set primary backup target';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
emit('success');
|
||||
dialog.value.close();
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
if (target.value) return await onSubmitEdit();
|
||||
|
||||
await onSubmitAdd();
|
||||
}
|
||||
|
||||
|
||||
async function getMemory() {
|
||||
// TODO what is this exactly?
|
||||
// if (props.provisioning) {
|
||||
// maxMemoryLimit.value = 4 * 1024 * 1024 * 1024;
|
||||
// return;
|
||||
// }
|
||||
|
||||
const [error, result] = await systemModel.memory();
|
||||
if (error) return console.error(error);
|
||||
|
||||
maxMemoryLimit.value = Math.ceil(result.memory / (1024*1024*1024)) * 1024 * 1024 * 1024;
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
async open(t = null) {
|
||||
target.value = t;
|
||||
|
||||
formError.value = {};
|
||||
busy.value = false;
|
||||
label.value = t?.label || '';
|
||||
provider.value = t?.provider || '';
|
||||
format.value = t?.format || '';
|
||||
isPrimary.value = t?.primary || false;
|
||||
providerConfig.value = t?.config || {};
|
||||
encrypted.value = t?.encrypted || false;
|
||||
encryptedFilenames.value = t?.encryptedFilenames || false;
|
||||
retention.value = t?.rentention || { keepWithinSecs: 0 };
|
||||
limits.value = t?.limits || {};
|
||||
|
||||
const currentRetentionString = JSON.stringify(t?.retention || {});
|
||||
let selectedRetention = backupRetentions.find(function (x) { return JSON.stringify(x.id) === currentRetentionString; });
|
||||
if (!selectedRetention) selectedRetention = backupRetentions[0];
|
||||
retention.value = selectedRetention.id;
|
||||
|
||||
// TODO define some default
|
||||
const tmp = t?.schedule.split(' ') || '00 00 2,23,11,7,8 * * 3,5,6,0';
|
||||
const hours = tmp[2].split(',');
|
||||
const days = tmp[5].split(',');
|
||||
if (days[0] === '*') configureDays.value = cronDays.map((day) => { return day.id; });
|
||||
else configureDays.value = days.map((day) => { return parseInt(day, 10); });
|
||||
|
||||
configureHours.value = hours.map((hour) => { return parseInt(hour, 10); });
|
||||
|
||||
|
||||
// ensure we have all required child objects
|
||||
if (!providerConfig.value.mountOptions) providerConfig.value.mountOptions = {};
|
||||
|
||||
// some sane defaults
|
||||
if (!limits.value.memoryLimit) limits.value.memoryLimit = 1024 * 1024 * 1024; // 1 GB
|
||||
if (!limits.value.uploadPartSize) limits.value.uploadPartSize = 10 * 1024 * 1024;
|
||||
if (!limits.value.syncConcurrency) limits.value.syncConcurrency = 10;
|
||||
if (!limits.value.downloadConcurrency) limits.value.downloadConcurrency = 10;
|
||||
if (!limits.value.copyConcurrency) limits.value.copyConcurrency = 10;
|
||||
|
||||
// needs translation for UI
|
||||
providerConfig.value.useHardlinks = !(t?.noHardlinks || true);
|
||||
providerConfig.value.encryptionPassword = t?.password || null;
|
||||
|
||||
await getMemory();
|
||||
|
||||
dialog.value.open();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog ref="dialog"
|
||||
:title="$t('backups.configureBackupStorage.title')"
|
||||
:confirm-label="$t('main.dialog.save')"
|
||||
:confirm-busy="busy"
|
||||
:reject-label="busy ? null :$t('main.dialog.cancel')"
|
||||
reject-style="secondary"
|
||||
@confirm="onSubmit()"
|
||||
>
|
||||
<div>
|
||||
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form">
|
||||
<fieldset :disabled="busy">
|
||||
<input style="display: none;" type="submit"/>
|
||||
<!-- TODO <div class="warning-label" v-show="oldProvider !== provider || oldFormat !== providerConfig.format">{{ $t('backups.configureBackupStorage.formatChangeNote') }}</div> -->
|
||||
|
||||
<BackupProviderForm v-model:provider="provider" v-model:format="format" v-model:provider-config="providerConfig" :form-error="formError"/>
|
||||
|
||||
<FormGroup>
|
||||
<!-- TODO translate -->
|
||||
<label for="labelInput">Label</label>
|
||||
<TextInput id="labelInput" v-model="label" />
|
||||
</FormGroup>
|
||||
|
||||
<!-- TODO translate -->
|
||||
<Checkbox v-model="isPrimary" label="primary backup target" />
|
||||
|
||||
<FormGroup>
|
||||
<label for="memoryLimitInput">{{ $t('backups.configureBackupStorage.memoryLimit') }}: <b>{{ prettyBinarySize(limits.memoryLimit, '1024 MB') }}</b></label>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.memoryLimitDescription') }}</div>
|
||||
<input type="range" id="memoryLimitInput" v-model="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(limits.uploadPartSize, 'Default (50 MiB)') }}</b></label>
|
||||
<p class="small">{{ $t('backups.configureBackupStorage.uploadPartSizeDescription') }}</p>
|
||||
<input type="range" id="uploadPartSizeInput" v-model="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>{{ limits.syncConcurrency }}</b></label>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.uploadConcurrencyDescription') }}</div>
|
||||
<input type="range" id="syncConcurrencyInput" v-model="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>{{ limits.downloadConcurrency }}</b></label>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.downloadConcurrencyDescription') }}</div>
|
||||
<input type="range" id="downloadConcurrencyInput" v-model="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>{{ limits.copyConcurrency }}</b></label>
|
||||
<div class="small">{{ $t('backups.configureBackupStorage.copyConcurrencyDescription') }}
|
||||
<span v-show="provider === 'digitalocean-spaces'">{{ $t('backups.configureBackupStorage.copyConcurrencyDigitalOceanNote') }}</span>
|
||||
</div>
|
||||
<input type="range" id="copyConcurrencyInput" v-model="limits.copyConcurrency" step="10" min="10" max="500" />
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<label for="daysInput">{{ $t('backups.configureBackupSchedule.schedule') }}</label>
|
||||
<p v-html="$t('backups.configureBackupSchedule.scheduleDescription')"></p>
|
||||
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<div>{{ $t('backups.configureBackupSchedule.days') }}: <MultiSelect id="daysInput" v-model="configureDays" :options="cronDays" option-key="id" option-label="name"></MultiSelect></div>
|
||||
<div>{{ $t('backups.configureBackupSchedule.hours') }}: <MultiSelect v-model="configureHours" :options="cronHours" option-key="id" option-label="name"></MultiSelect></div>
|
||||
</div>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<label for="retentionInput">{{ $t('backups.configureBackupSchedule.retentionPolicy') }}</label>
|
||||
<select id="retentionInput" v-model="retention">
|
||||
<option v-for="elem in backupRetentions" :key="elem.id" :value="elem.id">{{ elem.name }}</option>
|
||||
</select>
|
||||
</FormGroup>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</Dialog>
|
||||
</template>
|
||||
Reference in New Issue
Block a user