vortexbox.org

23 Apr 09 Automatically backup up your hard drive useing rsnapshot

Firstly follow the ‘How to add a second drive to your VortexBox’. I will assume the new hdd appears as /dev/sdb with an ext3 partition /dev/sdb1.

Create the folder /backup:

mkdir  /backup

Mount the new partition:

mount –t ext3 /dev/sdb1 /backup

Use this command to list all mounted partitions, their sizes and free space:

df –h

Install the package rsnapshot:

yum –y install rsnapshot

Now configure the rsnapshot.conf file, making a copy of the original just in case:

cd /etc
cp rsnapshot.conf old.rsnapshot.conf
nano rsnapshot.conf

Move the cursor to the line; snapshot_root and change it to read: (important – use tab not space to separate snapshot_root from /backup/)

snapshot_root /backup/

Next add the location of files to be backed up, scroll down the file until you find the backup points section. Comment out i.e. add# in front of the existing entries and then add you own, again using tab and not space:

backup /storage/ localhost/

Save the changes and exit. You are now ready to run a test; this will check the syntax without making any changes:

rsnapshot –t hourly

If all goes according to plan this next command will copy all of the files and folders in /storage to /backup, depending on the amount of data you have this may take minutes or even hours to complete, don’t worry if it takes a long time, subsequent backups will be much quicker as rsnapshot will only copy additions and changes:

rsnapshot hourly

The next step is to automate rsnapshot. To do this you need to add entries into the following folders; /etc/cron.hourly /etc/cron.daily and /etc/cron.weekly.

cd /etc/cron.hourly
nano rsnapshot_hourly

Copy the following into the file:

/usr/bin/rsnapshot hourly

Save and close. You now need to alter the permissions to allow the script to run:

chmod 755 rsnapshot_hourly

Repeat the above for /etc/cron.daily and /etc/cron.weekly, changing the text in the file accordingly.

Congratulations! You are now backing up you files, once an hour, once a day and once a week. If you look in /backup you will see folders:

daily.0
hourly.0
hourly.1
hourly.2

Looking at the folders, these represent:

daily.0 -contains the last daily backup
hourly.0 -contains the last hourly backup
hourly.1 -contains the backup from an hour ago and so on

So should you accidentally edit or delete a file and later wish to retrieve it, you can fall back to a backup that was made before the edit/delete, simply copy the file back to /storage from /backup. The easiest way to do this would be to add the following to /etc/samba/smb.conf:

[backup]
path = /backup
guest ok = yes
writeable = no
create mask = 0777

This will make your backups visible, but write protected, in your samba shares. If you have a hard drive failure on your main drive you now have a backup copy of your files. To be extra secure your could use a pair of USB hard drives that you cycle weekly or monthly and store one offsite in case of fire/flood/earthquake/burglary/plague of locusts etc.

This article was contributed by blazingtortoise.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • PDF
  • Propeller
  • Technorati
  • Twitter