-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcManage.sh
executable file
·94 lines (83 loc) · 2.97 KB
/
mcManage.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Minecraft AutoBackup
NOW=$(date +"%Y%m%d%H%M")
#Minecraft Home Directory
HOME='/home/user/mc/'
#Backup Directory
BACKUPDIR='/home/user/backups/mc/'
#Screen session name
SCREENSESSION='minecraft'
#Window name in screen
SCREENWINDOW='smp'
####
# Uncomment the following line if you use Tectonicus.
# This gets first active X Display. If you don't have X,
# uncommenting this will cause problem.
####
#export DISPLAY=:`ls /tmp/.X11-unix/X* | cut -b17`
do_incremental() {
if [ -e ${HOME}server.log.lck ] #check if server is running
then #Inform players that backup started
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "say ###Backup - Started###"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-off"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-all"`echo -ne '\015'`
sleep 5
tar -cjf ${BACKUPDIR}${NOW}.tgz --listed-incremental=${BACKUPDIR}`date +%Y%m`.snp -C ${HOME} .
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-on"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "say ###Backup - Complete###"`echo -ne '\015'`
return 0
else
return 1
fi
}
do_map() {
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "say ###Map - Generating###"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-off"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-all"`echo -ne '\015'`
rm -rf /var/www/map/*
#/usr/bin/python2.7 ~/Minecraft-Overviewer/overviewer.py ~/mc/Durance /var/www/map
java -Xmx4096M -jar /home/user/tectonicus/Tectonicus_v2.14.jar config=/home/user/tectonicus/config.xml
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-on"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "say ###Map - Complete###"`echo -ne '\015'`
}
do_full() {
if [ -e ${HOME}server.log.lck ] #check if server is running
then #Inform players that backup started
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "say ###Backup - Started###"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-off"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-all"`echo -ne '\015'`
sleep 5
tar -cjf ${BACKUPDIR}`date +%Y%m`-level0.tgz --listed-incremental=${BACKUPDIR}`date +%Y%m`.snp --level=0 -C ${HOME} .
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "save-on"`echo -ne '\015'`
screen -S ${SCREENSESSION} -p ${SCREENWINDOW} -X stuff "say ###Backup - Complete###"`echo -ne '\015'`
return 0
else
return 1
fi
return 1
}
do_clean ()
{
#find /home/user/backups/mc -mmin +2880 -exec rm {} \; #remove backups older than 2days
/bin/rm ${BACKUPDIR}`date --date="3 months ago" +"%Y%m"`*
}
case $1 in
"full")
do_full
;;
"incremental")
DOM=`date +"%d"`
HOUR=`date +"%H"`
if [ $DOM -eq 01 ] && [ $HOUR -eq 00 ]; then
exit 0
else
do_incremental
fi
;;
"map")
do_map
;;
"clean")
do_clean
;;
esac