Skip to content

Commit 7761905

Browse files
committed
created backup procedure for web domains
1 parent b477d8e commit 7761905

File tree

2 files changed

+84
-15
lines changed

2 files changed

+84
-15
lines changed

bin/v_backup_sys_user

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# Argument defenition
99
user="$1"
10+
output="$2"
1011

1112
# Importing variables
1213
source $VESTA/conf/vars.conf
@@ -21,7 +22,7 @@ source $V_CONF/vesta.conf
2122
#----------------------------------------------------------#
2223

2324
# Checking arg number
24-
check_args '1' "$#" 'user'
25+
check_args '1' "$#" 'user [output]'
2526

2627
# Checking argument format
2728
format_validation 'user'
@@ -36,9 +37,18 @@ is_user_valid
3637

3738
# Creating temporary random directory
3839
tmpdir=$(mktemp -p $V_TMP -d)
39-
echo "TMPDIR is $tmpdir"
40-
# Web domains
40+
41+
# Prinitng status
42+
if [ -z "$output" ]; then
43+
echo "$(date +%m-%d-%y" "%H:%m:%S) System backup for user $user"
44+
echo "TMPDIR is $tmpdir"
45+
fi
46+
47+
# WEB domains
4148
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
49+
if [ -z "$output" ]; then
50+
echo "-- WEB --"
51+
fi
4252
mkdir $tmpdir/web/
4353

4454
# Parsing unsuspeneded domains
@@ -48,34 +58,91 @@ if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
4858
domains=$(dom_clear_search)
4959

5060
for domain in $domains; do
51-
echo $domain
61+
if [ -z "$output" ]; then
62+
echo -e "\t$(date +%H:%m:%S) $domain"
63+
fi
5264

53-
# backup_domain
65+
# Defining domain variables
66+
domain_idn=$(idn -t --quiet -a "$domain")
67+
tpl_name=$(get_web_domain_value '$TPL')
68+
ssl_cert=$(get_web_domain_value '$SSL_CERT')
69+
nginx=$(get_web_domain_value '$NGINX')
70+
71+
# Building directory tree
5472
mkdir -p $tmpdir/web/$domain/conf $tmpdir/web/$domain/cert
5573

5674
# Packing data folders
5775
cd $V_HOME/$user/web/$domain
5876
tar -cf $tmpdir/web/$domain/$domain.tar \
5977
public_html public_shtml private document_errors cgi-bin stats
6078

61-
# Creating config folder
79+
# Creating web_domains config
6280
cd $tmpdir/web/$domain/
81+
conf="$V_USERS/$user/web_domains.conf"
6382
grep "DOMAIN='$domain'" $conf > conf/web_domains.conf
6483

65-
# Parsing httpd.conf
66-
tpl_name=$(get_web_domain_value '$TPL')
67-
tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
68-
conf="$V_HOME/$user/conf/httpd.conf"
69-
70-
71-
# Parsing nginx.conf
84+
# Apache config
85+
if [ "$WEB_SYSTEM" = 'apache' ]; then
86+
# Parsing httpd.conf
87+
tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
88+
conf="$V_HOME/$user/conf/httpd.conf"
89+
get_web_config_brds
90+
sed -n "$top_line,$bottom_line p" $conf > conf/httpd.conf
91+
92+
# SSL check
93+
if [ ! -z "$ssl_cert" ]; then
94+
tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
95+
conf="$V_HOME/$user/conf/shttpd.conf"
96+
get_web_config_brds
97+
sed -n "$top_line,$bottom_line p" $conf > conf/shttpd.conf
98+
fi
99+
fi
100+
101+
# Nginx config
102+
if [ ! -z "$nginx" ] ; then
103+
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
104+
conf="$V_HOME/$user/conf/nginx.conf"
105+
get_web_config_brds
106+
sed -n "$top_line,$bottom_line p" $conf > conf/nginx.conf
107+
108+
# SSL check
109+
if [ ! -z "$ssl_cert" ] ; then
110+
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
111+
conf="$V_HOME/$user/conf/snginx.conf"
112+
get_web_config_brds
113+
sed -n "$top_line,$bottom_line p" $conf > conf/snginx.conf
114+
fi
115+
fi
116+
117+
# Suplemental configs
118+
for sconfig in $(ls $V_HOME/$user/conf/|grep ".$domain.conf"); do
119+
cp $V_HOME/$user/conf/$sconfig conf/
120+
done
121+
122+
# SSL Certificates
123+
if [ ! -z "$ssl_cert" ] ; then
124+
cp $V_HOME/$user/conf/$ssl_cert.* cert/
125+
fi
126+
127+
tar -rf $tmpdir/web/$domain/$domain.tar conf cert
128+
mv $tmpdir/web/$domain/$domain.tar $tmpdir/web/
129+
rm -rf $tmpdir/web/$domain
130+
gzip -$V_BACKUP_GZIP $tmpdir/web/$domain.tar
72131

73132
done
74-
fi
133+
if [ -z "$output" ]; then
134+
echo
135+
fi
75136

76-
exit
137+
fi
77138

78139
# DNS domains
140+
if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
141+
if [ -z "$output" ]; then
142+
echo "-- DNS --"
143+
fi
144+
mkdir $tmpdir/dns/
145+
79146

80147
# Mail domains
81148

@@ -85,6 +152,7 @@ exit
85152

86153
# Vesta
87154

155+
exit
88156

89157
#----------------------------------------------------------#
90158
# Vesta #

conf/vars.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ V_LOCK=/var/lock/vesta
2323
V_HOME='/home'
2424
V_TMP='/tmp'
2525
V_BACKUP='/backup'
26+
V_BACKUP_GZIP='5'
2627

2728
# Other vars
2829
V_SUSPEND_URL='vestacp.com/faq/acc_suspended/'

0 commit comments

Comments
 (0)