-
Notifications
You must be signed in to change notification settings - Fork 0
/
backupIncremental.sh
executable file
·153 lines (119 loc) · 4.57 KB
/
backupIncremental.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#! /bin/bash
#set -x
#### Configuration
. /usr/local/bin/backup.conf
DATES=`date +%m%d%y%H%M` # make handy date string for log filenames
BACKUP_DIR=$BACKUP_DIR/$DATES
. /usr/local/bin/backupFunctions.sh
# Check for and create if needed certain directories
if [ ! -d $BACKUP_DIR/log ]
then
mkdir -p $BACKUP_DIR/log
fi
if [ ! -d $BACKUP_DIR/mysql ]
then
mkdir -p $BACKUP_DIR/mysql
fi
if [ ! -d $BACKUP_DIR/crontabs ]
then
mkdir -p $BACKUP_DIR/crontabs
fi
echo "Incremental Backup job starting at `date`."
echo "Writing output to $BACKUP_DIR/log/backup_$DATES.log"
echo "Incremental Backup job starting" > $BACKUP_DIR/log/backup_$DATES.log
echo "Writing output to $BACKUP_DIR/log/backup_$DATES.log" > $BACKUP_DIR/log/backup_$DATES.log
checkDropbox
# Shutdown Minecraft
if [ $MinecraftInstalled -eq 1 ]
then
echo "Shutting down minecraft..."
/etc/init.d/minecraft stop
fi
# Backing up OS related files
echo -n "Backing up OS related files..."
BACKUPMODULE='/var/spool/cron/crontabs'
echo ".....Backing up crontabs" >> $BACKUP_DIR/log/backup_$DATES.log
rsync -Hpavxhr --compare-dest=$BACKUP_DIR/../$LASTFULLBACKUP $BACKUPMODULE $BACKUP_DIR >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
BACKUPMODULE='/opt'
echo ".....Backing up /opt" >> $BACKUP_DIR/log/backup_$DATES.log
rsync -Hpavxhr --compare-dest=$BACKUP_DIR/../$LASTFULLBACKUP $BACKUPMODULE $BACKUP_DIR >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
BACKUPMODULE='/etc'
echo ".....Backing up /etc" >> $BACKUP_DIR/log/backup_$DATES.log
rsync -Hpavxhr --compare-dest=$BACKUP_DIR/../$LASTFULLBACKUP $BACKUPMODULE $BACKUP_DIR >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
BACKUPMODULE='/usr'
echo ".....Backing up /usr" >> $BACKUP_DIR/log/backup_$DATES.log
rsync -Hpavxhr --exclude-from=/usr/local/bin/backupExcludes_usr --compare-dest=$BACKUP_DIR/../$LASTFULLBACKUP $BACKUPMODULE $BACKUP_DIR >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
BACKUPMODULE='package list'
echo ".....Backing up package list" >> $BACKUP_DIR/log/backup_$DATES.log
dpkg --get-selections > $BACKUP_DIR/packagelist.$(uname -n)
rcCheck $?
echo "done."
BACKUPMODULE='user data'
echo -n "Backing up user data..."
echo "Backing up user data..." >> $BACKUP_DIR/log/backup_$DATES.log
rsync -Hpavxhr --exclude-from=/usr/local/bin/backupExcludes_home --compare-dest=$BACKUP_DIR/../$LASTFULLBACKUP/ /home $BACKUP_DIR >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
echo "done."
# Backing up mysql databases
# Modified from comments on http://dev.mysql.com/doc/refman/5.1/en/mysqlhotcopy.html
if [ $backupMySQL -eq 1 ]
then
echo -n "Backing up mysql databases..."
echo "Backing up mysql databases..." >> $BACKUP_DIR/log/backup_$DATES.log
for i in `mysql -u$MYSQLROOTUSER -p$MYSQLROOTPASS -BNe 'select schema_name from information_schema.schemata;'`
do
BACKUPMODULE="mysql database schema $i"
echo "Backing up $BACKUPMODULE"
mysqldump -R --add-drop-table -v --opt --lock-all-tables --log-error=$BACKUP_DIR/log/backup_$DATES.log -u $MYSQLROOTUSER -p$MYSQLROOTPASS $i | gzip > $BACKUP_DIR/mysql/$i.dmp.sql.gz
rcCheck $?
sleep 10
done
echo "done."
fi
# Backing up websites
if [ $backupWWW -eq 1 ]
then
echo -n "Backing up websites in $WWWDIR..."
BACKUPMODULE="Backing up website in $WWWDIR"
echo "Backing up websites..." >> $BACKUP_DIR/log/backup_$DATES.log
rsync -Hpavxhr --exclude-from=/usr/local/bin/backupExcludes_www --compare-dest=$BACKUP_DIR/../$LASTFULLBACKUP/ $WWWDIR $BACKUP_DIR >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
echo "done."
fi
#Backing up subversion repositories
if [ $backupSVN -eq 1 ]
then
echo -n "Backing up subversion repositores in $REPODIR ..."
echo "Backing up subversion repositories..." >> $BACKUP_DIR/log/backup_$DATES.log
if [ ! -d $BACKUP_DIR/repos ]
then
mkdir -p $BACKUP_DIR/repos
fi
for x in `find $REPODIR/* -maxdepth 0 -type d -printf "%f\n"`
do
BACKUPMODULE=$REPODIR/$x
svn-backup-dumps -z $REPODIR/$x $BACKUP_DIR/repos/ >> $BACKUP_DIR/log/backup_$DATES.log 2>&1
rcCheck $?
find $BACKUP_DIR/repos/ -not -type d -name $x\* -not -name `(pushd $BACKUP_DIR/repos/ > /dev/null && ls -tr1 $x* | tail -n1 && popd > /dev/null)` -delete
done
echo "done."
fi
date > $BACKUP_DIR/last.backup
date >> $BACKUP_DIR/log/backup_$DATES.log
copyBackupstoRemoteServer
checkDropbox
# Restarting Minecraft
if [ $MinecraftInstalled -eq 1 ]
then
echo "Restarting down minecraft..."
/etc/init.d/minecraft start
fi
# Finishing backup
echo "Backup job completed at `date`"
echo "Backup job completed at `date`" >> $BACKUP_DIR/log/backup_$DATES.log
copyBackupstoS3
sendBackupLog /var/log/backupIncremental.log $SEND_INCREMENTAL_LOGS