Rsync principle and basic tutorials

  
 

Rsync uses the Rsync algorithm to synchronize files between the local and remote hosts. This algorithm only transfers different parts of the two files, instead of transferring them all at once, so the speed is quite fast. The core algorithm assumes that similar files A and B are synchronized between two computers named and , with access to file A and access to file B

Rsync uses the so-called "Rsync algorithm" ” to synchronize the files between the local and remote hosts, this algorithm only transmits different parts of the two files, instead of transmitting them all at once, so the speed is quite fast.

The core of the algorithm:

Assume similar files A and B are synchronized between two computers named α and β where α has access to file A, &beta ; has access to file B. Also assume that the network bandwidth between host α and β is small. Then the rsync algorithm will be completed in the following five steps:

1.β The file B is divided into a set of non-overlapping blocks of fixed size S bytes. The last piece may be smaller than S.

2.β Perform two checks on each partitioned block: one is a 32-bit rolling weak check, and the other is a 128-bit MD4 strong check.

3.β Send these checksums to α.

4.α by searching all the data blocks of size A of file A (the offset can be optional, not necessarily a multiple of S), to find the same as a block of file B Weak check code and strong check code data block. This work can be done quickly with the help of rolling verification.

5.α is sent to β a sequence of instructions to generate a backup of file A on β Each instruction here is either a proof that file B owns a block of data without retransmission, or a block of data that is definitely not matched to any of the blocks of file B.

The advantages of Rsync are as follows:

1. You can save the entire directory tree and file system by mirroring;

2. It is easy to maintain the permissions, time, and time of the original file. Soft and hard links, etc.;

3. Can be installed without special permissions;

4. Optimized process, high file transfer efficiency;

5. Rcp, ssh can be used The way to transfer files, of course, can also be through a direct socket connection;

6. Support anonymous transmission.




Basic Syntax - by Remote Shell Method:

- rsync [OPTION] [USER@]HOST:SRC DEST- Use a remote shell (such as ssh, rsh) to copy the contents of the remote machine to the local machine. The SRC address path is separated by a single colon “:”. - rsync [OPTION] SRC [USER@]HOST:DEST- Use a remote shell (such as rsh, ssh) to copy the contents of the local machine to the remote machine. The DEST address path is separated by a single colon “:”. - via rsync daemon:

- rsync [OPTION] [USER@]HOST::SRC DEST or - rsync [OPTION] rsync://[USER@]HOST[:PORT]/SRC [DEST] - Copy files from the remote rsync server to the local machine. The SRC address path is separated by a double colon “::”. - rsync [OPTION] SRC [USER@]HOST::DEST or - rsync [OPTION] SRC rsync://[USER@]HOST[:PORT]/DEST- Copy files from the local machine to the remote rsync server. The DEST address path is separated by a double colon “::”.

If only the SRC parameter is specified in the rsync command without specifying the DEST parameter, it means that the source file list is displayed instead of a synchronous copy. There are many options for rsync. The commonly used options are as follows:



rsync Common Parameters


Option Description-a, &ndash ;archive archive mode, keeps all file attributes, equivalent to -rlptgoD -v, –verbose details output -r, –recursive recursively handles subdirectories -R, –relative uses relative path information -b, – Backup create backup -z, –compress compresses the backup file during transmission –delete is used to synchronize the directory, delete files that do not exist in SRC from DEST–progress shows the backup process



rsync mode

rsync [OPTION]… SRC [SRC]… [USER@]HOST:DEST

rsync [OPTION]&hellip ; [USER@]HOST:SRC DEST

rsync [OPTION]… SRC [SRC]… DEST

rsync [OPTION]… [USER@]HOST::SRC [DEST ]

rsync [OPTION]… SRC [SRC]… [USER@]HOST::DEST

rsync [OPTION]… rsync://[USER@]HOST[: PORT]/SRC [DEST]


rsync has six different working modes:

Copy local files; this mode of operation is initiated when neither the SRC nor the DES path information contains a single colon ":"; separator.

Use a remote shell program (such as rsh, ssh) to copy the contents of the local machine to a remote machine. This mode is initiated when the DST path address contains a single colon ":"; separator.

Use a remote shell program (such as rsh, ssh) to copy the contents of the remote machine to the local machine. This mode is initiated when the SRC address path contains a single colon ":"; separator.

Copy files from the remote rsync server to the local machine. This mode is initiated when the SRC path information contains the ”::” separator.

Copy files from the local machine to the remote rsync server. This mode is initiated when the DST path information contains a ”::” separator.

List of files for the remote machine. This is similar to rsync transfer, but just omit the local machine information in the command.




Use examples:- View server files and lists - # rsync 9.186.110.53:: View a list of modules available on the server and Comment Information - # rsync [email protected]::www/View the directory and file list in the server www module (using rsyncd user authentication) - # rsync [email protected]:/var/www/html/View Service Content in the /var/www/html directory (using the system user of the server for authentication, such as ibmuser)

- Keeping the client and server data synchronized - # rsync -avz [email protected]:: Www //backup1/use the background service mode to back up the contents of the server www module to the local /backup1 directory, retain the original permissions, attributes, owners and symbolic links when backing up, and use compression to speed up data transmission. - # rsync – avz [email protected]:/var/www/html /backup2/Use the ssh method to back up the remote /var/www/html directory to the local/backup2/directory - # rsync -avz –delete [email protected]::www//backup3/Back up the remote www module to the local/backup3/directory and synchronize the directory to delete the extra files in the local directory.

When there is a problem with the data on the server, you need to restore the server through the data of the client. As long as the client has the write permission of the server, you can restore the SRC and DEST parameters of the rsync command.

Copyright © Windows knowledge All Rights Reserved