
这是什么?
此模组挂钩到内置的存档系统并执行脚本:
每个脚本都在服务器根目录(.jar 文件旁边)中执行,并带有以下参数:
1 - 玩家数量
2 - 平均刻时间(浮点数)
3 - 服务器运行状态("true" 或 "false")
4 - 总世界名称数
5+ - 世界名称 #n(服务器可能同时运行多个世界,世界名称等于目录名称)
默认情况下,每个脚本在 /bin/bash 中执行,但你可以通过编辑 mods/backup-scripts/shell 文件来提供你自己的 Shell。
初始化脚本:
仅当自上次执行以来包含更改时,才会执行此脚本
若要手动强制在不包含更改的情况下执行,请从 mods/backup-scripts 目录中删除 .last-init-run 文件。
# 不要在这里使用 Shebang,通过编辑 `shell` 文件更改默认 shell
echo "脚本当前工作目录: $(pwd)"
echo "传递的参数: $#"
echo "玩家数量: ${1}"
echo "平均刻时间: ${2}"
echo "服务器运行状态: ${3}"
echo "总世界数: ${4}"
echo "世界名称: '${*:5:$4}'"
echo "创建 git 仓库"
git init
levelNames=${*:5:$4}
for levelName in "${levelNames[@]}" # 防止单词分割,因为 Minecraft 世界名称可能包含空格
do
echo "将 '$levelName' 添加到仓库"
git add "$levelName"
done
echo "创建初始提交"
git commit -m "自动备份 - $(date)"
echo "初始化完成!"
示例输出:
[15:52:21] [Server thread/INFO] (Minecraft) Done (15.286s)! For help, type "help"
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Script PWD: /Users/mateusz.budzisz/git/fabric/git-backup-fabric-mod/run
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Arguments passed: 4
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Player count: 0
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): TPS: 0.0
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Total levels: 1
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Level names: 'world'
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Creating git repository
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Initialized empty Git repository in /Users/mateusz.budzisz/git/fabric/git-backup-fabric-mod/run/.git/
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Adding 'world' to repository
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Creating initial commit
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): [main (root-commit) a142833] Automatic backup - Sun Aug 13 15:52:21 CEST 2023
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): 11 files changed, 1 insertion(+)
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.-1.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.-1.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.0.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.0.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/level.dat
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/poi/r.0.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.-1.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.-1.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.0.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.0.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/session.lock
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Initialization done!
存档时脚本 (OnSave script)
此脚本在每个自动存档时执行(Minecraft 每 5 分钟执行一次自动存档,使用 save-on 启用),你可以使用 save-all 强制保存。
默认脚本内容:
# 不要在这里使用 Shebang,通过编辑 `shell` 文件更改默认 shell
echo "脚本当前工作目录: $(pwd)"
echo "传递的参数: $#"
echo "玩家数量: ${1}"
echo "平均刻时间: ${2}"
echo "服务器运行状态: ${3}"
echo "总世界数: ${4}"
echo "世界名称: '${*:5:$4}'"
if [ "$1" -le 0 ] && [ "$3" = "true" ] ; then
echo "由于没有人在线,跳过备份"
exit 1
fi
# 平均刻时间是浮点数,因此使用这种奇怪的比较方式
if (( $(echo "$2 > 50" |bc -l) )) && [ "$3" = "true" ] ; then
echo "由于平均刻时间过高 ($2),跳过备份"
exit 2
fi
levelNames=${*:5:$4}
for levelName in "${levelNames[@]}" # 防止单词分割,因为 Minecraft 世界名称可能包含空格
do
echo "将 '$levelName' 添加到提交"
git add "$levelName"
done
```bash
echo "正在创建提交"
git commit -m "自动备份 - $(date)"
git push
echo "备份完成!"
示例输出:
[15:43:50] [Server thread/INFO] (BackupScripts) 在主线程之外运行脚本
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 脚本工作目录: /Users/mateusz.budzisz/git/fabric/git-backup-fabric-mod/run
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 传入参数: 4
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 玩家数量: 1
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 平均刻时间: 0.1340647
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 总层级数: 1
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 层级名称: 'world with space in name'
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 将 'world with space in name' 添加到提交中
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 正在创建提交
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): [main 7cd92d5] 自动备份 - Sun Aug 13 15:43:50 CEST 2023
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 9 个文件已更改,0 处插入(+),0 处删除(-)
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 备份完成!
[15:43:50] [Server thread/INFO] (BackupScripts) 主线程外关闭
默认脚本使用 GIT
这对于小型世界(例如:几 GB 以内)是可以的,但建议设置更可靠的解决方案,如 或

What is this?
This mod hooks itself to built in save system and executes scripts:
Each script is executed in server root directory (next to .jar file) with the following arguments:
1 - player count
2 - average tick time (float)
3 - server running ("true" or "false")
4 - total level names
5+ - level name #n (server may run multiple levels at once, level name is equal to directory name)
Each script is by default executed in /bin/bash, but you may provide your shell by editing mods/backup-scripts/shell file.
Init script:
This script is executed only if contains changes since last execution
To manually force execution without changes delete .last-init-run file from mods/backup-scripts directory.
# Do not use Shebang here, change default shell by editing `shell` file
echo "Script PWD: $(pwd)"
echo "Arguments passed: $#"
echo "Player count: ${1}"
echo "AVG Tick time: ${2}"
echo "Server running: ${3}"
echo "Total levels: ${4}"
echo "Level names: '${*:5:$4}'"
echo "Creating git repository"
git init
levelNames=${*:5:$4}
for levelName in "${levelNames[@]}" # Preventing word splitting, because minecraft level names may contain spaces
do
echo "Adding '$levelName' to repository"
git add "$levelName"
done
echo "Creating initial commit"
git commit -m "Automatic backup - $(date)"
echo "Initialization done!"
Example output:
[15:52:21] [Server thread/INFO] (Minecraft) Done (15.286s)! For help, type "help"
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Script PWD: /Users/mateusz.budzisz/git/fabric/git-backup-fabric-mod/run
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Arguments passed: 4
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Player count: 0
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): TPS: 0.0
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Total levels: 1
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Level names: 'world'
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Creating git repository
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Initialized empty Git repository in /Users/mateusz.budzisz/git/fabric/git-backup-fabric-mod/run/.git/
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Adding 'world' to repository
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Creating initial commit
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): [main (root-commit) a142833] Automatic backup - Sun Aug 13 15:52:21 CEST 2023
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): 11 files changed, 1 insertion(+)
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.-1.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.-1.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.0.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/entities/r.0.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/level.dat
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/poi/r.0.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.-1.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.-1.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.0.-1.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/region/r.0.0.mca
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): create mode 100644 world/session.lock
[15:52:21] [Server thread/INFO] (BackupScripts) (init.sh): Initialization done!
OnSave script
This script is executed at every auto save (Minecraft performs auto save every 5 minutes, use save-on to enable), you may use save-all to force save.
Default script contents:
# Do not use Shebang here, change default shell by editing `shell` file
echo "Script PWD: $(pwd)"
echo "Arguments passed: $#"
echo "Player count: ${1}"
echo "AVG Tick time: ${2}"
echo "Server running: ${3}"
echo "Total levels: ${4}"
echo "Level names: '${*:5:$4}'"
if [ "$1" -le 0 ] && [ "$3" = "true" ] ; then
echo "Skipping backup as no one is online"
exit 1
fi
# AVG tick time is float, hence this wierd comparison
if (( $(echo "$2 > 50" |bc -l) )) && [ "$3" = "true" ] ; then
echo "Skipping backup as avg tick time is too high ($2)"
exit 2
fi
levelNames=${*:5:$4}
for levelName in "${levelNames[@]}" # Preventing word splitting, because minecraft level names may contain spaces
do
echo "Adding '$levelName' to commit"
git add "$levelName"
done
echo "Creating commit"
git commit -m "Automatic backup - $(date)"
git push
echo "Backup done!"
Example output:
[15:43:50] [Server thread/INFO] (BackupScripts) Running scripts off main thread
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Script PWD: /Users/mateusz.budzisz/git/fabric/git-backup-fabric-mod/run
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Arguments passed: 4
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Player count: 1
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): AVG tick time: 0.1340647
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Total levels: 1
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Level names: 'world with space in name'
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Adding 'world with space in name' to commit
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Creating commit
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): [main 7cd92d5] Automatic backup - Sun Aug 13 15:43:50 CEST 2023
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): 9 files changed, 0 insertions(+), 0 deletions(-)
[15:43:50] [Thread-13/INFO] (BackupScripts) (on-save.sh): Backup done!
[15:43:50] [Server thread/INFO] (BackupScripts) Shutdown of off main thread
Default scripts use GIT
Which is fine for small worlds (e.g.: up to few gigabytes), but it is recommended to setup more reliable solution as or
评论 0
登录后参与评分
还没有评论,来抢沙发吧