-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
56 lines (49 loc) · 1.65 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Example backup script for FTB server
# Author: Ciaran Crocker <[email protected]>
#Settings
SERVICE='lcdev.jar'
OPTIONS='nogui'
USERNAME='lcmc'
WORLD='world'
MCPATH='/home/lcmc/lcdev'
BACKUPPATH='/lcmc/backups'
NOW=`date "+%Y-%m-%d_%Hh%M"`
BACKUP_FILE="$BACKUPPATH/${WORLD}_${NOW}.tar"
ME=`whoami`
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "$SERVICE is running... suspending saves"
as_user "screen -p 0 -S lootchest -X eval 'stuff \"say SERVER BACKUP STARTING. Server going readonly...\"\015'"
as_user "screen -p 0 -S lootchest -X eval 'stuff \"save-off\"\015'"
as_user "screen -p 0 -S lootchest -X eval 'stuff \"save-all\"\015'"
sync
sleep 10
else
echo "$SERVICE is not running. Not suspending saves."
fi
echo "Backing up minecraft world..."
#as_user "cd $MCPATH && cp -r $WORLD $BACKUPPATH/${WORLD}_`date "+%Y.%m.%d_%H.%M"`"
as_user "tar -C \"$MCPATH\" -cf \"$BACKUP_FILE\" $WORLD"
echo "Backing up $SERVICE"
as_user "tar -C \"$MCPATH\" -rf \"$BACKUP_FILE\" $SERVICE"
#as_user "cp \"$MCPATH/$SERVICE\" \"$BACKUPPATH/minecraft_server_${NOW}.jar\""
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "$SERVICE is running... re-enabling saves"
as_user "screen -p 0 -S lootchest -X eval 'stuff \"save-on\"\015'"
as_user "screen -p 0 -S lootchest -X eval 'stuff \"say SERVER BACKUP ENDED. Server going read-write...\"\015'"
else
echo "$SERVICE is not running. Not resuming saves."
fi
echo "Compressing backup..."
as_user "gzip -f \"$BACKUP_FILE\""
echo "Done."
# Jobs a good 'un