mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-05 00:52:59 +01:00
🔨 Add backup type in setting
This commit is contained in:
parent
075604685d
commit
d508a8460d
@ -1,7 +1,7 @@
|
||||
import fs from "fs";
|
||||
import Joi from "joi";
|
||||
import logger from "../config/winston.js";
|
||||
import type { BackupConfig } from "../types/services/backupConfig.js";
|
||||
import { BackupConfig, BackupType } from "../types/services/backupConfig.js";
|
||||
import backupConfigValidation from "../types/services/backupConfigValidation.js";
|
||||
|
||||
const backupConfigPath = "/data/backupConfigV2.json";
|
||||
@ -40,10 +40,7 @@ export function getBackupDefaultConfig(): BackupConfig {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
exclude: {
|
||||
addon: [],
|
||||
folder: [],
|
||||
},
|
||||
backupType: BackupType.FULL,
|
||||
autoStopAddon: [],
|
||||
password: {
|
||||
enabled: false,
|
||||
|
@ -15,6 +15,11 @@ export enum Weekday {
|
||||
SATURDAY
|
||||
}
|
||||
|
||||
export enum BackupType {
|
||||
FULL= "FULL",
|
||||
PARTIAL = "PARTIAL"
|
||||
}
|
||||
|
||||
|
||||
export interface BackupConfig {
|
||||
nameTemplate: string;
|
||||
@ -22,8 +27,9 @@ export interface BackupConfig {
|
||||
autoClean: {
|
||||
homeAssistant: AutoCleanConfig;
|
||||
webdav: AutoCleanConfig;
|
||||
}
|
||||
exclude: {
|
||||
},
|
||||
backupType: BackupType;
|
||||
exclude?: {
|
||||
addon: string[];
|
||||
folder: string[];
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Joi from "joi";
|
||||
import { CronMode } from "./backupConfig.js";
|
||||
import { BackupType, CronMode } from "./backupConfig.js";
|
||||
|
||||
const CronConfigValidation = {
|
||||
id: Joi.string().required().not().empty(),
|
||||
@ -46,10 +46,17 @@ const backupConfigValidation = {
|
||||
homeAssistant: Joi.object(AutoCleanConfig).required(),
|
||||
webdav: Joi.object(AutoCleanConfig).required(),
|
||||
}).required(),
|
||||
exclude: Joi.object({
|
||||
addon: Joi.array().items(Joi.string().not().empty()).required(),
|
||||
folder: Joi.array().items(Joi.string().not().empty()).required(),
|
||||
}).required(),
|
||||
backupType: Joi.string()
|
||||
.required()
|
||||
.valid(BackupType.FULL, BackupType.PARTIAL),
|
||||
exclude: Joi.alternatives().conditional("backupType", {
|
||||
is: BackupType.PARTIAL,
|
||||
then: Joi.object({
|
||||
addon: Joi.array().items(Joi.string().not().empty()).required(),
|
||||
folder: Joi.array().items(Joi.string().not().empty()).required(),
|
||||
}).required(),
|
||||
otherwise: Joi.forbidden(),
|
||||
}),
|
||||
autoStopAddon: Joi.array().items(Joi.string().not().empty()),
|
||||
password: Joi.object({
|
||||
enabled: Joi.boolean().required(),
|
||||
|
@ -33,6 +33,9 @@ defineProps<{ loading: boolean }>();
|
||||
const backupConfigStore = useBackupConfigStore();
|
||||
const { data, addons, invertedAddons } = storeToRefs(backupConfigStore);
|
||||
watch(invertedAddons, () => {
|
||||
if (!data.value.exclude) {
|
||||
data.value.exclude = { addon: [], folder: [] };
|
||||
}
|
||||
data.value.exclude.addon = [];
|
||||
for (const addon of addons.value) {
|
||||
if (!invertedAddons.value.includes(addon.slug)) {
|
||||
|
@ -30,13 +30,33 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row>
|
||||
<v-col cols="12" md="6">
|
||||
<BackupConfigFolder :loading="loading"></BackupConfigFolder>
|
||||
</v-col>
|
||||
<v-col cols="12" md="6">
|
||||
<BackupConfigAddon :loading="loading"></BackupConfigAddon>
|
||||
<v-col>
|
||||
<div class="text-subtitle-1 text-medium-emphasis">Backup Type</div>
|
||||
<v-select
|
||||
:items="
|
||||
Object.entries(BackupType).map((value) => {
|
||||
return { title: value[0], value: value[1] };
|
||||
})
|
||||
"
|
||||
v-model="data.backupType"
|
||||
hide-details="auto"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
color="orange"
|
||||
>
|
||||
</v-select>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-fade-transition>
|
||||
<v-row v-if="data.backupType == BackupType.Partial">
|
||||
<v-col cols="12" md="6">
|
||||
<BackupConfigFolder :loading="loading"></BackupConfigFolder>
|
||||
</v-col>
|
||||
<v-col cols="12" md="6">
|
||||
<BackupConfigAddon :loading="loading"></BackupConfigAddon>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-fade-transition>
|
||||
<v-divider class="my-4"></v-divider>
|
||||
<v-row>
|
||||
<v-col class="text-center">
|
||||
@ -81,6 +101,7 @@ import BackupConfigFolder from "./BackupConfig/BackupConfigFolder.vue";
|
||||
import BackupConfigAutoClean from "./BackupConfig/BackupConfigAutoClean.vue";
|
||||
import BackupConfigSecurity from "./BackupConfig/BackupConfigSecurity.vue";
|
||||
import BackupConfigAutoStop from "./BackupConfig/BackupConfigAutoStop.vue";
|
||||
import { BackupType } from "@/types/backupConfig";
|
||||
|
||||
const backupConfigStore = useBackupConfigStore();
|
||||
const { data } = storeToRefs(backupConfigStore);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { BackupConfig } from "@/types/backupConfig";
|
||||
import { BackupType, type BackupConfig } from "@/types/backupConfig";
|
||||
import type { WebdavConfig } from "@/types/webdavConfig";
|
||||
import kyClient from "./kyClient";
|
||||
|
||||
@ -27,6 +27,12 @@ export function saveBackupConfig(config: BackupConfig) {
|
||||
}
|
||||
|
||||
function cleanupConfig(config: BackupConfig) {
|
||||
if (config.backupType == BackupType.Full) {
|
||||
config.exclude = undefined;
|
||||
} else if (!config.exclude) {
|
||||
config.exclude = { addon: [], folder: [] };
|
||||
}
|
||||
|
||||
if (!config.autoClean.homeAssistant.enabled) {
|
||||
config.autoClean.homeAssistant.nbrToKeep = undefined;
|
||||
}
|
||||
@ -34,7 +40,7 @@ function cleanupConfig(config: BackupConfig) {
|
||||
config.autoClean.webdav.nbrToKeep = undefined;
|
||||
}
|
||||
|
||||
if (!config.password.enabled){
|
||||
if (!config.password.enabled) {
|
||||
config.password.value = undefined;
|
||||
}
|
||||
return config;
|
||||
|
@ -22,6 +22,11 @@ export enum Weekday {
|
||||
SATURDAY,
|
||||
}
|
||||
|
||||
export enum BackupType {
|
||||
Full = "FULL",
|
||||
Partial = "PARTIAL",
|
||||
}
|
||||
|
||||
export const weekdayFriendly = [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
@ -39,7 +44,8 @@ export interface BackupConfig {
|
||||
homeAssistant: AutoCleanConfig;
|
||||
webdav: AutoCleanConfig;
|
||||
};
|
||||
exclude: {
|
||||
backupType: BackupType;
|
||||
exclude?: {
|
||||
addon: string[];
|
||||
folder: string[];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user