Skip to content

Commit a91ac85

Browse files
committed
added LA and Disk space verifications
1 parent 465383c commit a91ac85

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

bin/v_backup_sys_user

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ is_user_valid
3636
# Checking user backups
3737
is_backup_enabled
3838

39+
# Checking load averages
40+
la=$(cat /proc/loadavg |cut -f 1 -d ' '|cut -f 1 -d '.')
41+
i=0
42+
while [ "$la" -ge "$V_BACKUP_LA_LIMIT" ]; do
43+
if [ -z "$output" ]; then
44+
echo "$(date +%m-%d-%y" "%H:%m:%S) Load Average $la"
45+
echo
46+
fi
47+
48+
sleep 60
49+
50+
if [ "$i" -ge "15" ]; then
51+
echo "Error: LA is too high"
52+
log_event 'debug' "$E_LOAD_AVERAGE $V_EVENT"
53+
exit $E_LOAD_AVERAGE
54+
fi
55+
56+
i=$((i + 1))
57+
done
58+
3959

4060
#----------------------------------------------------------#
4161
# Action #
@@ -383,7 +403,7 @@ local_backup(){
383403
fi
384404

385405
# Checking retention
386-
archives=$(ls -lrt $V_BACKUP/ |awk '{print $9}' |grep "^$user.")
406+
archives=$(ls -lrt $V_BACKUP/ |awk '{print $9}' |grep "^$user\.")
387407
archives_q=$(echo "$archives" |wc -l)
388408
if [ "$archives_q" -ge "$backups" ]; then
389409
archives_r=$((archives_q - backups))
@@ -396,9 +416,20 @@ local_backup(){
396416
done
397417
fi
398418

419+
# Checking disk space
420+
disk_usage=$(df $V_BACKUP | awk '{print $5}'|tail -n1|cut -f 1 -d '%')
421+
if [ "$disk_usage" -ge "$V_BACKUP_DISK_LIMIT" ]; then
422+
echo "Error: Not enough disk space"
423+
log_event 'debug' "$E_DISK_SPACE $V_EVENT"
424+
exit $E_DISK_SPACE
425+
fi
426+
399427
# Creating final tarball
400428
cd $tmpdir
401429
tar -cf $V_BACKUP/$user.$V_DATE.tar .
430+
chmod 640 $V_BACKUP/$user.$V_DATE.tar
431+
chown root:$user $V_BACKUP/$user.$V_DATE.tar
432+
402433
localbackup='yes'
403434

404435
if [ -z "$output" ]; then
@@ -458,7 +489,7 @@ ftp_backup(){
458489
fi
459490

460491
# Checking retention
461-
archives=$(ftpc "ls" |awk '{print $9}' |grep "^$user.")
492+
archives=$(ftpc "ls" |awk '{print $9}' |grep "^$user\.")
462493
archives_q=$(echo "$archives" | wc -l)
463494
if [ "$archives_q" -ge "$backups" ]; then
464495
# Removing old backups

0 commit comments

Comments
 (0)