Skip to content

Commit d5e45f2

Browse files
committed
Handle error code correctly
1 parent 0d40041 commit d5e45f2

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

bin/v-backup-user

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,27 +593,29 @@ backup_new_date=$(date +"%Y-%m-%d_%H-%M-%S")
593593

594594
echo -e "\n-- SUMMARY --" |tee -a $BACKUP/$user.log
595595

596+
errorcode="0"
596597
# Switching on backup system types
597598
for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
598599
case $backup_type in
599600
local) local_backup ;;
600-
ftp) backup_error=$(ftp_backup) ;;
601-
sftp) backup_error=$(sftp_backup) ;;
601+
ftp) ftp_backup ;;
602+
sftp) sftp_backup ;;
602603
google) google_backup ;;
603-
b2) backup_error=$(b2_backup) ;;
604+
b2) b2_backup ;;
604605
esac
605606
done
606607

607608
# Removing tmpdir
608609
rm -rf $tmpdir
609-
610-
if [[ ! -z $backup_error ]]; then
610+
if [[ "$errorcode" != "0" ]]; then
611611
if [[ "$BACKUP_SYSTEM" =~ "local" ]]; then
612-
echo -e "\nLocal backup was successfully executed. Remote backup failed for reason:"
613-
echo -e "\n$backup_error"
612+
echo -e "$(date "+%F %T") *** Local backup was successfully executed. Remote backup failed ***" |\
613+
tee -a $BACKUP/$user.log
614614
BACKUP_SYSTEM="local"
615615
else
616-
echo -e "\nBack up failed due to: \n$backup_error"
616+
echo -e "$(date "+%F %T") *** Remote backup failed ***" |\
617+
tee -a $BACKUP/$user.log
618+
617619
exit $error_code;
618620
fi
619621
fi

func/backup.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ftp_backup() {
6161
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
6262
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
6363
echo "$error"
64-
error_code=$E_NOTEXIST
64+
errorcode="$E_NOTEXIST"
6565
return "$E_NOTEXIST"
6666
fi
6767

@@ -78,7 +78,8 @@ ftp_backup() {
7878
error="Can't parse ftp backup configuration"
7979
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
8080
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
81-
error_code=$E_PARSING
81+
echo "$error"
82+
errorcode="$E_PARSING"
8283
return "$E_PARSING"
8384
fi
8485

@@ -90,10 +91,10 @@ ftp_backup() {
9091
ferror=$(echo $fconn |grep -i -e failed -e error -e "Can't" -e "not conn")
9192
if [ ! -z "$ferror" ]; then
9293
error="Error: can't login to ftp ftp://$USERNAME@$HOST"
93-
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
94+
echo "$error" |$SENDMAIL -s "$subj" $email $notify
9495
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
9596
echo "$error"
96-
error_code=$E_CONNECT
97+
errorcode="$E_CONNECT"
9798
return "$E_CONNECT"
9899
fi
99100

@@ -108,9 +109,10 @@ ftp_backup() {
108109
ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir" |grep -v Trying)
109110
if [ ! -z "$ftp_result" ] ; then
110111
error="Can't create ftp backup folder ftp://$HOST$BPATH"
111-
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
112+
echo "$error" |$SENDMAIL -s "$subj" $email $notify
112113
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
113-
error_code=$E_FTP
114+
echo "$error"
115+
errorcode="$E_FTP"
114116
return "$E_FTP"
115117
fi
116118

@@ -278,7 +280,7 @@ sftp_backup() {
278280
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
279281
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
280282
echo "$error"
281-
error_code=$E_NOTEXIST
283+
errorcode="$E_NOTEXIST"
282284
return "$E_NOTEXIST"
283285
fi
284286

@@ -296,7 +298,7 @@ sftp_backup() {
296298
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
297299
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
298300
echo "$error"
299-
error_code=$E_PARSING
301+
errorcode="$E_PARSING"
300302
return "$E_PARSING"
301303
fi
302304

@@ -321,7 +323,7 @@ sftp_backup() {
321323
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
322324
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
323325
echo "$error"
324-
error_code=$rc
326+
errorcode="$rc"
325327
return "$rc"
326328
fi
327329

0 commit comments

Comments
 (0)