QQgit/scripts/rollback.sh

34 lines
1.3 KiB
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
# =============================================================================
# rollback.sh —— 从 /var/backups 的 tar 包还原线上 custom/ 与 app.ini
#
# ./scripts/rollback.sh # 列出可用备份
# ./scripts/rollback.sh <备份文件> # 还原指定备份(会再问一次 y/N)
# ./scripts/rollback.sh --list # 同上,列出
# =============================================================================
set -euo pipefail
BACKUP_DIR="/var/backups"
DST_CUSTOM="/var/lib/gitea/custom"
if [ "${1:-}" = "" ] || [ "${1:-}" = "--list" ]; then
echo "可用备份(新的在上):"
ls -1t "$BACKUP_DIR"/gitea-custom-*.tar.gz 2>/dev/null || echo " (没有找到备份)"
echo
echo "还原用法:./scripts/rollback.sh $BACKUP_DIR/gitea-custom-<时间戳>.tar.gz"
exit 0
fi
BACKUP="$1"
[ -f "$BACKUP" ] || { echo "备份不存在:$BACKUP" >&2; exit 1; }
echo "将把 $BACKUP 解包覆盖 /var/lib/gitea/custom 与 /etc/gitea/app.ini"
read -r -p "确认还原?(y/N) " ans
[ "$ans" = "y" ] || [ "$ans" = "Y" ] || { echo "已取消"; exit 0; }
sudo tar xzf "$BACKUP" -C /
sudo chown -R git:git "$DST_CUSTOM"
sudo systemctl restart gitea
sleep 2
systemctl is-active gitea && echo "还原完成,gitea 运行中"