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

55
backup-web.sh Executable file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# ==============================================================================
# Web Instance Backup Script
# ==============================================================================
# Requires --dir to identify which instance to back up.
# No pre-backup commands — just static files.
#
# Usage: backup-web.sh --dir acme
# backup-web.sh --dir acme --cold
# ==============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/common.sh"
parse_args "$@"
[[ -n "$ARG_DIR" ]] || fatal "--dir is required. Example: $0 --dir acme"
DIR_NAME="$ARG_DIR"
BASE_DIR="/opt/${DIR_NAME}"
CONFIG_NAME="web-${DIR_NAME}"
BACKUP_DIR="/opt/backup"
STAMP="$(date +%Y%m%d-%H%M%S)"
BACKUP_FILE="${BACKUP_DIR}/backup-${DIR_NAME}-${STAMP}.tar.gz"
[[ -d "$BASE_DIR" ]] || fatal "Web instance '${DIR_NAME}' is not deployed at ${BASE_DIR}."
mkdir -p "$BACKUP_DIR"
# --- Cold backup: stop container ---
if [[ "$ARG_COLD" == "1" ]]; then
info "Running cold backup (stopping container)..."
(cd "$BASE_DIR" && docker compose down)
fi
# --- Create archive ---
info "Creating archive..."
tar czf "$BACKUP_FILE" -C / \
"opt/${DIR_NAME}" \
"opt/traefik/dynamic/${CONFIG_NAME}.yml" 2>/dev/null || \
tar czf "$BACKUP_FILE" -C / \
"opt/${DIR_NAME}"
# --- Cold: restart ---
if [[ "$ARG_COLD" == "1" ]]; then
(cd "$BASE_DIR" && docker compose up -d)
ok "Container restarted."
fi
# --- Rotate old backups (keep last 5) ---
# shellcheck disable=SC2012
ls -t "${BACKUP_DIR}/backup-${DIR_NAME}-"*.tar.gz 2>/dev/null | tail -n +6 | xargs -r rm --
ok "Backup: ${BACKUP_FILE} ($(du -h "$BACKUP_FILE" | cut -f1))"