Rsync simplified

Rysnc is a copying tool utility.  It can work across local folders, network and even via SSH to a a remove server.

NOTE  : Rsync copies from one place to the other. It does not sync data between two folders.  It can ‘push‘ data from a ‘source‘ folder to a ‘destination‘ folder.

Usage : rsync (flags)  sourcefolder/ destinationfolder

Please note the /  after the source folder is critical to make sure files in the sourcefolder are copied to within the destinationfolder. IF the is not used, rysnc will create a new folder called sourcefolder within the destinationfolder

practical examples :

create a mirror of work/projects folder in backup/projects.

rsync -avz --delete /work/projects/   /backup/projects

create a mirror of work/projects folder in  a remote server holding backup/projects.

rsync -avz --delete /work/projects/ projpi@192.168.0.100:/backup/projects

(where projpi@192.168.0.100 is the username@remotehost:)

create a mirror of work/projects folder from  a remote server holding backup/projects.

rsync -avz --delete projpi@192.168.0.100:/backup/projects/ /work/projects

(where projpi@192.168.0.100 is the username@remotehost:)

Specify a port (in this example, port 2025) during remote copy

rsync -avPz --delete /work/projects/ -e 'ssh -p 2025' projpi@192.168.0.100:/backup/projects

Output to a log file called rsync.log :

rsync -avz --progress --delete /work/projects/   /backup/projects --log-file=/home/pi/rsync.log

flags :

-r : recursive flag – copies data recursively but does not preserve time stamps and permissions.

-a : archive flag – copies data recursively and preserves symbolic links, file permissions, time stamps and ownership of user and group.

-v : verbose flag

–verbose : increase verbosity

-q : quiet mode ; suppress non error messages

-z : compress data while file transfer

-h : human readable

-progress : show progress wile transferring data.

-delete : delete files that exist in the destination but donot exist in the source (useful while creating a mirror copy of a folder)

-remove-source-files : delete  source files after completing transfer to destination.

-n : do a dry run to test your command (always use with v to see what is happening)

–dry-run :  do a dry run to test your command (always use with v to see what is happening)

-e : to specify usage with remote shell. usage  -e ‘ssh -p 2234’

-u : skip files with newer time stamps in the destination folder.

-h : display help

–partial : keep partial file during an interrupted file transfer and delete the partial file after data transfer is complete.

-P : a very useful flag that combines –progress and –partial

 

 

 

Leave a Reply