rsync(remote sync) commonly found on Unix-like systems which is a remote/local file synchronisation utility where It uses an algorithm that minimises the amount of data copied by only moving the portions of files that have changed. Without beating around the bush let’s get our hands dirty. I found this link really interesting. Also check out this link for the difference between scp and rsync.

Basic syntax and options of rsync

  • -v , –verbose : verbose
  • -r , –recursive : copies data recursively (but don’t preserve timestamps and permission while transferring data)
  • -a , –archive : archive mode( copy files recursively and preserve symbolic links, file permissions, user & group ownerships and timestamps)
  • -z , –compress : compress file data
  • -P , –progress : show progress during transfer

Note : Any of the below commands with -P option will show the progress of the transfer. I will be using below list of files.

rsync file list for examples

rsync file list for examples

1. Dry Run with rsync

If you are not sure about rsync command output do a dry run and see the output. It will not actually do the transfer but give the exact output as the transfer occured.

2. Copy/Sync Files and Directory Locally

Let’s start with the basics. Copying files locally.

3. Copy/Sync Files and Directory to or From a Remote Server

Now we are going to copy file to the remote server which is from test1 folder

4. Rsync Over SSH

You can also specify any remote shell you like, either by using the -e command line option.

Interesting : Is it possible to specify a different ssh port when using rsync? Yes.

5. Set Bandwidth Limit

If you are doing a huge file transfer make sure you apply a bandwidth limit before it eat out the available bandwidth. use –bwlimit=<kb/second>.

6. Automatically Delete source Files after successful Transfer

It tells rsync to remove from the sending side the files that are a part of the transfer and have been successfully duplicated on the receiving side.

7. Sync with –delete

You can delete files on the receiving side that don’t exist on the sending side with –delete option.

Please see the link for a more complex scenario in this link1 and link2. Also you might want to exclude and include files when transferring over the network as mentioned in this link. If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).


Be Sociable, Share!