Send email alert when backup limit exceeded

If you’re on a VPS or dedicated server and paying for our automatic backup service, you might like to know when you’ve gone over the current backup disk-space limit you’re paying for.

Email alert script

Below we’ll create a disk-space monitoring script that can email us when our backup limit is exceeded.

This requires having root access to your server already.

 

  1. Login to your server with SSH
  2. Run the following commands to create our script:
    touch /etc/cron.daily/backupDiskCheck.cron chmod 755 /etc/cron.daily/backupDiskCheck.cron 
  3. Now 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
  4. If you were following along and using nano to edit this file, you can now hit Ctrl-O to bring up the write file dialog, and then hit Enter to save your changes.

Now once a day your server should check to see if the disk-space usage is over the current level of automatic backups you’re paying for.

If it does exceed this limit, then you should receive an email at the address you entered with a message like:

 03/Sep/2013 16:28:04: Your server vps0123.inmotionhosting.com is currently OVER the 10G automatic backup limit, and is using 28G on the / partition.
InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X