Andrew Que Sites list Photos
Projects Contact
Main

January 06, 2021

E-mails for failed backups

   I have backup scripts that run periodically.  The Backup Dragon moved off-site and is now running.  Every hour it makes a request to DrQue.net that registers the IP address.  SSH on a non-standard port allows the Data Dragon to connect to it and do backups.  With the backups running, one last item I wanted to make sure was working was e-mails in case of a failure.  I found the program msmtp which simply allows me to send e-mail from the command line.
#!/bin/bash
ip=`ssh used@webServer "cat /directory/ipAddress.txt"`
now=`date`
echo "Sync date: $now" > /path/backupReport.txt
echo "Remote IP: $ip" >> /path/backupReport.txt

start=`date +%s.%N`
rsync -arv -e 'ssh -p <port>' --exclude-from /path/exclude-list /path/to/backup/ used@$ip:/path/to/destination/ >> /path/backupReport.txt 2> /path/backupReportErrors.txt
if [ $? != 0 ]; then
  # If there was an error, send an e-mail detailing what went wrong.
  errorMessage=`cat /path/backupReportErrors.txt`
  echo "ERROR: Backups failed"
  echo -e "Subject: ERROR: Backups failed.

$errorMessage" | msmtp username@domain
fi

end=`date +%s.%N`
delta=`awk '{print $1-$2}' <<< "$end $start"`
now=`date`
echo "Finished: $now ($delta seconds)" >> /path/backupReport.txt
   This script first logs into the webserver to fetch the saved IP address of the remote machine.  Then it creates a backup report file, notes the current time and the IP address of the remote machine.  Then rsync is used over SSH to synchronize the two servers.  Output is logged to the backup report, and errors are logged to a separate log file.  If rsync runs into any problems, an e-mail is composed with the contents of the error report and sent using msmtp.  Lastly the time it took to run the backup is calculated and written to the backup report.
   The script should run on any Linux system and only requires rsync and msmtp.  I use a similar script for the daily in-house backups from the Snow Dragon to the Red Dragon.
   Picked up the last of the foam adhesive and the remaining drywall.  The work went pretty quick although the temperature in the garage seems a lot colder than it did yesterday.  With the drywall up I can start on mudding, but plan to call it a night with the progress already made.  Back to work tomorrow which means I need to setup a temporary work bench.  I thought maybe I would get everything finished so I'd have a real work bench, but that was overly optimistic.  No problem, a temporary bench is an easy thing to do.
   A lot of progress made on the north wall.  First I built a dust tent and put an exhaust blower in the window.  I had to cut off a couple of metal ties used when pouring the foundation.  Then I had to grind some high points of the basement wall down.  Last time I did this I filled the basement with a thick layer of concrete dust.  This time the dust was much less, although it did escape the dust tent. 
   After grinding I washed the wall, and then painted the bare sections.  After that I put up the first layer of foam insulation, followed by the studs using for framing.  I recycled some wood from my old setup (the black studs).  I'm not a fan of the concrete screws I am using as they like to break-off.  I had to drill two additional holes for the ones that broke, but the wood is securely mounted to the wall.
   Once the studs were in place I pulled out all the old rim joist insulation.  One of the mice living there must have found a bag of sun flower seeds as there were a lot of shells in one of the nests.  As before, the mice had made tunnels in the insulation.  There were not any signs they could get in from the outside at any point so I didn't have to patch anything.  After clearing out the old insulation and cleaning up the mouse leftovers I cut off all the protruding nails.  Then I cut foam insulation, installed it and caulked it.
   I got a start on the second layer of insulation on the wall but ran out of adhesive.  I'll have to pick more up tomorrow.  I needed to stop anyway as it was past 10:00 pm and I shouldn't be running the table saw that late.