forked from vncloudsco/rclonebackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_goc.sh
219 lines (184 loc) · 6.77 KB
/
code_goc.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
SERVER_NAME="$(ifconfig | grep broadcast | awk {'print $2'} | head -1)" # get IP
# SERVER_NAME="$(ifconfig | grep broadcast | awk {'print $2'} | awk '{if(NR==1) print $0}')"
# SERVER_NAME="$(ifconfig | grep broadcast | awk {'print $2'} | sed -n 1p)"
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/root/backup/$TIMESTAMP"
MYSQLPATH="$(mysql --help | grep "Default options" -A 1 | sed -n 2p | awk {'print $2'} | sed 's/\~/\/root/')"
MYSQL_USER="$(cat /usr/local/vesta/conf/mysql.conf | awk {'print $2'} | awk -F '=' {'print $NF'} | sed "s/'//g")"
MYSQL_PASSWORD="$(cat /usr/local/vesta/conf/mysql.conf | awk {'print $3'} | awk -F '=' {'print $NF'} | sed "s/'//g")"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
SECONDS=0
CHECKSQL="$(ls /usr/bin/ | grep mysql)"
NGINX="$(ls /etc/ | grep nginx)"
NGINX_DIR="$(nginx -V 2>&1 | grep -o '\-\-conf-path=\(.*conf\)' | grep -o '.*/' | awk -F '=' {'print $NF'})"
HTTPD="$(ls /etc/ | grep -w httpd)"
HTTPD_DIR="$(httpd -S 2>&1 | grep ServerRoot | sed 's/\"//g' | awk {'print $2'})"
LOG_DIR=/var/log/
SENTORA="$(ls /var/ | grep sentora)"
KUSANAGI="$(ls /home/ | grep kusanagi)"
CWP="$(ls /usr/local/ | grep cwpsrv)"
DA="$(ls /usr/local/ | grep directadmin)"
VESTA="$(ls /usr/local/ | grep vesta)"
EE="$(ls /etc/ | grep ee)"
VNC_RCLONE="$(rclone config file | grep rclone.conf | sed 's/rclone.conf//')"
VNC_RCLONE_REMOTE="$(cat $VNC_RCLONE/rclone.conf | grep "\[" | sed 's/\[//' | sed 's/\]//')"
mkdir -p "$BACKUP_DIR"
if [[ $CHECKSQL == "mysql" ]];
then
mkdir -p "$BACKUP_DIR/mysql"
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"`
echo "Starting Backup Database";
for db in $databases; do
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.sql.gz"
done
echo "Finished";
echo '';
else
echo "VPS not install Mysql"
fi
echo "Starting Backup Website";
# Loop through /home directory
if [ "$SENTORA" = "sentora" ]
then
echo "VPS User sentora ";
echo "Backup sentora Config";
for D in /var/sentora/hostdata/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # No Cache
fi
done
cp /root/passwords.txt $BACKUP_DIR/sentora_password
cp -r /etc/sentora/configs/ $BACKUP_DIR/sentora_config
cp -r /etc/sentora/configs/apache/ $BACKUP_DIR/apache_config
cp -r /etc/sentora/configs/proftpd/ $BACKUP_DIR/apache_FTP
cp -r /var/sentora/logs/ $BACKUP_DIR/logs
cp -r /var/sentora/vmail/ $BACKUP_DIR/vmail
elif [[ "$KUSANAGI" = "kusanagi" ]]; then
echo "VPS User kusanagi ";
echo "Backup kusanagi Config";
sleep 10
for D in /home/kusanagi/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
elif [[ "$EE" = "ee" ]]; then
echo "VPS User easyengine ";
echo "Backup easyengine Config";
sleep 10
cp /etc/ee/ee.conf $BACKUP_DIR/easyengine
for D in /var/www/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
elif [[ "$VESTA" = "vesta" ]]; then
echo "VPS User vestacp ";
echo "Backup vestacp Config";
cp /usr/local/vesta $BACKUP_DIR/vesta
cp /usr/local/vesta/php/var/log/php-fpm.log $BACKUP_DIR/vesta/php-fpm.log
for D in /home/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
elif [[ "$CWP" = "cwpsrv" ]]; then
echo "VPS User CWP ";
echo "Backup CWP Config";
cp /root/.my.cnf $BACKUP_DIR/cwp
cp /usr/local/apache/conf/ and /usr/local/apache/conf.d/ $BACKUP_DIR/cwp_httpd
cp /etc/named/ $BACKUP_DIR/named
cp /var/named/ $BACKUP_DIR/var_named
for D in /home/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
elif [[ "$DA" = "directadmin" ]]; then
echo "VPS User directadmin ";
echo "Backup directadmin Config";
cp /usr/local/directadmin/conf/mysql.conf $BACKUP_DIR/directadmin
cp /etc/my.cnf $BACKUP_DIR/directadmin
for D in /home/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
else
echo "VPS User Orther Control ";
echo "Backup Config";
for D in /home/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
for D in /var/www/*; do
if [ -d "${D}" ]; then #If a directory
domain=${D##*/} # Domain name
echo "- "$domain;
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain -q -x home/$domain/wp-content/cache/**\* # Không backup cache c?a website
fi
done
fi
echo "Finished";
echo '';
echo "Starting Backup Server Configuration";
if [ "$NGINX" = "nginx" ] && [ "$HTTPD" = "httpd" ]
then
echo "Starting Backup nginx proxy, apache backend Configuration";
cp -r $NGINX_DIR $BACKUP_DIR/nginx
cp -r $HTTPD_DIR $BACKUP_DIR/httpd
cp -r $LOG_DIR $BACKUP_DIR/log
echo "Finished";
echo '';
elif [ "$NGINX" = "nginx" ];
then
echo "Starting Backup NGINX Configuration";
cp -r $NGINX_DIR/ $BACKUP_DIR/nginx
cp -r $LOG_DIR $BACKUP_DIR/log
echo "Finished";
echo '';
elif [ "$HTTPD" = "httpd" ];
then
echo "Starting Backup HTTPD (apache) Configuration";
cp -r $HTTPD_DIR $BACKUP_DIR/httpd
cp -r $LOG_DIR $BACKUP_DIR/log
echo "Finished";
echo '';
else
echo "VPS directory http, nginx not found";
fi
size=$(du -sh $BACKUP_DIR | awk '{ print $1}')
echo "Starting Uploading Backup";
for i in $VNC_RCLONE_REMOTE
do
rclone copy $BACKUP_DIR "$i:$SERVER_NAME/$TIMESTAMP" >> /var/log/rclone.log 2>&1
echo "done upload $i"
done
# Clean up
for i in $VNC_RCLONE_REMOTE
do
rclone -q --min-age 30d delete "$i:$SERVER_NAME"
echo "done remote $i"
done
rm -rf $BACKUP_DIR
echo "Finished";
echo '';
duration=$SECONDS
echo "Total $size, $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."