Making a backup reminder script

105

Author: Duane Odom

I like to back up the data on my laptop computer as often as possible, just in case I have trouble with it. I have some large files on the laptop that prevent me from scheduling an Internet backup to my home machine, so I have written a script that reminds me to periodically plug in an external USB drive; then upon clicking continue, the reminder script runs my custom backup script.

I use the at scheduling daemon to schedule the backup reminders, and xdialog to present a graphical interface for the reminders. The script presents a GUI that prompts you to prepare for your backup (plug in your USB drive, bring up your network interface, etc.). It then prompts you to click either the Continue button, which runs your backup script and upon completion schedules the next reminder, or click the Snooze button, which delays the reminder by a definable amount of time. You can also close the window without responding, which skips the reminder and schedules the next one. The script sends you an email message upon successful completion of a backup, failure of a backup, or skipping a backup. This loop continues until you decide to break it.

Since the reminders are scheduled using the at daemon, you can use the command atq to see when the next reminder is scheduled, and atrm (with the job number) to remove the reminder from the schedule. If you remove a reminder with atrm, you break the loop, so you must run the backup_reminder script manually to get it started again.

To try my script yourself, download it and copy it to a location in your path, give it executable permissions (chmod +x backup_reminder) and run it to perform the first backup.

You’ll need to write your own backup script to perform the actual backup when your reminder pops up. My current backup script simply mounts the USB hard drive, calls rsync to sync the drive with my local data, and unmounts the drive when the synchronization is complete. Here are a couple of links to articles that may help you to use rsync in your backup script and to prepare a USB hard drive for use as your backup drive.

It’s best to write your backup script such that it returns sensible values if it fails. For instance, if my script fails to mount the USB drive it will exit with code “1” to indicate a failure, which allows the backup reminder script to send me an email message indicating the failure. You can make the error reporting much more complex and informative by using more exit codes.

If you don’t like Xdialog’s GUI style, you can try Gtkdialog, zenity or kdialog as dialog generators.

Category:

  • System Administration