Created
January 21, 2018 01:07
-
-
Save reillysiemens/fa780306365f52a16722e52ebb154fa4 to your computer and use it in GitHub Desktop.
Minecraft Backup
This file contains hidden or 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/sh | |
: ${MINECRAFT_WORLD="survival"} | |
src="/srv/${MINECRAFT_WORLD}/world" | |
dst="/var/games/minecraft/${MINECRAFT_WORLD}.txz" | |
send_command() { | |
world=$1 | |
cmd=$2 | |
# Send the command to the tmux session. | |
/usr/local/bin/tmux send-keys -t ${world} "${cmd}" C-m | |
} | |
save_off() { | |
world=$1 | |
send_command ${world} "save-off" | |
} | |
save_on() { | |
world=$1 | |
send_command ${world} "save-on" | |
} | |
save_all() { | |
world=$1 | |
send_command ${world} "save-all" | |
} | |
archive() { | |
src=$1 | |
dst=$2 | |
tmp="/tmp/$(basename ${dst})" | |
# Create the archive at a temporary location first to minimize | |
# inconsistencies stemming from access when the new archive is being | |
# written. | |
/usr/bin/tar -a -cf ${tmp} ${src} | |
/bin/mv ${tmp} ${dst} | |
} | |
# Turn off world auto-saving. | |
save_off ${MINECRAFT_WORLD} | |
# Save the world. | |
save_all ${MINECRAFT_WORLD} | |
# Archive the world. | |
archive ${src} ${dst} | |
# Turn on world auto-saving. | |
save_on ${MINECRAFT_WORLD} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment