v_backup_sys_user 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/bin/bash
  2. # info: backup system user with all its objects
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. output="$2"
  9. # Importing variables
  10. source $VESTA/conf/vars.conf
  11. source $V_FUNC/shared_func.sh
  12. source $V_FUNC/domain_func.sh
  13. source $V_FUNC/db_func.sh
  14. source $V_CONF/vesta.conf
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '1' "$#" 'user [output]'
  20. # Checking argument format
  21. format_validation 'user'
  22. # Checking user
  23. is_user_valid
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. # Creating temporary random directory
  28. tmpdir=$(mktemp -p $V_TMP -d)
  29. # Prinitng status
  30. if [ -z "$output" ]; then
  31. echo "$(date +%m-%d-%y" "%H:%m:%S) System backup for user $user"
  32. echo "TMPDIR is $tmpdir"
  33. fi
  34. # WEB domains
  35. if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
  36. if [ -z "$output" ]; then
  37. echo "-- WEB --"
  38. fi
  39. mkdir $tmpdir/web/
  40. # Parsing unsuspeneded domains
  41. conf="$V_USERS/$user/web.conf"
  42. field='$DOMAIN'
  43. search_string='DOMAIN='
  44. domains=$(dom_clear_search)
  45. for domain in $domains; do
  46. if [ -z "$output" ]; then
  47. echo -e "\t$(date +%H:%m:%S) $domain"
  48. fi
  49. # Defining domain variables
  50. domain_idn=$(idn -t --quiet -a "$domain")
  51. tpl_name=$(get_web_domain_value '$TPL')
  52. ssl_cert=$(get_web_domain_value '$SSL_CERT')
  53. nginx=$(get_web_domain_value '$NGINX')
  54. # Building directory tree
  55. mkdir -p $tmpdir/web/$domain/conf $tmpdir/web/$domain/cert
  56. # Packing data folders
  57. cd $V_HOME/$user/web/$domain
  58. tar -cf $tmpdir/web/$domain/$domain.tar \
  59. public_html public_shtml private document_errors cgi-bin stats
  60. # Creating web.config
  61. cd $tmpdir/web/$domain/
  62. conf="$V_USERS/$user/web.conf"
  63. grep "DOMAIN='$domain'" $conf > conf/web.conf
  64. # Apache config
  65. if [ "$WEB_SYSTEM" = 'apache' ]; then
  66. # Parsing httpd.conf
  67. tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
  68. conf="$V_HOME/$user/conf/httpd.conf"
  69. get_web_config_brds
  70. sed -n "$top_line,$bottom_line p" $conf > conf/httpd.conf
  71. # SSL check
  72. if [ ! -z "$ssl_cert" ]; then
  73. tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
  74. conf="$V_HOME/$user/conf/shttpd.conf"
  75. get_web_config_brds
  76. sed -n "$top_line,$bottom_line p" $conf > conf/shttpd.conf
  77. fi
  78. fi
  79. # Nginx config
  80. if [ ! -z "$nginx" ] ; then
  81. tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
  82. conf="$V_HOME/$user/conf/nginx.conf"
  83. get_web_config_brds
  84. sed -n "$top_line,$bottom_line p" $conf > conf/nginx.conf
  85. # SSL check
  86. if [ ! -z "$ssl_cert" ] ; then
  87. tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
  88. conf="$V_HOME/$user/conf/snginx.conf"
  89. get_web_config_brds
  90. sed -n "$top_line,$bottom_line p" $conf > conf/snginx.conf
  91. fi
  92. fi
  93. # Suplemental configs
  94. for sconfig in $(ls $V_HOME/$user/conf/|grep ".$domain.conf"); do
  95. cp $V_HOME/$user/conf/$sconfig conf/
  96. done
  97. # SSL Certificates
  98. if [ ! -z "$ssl_cert" ] ; then
  99. cp $V_HOME/$user/conf/$ssl_cert.* cert/
  100. fi
  101. tar -rf $tmpdir/web/$domain/$domain.tar conf cert
  102. mv $tmpdir/web/$domain/$domain.tar $tmpdir/web/
  103. rm -rf $tmpdir/web/$domain
  104. gzip -$V_BACKUP_GZIP $tmpdir/web/$domain.tar
  105. done
  106. if [ -z "$output" ]; then
  107. echo
  108. fi
  109. fi
  110. # DNS domains
  111. if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
  112. if [ -z "$output" ]; then
  113. echo "-- DNS --"
  114. fi
  115. mkdir $tmpdir/dns/
  116. # Parsing unsuspeneded domains
  117. conf="$V_USERS/$user/dns.conf"
  118. field='$DOMAIN'
  119. search_string='DOMAIN='
  120. domains=$(dom_clear_search)
  121. for domain in $domains; do
  122. if [ -z "$output" ]; then
  123. echo -e "\t$(date +%H:%m:%S) $domain"
  124. fi
  125. # Building directory tree
  126. mkdir $tmpdir/dns/$domain
  127. # Creating dns_domains config
  128. cd $tmpdir/dns/$domain/
  129. conf="$V_USERS/$user/dns.conf"
  130. grep "DOMAIN='$domain'" $conf > dns.conf
  131. # Backingup dns recods
  132. cp $V_USERS/$user/zones/$domain $domain
  133. cp /etc/namedb/$domain.db $domain.db
  134. done
  135. fi
  136. # Mail domains
  137. # DatbaBases
  138. # Cron jobs
  139. # Vesta
  140. exit
  141. #----------------------------------------------------------#
  142. # Vesta #
  143. #----------------------------------------------------------#
  144. # Logging
  145. log_event 'system' "$V_EVENT"
  146. exit $OK