forked from Ubuntu-ve/lnmp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.sh
executable file
·136 lines (125 loc) · 4.63 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
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
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://blog.linuxeye.com
#
# Notes: OneinStack for CentOS/RadHat 6+ Debian 7+ and Ubuntu 12+
#
# Project home page:
# https://oneinstack.com
# https://github.com/lj2007331/oneinstack
# Check if user is root
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
pushd tools > /dev/null
. ../options.conf
DB_Local_BK() {
for D in `echo $db_name | tr ',' ' '`
do
./db_bk.sh $D
done
}
DB_Remote_BK() {
for D in `echo $db_name | tr ',' ' '`
do
./db_bk.sh $D
DB_GREP="DB_${D}_`date +%Y`"
DB_FILE=`ls -lrt $backup_dir | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
echo "file:::$backup_dir/$DB_FILE $backup_dir push" >> config_bakcup.txt
echo "com:::[ -e "$backup_dir/$DB_FILE" ] && rm -rf $backup_dir/DB_${D}_$(date +%Y%m%d --date="$expired_days days ago")_*.tgz" >> config_bakcup.txt
done
}
DB_COS_BK() {
for D in `echo $db_name | tr ',' ' '`
do
./db_bk.sh $D
DB_GREP="DB_${D}_`date +%Y`"
DB_FILE=`ls -lrt $backup_dir | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
${python_install_dir}/bin/coscmd upload $backup_dir/$DB_FILE /`date +%F`/$DB_FILE
[ $? -eq 0 ] && ${python_install_dir}/bin/coscmd delete -r -f `date +%F --date="$expired_days days ago"` > /dev/null 2>&1
done
}
DB_UPYUN_BK() {
for D in `echo $db_name | tr ',' ' '`
do
./db_bk.sh $D
DB_GREP="DB_${D}_`date +%Y`"
DB_FILE=`ls -lrt $backup_dir | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
/usr/local/bin/upx put $backup_dir/$DB_FILE /`date +%F`/$DB_FILE
[ $? -eq 0 ] && /usr/local/bin/upx rm -a `date +%F --date="$expired_days days ago"` > /dev/null 2>&1
done
}
WEB_Local_BK() {
for W in `echo $website_name | tr ',' ' '`
do
./website_bk.sh $W
done
}
WEB_Remote_BK() {
for W in `echo $website_name | tr ',' ' '`
do
if [ `du -sm "$wwwroot_dir/$WebSite" | awk '{print $1}'` -lt 1024 ];then
./website_bk.sh $W
Web_GREP="Web_${W}_`date +%Y`"
Web_FILE=`ls -lrt $backup_dir | grep ${Web_GREP} | tail -1 | awk '{print $NF}'`
echo "file:::$backup_dir/$Web_FILE $backup_dir push" >> config_bakcup.txt
echo "com:::[ -e "$backup_dir/$Web_FILE" ] && rm -rf $backup_dir/Web_${W}_$(date +%Y%m%d --date="$expired_days days ago")_*.tgz" >> config_bakcup.txt
else
echo "file:::$wwwroot_dir/$W $backup_dir push" >> config_bakcup.txt
fi
done
}
WEB_COS_BK() {
for W in `echo $website_name | tr ',' ' '`
do
[ ! -e "$wwwroot_dir/$WebSite" ] && { echo "[$wwwroot_dir/$WebSite] not exist"; break; }
PUSH_FILE="$backup_dir/Web_${W}_$(date +%Y%m%d_%H).tgz"
if [ ! -e "$PUSH_FILE" ]; then
pushd $wwwroot_dir
tar czf $PUSH_FILE ./$W
popd
fi
${python_install_dir}/bin/coscmd upload $PUSH_FILE /`date +%F`/Web_${W}_$(date +%Y%m%d_%H).tgz
if [ $? -eq 0 ]; then
${python_install_dir}/bin/coscmd delete -r -f `date +%F --date="$expired_days days ago"` > /dev/null 2>&1
[ -e "$PUSH_FILE" -a -z "`echo $backup_destination | grep -ow 'local'`" ] && rm -rf $PUSH_FILE
fi
done
}
WEB_UPYUN_BK() {
for W in `echo $website_name | tr ',' ' '`
do
[ ! -e "$wwwroot_dir/$WebSite" ] && { echo "[$wwwroot_dir/$WebSite] not exist"; break; }
[ ! -e "$backup_dir" ] && mkdir -p $backup_dir
PUSH_FILE="$backup_dir/Web_${W}_$(date +%Y%m%d_%H).tgz"
if [ ! -e "$PUSH_FILE" ]; then
pushd $wwwroot_dir
tar czf $PUSH_FILE ./$W
popd
fi
/usr/local/bin/upx put $PUSH_FILE /`date +%F`/Web_${W}_$(date +%Y%m%d_%H).tgz
if [ $? -eq 0 ]; then
/usr/local/bin/upx rm -a `date +%F --date="$expired_days days ago"` > /dev/null 2>&1
[ -e "$PUSH_FILE" -a -z "`echo $backup_destination | grep -ow 'local'`" ] && rm -rf $PUSH_FILE
fi
done
}
for DEST in `echo $backup_destination | tr ',' ' '`
do
if [ "$DEST" == 'local' ]; then
[ -n "`echo $backup_content | grep -ow db`" ] && DB_Local_BK
[ -n "`echo $backup_content | grep -ow web`" ] && WEB_Local_BK
fi
if [ "$DEST" == 'remote' ]; then
echo "com:::[ ! -e "$backup_dir" ] && mkdir -p $backup_dir" > config_bakcup.txt
[ -n "`echo $backup_content | grep -ow db`" ] && DB_Remote_BK
[ -n "`echo $backup_content | grep -ow web`" ] && WEB_Remote_BK
./mabs.sh -c config_bakcup.txt -T -1 | tee mabs.log
fi
if [ "$DEST" == 'cos' ]; then
[ -n "`echo $backup_content | grep -ow db`" ] && DB_COS_BK
[ -n "`echo $backup_content | grep -ow web`" ] && WEB_COS_BK
fi
if [ "$DEST" == 'upyun' ]; then
[ -n "`echo $backup_content | grep -ow db`" ] && DB_UPYUN_BK
[ -n "`echo $backup_content | grep -ow web`" ] && WEB_UPYUN_BK
fi
done