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