Automated backup of Ubuntu user files and LVM configuration [Scheduled jobs series #1]

I’ve put together a short series on the jobs I have running on my NAS on a regular basis which I rely on to backup various config files or even the whole filesystem, or to monitor the health of my hard drives. Feel free to copy should you wish.

This script backs up & emails the following:

  • LVM config files – needed for recovering from some types of hard drive failures. These files can be used to recover from an accidental change (like deleting the wrong LV), LVM also keeps a backup copy of the most recent metadata in /etc/lvm/backup. These can be used to restore metadata to a replacement disk, or repair corrupted metadata.
  • Any user created scripts in the ~/scripts/* directory.

Okay, let’s create our backup script and open it to write contents…

Use the script below, but change the various parts of it to match your specific requirements (e.g. exactly what locations you want to backup), in particular the email address at the end which you use to send the confirmation to. You can also use a Pushbullet notification if you have set this up (see how to here).

Now make this script executable…

To run the script on a regular basis (I run it on the first of every month), add the command to cron via Webmin or via command line using guide here.

1 Comment

Leave a Reply

(email optional)