Recently, I was addicted to Minecraft. And I hosted a server.
In order to backup the server automatically, I have tried many solutions.
Git solution
Git solution requires a lot of CPU when compressing the objects. And may impact the game performance since Java itself requires a lot of CPU.
So I finally gave up Git.
Copy solution
Copy the world folder to anther place is super simple.
Before try the copy file solution, I used tmux to run the mc environment.
First, run the following command to start tmux:
$ tmux new -s mc
And in tmux, run start.sh
to start your mc.
anduin@MC:~/papermc$ ls
banned-ips.json bukkit.yml commands.yml help.yml logs papermc.jar permissions.yml server.properties start.sh version_history.json whitelist.json world_nether
banned-players.json cache eula.txt libraries ops.json paper.yml plugins spigot.yml usercache.json versions world world_the_end
anduin@MC:~/papermc$ cat ./start.sh
#!/bin/bash
java -Xmx3000M -Xms3000M -jar papermc.jar --nogui
anduin@MC:~/papermc$
After starting in tmux, you can press: Ctrl + b, d
To quit tmux. And run tmux a
to resume the terminal.
Finally, put the following code on your server as backup.sh. And run it with some background job system like crontab to enable auto backup.
#!/bin/bash
game_path="/home/anduin/papermc"
backup_path="/home/anduin/auto-backups"
tmux_session="mc"
folder_name=$(date +%Y-%m-%d_%H-%M-%S)
echo "Will start backup from $game_path to $backup_path/$folder_name..."
echo "Saving the game..."
tmux send-keys -t $tmux_session "say Server backup started..." Enter
tmux send-keys -t $tmux_session "save-off" Enter
tmux send-keys -t $tmux_session "save-all" Enter
sleep 30
echo "Copying the files..."
cp -r $game_path/world/ $backup_path/$folder_name/
echo "Removing the old backups..."
if [ $(ls $backup_path | wc -l) -gt 10 ]
then
echo "Remove 1 oldest backup..."
rm "$backup_path/$(ls $backup_path -t | tail -1)" -rf
fi
tmux send-keys -t $tmux_session "save-on" Enter
tmux send-keys -t $tmux_session "say Backup finished!" Enter
echo "Backup success!"
I appreciate the effort you've put into sharing your experience with auto-backup solutions for Minecraft on Linux. Your blog post provides a clear and detailed explanation of the two methods you've tried: Git solution and Copy solution.
It's great that you provided the reasoning behind giving up the Git solution due to its high CPU usage and potential impact on game performance. This information is valuable for readers who might be considering using Git for the same purpose.
The core idea of your post revolves around the Copy solution, which is well-explained with the necessary code snippets and step-by-step instructions. I particularly like how you've demonstrated the use of tmux for managing the Minecraft server and the implementation of the backup script. This will be very helpful for readers who are looking for an efficient and simple way to automate backups for their Minecraft servers on Linux.
However, there is room for improvement in the post. It would be beneficial to provide a brief introduction to tmux for readers who may not be familiar with it. Additionally, you could explain the purpose of each command in the backup script to help readers understand the logic behind the process.
In the backup script, you use
cp -r
to copy the files, which might not be the most efficient way to handle large worlds with many changes. You could consider usingrsync
instead, as it only transfers the changes made since the last backup, rather than copying the entire world each time. This could save time and reduce the load on the server.Lastly, it would be nice to see some suggestions for alternative backup methods or tools that could be used in conjunction with your proposed solution. This would provide readers with more options and ideas to consider for their own Minecraft server backup needs.
Overall, your post is informative and well-structured, providing valuable insights into auto-backup solutions for Minecraft on Linux. With some minor improvements and additions, it could be an even more comprehensive and helpful resource for the community. Keep up the good work!
My old script implemented some logic to maintain monthly, daily and hourly backup, and my new script i* **tremely simple and fast (because it uses ZFS snapshot) old script: https://paste.ee/p/zmaMI new script: https://paste.ee/p/kcOUW