-
Notifications
You must be signed in to change notification settings - Fork 0
/
minecraft_backup.sh
30 lines (22 loc) · 1.2 KB
/
minecraft_backup.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
#!/bin/bash
# USAGE: ./minecraft_backup.sh
# Tell the Minecraft server to save the world and then copy it.
screen -S minecraft -X stuff "/say Saving the world...$(printf \\r)"
screen -S minecraft -X stuff "/save-off$(printf \\r)"
sleep 2s
screen -S minecraft -X stuff "/save-all$(printf \\r)"
sleep 2s
# Rotate 10 backups by deleting the oldest one and shifting the rest.
rm -r ~/minecraft-backups/backup-9/ 2> /dev/null
mv ~/minecraft-backups/backup-8/ ~/minecraft-backups/backup-9/ 2> /dev/null
mv ~/minecraft-backups/backup-7/ ~/minecraft-backups/backup-8/ 2> /dev/null
mv ~/minecraft-backups/backup-6/ ~/minecraft-backups/backup-7/ 2> /dev/null
mv ~/minecraft-backups/backup-5/ ~/minecraft-backups/backup-6/ 2> /dev/null
mv ~/minecraft-backups/backup-4/ ~/minecraft-backups/backup-5/ 2> /dev/null
mv ~/minecraft-backups/backup-3/ ~/minecraft-backups/backup-4/ 2> /dev/null
mv ~/minecraft-backups/backup-2/ ~/minecraft-backups/backup-3/ 2> /dev/null
mv ~/minecraft-backups/backup-1/ ~/minecraft-backups/backup-2/ 2> /dev/null
mv ~/minecraft-backups/backup-0/ ~/minecraft-backups/backup-1/ 2> /dev/null
cp -r ~/minecraft/world ~/minecraft-backups/backup-0
screen -S minecraft -X stuff "/save-on$(printf \\r)"
sleep 2s