Usage of rsync under Linux

 

1. Overview of rsync

Rsync is a data mirroring backup tool under unix-like systems. It can be seen from the naming of the software-remote sync. rsync is a file synchronization and data transmission tool under the Linux system. It uses the "rsync" algorithm to synchronize files between a client and a remote file server, or to back up data from one partition to another in the local system. On the partition. If there is a data transmission interruption during rsync backup, you can continue to transmit the inconsistent part after recovery. rsync can perform full or incremental backups. Its main features are:

1. You can mirror the entire directory tree and file system;

2. It is easy to maintain the original file permissions, time, soft and hard links; no special permissions can be installed;

3. Data can be synchronized incrementally, the file transfer efficiency is high, so the synchronization time is short;

4. You can use rcp, ssh and other methods to transfer files, of course, you can also connect through a direct socket;

5. Support anonymous transmission to facilitate website mirroring, etc .;

6. Encrypted transmission data to ensure data security;

 

 

 

-v is "--verbose", which is the detailed mode output; -z means "--compress", that is, the data is compressed during transmission;

-r means "--recursive", that is, recursively process subdirectories; -t is "--time", that is, keep file time information;

-o means "owner", used to keep the file owner information; -p is "perms", used to keep the file permissions;

-g is "group", used to maintain the file group information;

--progress is used to show the process of data mirror synchronization;

 

 

The --delete option specifies that the data mirroring synchronization is performed on the basis of the rsync server, that is, to keep the rsync server-side directory and the client directory exactly the same;

--exclude option is used to exclude file types that do not need to be transferred;

 

 

The advantages and disadvantages of rsync

Compared with the traditional cp and tar backup methods, rsync has the advantages of high security, rapid backup, and support for incremental backup. Through rsync, it can solve the data backup requirements that do not require real-time requirements. For example, regularly back up file server data to The remote server regularly performs data mirroring on the local disk.

However, as the system scale continues to expand, the shortcomings of rsync are gradually exposed. First, when rsync performs data synchronization, it is necessary to scan all files for comparison, and then perform differential transmission. If the file is large, scanning the file is very time-consuming, and the changed file is often a small part, so rsync is a very inefficient way. Secondly, rsync cannot monitor and synchronize data in real time. Although it can trigger synchronization through the Linux daemon, there will be a time difference between the two trigger actions, which may lead to inconsistency between server and client data


After configuring the rsync server, the next step is to issue the rsync command on the client to back up the files on the server to the client. rsync is a very powerful tool, and its commands also have many feature options. We will analyze and explain its options one by one.
The Rsync command format can be the following six types:
  rsync [OPTION] ... SRC DEST
  rsync [OPTION] ... SRC [USER @] HOST: DEST
  rsync [OPTION] ... [USER @] HOST: SRC DEST
  rsync [OPTION] ... [USER @] HOST :: SRC DEST
  rsync [OPTION] ... SRC [USER @] HOST :: DEST
  rsync [OPTION] ... rsync: // [USER @] HOST [: PORT ] / SRC [DEST]
  corresponding to the above six command formats, rsync has six different working modes:
  1) Copy local files This working mode is started when neither SRC nor DES path information contains a single colon ":" separator. Such as: rsync -a / data / backup
  2) Use a remote shell program (such as rsh, ssh) to copy the contents of the local machine to the remote machine. This mode is initiated when the DST path address contains a single colon ":" separator. Such as: rsync -avz * .c foo: src
  3) 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. Such as: rsync -avz foo: src / bar / data
  4) Copy files from the remote rsync server to the local machine. This mode is activated when the SRC path information contains "::" separator. Such as: rsync -av [email protected] :: www / databack
  5) Copy files from the local machine to the remote rsync server. This mode is activated when the DST path information contains "::" separator. For example: rsync -av / databack [email protected] :: www
  6) List the file list of the remote machine. This is similar to rsync transmission, but as long as the local machine information is omitted in the command. For example: rsync -v rsync: //172.16.78.192/www
The specific explanation of rsync parameters is as follows:
-v, --verbose verbose mode output
-q, --quiet streamlined output mode
-c, --checksum Turn on the verification switch, Force verification of file transfers
-a, --archive archive mode, which means that files are transferred recursively and keep all file attributes, which is equal to -rlptgoD
-r, --recursive Recursive processing of subdirectories
-R,- relative Use relative path information
-b, --backup to create a backup, that is, when the same file name already exists for the destination, rename the old file to ~ filename. You can use the --suffix option to specify different backup file prefixes.
--backup-dir Store backup files (such as ~ filename) in a directory.
-suffix = SUFFIX Define the backup file prefix
-u, --update Only update, that is, skip all files that already exist in DST, and the file time is later than the file to be backed up. (Do not overwrite updated files)
-l, --links retain soft links
-L, --copy-links treat soft links like regular files
--copy-unsafe-links only copy links pointing outside the SRC path directory tree
--safe-links Ignore links pointing outside the directory tree of the SRC path
-H, --hard-links keep hard links
-p, --perms keep file permissions
-o, --owner keep file owner information
-g, --group keep files Group information-
D, --devices keep device file information-
t, --times keep file time information-
S, --sparse perform special processing on sparse files to save DST space-
n, --dry-run The file will be transferred
-W, --whole-file copy the file without incremental detection
-x, --one-file-system Do not cross the file system boundary
-B, --block-size = SIZE block used by the verification algorithm Size, default is 700 bytes
-e, --rsh = COMMAND specifies to use rsh, ssh for data synchronization
--rsync-path = PATH specifies the path information of the rsync command on the remote server
-C, --cvs-exclude use The same method as CVS automatically ignores files, used to exclude those files that do not want to be transferred--
existing only updates those that already exist in DST files without backing up those newly created files
--delete delete those DST SRC is not in the file
--delete-excluded delete receiving end of the same files that are specified excluded this option
and then delete after the end of the --delete-after transmission
--ignore-errors IO error also occurs promptly delete
--max-delete = NUM ​​delete at most NUM files
--partial keep those files that have not been completely transferred for some reason, so speed up the subsequent transfer again
--force force delete the directory even if it is not empty
--numeric-ids will not The numeric user and group ID match the user name and group name
--timeout = TIME IP timeout time, the unit is seconds
-I, --ignore-times do not skip those files with the same time and length
--size-only when When deciding whether to back up a file, just look at the file size without considering the file time
--modify-window = NUM ​​Determine whether the file has the same timestamp window, the default is 0
-T --temp-dir = DIR in DIR Create temporary files
--compare-dest = DIR Also compare the files in DIR to determine whether you need to backup
-P is equivalent to --partial
--progress shows the backup process
-z, --compress compresses the backup files during transmission
--exc lude = PATTERN specifies the mode of excluding files
that do not need to be transferred
--exclude-from = FILE exclude files in the specified pattern in FILE
--include-from = FILE do not exclude files matching the specified pattern in FILE
--version print version information
--address bind to a specific address
--config = FILE specify Other configuration files, do not use the default rsyncd.conf file
--port = PORT specify other rsync service port
--blocking-io use blocking IO
-stats for remote shell to give the transmission status of some files
--progress in transmission Real
- time transmission process --log-format = formAT specify log file format
--password-file = FILE get password from FILE
--bwlimit = KBPS limit I / O bandwidth, KBytes per second
-h, --help display help information
 

Generally use the azv option

Published 19 original articles · praised 4 · 170,000 views +

Guess you like

Origin blog.csdn.net/u011250186/article/details/105657820