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.\n\n$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.
   With some assistance I was able to take down the hanging shelve that hung over my main work bench.  It had an off-shoot shelve next to it that hold the network switch, router and single board computers.  That shelve has nothing else supporting that side.  To work around this, I ran twine from the ceiling to hold it up.  There isn't a lot of weight on the shelve and twine was easier than cutting a temporary board.
   Now I have complete access to the north wall.  The first order of business was to remove the remains of some kind of shelving unit and outlets.  When I moved in, one of the standard NEMA 5-15 outlets had been wired for 240 VAC.  It was labelled as such on the outlet, but I have no idea why it was wired that way.  They make outlets specifically for 240 such as the NEMA 6-15 and I might add one myself.  In addition to the outlet being wired to double the normal voltage, it was also fed from two independent breakers.  In such a setup, if one leg tripped, the 240 VAC wouldn't turn off--it would simply lose the neutral and still have 120 VAC to ground.  So that setup had to go.
   My area is now completely run from my own sub-panel.  I had to disconnect the lights from the switch when I rotated the main bench.  So I put a temporary plug on the wires for the lights and just unplug them at the end of the day.  I used one of the boxes I took down as a temporary power box.
   With the wall exposed I can move onto the next step of getting it ready for insulation.  But that will have to wait until next year.