WEB/rollback.sh
2026-03-28 17:55:54 +08:00

22 lines
696 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.

#!/bin/bash
USER="root"
IP="1.2.3.4" # 请修改为您的服务器实际 IP
BASE_PATH="/www/wwwroot/my-project" # 请修改为您的项目在服务器上的存放路径
# SSH 密钥提示:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICJtwa+MFLQEgkEbcGQ6dkQOiFydRvjVeidJ/7uBsF2e 3313488199@qq.com
echo "⏪ 正在回滚到上一个版本..."
ssh $USER@$IP << EOF
# 获取 releases 目录下按时间排序的倒数第二个版本
PREVIOUS_VERSION=$(ls -dt $BASE_PATH/releases/*/ | sed -n '2p')
if [ -z "$PREVIOUS_VERSION" ]; then
echo "❌ 找不到可回滚的历史版本"
exit 1
fi
ln -sfn $PREVIOUS_VERSION $BASE_PATH/current
echo "✅ 已回滚至: $PREVIOUS_VERSION"
EOF