Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Rsync(Remote sync) command and features  (Read 1589 times)

0 Members and 1 Guest are viewing this topic.

rinop

  • Guest
Rsync(Remote sync) command and features
« on: May 18, 2017, 12:49:55 pm »
Rysync is popular due to its features like speed,security and low bandwidth. It's quicker than scp (Secure Copy) command in light of the fact that rsync uses remote-update protocol which allows to transfer the differences between two files. In most systems have rsync accessible, you may install it using the following command :

# yum install rsync

Basic syntax of rsync:

# rsync <options> <source> <destination>


Rsync consider nearby machine as client and remote machine as Server.

Let us see few examples :

1. Synchronise a single file from one location to another within local machine  :


[root@localhost]# rsync -zvh rsynctestfile.txt   /test/rsynctestfile.txt

v – Verbose
h – Human-readable
z – Compress

by executing above command rsynctestfile.txt file will be synced to /test/rsynctestfile.txt


2. Let us see two examples of synchronise a directory to another directory within local machine :

[root@localhost]# rsync -av /rsynctestfolder/*.txt  /test/
a – archive mode

Above example will copy only matching *.txt pattern from /rsynctestfolder directory to remote directory /test/

[root@localhost]# rsync -av /rsynctestfolder /test/

by executing above example will copy data and creates a directory in destination directory because we did not give / after the directory. If we give / after rsynctestfolder directory it will not create directory in remote path it only copies files from source.

3. Synchronise data from directory to a remote machine :

[root@localhost]# rsync -tv /rsynctestfolder/*.txt remoteIPaddress:/test/
t – preserve time stamps

This will copy all files with matching pattern *.txt from the rsynctestfolder  to /test/ on the remote machine. If any of the files already exist it will send only the differences.

4. Copy data to remote host with compression option :

[root@localhost]#  rsync -azv /rsynctestfolder/ remoteIPaddress:/test/

using z option with rsync command will compress file data during the transfer to reduce bandwidth, most useful while transferring large data with remote server.

5. Synchronise data from remote host to local machine :

We can also sync data from remote machine to local host.

Please see the example below :

[root@localhost]#  rsync -azv remoteIPaddress:/test/ /rsynctestfolder/

here we copied the data, where source as remote machine and destination as local machine.

6. Without overwriting updated destination path files :

[root@localhost]# rsync -azuv /rsynctestfolder /test/

Some cases we do not want to overwrite updated synced data with old data, use -u option along with rsync command to not overwrite the destination files.

7. Transfer by limiting the size of the files :

[root@localhost]# rsync -azv --max-size='1000k' /rsynctestfolder/ remoteIP address:/test/

above command option will copy files which are not more than 1000KB in size.

8. See Rsync progress while synchronising :

[root@localhost]#  rsync -azv --progress /rsynctestfolder/ remoteIPaddress:/test/

use add option --progress which will show current copy progress information.

9. To make exact copy of source and destination :

[root@localhost]#  rsync -azv --delete /rsynctestfolder/ remoteIPaddress:/test/

Use rsync command with –delete option will delete destination files which is not present in source


Please refer man rsync or rsync --help for more details.