Tuesday, September 25, 2012

Rsync for backups

On my home network I had a need to backup my server and several desktops.  I went out and bought a 2TB external USB drive which I use for this. I decided to use rsync to do the backups and would have it run by cron.

Backup Script.
Here is the script that I wrote to do the backups. 
rsync -av --progress --delete --log-file=/var/log/backups/home-$(date +%Y%m%d)_rsync.log --exclude "/home/username/.gvfs" /home /blackdrive/HomeBackup
rsync -av --progress --delete --log-file=/var/log/backups/root-$(date +%Y%m%d)_rsync.log /root /blackdrive/RootBackup
rsync -av --progress --delete --log-file=/var/log/backups/storage-$(date +%Y%m%d)_rsync.log /storage /blackdrive/StorageBackup
rsync -av --progress --delete --log-file=/var/log/backups/etc-$(date +%Y%m%d)_rsync.log /etc /blackdrive/EtcBackup

I've mounted the drive at /blackdrive  ( Imaginative name.  The case is black).  Some interesting things of note in this script.  I store the logs of the backups in /var/log/backups by date.  and when backing up the home directory on my fedora server I exclude the .gvfs folder.  This is a virtual filesystem used by my desktop that no other processes seem to be able to open and it causes rsync to report problems.  the --delete cleans out files on the target drive that I've deleted on the source drive. 

Cronjob.
I then created a cronjob with this entry:
0 4 * * * /root/backups.sh

This runs the backup script at 4am everyday.  I figured no one in my house would be awake at that time.

If your wondering where the backup of the other desktops occurs.  I mount the /storage volume via nfs and samba on the various boxes in my house and they all push their backups to that folder.

2 comments:

  1. Hey there! Do you know if they make any plugins to safeguard against hackers? I'm kinda paranoid about losing everything I've worked hard on. Any recommendations?

    ReplyDelete
  2. You actually make it appear really easy with your presentation but I to find this topic to be really one thing that I feel I'd by no means understand. It kind of feels too complicated and extremely wide for me. I'm looking ahead in your subsequent put up, I will attempt to get the hold of it!

    ReplyDelete