فهرست منبع

#1245 FIx issue with delete backups

Jaap Marcus 4 سال پیش
والد
کامیت
09dc570c9c
2فایلهای تغییر یافته به همراه40 افزوده شده و 32 حذف شده
  1. 13 3
      bin/v-backup-user
  2. 27 29
      func/backup.sh

+ 13 - 3
bin/v-backup-user

@@ -597,16 +597,26 @@ echo -e "\n-- SUMMARY --" |tee -a $BACKUP/$user.log
 for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
     case $backup_type in
         local) local_backup ;;
-        ftp)   ftp_backup ;;
-        sftp)  sftp_backup ;;
+        ftp)   backup_error=$(ftp_backup) ;;
+        sftp)  backup_error=$(sftp_backup) ;;
         google) google_backup ;;
-        b2) b2_backup ;;
+        b2) backup_error=$(b2_backup) ;;
     esac
 done
 
 # Removing tmpdir
 rm -rf $tmpdir
 
+if [[ ! -z $backup_error ]]; then
+    if [[ "$BACKUP_SYSTEM"  =~ "local" ]]; then 
+        echo -e "\nLocal backup was successfully executed. How ever the remote backup failed for reason:"
+        echo -e "\n$backup_error"
+        BACKUP_SYSTEM="local"
+    else
+        echo -e "\nBack up failed due to: \n$backup_error"
+        exit $error_code;
+    fi
+fi
 # Calculation run time
 run_time=$((end_time - start_time))
 run_time=$((run_time / 60))

+ 27 - 29
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"
+        error_code=$E_NOTEXIST
+        return "$E_NOTEXIST"
     fi
 
     # Parse config
@@ -76,11 +76,10 @@ 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"
+        error_code=$E_PARSING
+        return "$E_PARSING"
     fi
 
     # Debug info
@@ -91,11 +90,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
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_CONNECT" "$error"
+        echo "$error"
+        error_code=$E_CONNECT
+        return "$E_CONNECT"
     fi
 
     # Check ftp permissions
@@ -109,11 +108,10 @@ 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
+        echo "$error" |$SENDMAIL -s "$subj" $email "yes"
         sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
-        check_result "$E_FTP" "$error"
+        error_code=$E_FTP
+        return "$E_FTP"
     fi
 
     # Checking retention
@@ -277,11 +275,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"
+        error_code=$E_NOTEXIST
+        return "$E_NOTEXIST" 
     fi
 
     # Parse config
@@ -295,11 +293,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"
+        error_code=$E_PARSING
+        return "$E_PARSING" 
     fi
 
     # Debug info
@@ -320,11 +318,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"
+        error_code=$rc
+        return "$rc"
     fi
 
     # Checking retention