Add daily backup scripts for PostgreSQL, MariaDB, and Gitea.
Enable scheduled backups of ncue.net databases and git.ncue.net repository mirrors via .env-driven shell scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
50
scripts/daily-backup.sh
Executable file
50
scripts/daily-backup.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# PostgreSQL + MariaDB + Gitea 저장소 일일 통합 백업
|
||||
# 운영 cron 예: 0 2 * * * cd /path/ncue_backup && bash scripts/daily-backup.sh >> /var/log/ncue-backup.log 2>&1
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
# shellcheck source=scripts/lib/load-env.sh
|
||||
source "$REPO_ROOT/scripts/lib/load-env.sh"
|
||||
# shellcheck source=scripts/lib/common.sh
|
||||
source "$REPO_ROOT/scripts/lib/common.sh"
|
||||
|
||||
load_project_env "$REPO_ROOT/.env"
|
||||
|
||||
BACKUP_DIR="${BACKUP_DIR:-$REPO_ROOT/backup}"
|
||||
BACKUP_STAMP="${BACKUP_STAMP:-$(date +%Y%m%d)}"
|
||||
BACKUP_RUN_DIR="$BACKUP_DIR/$BACKUP_STAMP"
|
||||
export BACKUP_DIR BACKUP_STAMP BACKUP_RUN_DIR
|
||||
|
||||
mkdir -p "$BACKUP_RUN_DIR" "$BACKUP_DIR/latest"
|
||||
|
||||
echo "[$(log_ts)] daily-backup start → $BACKUP_RUN_DIR"
|
||||
|
||||
failures=0
|
||||
|
||||
run_step() {
|
||||
local name="$1"
|
||||
local script="$2"
|
||||
echo "[$(log_ts)] daily-backup step: $name"
|
||||
if bash "$script"; then
|
||||
echo "[$(log_ts)] daily-backup step ok: $name"
|
||||
else
|
||||
echo "[$(log_ts)] daily-backup step failed: $name" >&2
|
||||
failures=$((failures + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
run_step "postgresql" "$REPO_ROOT/scripts/pg-backup.sh"
|
||||
run_step "mariadb" "$REPO_ROOT/scripts/mr-backup.sh"
|
||||
run_step "gitea" "$REPO_ROOT/scripts/gitea-backup.sh"
|
||||
|
||||
ln -sfn "$BACKUP_RUN_DIR" "$BACKUP_DIR/latest"
|
||||
|
||||
prune_old_backups "$BACKUP_DIR" "${BACKUP_RETENTION_DAYS:-30}"
|
||||
|
||||
if [[ "$failures" -gt 0 ]]; then
|
||||
echo "[$(log_ts)] daily-backup finished with ${failures} failure(s)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[$(log_ts)] daily-backup done → $BACKUP_DIR/latest"
|
||||
Reference in New Issue
Block a user