feat(backup): add backup scripts workflow

This commit is contained in:
2026-03-10 09:48:53 +01:00
parent fb96cc3c32
commit 0863dfad2e
10 changed files with 857 additions and 34 deletions

View File

@@ -0,0 +1,18 @@
import scripts from "../config/backup-script.json"
type BackupScript = {
key: string
label: string
icon?: string
command: string
}
export default defineEventHandler(() => {
return {
scripts: (scripts as BackupScript[]).map(({ key, label, icon }) => ({
key,
label,
icon: icon || "mdi:play-circle-outline"
}))
}
})

View File

@@ -0,0 +1,55 @@
import { exec } from "node:child_process"
import scripts from "../config/backup-script.json"
type BackupScript = {
key: string
label: string
command: string
}
function runCommand(command: string): Promise<string> {
return new Promise((resolve, reject) => {
exec(command, { timeout: 10 * 60 * 1000 }, (error, stdout, stderr) => {
if (error) {
reject(stderr || error.message)
return
}
resolve(stdout || stderr)
})
})
}
export default defineEventHandler(async (event) => {
const body = await readBody<{ key?: string }>(event)
const key = typeof body?.key === "string" ? body.key : null
if (!key) {
throw createError({
statusCode: 400,
statusMessage: "Clé de script manquante"
})
}
const script = (scripts as BackupScript[]).find((item) => item.key === key)
if (!script) {
throw createError({
statusCode: 404,
statusMessage: "Script introuvable"
})
}
try {
const output = await runCommand(script.command)
return {
ok: true,
key: script.key,
label: script.label,
output: output.trim()
}
} catch (error) {
throw createError({
statusCode: 500,
statusMessage: `Erreur execution script: ${String(error)}`
})
}
})

View File

@@ -0,0 +1,20 @@
[
{
"key": "backup-bdd-recette",
"label": "Backup BDD recette",
"icon": "mdi:database-export",
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/RecetteScripts && bash backup-bdd-recette.sh && exit'"
},
{
"key": "check-statut-recette",
"label": "Check statut recette",
"icon": "mdi:server-network",
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/RecetteScripts && bash check-statut-recette.sh && exit'"
},
{
"key": "backup-vaultwarden",
"label": "Backup vaultwarden",
"icon": "mdi:data",
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/BackupVaultWarden && bash backup-vaultwarden.sh && exit'"
}
]

View File

@@ -2,7 +2,7 @@
{
"key": "remote",
"label": "Serveur distant",
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Scripts-Serveur && bash check_storage.sh && exit'"
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/CheckStorage && bash check-storage.sh && exit'"
},
{
"key": "local",