The rsync command is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through the LAN/WAN. Rsync uses the so-called "rsync algorithm" to synchronize files between the local and remote hosts. This algorithm only transfers different parts of the two files, instead of transmitting the entire file each time, therefore, the speed is quite fast. Rsync is a very powerful tool, and its commands have many special options. The following describes the options one by one.
If rsync is not installed, run yum or apt-get.
The command options are as follows. The common parameters are rsync-avz and rsync-delete:
-A, -- archive mode, indicating that the file is transmitted recursively and all file attributes are kept, equal to-rlptgoD.
-V, -- verbose detailed mode output.
-Z, -- compress compresses the backup files during transmission.
-- Delete: delete the files that are not in the SRC file in DST.
-- Delete-excluded: delete files specified by this option at the receiving end.
-- Delete-after: delete the file after the transfer is completed.
-Q, -- quiet simplified output mode.
-C, -- checksum: enable the verification switch to force file transfer verification.
-R, -- recursive processes subdirectories in recursive mode.
-R, -- relative uses relative path information.
-B, -- backup creates a backup, that is, if the object already has the same file name, rename the old file ~ Filename. You can use the -- suffix option to specify different backup file prefixes.
-- Backup-dir: backs up files (for example ~ Filename) is stored in the directory.
-Suffix = SUFFIX defines the backup file prefix.
-U, -- update only performs updates, that is, skipping all files that already exist in DST and whose file time is later than the one to be backed up does not overwrite the updated files.
-L, -- links retains soft links.
-L, -- copy-links handles soft links like regular files.
-- Copy-unsafe-links only copies links that point to the directory tree outside the SRC path.
-- Safe-links ignores links other than the SRC path directory tree.
-H, -- hard-links retains the hard link.
-P, -- perms maintains the file permission.
-O, -- owner keeps the file owner information.
-G, -- group: Keep file group information.
-D, -- devices to keep the device file information.
-T, -- times to keep the file time information.
-S, -- sparse performs special processing on sparse files to save DST space.
-N, -- dry-run indicates which files will be transmitted.
-W, -- whole-file: Copy files without incremental detection.
-X, -- one-file-system do not span the boundaries of the file system.
-B, -- block-size = SIZE indicates the block size used by the algorithm. The default value is 700 bytes.
-E, -- rsh = command specifies that rsh and ssh are used for data synchronization.
-- Rsync-path = PATH specifies the path of the rsync command on the remote server.
-C, -- cvs-exclude automatically ignores files in the same way as CVS to exclude files that do not want to be transmitted.
-- Existing only updates the files that already exist in DST, instead of backing up those new files.
-- Ignore-errors is deleted when an IO error occurs.
-- Max-delete = NUM: a maximum of NUM files can be deleted.
-- Partial retains the files that are not completely transferred for any reason, so as to speed up subsequent re-transmission.
-P is equivalent to -- partial.
-- Force deletes the Directory, even if it is not empty.
-- Numeric-ids does not match the user name and group name of a number with the group id.
-- Timeout = time ip timeout time, in seconds.
-I, -- ignore-times does not skip files with the same time and length.
-- Size-only: when determining whether to back up a file, only check the file size, regardless of the file time.
-- Modify-window = NUM determines whether the timestamp window of the file is used at the same time. The default value is 0.
-T -- temp-dir = DIR: create a temporary file in DIR.
-- Compare-dest = DIR compare the files in DIR to determine whether to back up data.
-- Progress displays the backup process.
-- Exclude = PATTERN specifies the file mode that does not need to be transmitted.
-- Include = PATTERN specifies the file mode to be transmitted without exclusion.
-- Exclude-from = FILE: exclude files in the specified mode in the FILE.
-- Include-from = FILE: files that match the specified FILE mode are not excluded.
-- Version: prints version information.
-- Address is bound to a specific address.
-- Config = FILE: specify other configuration files. The default rsyncd. conf FILE is not used.
-- Port = PORT specifies other rsync service ports.
-- Blocking-io: Block IO for remote shell.
-Stats indicates the transmission status of some files.
-- The actual transmission process of progress during transmission.
-- Log-format = formAT specifies the log file format.
-- Password-file = FILE: obtain the password from the FILE.
-- Bwlimit = KBPS limits I/O bandwidth, KBytes per second. -
H, -- help: displays help information.
The host can synchronize data remotely between the local host and the remote host. The command syntax is as follows:
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]
Through the above syntax, we can know that rsync can synchronize data on the local machine as well as data between local and remote hosts, between remote hosts and local machines, and between remote hosts and remote hosts. For the preceding six command formats, rsync has six different working modes:
1. Copy the local file. This mode is enabled when the SRC and DES paths do not contain a single colon ":" separator. For example, rsync-avz/data/backup
2. Use a remote shell program (such as rsh and ssh) to copy the content of the local machine to the remote machine. This mode is enabled when the DST path address contains a single colon (:) separator. For example, rsync-avz *. c foo: src
3. Use a remote shell program (such as rsh and ssh) to copy the contents of the remote machine to the local machine. This mode is enabled when the SRC address path contains a single colon (:) separator. For example, rsync-avz foo: src/bar/data
4. Copy files from the remote rsync server to the local machine. Use ssh for data transfer, need to use rsync-avz "-e ssh-p 22" root@59.46.x.x:/home/webcode/21 yunwei/home/webcode/21 yunwei
5. Copy files from the local machine to the remote rsync server. Use ssh for data transfer, use rsync-avz "-e ssh-p 22" webcode/21 yunwei root@59.46.x.x:/home/webcode/21 yunwei
6. List of remote machine files. This is similar to rsync transmission, but you only need to omit the local machine information in the command. For example, rsync-v rsync: // 192.168.78.192/www