Publish deployment and backup scripts
This commit is contained in:
34
backup-traefik.sh
Executable file
34
backup-traefik.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Traefik Backup Script
|
||||
# ==============================================================================
|
||||
# Archives /opt/traefik/ (acme.json certs + all dynamic configs).
|
||||
# Always hot — Traefik doesn't need to be stopped for file copy.
|
||||
#
|
||||
# Usage: backup-traefik.sh
|
||||
# ==============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "${SCRIPT_DIR}/common.sh"
|
||||
parse_args "$@"
|
||||
|
||||
SERVICE_NAME="traefik"
|
||||
BASE_DIR="/opt/${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 "Traefik is not deployed at ${BASE_DIR}."
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
info "Creating archive (hot — Traefik stays running)..."
|
||||
tar czf "$BACKUP_FILE" -C / "opt/${SERVICE_NAME}"
|
||||
|
||||
# --- 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))"
|
||||
Reference in New Issue
Block a user