23rd Mar 2009
Using rsync as a backup solution
I am mainly a MAC user. With the new Leopard, I was introduced to the wonderful Time Machine backup concept.
Read some about it on the internet and it seems a very smart way to perform periodic backups. The idea is to make a full backup of a given set of files and if the file is unchanged, the program just makes a hard link to the previous backup, saving time and space. Since Time Machine is designed for MAC, I searched for a solution in Linux environment. I didn’t have to search long to find out that rsync is the master utility to accomplish such task.
I start studying rsync and I can say I know close to nothing about it
But so far I grasped the basic idea that enabled me to craft a bash script to manage my backups. So far I am so impressed with it, that I decided to share this “excitment” with anyone out there in the look-out for the perfect backup solution. Rsync is great also because it allows to perform backups over the network using secure shell (ssh) as the prefered method of connection/ authentication, therefore making it flexible, powerful and easy to use.
The man page for rync is very complex, unveiling the true power of the utility. Most probably you won’t use most of the options on the day-to-day basis, but it’s a good point of reference and memory refreshing.
The script you’ll see bellow was created for linux, but I’m using it very successful on my MAC. Currently I’m backing up my remote website data, to my external hard drive connected to my MAC laptop. I created a cron job (yes, MAC also have cron) that looks like this:
30 0,3,6,9,12,15,18,22 * * * /Users/marian/bin/backup.sh hourly > /dev/null 2>&
10 13 * * * /Users/marian/bin/backup.sh daily > /dev/null 2>&
10 23 * * 6 /Users/marian/bin/backup.sh weekly > /dev/null 2>&1
0 21 1 * * /Users/marian/bin/backup.sh monthly > /dev/null 2>&1
40 22 1 12 * /Users/marian/bin/backup.sh yearly > /dev/null 2>&1
The backup.sh script looks like this:
The script might seem “hairy” at first, but is just a bunch of conditional statements to make sure the backup run smoothly unattended. If you are to accomplish the same task at the command line (not using a script), you would only enter one line. Something like this:
rsync --exclude-from /some/path/excludes.txt --link-dest=/dest/dir/hourly.0 /source/dir/ /dest/dir/hourly.latest/ 2>&1 | tee -a log.txt
I hope this helps someone.
I am mainly a MAC user. With the new Leopard, I was introduced to the wonderful Time Machine backup concept.
Read some about it on the internet and it seems a very smart way to perform periodic backups. The idea is to make a full backup of a given set of files and if the file is unchanged, the program just makes a hard link to the previous backup, saving time and space. Since Time Machine is designed for MAC, I searched for a solution in Linux environment. I didn’t have to search long to find out that rsync is the master utility to accomplish such task.
I start studying rsync and I can say I know close to nothing about it
But so far I grasped the basic idea that enabled me to craft a bash script to manage my backups. So far I am so impressed with it, that I decided to share this “excitment” with anyone out there in the look-out for the perfect backup solution. Rsync is great also because it allows to perform backups over the network using secure shell (ssh) as the prefered method of connection/ authentication, therefore making it flexible, powerful and easy to use.
The man page for rync is very complex, unveiling the true power of the utility. Most probably you won’t use most of the options on the day-to-day basis, but it’s a good point of reference and memory refreshing.
The script you’ll see bellow was created for linux, but I’m using it very successful on my MAC. Currently I’m backing up my remote website data, to my external hard drive connected to my MAC laptop. I created a cron job (yes, MAC also have cron) that looks like this:
30 0,3,6,9,12,15,18,22 * * * /Users/marian/bin/backup.sh hourly > /dev/null 2>&
10 13 * * * /Users/marian/bin/backup.sh daily > /dev/null 2>&
10 23 * * 6 /Users/marian/bin/backup.sh weekly > /dev/null 2>&1
0 21 1 * * /Users/marian/bin/backup.sh monthly > /dev/null 2>&1
40 22 1 12 * /Users/marian/bin/backup.sh yearly > /dev/null 2>&1
The backup.sh script looks like this:
The script might seem “hairy” at first, but is just a bunch of conditional statements to make sure the backup run smoothly unattended. If you are to accomplish the same task at the command line (not using a script), you would only enter one line. Something like this:
rsync --exclude-from /some/path/excludes.txt --link-dest=/dest/dir/hourly.0 /source/dir/ /dest/dir/hourly.latest/ 2>&1 | tee -a log.txt
I hope this helps someone.
Posted by marian under
General Computers, MAC, Linux
No Comments »