Files
thebet365/scripts/backup-db.sh
2026-06-13 22:16:14 +08:00

48 lines
861 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 备份生产 Docker PostgreSQL 到 ./backups输出 gzip 与 sha256 校验文件
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/deploy-lib.sh
source "$SCRIPT_DIR/deploy-lib.sh"
PREFIX="manual"
usage() {
cat <<'EOF'
用法: scripts/backup-db.sh [选项]
选项:
--prefix NAME 备份文件名前缀,默认 manual
-h, --help 显示帮助
示例:
./scripts/backup-db.sh
./scripts/backup-db.sh --prefix pre-release
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--prefix)
PREFIX="${2:?缺少 --prefix 参数值}"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
die "未知参数: $1"
;;
esac
done
cd "$ROOT"
require_docker
ensure_env_file || exit 1
start_infra
backup_database "$PREFIX"
prune_old_backups