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

56 lines
1.7 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 部署包 —— 一键恢复
# 用法:bash restore.sh <backups/data-<时间戳>.tar.gz>
# 或 bash restore.sh <backups/gitea-dump-<时间戳>.zip>(仅恢复 dump)
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
if [ $# -lt 1 ]; then
echo "用法:bash restore.sh <备份文件>"
echo " - data-*.tar.gz 恢复完整 data 卷"
echo " - gitea-dump-*.zip 仅恢复 gitea dump"
exit 1
fi
SRC="$1"
if [ ! -f "$SRC" ]; then
echo "❌ 找不到备份文件:$SRC"
exit 1
fi
echo "==> 停止服务..."
docker compose -f "$ROOT_DIR/docker-compose.yml" down 2>/dev/null || true
case "$SRC" in
*data-*.tar.gz)
echo "==> 恢复 data 卷..."
tar -xzf "$SRC" -C "$ROOT_DIR"
echo "✅ data 卷已恢复到 $ROOT_DIR/data/"
;;
*gitea-dump-*.zip)
echo "==> 恢复 gitea dump..."
docker compose -f "$ROOT_DIR/docker-compose.yml" up -d gitea
sleep 5
docker compose -f "$ROOT_DIR/docker-compose.yml" cp \
"$SRC" gitea:/data/restore.zip
docker compose -f "$ROOT_DIR/docker-compose.yml" exec -T gitea \
gitea restore --config /data/gitea/conf/app.ini --file /data/restore.zip
echo "✅ gitea dump 已恢复"
;;
*)
echo "❌ 无法识别的备份文件类型:$SRC"
exit 1
;;
esac
echo "==> 启动服务..."
docker compose -f "$ROOT_DIR/docker-compose.yml" up -d
echo "✅ 恢复完成,检查状态:"
docker compose -f "$ROOT_DIR/docker-compose.yml" ps