-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-minecraft.sh
executable file
·32 lines (26 loc) · 1.04 KB
/
backup-minecraft.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# wipe any stale screens
#sudo -u minecraft screen -wipe
# First, check if the server is even running. If not, then do nothing and exit.
if screen -ls minecraft/ | grep 'Private\|Attached\|Detached'; then
echo server active, backing up
# save the world
sudo -u minecraft screen -X stuff "say Preparing for server snapshot, world saving disabled. $(printf '\r')"
sudo -u minecraft screen -X stuff "save-all $(printf '\r')"
# turn off seever saving
sudo -u minecraft screen -X stuff "save-off $(printf '\r')"
if ! mountpoint -q /mnt/btrfs ;then
echo "btrfs root not mounted, mounting"
mount /mnt/btrfs
fi
# create new snapshot of minecraft directory
sleep 5 # just in case
btrfs subvolume snapshot -r /srv/minecraft /mnt/btrfs/backups/minecraft_backup_`date +%F-%H%M%S`
#umount /mnt/btrfs
# turn server saving back on
sudo -u minecraft screen -X stuff "save-on $(printf '\r')"
sudo -u minecraft screen -X stuff "say Server snapshot complete, world saving enabled. $(printf '\r')"
else
echo no active server, exiting
exit
fi