forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_backup_sys_user
More file actions
executable file
·165 lines (126 loc) · 4.46 KB
/
Copy pathv_backup_sys_user
File metadata and controls
executable file
·165 lines (126 loc) · 4.46 KB
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
#!/bin/bash
# info: backup system user with all its objects
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
output="$2"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/domain_func.sh
source $V_FUNC/db_func.sh
source $V_CONF/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'user [output]'
# Checking argument format
format_validation 'user'
# Checking user
is_user_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Creating temporary random directory
tmpdir=$(mktemp -p $V_TMP -d)
# Prinitng status
if [ -z "$output" ]; then
echo "$(date +%m-%d-%y" "%H:%m:%S) System backup for user $user"
echo "TMPDIR is $tmpdir"
fi
# WEB domains
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
if [ -z "$output" ]; then
echo "-- WEB --"
fi
mkdir $tmpdir/web/
# Parsing unsuspeneded domains
conf="$V_USERS/$user/web_domains.conf"
field='$DOMAIN'
search_string='DOMAIN='
domains=$(dom_clear_search)
for domain in $domains; do
if [ -z "$output" ]; then
echo -e "\t$(date +%H:%m:%S) $domain"
fi
# Defining domain variables
domain_idn=$(idn -t --quiet -a "$domain")
tpl_name=$(get_web_domain_value '$TPL')
ssl_cert=$(get_web_domain_value '$SSL_CERT')
nginx=$(get_web_domain_value '$NGINX')
# Building directory tree
mkdir -p $tmpdir/web/$domain/conf $tmpdir/web/$domain/cert
# Packing data folders
cd $V_HOME/$user/web/$domain
tar -cf $tmpdir/web/$domain/$domain.tar \
public_html public_shtml private document_errors cgi-bin stats
# Creating web_domains config
cd $tmpdir/web/$domain/
conf="$V_USERS/$user/web_domains.conf"
grep "DOMAIN='$domain'" $conf > conf/web_domains.conf
# Apache config
if [ "$WEB_SYSTEM" = 'apache' ]; then
# Parsing httpd.conf
tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
conf="$V_HOME/$user/conf/httpd.conf"
get_web_config_brds
sed -n "$top_line,$bottom_line p" $conf > conf/httpd.conf
# SSL check
if [ ! -z "$ssl_cert" ]; then
tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
conf="$V_HOME/$user/conf/shttpd.conf"
get_web_config_brds
sed -n "$top_line,$bottom_line p" $conf > conf/shttpd.conf
fi
fi
# Nginx config
if [ ! -z "$nginx" ] ; then
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
conf="$V_HOME/$user/conf/nginx.conf"
get_web_config_brds
sed -n "$top_line,$bottom_line p" $conf > conf/nginx.conf
# SSL check
if [ ! -z "$ssl_cert" ] ; then
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
conf="$V_HOME/$user/conf/snginx.conf"
get_web_config_brds
sed -n "$top_line,$bottom_line p" $conf > conf/snginx.conf
fi
fi
# Suplemental configs
for sconfig in $(ls $V_HOME/$user/conf/|grep ".$domain.conf"); do
cp $V_HOME/$user/conf/$sconfig conf/
done
# SSL Certificates
if [ ! -z "$ssl_cert" ] ; then
cp $V_HOME/$user/conf/$ssl_cert.* cert/
fi
tar -rf $tmpdir/web/$domain/$domain.tar conf cert
mv $tmpdir/web/$domain/$domain.tar $tmpdir/web/
rm -rf $tmpdir/web/$domain
gzip -$V_BACKUP_GZIP $tmpdir/web/$domain.tar
done
if [ -z "$output" ]; then
echo
fi
fi
# DNS domains
if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
if [ -z "$output" ]; then
echo "-- DNS --"
fi
mkdir $tmpdir/dns/
# Mail domains
# DatbaBases
# Cron jobs
# Vesta
exit
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event 'system' "$V_EVENT"
exit $OK