December 06, 2023

Minecraft Java Server Backup

 #!/bin/bash

function rcon {
    /home/minecraft/minecraft-20231204/tools/mcrcon -H 127.0.0.1 -P 25575 -p YOURCONSOLEPASSWORD "$1"
}


rcon 'say [WARNING] Server backup process will begin in 15 minutes'
sleep 10m

rcon 'say [WARNING] Server backup process will begin in 5 minutes'
sleep 5m

rcon 'say [WARNING] Server backup process is starting NOW.'

rcon "save-off"
rcon "save-all"

day=$(date '+%d-%m-%Y_%H-%M-%S')
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"

tar czf /media/nas-backup/minecraft/quilt/$archive_file /media/nas-media/Aidan/minecraft-20231204

sleep 2

rcon "save-on"

rcon 'say [NOTICE] Server backup process is complete. Carry on.'

No comments: