Publish deployment and backup scripts

This commit is contained in:
2026-04-11 00:21:08 +02:00
parent 86204e0836
commit 9de9acec48
27 changed files with 3709 additions and 206 deletions

69
backup-open-webui.sh Executable file
View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
# ==============================================================================
# Open WebUI Backup Script
# ==============================================================================
# Creates a backup archive of Open WebUI data and Traefik config.
#
# Open WebUI uses SQLite internally. Hot backup copies the data directory
# while running (safe for most cases). Use --cold for guaranteed consistency.
#
# Usage: backup-open-webui.sh
# backup-open-webui.sh --cold
# ==============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/common.sh"
parse_args "$@"
SERVICE_NAME="open-webui"
BASE_DIR="/opt/${SERVICE_NAME}"
CONFIG_NAME="${SERVICE_NAME}"
BACKUP_DIR="/opt/backup"
STAMP="$(date +%Y%m%d-%H%M%S)"
BACKUP_FILE="${BACKUP_DIR}/backup-${SERVICE_NAME}-${STAMP}.tar.gz"
[[ -d "$BASE_DIR" ]] || fatal "Open WebUI is not deployed at ${BASE_DIR}."
mkdir -p "$BACKUP_DIR"
# --- Hot backup: attempt SQLite .backup if sqlite3 is available ---
if [[ "$ARG_COLD" != "1" ]]; then
info "Running hot backup (containers stay up)..."
local_db="${BASE_DIR}/data/webui.db"
if [[ -f "$local_db" ]] && command -v sqlite3 &>/dev/null; then
info "Creating SQLite snapshot..."
sqlite3 "$local_db" ".backup '${BASE_DIR}/data/webui-backup.db'" 2>/dev/null || \
warn "SQLite .backup failed — archive will contain live database file."
fi
fi
# --- Cold backup: stop containers ---
if [[ "$ARG_COLD" == "1" ]]; then
info "Running cold backup (stopping containers)..."
(cd "$BASE_DIR" && docker compose down)
fi
# --- Create archive ---
info "Creating archive..."
tar czf "$BACKUP_FILE" -C / \
"opt/${SERVICE_NAME}" \
"opt/traefik/dynamic/${CONFIG_NAME}.yml" 2>/dev/null || \
tar czf "$BACKUP_FILE" -C / \
"opt/${SERVICE_NAME}"
# --- Cold: restart ---
if [[ "$ARG_COLD" == "1" ]]; then
(cd "$BASE_DIR" && docker compose up -d)
ok "Containers restarted."
fi
# --- Clean up snapshot ---
rm -f "${BASE_DIR}/data/webui-backup.db" 2>/dev/null
# --- Rotate old backups (keep last 5) ---
# shellcheck disable=SC2012
ls -t "${BACKUP_DIR}/backup-${SERVICE_NAME}-"*.tar.gz 2>/dev/null | tail -n +6 | xargs -r rm --
ok "Backup: ${BACKUP_FILE} ($(du -h "$BACKUP_FILE" | cut -f1))"