Skip to content

Instantly share code, notes, and snippets.

@jogerj
Forked from renamedquery/backup.sh
Last active January 25, 2023 16:53
Show Gist options
  • Save jogerj/87ca68ad79b7dc5800cd810056c25721 to your computer and use it in GitHub Desktop.
Save jogerj/87ca68ad79b7dc5800cd810056c25721 to your computer and use it in GitHub Desktop.
RCON bash script to backup minecraft server directory
#!/bin/bash
MCRCON_PATH="/usr/local/bin"
BACKUP_PATH="/home/opc/mc_backup"
MC_PATH="/home/opc/minecraft"
IP="127.0.0.1"
PORT="25575"
PASS="[password]"
function rcon {
$MCRCON_PATH/mcrcon -H $IP -P $PORT -p $PASS "$1"
}
rcon "save-off"
rcon "save-all"
tar -cvpzf $BACKUP_PATH/server-$(date +%F_%R).tar.gz $MC_PATH
rcon "save-on"
## Delete older backups
find $BACKUP_PATH -type f -mtime +7 -name '*.gz' -delete
##file paths and other details omitted for this public copy, just replace them with your information if you want to use this
##i have this set up on crontab to run every 6 hours
##enjoy :)
@jogerj
Copy link
Author

jogerj commented Nov 7, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment