Skip to content

Commit 09dc570

Browse files
committed
hestiacp#1245 FIx issue with delete backups
1 parent e167c2e commit 09dc570

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

bin/v-backup-user

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,16 +597,26 @@ echo -e "\n-- SUMMARY --" |tee -a $BACKUP/$user.log
597597
for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
598598
case $backup_type in
599599
local) local_backup ;;
600-
ftp) ftp_backup ;;
601-
sftp) sftp_backup ;;
600+
ftp) backup_error=$(ftp_backup) ;;
601+
sftp) backup_error=$(sftp_backup) ;;
602602
google) google_backup ;;
603-
b2) b2_backup ;;
603+
b2) backup_error=$(b2_backup) ;;
604604
esac
605605
done
606606

607607
# Removing tmpdir
608608
rm -rf $tmpdir
609609

610+
if [[ ! -z $backup_error ]]; then
611+
if [[ "$BACKUP_SYSTEM" =~ "local" ]]; then
612+
echo -e "\nLocal backup was successfully executed. How ever the remote backup failed for reason:"
613+
echo -e "\n$backup_error"
614+
BACKUP_SYSTEM="local"
615+
else
616+
echo -e "\nBack up failed due to: \n$backup_error"
617+
exit $error_code;
618+
fi
619+
fi
610620
# Calculation run time
611621
run_time=$((end_time - start_time))
612622
run_time=$((run_time / 60))

func/backup.sh

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local_backup(){
2525
rm -rf $tmpdir
2626
rm -f $BACKUP/$user.log
2727
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
28-
echo "Not enough disk space" |$SENDMAIL -s "$subj" $email $notify
28+
echo "Not enough disk space" |$SENDMAIL -s "$subj" $email "yes"
2929
check_result "$E_DISK" "Not enough dsk space"
3030
fi
3131

@@ -58,11 +58,11 @@ ftp_backup() {
5858
# Checking config
5959
if [ ! -e "$HESTIA/conf/ftp.backup.conf" ]; then
6060
error="ftp.backup.conf doesn't exist"
61-
rm -rf $tmpdir
62-
rm -f $BACKUP/$user.log
63-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
61+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
6462
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
65-
check_result "$E_NOTEXIST" "$error"
63+
echo "$error"
64+
error_code=$E_NOTEXIST
65+
return "$E_NOTEXIST"
6666
fi
6767

6868
# Parse config
@@ -76,11 +76,10 @@ ftp_backup() {
7676
# Checking variables
7777
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
7878
error="Can't parse ftp backup configuration"
79-
rm -rf $tmpdir
80-
rm -f $BACKUP/$user.log
81-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
79+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
8280
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
83-
check_result "$E_PARSING" "$error"
81+
error_code=$E_PARSING
82+
return "$E_PARSING"
8483
fi
8584

8685
# Debug info
@@ -91,11 +90,11 @@ ftp_backup() {
9190
ferror=$(echo $fconn |grep -i -e failed -e error -e "Can't" -e "not conn")
9291
if [ ! -z "$ferror" ]; then
9392
error="Error: can't login to ftp ftp://$USERNAME@$HOST"
94-
rm -rf $tmpdir
95-
rm -f $BACKUP/$user.log
96-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
93+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
9794
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
98-
check_result "$E_CONNECT" "$error"
95+
echo "$error"
96+
error_code=$E_CONNECT
97+
return "$E_CONNECT"
9998
fi
10099

101100
# Check ftp permissions
@@ -109,11 +108,10 @@ ftp_backup() {
109108
ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir" |grep -v Trying)
110109
if [ ! -z "$ftp_result" ] ; then
111110
error="Can't create ftp backup folder ftp://$HOST$BPATH"
112-
rm -rf $tmpdir
113-
rm -f $BACKUP/$user.log
114-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
111+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
115112
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
116-
check_result "$E_FTP" "$error"
113+
error_code=$E_FTP
114+
return "$E_FTP"
117115
fi
118116

119117
# Checking retention
@@ -277,11 +275,11 @@ sftp_backup() {
277275
# Checking config
278276
if [ ! -e "$HESTIA/conf/sftp.backup.conf" ]; then
279277
error="Can't open sftp.backup.conf"
280-
rm -rf $tmpdir
281-
rm -f $BACKUP/$user.log
282-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
278+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
283279
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
284-
check_result "$E_NOTEXIST" "$error"
280+
echo "$error"
281+
error_code=$E_NOTEXIST
282+
return "$E_NOTEXIST"
285283
fi
286284

287285
# Parse config
@@ -295,11 +293,11 @@ sftp_backup() {
295293
# Checking variables
296294
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
297295
error="Can't parse sftp backup configuration"
298-
rm -rf $tmpdir
299-
rm -f $BACKUP/$user.log
300-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
296+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
301297
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
302-
check_result "$E_PARSING" "$error"
298+
echo "$error"
299+
error_code=$E_PARSING
300+
return "$E_PARSING"
303301
fi
304302

305303
# Debug info
@@ -320,11 +318,11 @@ sftp_backup() {
320318
$E_CONNECT) error="Can't login to sftp host $HOST" ;;
321319
$E_FTP) error="Can't create temp folder on sftp $HOST" ;;
322320
esac
323-
rm -rf $tmpdir
324-
rm -f $BACKUP/$user.log
325-
echo "$error" |$SENDMAIL -s "$subj" $email $notify
321+
echo "$error" |$SENDMAIL -s "$subj" $email "yes"
326322
sed -i "/ $user /d" $HESTIA/data/queue/backup.pipe
327-
check_result "$rc" "$error"
323+
echo "$error"
324+
error_code=$rc
325+
return "$rc"
328326
fi
329327

330328
# Checking retention

0 commit comments

Comments
 (0)