Bash – File Backup Script

image_pdfimage_print

This script uses rdiff-backup to backup files on a Linux host using rysnc. The script then sends an email that notifies of it’s completion. Make sure to install the rdiff-backup package on your distro before running it.

#!/bin/bash

#Backup script
#By: Ronny L. Bull

SUBJECT="System Backup";
TO="youremail@yourdomain.com";
MESSAGE="System backup completed";

#backup from one location to another
nice -19 rdiff-backup --exclude /boot/lost+found /boot/ /var/backup/boot/

nice -19 rdiff-backup --exclude /home/lost+found /home/ /var/backup/home/

nice -19 rdiff-backup /etc/ /var/backup/etc/

nice -19 rdiff-backup /root/ /var/backup/root/

echo "Subject: $SUBJECT
$MESSAGE" | sendmail $TO

exit

Script Notes:

The script uses a nice value of -19 so that it does not interfere too much with other running processes since file copying is a fairly taxing IO process. Also passing the –exclude flag to rdiff-backup allows you to exclude certain directories from being backed up, such as LOST+FOUND.

  1. No Comments