-
-
Save javasboy/c061869d5eddaa6dd49e238185315136 to your computer and use it in GitHub Desktop.
Minecraft auto backup 下面是回档脚本,注意更改为你自己的存档文件夹
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
# tmux 会话名字 | |
sessionName=mc | |
# 服务器关闭警告信息 | |
stopDelay=10 | |
stopWarn=服务器将在${stopDelay}秒后关闭进行备份 | |
# 存档位置 | |
saveDir=world_1.16.5_survival*/ | |
# 服务器启动脚本 | |
startScript=1.18.2_survival.sh | |
# 备份位置 | |
backupPath=bak | |
# 存档保留天数 | |
backupDays=3 | |
# 警告并关闭服务器 | |
tmux send-keys -t ${sessionName} say Space ${stopWarn} Enter | |
sleep ${stopDelay} | |
tmux send-keys -t ${sessionName} stop Enter | |
echo 服务器关闭ing... | |
# 等待服务器关闭 | |
sleep 30 | |
# 开始备份 | |
echo 开始备份... | |
if [ -z "${backupPath}" ]; then | |
tar -czf auto-backup-`date +%Y-%m-%d-%H-%M-%S`.tar.gz ${saveDir} | |
else | |
mkdir -p ${backupPath} | |
tar -czf ${backupPath}/auto-backup-`date +%Y-%m-%d-%H-%M-%S`.tar.gz ${saveDir} | |
fi | |
echo 备份完毕 | |
# 删除旧存档 | |
find ${backupPath} -mtime +${backupDays} -name "auto-backup-*.tar.gz" -exec rm {} \; | |
# 重启服务器 | |
tmux send-keys -t ${sessionName} bash Space ${startScript} Enter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p 请输入要恢复的存档: archive | |
set -v | |
tar -xzf $archive -C ../ | |
set +v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment