This is the script I use that will:
- Automatically backup minecraft map
- Automatically update minecraft server
- Automatically restart the server if it stops or dies
#!/bin/bash while [ true ]; do # make md5 of current file for update check. md5sum minecraft_server.jar > minecraft_server.jar.md5 wget -o updatelog.log -N --trust-server-names http://www.minecraft.net/download/minecraft_server.jar # display updated status if md5sum -c --status minecraft_server.jar.md5 then echo "Server Up to Date." else echo "Updated Server!" fi java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui rsync -a --delete --progress /home/dan/serv/minecraft/world "/home/dan/serv/minecraft/bak/world"`eval date +%Y%m%d`"" done |
Code Explained:
This will put the server in an infinite loop. You can kill it by hitting Control+C a couple times in a row.
while [ true ]; do |
This will make a hash of the current minecraft_server.jar and then download the newest copy using wget.
md5sum minecraft_server.jar > minecraft_server.jar.md5 wget -o updatelog.log -N --trust-server-names http://www.minecraft.net/download/minecraft_server.jar |
This will run minecraft in headless mode and with a limit on RAM.
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui |
This will create a backup of the minecraft world folder in a backup folder. You probably should work on this part.
rsync -a --delete --progress /path/to/minecraft/world "/path/to/minecraft/bak/world"`eval date |
Well, hope this helps someone. Have a good day.