Rsync: Transferring files between two hosts

Rsync is a versatile file copying tool. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync also has options to delete extraneous files from the receiving side (ones that aren’t on the sending side), but only for the directories that are being synchronized.

Configuring Rsync:

rsync -av --exclude 'share/web/moodle/sessions/' --exclude 'share/wordpress/uploads/wpcf7_captcha/' --delete --rsync-path "sudo rsync" /data/ 172.31.X.X:/data/ &>/home/fsync/rsyncjob/output.


Options Description:

--archive : Copies recursively (all directories and  
            subdirectories) while preserving symbolic links, 
            permissions, file ownerships and timestamps.

--exclude : This option allows you to add rules to selectively  
            exclude certain files from the list of files to be   
            transferred . The path should be relative path and  
            not absolute path to exclude. 

--delete  : This deletes file on receiving side that are not 
            available/removed on sending side. 

--rsync-path : This specifies what program  is to be run on the 
               remote machine to start-up rsync. Often used  
               when rsync is not in the default remote-shell’s 
               path (e.g. --rsync-path=/usr/local/bin/rsync)

In the above example , we are using the rsync-path option to use sudo wrapper on destination host .

Following further configuration needs to be setup to enable sudo  and also password-less access for that particular user which will be used to transfer the files .

Enable the following settings in /etc/sudoers

Defaults:fsync    !requiretty
Cmnd_Alias FSYNC = /usr/bin/rsync
fsync   ALL=(ALL)       NOPASSWD: FSYNC



Comments

Popular Posts