Kaynağa Gözat

Merge pull request #1741 from jaapmarcus/fix/restore-user

Fix restore-user
Kristan Kenney 4 yıl önce
ebeveyn
işleme
a35c3a78cd
3 değiştirilmiş dosya ile 52 ekleme ve 41 silme
  1. 15 2
      bin/v-backup-user
  2. 10 12
      bin/v-restore-user
  3. 27 27
      func/backup.sh

+ 15 - 2
bin/v-backup-user

@@ -70,7 +70,8 @@ let u_disk=$(grep "U_DISK=" $HESTIA/data/users/$user/user.conf |cut -f 2 -d \')*
 let v_disk=$(($(stat -f --format="%a*%S" $BACKUP)))/1024/1024
 
 if [ "$u_disk" -gt "$v_disk" ]; then
-    echo "not enough diskspace available to perform the backup." |$SENDMAIL -s "$subj" $email $notify
+    # Always notify on failure
+    echo "not enough diskspace available to perform the backup." | $SENDMAIL -s "$subj" $email "yes"
     check_result $E_LIMIT "not enough diskspace available to perform the backup."
 fi
 
@@ -82,7 +83,7 @@ fi
 tmpdir=$(mktemp -p $BACKUP_TEMP -d)
 
 if [ "$?" -ne 0 ]; then
-    echo "Can't create tmp dir $tmpdir" |$SENDMAIL -s "$subj" $email $notify
+    echo "Can't create tmp dir $tmpdir" |$SENDMAIL -s "$subj" $email "yes"
     check_result $E_NOTEXIST "can't create tmp dir"
 fi
 
@@ -592,6 +593,7 @@ backup_new_date=$(date +"%Y-%m-%d_%H-%M-%S")
 
 echo -e "\n-- SUMMARY --" |tee -a $BACKUP/$user.log
 
+errorcode="0"
 # Switching on backup system types
 for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
     case $backup_type in
@@ -605,7 +607,18 @@ done
 
 # Removing tmpdir
 rm -rf $tmpdir
+if [[ "$errorcode" != "0" ]]; then
+    if [[ "$BACKUP_SYSTEM"  =~ "local" ]]; then 
+        echo -e "$(date "+%F %T") *** Local backup was successfully executed. Remote backup failed ***" |\
+        tee -a $BACKUP/$user.log
+        BACKUP_SYSTEM="local"
+    else
+        echo -e "$(date "+%F %T") *** Remote backup failed ***" |\
+        tee -a $BACKUP/$user.log
 
+        exit $error_code;
+    fi
+fi
 # Calculation run time
 run_time=$((end_time - start_time))
 run_time=$((run_time / 60))

+ 10 - 12
bin/v-restore-user

@@ -287,12 +287,6 @@ if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then
                 FTP_USER="${user}_${FTP_USER}"
             fi
 
-            # Converting stats users
-            if [ ! -z "$STATS_USER" ]; then
-                STATS_USER=$(echo "$STATS_USER"  |sed -e "s/${old_user}_//")
-                STATS_USER="${user}_${STATS_USER}"
-            fi
-
             # Copying SSL certificates
             if [ "$SSL" = 'yes' ]; then
 
@@ -309,7 +303,7 @@ if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then
                     done
                 fi
             fi
-
+            
             # Merging web.conf keys
             str="DOMAIN='$domain' IP='$IP' IP6='$IP6' ALIAS='$ALIAS'"
             str="$str CUSTOM_DOCROOT='$CUSTOM_DOCROOT' CUSTOM_PHPROOT='$CUSTOM_PHPROOT'"
@@ -317,7 +311,8 @@ if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then
             str="$str FASTCGI_CACHE='$FASTCGI_CACHE' FASTCGI_DURATION='$FASTCGI_DURATION'"
             str="$str TPL='$TPL' SSL='$SSL' SSL_HOME='$SSL_HOME'"
             str="$str LETSENCRYPT='$LETSENCRYPT' FTP_USER='$FTP_USER'"
-            str="$str FTP_MD5='$FTP_MD5' BACKEND='$BACKEND' PROXY='$PROXY'"
+            str="$str FTP_MD5='$FTP_MD5' FTP_PATH='$FTP_PATH'"
+            str="$str BACKEND='$BACKEND' PROXY='$PROXY'"
             str="$str PROXY_EXT='$PROXY_EXT' STATS='$STATS'"
             str="$str STATS_USER='$STATS_USER' STATS_CRYPT='$STATS_CRYPT'"
             str="$str U_DISK='$U_DISK' U_BANDWIDTH='0' SUSPENDED='no'"
@@ -328,11 +323,11 @@ if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then
             if [ ! -z "$WEB_BACKEND" ]; then
                 $BIN/v-add-web-domain-backend $user $domain $BACKEND
             fi
-
-            # Rebuilding vhost
-            rebuild_web_domain_conf
         fi
-
+                
+        # Rebuilding vhost
+        rebuild_web_domain_conf
+        
         # Restoring web domain data
         if [ -d "$HOMEDIR/$user/web/$domain/public_html" ]; then
             rm -rf $HOMEDIR/$user/web/$domain/public_html/*
@@ -365,6 +360,9 @@ if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then
             find $HOMEDIR/$user/web/$domain/ -user $old_uid \
                 -exec chown -h $user:$user {} \;
         fi
+        
+        # Rebuilding web config for the second time to make sure ftp users keep working 
+        rebuild_web_domain_conf
     done
 
     # Adding user to traffic queue

+ 27 - 27
func/backup.sh

@@ -25,7 +25,7 @@ local_backup(){
         rm -rf $tmpdir
         rm -f $BACKUP/$user.log
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        echo "Not enough disk space" |$SENDMAIL -s "$subj" $email $notify
+        echo "Not enough disk space" |$SENDMAIL -s "$subj" $email "yes"
         check_result "$E_DISK" "Not enough dsk space"
     fi
 
@@ -58,11 +58,11 @@ ftp_backup() {
     # Checking config
     if [ ! -e "$HESTIA/conf/ftp.backup.conf" ]; then
         error="ftp.backup.conf doesn't exist"
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
-        echo "$error" |$SENDMAIL -s "$subj" $email $notify
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_NOTEXIST" "$error"
+        echo "$error"
+        errorcode="$E_NOTEXIST"
+        return "$E_NOTEXIST"
     fi
 
     # Parse config
@@ -76,11 +76,11 @@ ftp_backup() {
     # Checking variables
     if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
         error="Can't parse ftp backup configuration"
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
-        echo "$error" |$SENDMAIL -s "$subj" $email $notify
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_PARSING" "$error"
+        echo "$error"
+        errorcode="$E_PARSING"
+        return "$E_PARSING"
     fi
 
     # Debug info
@@ -91,11 +91,11 @@ ftp_backup() {
     ferror=$(echo $fconn |grep -i -e failed -e error -e "Can't" -e "not conn")
     if [ ! -z "$ferror" ]; then
         error="Error: can't login to ftp ftp://$USERNAME@$HOST"
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
         echo "$error" |$SENDMAIL -s "$subj" $email $notify
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_CONNECT" "$error"
+        echo "$error"
+        errorcode="$E_CONNECT"
+        return "$E_CONNECT"
     fi
 
     # Check ftp permissions
@@ -109,11 +109,11 @@ ftp_backup() {
     ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir" |grep -v Trying)
     if [ ! -z "$ftp_result" ] ; then
         error="Can't create ftp backup folder ftp://$HOST$BPATH"
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
         echo "$error" |$SENDMAIL -s "$subj" $email $notify
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_FTP" "$error"
+        echo "$error"
+        errorcode="$E_FTP"
+        return "$E_FTP"
     fi
 
     # Checking retention
@@ -277,11 +277,11 @@ sftp_backup() {
     # Checking config
     if [ ! -e "$HESTIA/conf/sftp.backup.conf" ]; then
         error="Can't open sftp.backup.conf"
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
-        echo "$error" |$SENDMAIL -s "$subj" $email $notify
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_NOTEXIST" "$error"
+        echo "$error"
+        errorcode="$E_NOTEXIST"
+        return "$E_NOTEXIST" 
     fi
 
     # Parse config
@@ -295,11 +295,11 @@ sftp_backup() {
     # Checking variables
     if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
         error="Can't parse sftp backup configuration"
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
-        echo "$error" |$SENDMAIL -s "$subj" $email $notify
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_PARSING" "$error"
+        echo "$error"
+        errorcode="$E_PARSING"
+        return "$E_PARSING" 
     fi
 
     # Debug info
@@ -320,11 +320,11 @@ sftp_backup() {
             $E_CONNECT) error="Can't login to sftp host $HOST" ;;
             $E_FTP) error="Can't create temp folder on sftp $HOST" ;;
         esac
-        rm -rf $tmpdir
-        rm -f $BACKUP/$user.log
-        echo "$error" |$SENDMAIL -s "$subj" $email $notify
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$rc" "$error"
+        echo "$error"
+        errorcode="$rc"
+        return "$rc"
     fi
 
     # Checking retention