Files
blog/gitea-backup/scripts/backup.sh
T

37 lines
1.3 KiB
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.
#!/bin/bash
# =============================================================================
# Gitea 部署包 —— 一键备份
# 备份内容:
# 1. gitea dump(仓库 + 用户 + 配置 + secrets 加密导出)
# 2. 完整 data 卷(gitea.db / app.ini / runner 配置 / upyun-sync 目录)
# 产物输出到 backups/ 目录
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
BACKUP_DIR="$ROOT_DIR/backups"
STAMP="$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BACKUP_DIR"
echo "==> 1/2 导出 Gitea dump(含 secrets)..."
docker compose -f "$ROOT_DIR/docker-compose.yml" exec -T gitea \
gitea dump --config /data/gitea/conf/app.ini \
--file /data/gitea-dump.zip \
-R -S 2>/dev/null || {
echo "⚠️ gitea dump 失败(容器可能未运行),跳过,仅备份 data 卷"
}
# 把 dump 产物从容器拷出来
docker compose -f "$ROOT_DIR/docker-compose.yml" cp \
gitea:/data/gitea-dump.zip "$BACKUP_DIR/gitea-dump-$STAMP.zip" 2>/dev/null || true
echo "==> 2/2 打包 data 卷..."
tar -czf "$BACKUP_DIR/data-$STAMP.tar.gz" -C "$ROOT_DIR" data/
echo ""
echo "✅ 备份完成:"
ls -lh "$BACKUP_DIR" | tail -5
echo ""
echo "⚠️ 产物含密钥,请勿上传网盘/公开仓库。"