-
Notifications
You must be signed in to change notification settings - Fork 0
/
fback0.1
executable file
·109 lines (95 loc) · 2.13 KB
/
fback0.1
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
#!/bin/sh
# SET FTP server you want back up to
FTP_HOST=
FTP_USER=
FTP_PASS=
# Auto clear the backup file
AUTO_CLEAN=
# Set the package directory
BAK_DIR="/root/backnmp/fnmp"
# Set Databases Directory to back up
DB="/usr/local/mysql/var"
# Set Nginx-Configure file to back up
CONF_NGINX="/usr/local/nginx/conf"
# Set Apache-Configure file to back up
CONF_APACHE="/usr/local/apache/conf"
# Set WWWROOT to back up
WWWROOT="/home/wwwroot"
# Set Other File to back up
FILE=""
# Begin
clear
echo "Running the fback script now ..."
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script!"
exit 1
fi
BAK_NAME=backup_`date +%Y%m%d_%H%M_%S`
mkdir -p $BAK_NAME/db $BAK_NAME/conf/nginx $BAK_NAME/wwwroot
cd $BAK_NAME
if [ -n "$DB" ]; then
echo "Copy databases..."
cp -rf $DB/* db
rm -rf db/*.*
fi
if [ -n "$CONF_NGINX" ]; then
echo "Copy nginx-conf files..."
cp -rf $CONF_NGINX/* conf/nginx
fi
if [ -f "/root/lnmpa" ] && [ -n "$CONF_APACHE" ]; then
echo "Copy apache-conf files..."
mkdir conf/apache
cp -rf $CONF_APACHE/* conf/apache
fi
if [ -n "$WWWROOT" ]; then
echo "Copy wwwroot..."
cp -rf $WWWROOT/* wwwroot
fi
if [ -n "$FILE" ]; then
echo "Copy other files..."
mkdir file
cp -rf $FILE/* file
fi
echo "Buid restore script..."
cat >restore0.1<<EOF
cp -rf db/* $DB
chown -R mysql:mysql $DB/*
cp -rf wwwroot/* $WWWROOT
chown -R www:www $WWWROOT
if [ -d "file" ]; then
cp -rf file/* $FILE
fi
if [ -f "/root/lnmpa" ]; then
cp -rf conf/nginx/* $CONF_NGINX
cp -rf conf/apache/* $CONF_APACHE
/root/lnmpa restart
else
cp -rf conf/nginx/* $CONF_NGINX
/root/lnmpa restart
fi
EOF
cd ..
echo "Compress..."
mkdir -p $BAK_DIR
tar czf $BAK_NAME.tar $BAK_NAME
mv -f $BAK_NAME.tar $BAK_DIR
rm -rf $BAK_NAME
if [ -n "$FTP_HOST" ] && [ -n "$FTP_USER" ] && [ -n "$FTP_PASS" ]; then
cd $BAK_DIR
echo "Ftp file to server"
ftp -n $FTP_HOST > ftp.log 2>&1 <<EOF
user $FTP_USER $FTP_PASS
binary
put $BAK_NAME.tar
bye
EOF
if [ "$AUTO_CLEAN" = "yes" ]; then
rm -rf $BAK_NAME.tar
fi
cat ftp.log
rm -f ftp.log
fi
echo -e "Backup Success, Visit \e[0;32mhttp://ahuang.org\e[0m for more information."
echo " "
echo " "