Files
finance-backend/finance-server/deploy/backup.sh
T

33 lines
975 B
Bash
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
# 财务系统每日备份(CentOS)
# 依赖 /etc/finance/backup.cnf(chmod 600),内容示例:
# [client]
# host=127.0.0.1
# port=3307
# user=fin_migrate
# password=替换成密码
set -euo pipefail
umask 077
BACKUP_DIR="${BACKUP_DIR:-/data/backup}"
KEEP_DAYS="${KEEP_DAYS:-30}"
DB_NAME="${DB_NAME:-fin_platform}"
MYSQL_DEFAULTS="${MYSQL_DEFAULTS:-/etc/finance/backup.cnf}"
STAMP="$(date +%F_%H%M%S)"
mkdir -p "${BACKUP_DIR}"
echo "[1/2] 备份 MySQL ${DB_NAME}"
mysqldump --defaults-extra-file="${MYSQL_DEFAULTS}" \
--single-transaction --routines --triggers --events \
"${DB_NAME}" | gzip > "${BACKUP_DIR}/fin_platform_${STAMP}.sql.gz"
echo "[2/2] 备份配置与加密密钥"
tar czf "${BACKUP_DIR}/finance_conf_${STAMP}.tgz" \
/etc/finance/finance.env \
/data/finance/runtime/secret-enc.key \
/opt/finance/finance-server-1.0.0.jar
find "${BACKUP_DIR}" -type f -mtime +"${KEEP_DAYS}" -delete
echo "备份完成: ${BACKUP_DIR}"