Setting email alert when backup limit exceeds
If you have hosted your web site on a VPS or a dedicated server, you would possibly like to get an update if this current backup disk-space limit exceeds.
So here is a step by step method to create a disk-space monitoring script that may send you an email if the backup limit exceeds.
To your server, you must be already having root access.
Step: 1. Login to your server with SSH
Step: 2. Run the following commands to create a script:
touch /etc/cron.daily/backupDiskCheck.cron
chmod 755 /etc/cron.daily/backupDiskCheck.cron
Step: 3. Now by using a text editor like nano create the following script:
nano /etc/cron.daily/backupDiskCheck.cron
Change the [email protected] address and the 10 threshold below:
#!/bin/bash
ADMIN=”[email protected]”
THRESHOLD=10
df -h | awk ‘/\/$/ {print $3,$NF}’ | while read output;
do
usedDisk=$(echo $output | awk ‘{print $1}’ | sed ‘s#G##’)
partition=$(echo $output | awk ‘{print $2}’)
if [ $usedDisk -ge $THRESHOLD ] && [ $partition = “/” ]
then
echo “$(date +%d/\%h/%Y” “%T): Your server $(hostname) is OVER the \
$(echo $THRESHOLD)G automatic backup limit, you’re using $(echo $usedDisk)G on \
the $partition partition.” | mail -s”Alert: Over Automatic Backup limit” $ADMIN
fi
done
Step: 4. If you were following along and using nano to edit this file, you can now press Ctrl-O to bring up the write file dialog, and then press Enter to save the changes.
Now once a day your server will check to see if the disk-space usage is over the current level of automatic backups or not.
If the limit exceeds, you will receive an email at the email address you entered in the script.