SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Wednesday, June 1, 2011

rsync for beginners

rsync -azv --progress --append --exclude=filename1 filename2  -e "ssh [options]" source destination

Options:
-a :  The files are transferred in "archive" mode, which ensures that symbolic links,
devices, attributes, permissions, ownerships, recursive etc 

-z : enable compression

-v : verbose

--progress : displays the progress of file transfer. This is useful if the file size is big

--append :  rsync will resume file transfer from a broken pipe.

--exclude : listed files will not be transfered.


-e : Specify the remote shell to use


Example :
rsync -azv --progress --append --exclude=sample.txt -e "ssh -p 22022" /home/user_source/ user_destination@123.123.123.123:/home/user_destination/backup/

In the above example all the files and folder from source directory ( /home/user_source/ )  will be transfered in archive mode to the destination folder (/home/user_destination/backup/ ), where the destination computer accepts connection on port 22022. If the connection breaks, running the above command will resume the incomplete file transfer.


Importance of trailing slash

A trailing / on a source name means "copy the contents of this directory". Without a trailing slash it means "copy the directory". 



Example:


   rsync -a foo/ bar/


directory bar will end up with a copy of the contents of foo. So a file foo/wibble.txt will end up as bar/wibble.txt. If on the other hand you say:


   rsync -a foo bar/


then you end up with a directory structure 'bar/foo/...', and wibble.txt ends up as bar/foo/wibble.txt


Other than that, the presence or absence of the trailing slash on the *target* directory doesn't make a great deal of difference.  I usually try and work things so that the rsync command line always has trailing slashes on both the source and the destination directories simply for consistencies' sake.

No comments:

Post a Comment