2021-10-23 03:08:02 +02:00
|
|
|
<template>
|
|
|
|
<div class="w-full h-full">
|
|
|
|
<div class="bg-bg rounded-md shadow-lg border border-white border-opacity-5 p-4 mb-8">
|
|
|
|
<div class="flex items-center mb-2">
|
|
|
|
<h1 class="text-xl">Backups</h1>
|
|
|
|
</div>
|
|
|
|
|
2022-08-20 22:10:31 +02:00
|
|
|
<p class="text-base mb-4 text-gray-300">Backups include users, user progress, library item details, server settings, and images stored in <span class="font-mono text-gray-100">/metadata/items</span> & <span class="font-mono text-gray-100">/metadata/authors</span>. <br />Backups <strong>do not</strong> include any files stored in your library folders.</p>
|
2021-10-23 03:08:02 +02:00
|
|
|
|
|
|
|
<div class="flex items-center py-2">
|
2022-08-19 01:46:42 +02:00
|
|
|
<ui-toggle-switch v-model="enableBackups" small :disabled="updatingServerSettings" @input="updateBackupsSettings" />
|
|
|
|
<ui-tooltip :text="backupsTooltip">
|
|
|
|
<p class="pl-4 text-lg">Enable automatic backups <span class="material-icons icon-text">info_outlined</span></p>
|
2021-10-23 03:08:02 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</div>
|
|
|
|
|
2022-08-19 01:46:42 +02:00
|
|
|
<div v-if="enableBackups" class="mb-6">
|
|
|
|
<div class="flex items-center pl-6">
|
|
|
|
<span class="material-icons-outlined text-black-50">schedule</span>
|
|
|
|
<p class="text-gray-100 px-2">{{ scheduleDescription }}</p>
|
|
|
|
<span class="material-icons text-lg text-black-50 hover:text-yellow-500 cursor-pointer" @click="showCronBuilder = !showCronBuilder">edit</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-02 01:06:22 +02:00
|
|
|
|
2021-10-23 03:08:02 +02:00
|
|
|
<div class="flex items-center py-2">
|
|
|
|
<ui-text-input type="number" v-model="backupsToKeep" no-spinner :disabled="updatingServerSettings" :padding-x="1" text-center class="w-10" @change="updateBackupsSettings" />
|
|
|
|
|
|
|
|
<p class="pl-4 text-lg">Number of backups to keep</p>
|
|
|
|
</div>
|
|
|
|
|
2022-04-23 19:19:31 +02:00
|
|
|
<div class="flex items-center py-2">
|
|
|
|
<ui-text-input type="number" v-model="maxBackupSize" no-spinner :disabled="updatingServerSettings" :padding-x="1" text-center class="w-10" @change="updateBackupsSettings" />
|
|
|
|
|
2022-04-23 19:23:01 +02:00
|
|
|
<ui-tooltip :text="maxBackupSizeTooltip">
|
|
|
|
<p class="pl-4 text-lg">Maximum backup size (in GB) <span class="material-icons icon-text">info_outlined</span></p>
|
|
|
|
</ui-tooltip>
|
2022-04-23 19:19:31 +02:00
|
|
|
</div>
|
|
|
|
|
2021-10-23 03:08:02 +02:00
|
|
|
<tables-backups-table />
|
|
|
|
</div>
|
2022-08-19 01:46:42 +02:00
|
|
|
|
|
|
|
<modals-backup-schedule-modal v-model="showCronBuilder" :cron-expression.sync="cronExpression" />
|
2021-10-23 03:08:02 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
updatingServerSettings: false,
|
2022-08-19 01:46:42 +02:00
|
|
|
enableBackups: true,
|
2021-10-27 01:29:04 +02:00
|
|
|
backupsToKeep: 2,
|
2022-04-23 19:19:31 +02:00
|
|
|
maxBackupSize: 1,
|
2022-08-19 01:46:42 +02:00
|
|
|
cronExpression: '',
|
|
|
|
newServerSettings: {},
|
|
|
|
showCronBuilder: false
|
2021-10-27 01:29:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
serverSettings(newVal, oldVal) {
|
|
|
|
if (newVal && !oldVal) {
|
|
|
|
this.newServerSettings = { ...this.serverSettings }
|
|
|
|
this.initServerSettings()
|
|
|
|
}
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-08-19 01:46:42 +02:00
|
|
|
backupsTooltip() {
|
|
|
|
return 'Backups saved in /metadata/backups'
|
2021-10-27 01:29:04 +02:00
|
|
|
},
|
2022-04-23 19:23:01 +02:00
|
|
|
maxBackupSizeTooltip() {
|
|
|
|
return 'As a safeguard against misconfiguration, backups will fail if they exceed the configured size.'
|
|
|
|
},
|
2021-10-27 01:29:04 +02:00
|
|
|
serverSettings() {
|
|
|
|
return this.$store.state.serverSettings
|
2022-08-19 01:46:42 +02:00
|
|
|
},
|
|
|
|
scheduleDescription() {
|
|
|
|
if (!this.cronExpression) return ''
|
|
|
|
const parsed = this.$parseCronExpression(this.cronExpression)
|
|
|
|
return parsed ? parsed.description : 'Custom cron expression ' + this.cronExpression
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateBackupsSettings() {
|
2022-04-23 19:19:31 +02:00
|
|
|
if (isNaN(this.maxBackupSize) || this.maxBackupSize <= 0) {
|
|
|
|
this.$toast.error('Invalid maximum backup size')
|
|
|
|
return
|
|
|
|
}
|
2021-10-23 03:08:02 +02:00
|
|
|
if (isNaN(this.backupsToKeep) || this.backupsToKeep <= 0 || this.backupsToKeep > 99) {
|
|
|
|
this.$toast.error('Invalid number of backups to keep')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var updatePayload = {
|
2022-08-19 01:46:42 +02:00
|
|
|
backupSchedule: this.enableBackups ? this.cronExpression : false,
|
2022-04-23 19:19:31 +02:00
|
|
|
backupsToKeep: Number(this.backupsToKeep),
|
|
|
|
maxBackupSize: Number(this.maxBackupSize)
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
this.updateServerSettings(updatePayload)
|
|
|
|
},
|
|
|
|
updateServerSettings(payload) {
|
|
|
|
this.updatingServerSettings = true
|
|
|
|
this.$store
|
|
|
|
.dispatch('updateServerSettings', payload)
|
|
|
|
.then((success) => {
|
|
|
|
console.log('Updated Server Settings', success)
|
|
|
|
this.updatingServerSettings = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update server settings', error)
|
|
|
|
this.updatingServerSettings = false
|
|
|
|
})
|
2021-10-27 01:29:04 +02:00
|
|
|
},
|
|
|
|
initServerSettings() {
|
|
|
|
this.newServerSettings = this.serverSettings ? { ...this.serverSettings } : {}
|
|
|
|
|
|
|
|
this.backupsToKeep = this.newServerSettings.backupsToKeep || 2
|
2022-08-19 01:46:42 +02:00
|
|
|
this.enableBackups = !!this.newServerSettings.backupSchedule
|
2022-04-23 19:19:31 +02:00
|
|
|
this.maxBackupSize = this.newServerSettings.maxBackupSize || 1
|
2022-08-19 01:46:42 +02:00
|
|
|
this.cronExpression = this.newServerSettings.backupSchedule || '30 1 * * *'
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
},
|
2021-10-27 01:29:04 +02:00
|
|
|
mounted() {
|
|
|
|
this.initServerSettings()
|
|
|
|
}
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
</script>
|