How To Use Rsync

Introduction


Rsync, which stands for remote sync, is a file synchronization tool remotely and locally. It uses an algorithm that minimizes the amount of data that is copied by simply moving the portions of files that have changed.

History Of Rsync


Andrew Tridgell and Paul Mackerras wrote the original rsync, which was first announced on 19 June 1996. Tridgell discusses the design, implementation and performance of rsync in chapters 3 through 5 of his Ph.D. thesis in 1999. It is currently maintained by Wayne Davison.

What Is Rsync?


Rsync is a very flexible network-enabled synchronization tool. It can also refer to a network protocol that was developed to utilize this tool.

Rsync is a widely-used utility to keep copies of a file on two computer systems the same. It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program. The rsync algorithm, a type of delta encoding, is used to minimize network usage. Zlib may be used for additional compression, and SSH or stunnel can be used for data security.

Due to its ubiquity on Linux and Unix-like systems and its popularity as a tool for system scripts, it is included on most Linux distributions by default.

Rsync Examples


In this guide, we will cover the basic usage of this powerful utility. We will be using an CentOS 6 VPS in the examples, but you can use any modern Linux distribution to follow along.

How To Use Rsync



Rsync basic syntax is very straight forward, and operates in a manner similar with ssh, scp, and cp.
We will create two directories test and some of the test file with the following command:


cd ~
mkdir test1
mkdir test2
touch test2/file{1..100}


We now have a directory called test1 with 100 empty file in it.

ls test1


and the output will look like this

file1    file15  file21  file28  file34  file40  file47  file53  file6   file66  file72  file79  file85  file91  file98
file10   file16  file22  file29  file35  file41  file48  file54  file60  file67  file73  file8   file86  file92  file99
file100  file17  file23  file3   file36  file42  file49  file55  file61  file68  file74  file80  file87  file93
file11   file18  file24  file30  file37  file43  file5   file56  file62  file69  file75  file81  file88  file94
file12   file19  file25  file31  file38  file44  file50  file57  file63  file7   file76  file82  file89  file95
file13   file2   file26  file32  file39  file45  file51  file58  file64  file70  file77  file83  file9   file96
file14   file20  file27  file33  file4   file46  file52  file59  file65  file71  file78  file84  file90  file97

We also have an empty directory called test2. To align the contents of test1 to test2 on the same system, type:

rsync -avz test1/ test2


The meaning of option:
-a = option is a combination flag
-v = increase verbosity
-z = reduce the network transfer by adding compression
-e = specify the remote shell to use

How To Use Rsync to Sync with a Remote and Local system



from local to remote system



# rsync -avz -e 'ssh -p sshport' folder/file nameuser@ipORhostname:/destinationfolder


examples:

# rsync -avz -e 'ssh -p 22' devel/*tgz root@192.168.1.11:/home/servermox 

This command will transfer all files in the folder devel to /home/servermox to remote system

from remote to local system



# rysnc -avz -e 'ssh -p sshport' nameuser@ipORhostname:/originfolderORfile /destinationfolder


examples:

# rysnc -avz -e 'ssh -p 22' root@192.168.1.21:/home/servermox/* /home


This command will transfer all files in the folder /home/servermox/ from remote system to /home folder at local system


wish you luck!
Previous
Next Post »