-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserverbackup.sh
executable file
·81 lines (71 loc) · 1.51 KB
/
webserverbackup.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
#!/bin/bash
USER="root"
PASSWORD="PaSsWoRd"
OUTPUT="/var/www/backup"
GITDIR="OUTPUT/.git"
DBS=`mysql --user=$USER --password=$PASSWORD --skip-column-names -e "SHOW DATABASES;" | tr -d "| "`
SERVICES=( cron.d logrotate.d monit nginx)
EXCLUDES=( 'information_schema')
NUM_EXCLUDES=${#EXCLUDES[@]}
DATE=`date +%Y%m%d`
function chk-output-dir {
if [ ! -d $OUTPUT/$outputdir ]; then
mkdir -p $OUTPUT/$outputdir;
fi
}
function chk-git-dir {
if [ ! -d $GITDIR ]; then
git=1
# echo "Git exist"
else
git=0
# echo "Git not exist"
fi
}
function backup-mysql {
for db in $DBS; do
skip=0
count=0
while [ $count -lt $NUM_EXCLUDES ] ; do
if [ "$db" = ${EXCLUDES[$count]} ] ; then
skip=1
fi
count=$((count+1))
done
if [ $skip -eq 0 ] ; then
mysqldump --force --opt --user=$USER --password=$PASSWORD --databases $db > $OUTPUT/mysql/$db.sql
fi
done
}
function backup-conf {
for index in ${!SERVICES[*]}; do
outputdir=/conf/${SERVICES[$index]}
chk-output-dir
mount --bind /etc/${SERVICES[$index]} $OUTPUT/$outputdir
done
}
function umount-output {
for index in ${!SERVICES[*]}; do
umount $OUTPUT/conf/${SERVICES[$index]}
done
}
function git-push {
cd $OUTPUT
git add *
git commit -m "Commit date $DATE"
# git push -u origin master
}
function main {
outputdir=mysql
chk-output-dir
outputdir=conf
chk-output-dir
backup-mysql
backup-conf
chk-git-dir
if [ $git ]; then
git-push
fi
umount-output
}
main