Tuesday, June 7, 2011


Backing up data using rsync command

I have stopped using scp to copy files from computer to computer and far prefer to use rsync.
rsync command uses the same format as scp, (so there is no learning curve and if you are used to using scp, then switching to rsync is no trouble at all) rsync has the benefit of being able to continue from a failed copy, and also has a wealth of other advantages over scp.

rsync is a great tool for backing up and restoring files.

Example of the remote server and folder that needs to be backup or copied:
Remote host name: server.example.com
Remote folder: /home/serverfolder/
Remote user: user1

rsync -arv user1@serverexample.com:/home/serverfolder/ /home/cgerada

(/home/cgerada is the local folder path of the machine I am on and to were I want to copy to)
or to copy into the directory that I am currently in you could type
rsync -arv user1@serverexample.com:/home/serverfolder/ .

Here is what the "-arv" option does:
a = archive - means it preserves permissions (owners, groups), times, symbolic links, and devices.
r = recursive - means it copies directories and sub directories
v = verbose - means that it prints on the screen what is being copied
add --progress at the end of the command to get a running tally of what's going on
rsync -avr * /media/usb/ --progress

another good example

rsync -avr --progress --delete --log-file=/var/log/$(date +%Y%m%d)_rsync.log user1@serverexample.com:/home/folder/ /home/folder/

will create a log file and document the progress into the logfile
-- delete will delete on the destination server what ever files have been deleted from the source  (it wont delete files on your source server, only destination)

Excluding files

rsync -avr --exclude '*.iso' source/ destination/

Will Exclude all iso files

or you can write it like this , it doesn't matter, it still works
rsync -avr source/ destination/ --exclude '*.iso' --progress