I. Overview of Rsync
Rsync is a data-mirroring Backup tool under Unix-like systems, and--remote sync can be seen from the name of the software. Rsync is a file synchronization and data Transfer tool under the Linux system that 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 on the local system. If Rsync has a data transfer interruption during the backup process, it can continue to transmit the inconsistent portions after recovery. Rsync can perform full or incremental backups. Its main features are:
1. Can be mirrored to save the entire directory tree and file system;
2. It is easy to maintain the original file permissions, time, soft and hard links, without special permission to install;
3. Can synchronize data incrementally, file transfer efficiency is high, so synchronization time is short;
4. You can use RCP, ssh and other means to transfer files, of course, you can also through a direct socket connection;
5. Support anonymous transmission, in order to facilitate the site mirror image, etc.;
6. Encrypt transmission data, ensure the security of data;
-V is "--verbose", that is verbose mode output,-Z means "--compress", that is, the data compression processing when transmitting;
-R means "--recursive", that is, the subdirectory is processed in recursive mode, and-T is "--time", that is, keeping the file time information;
-O means "owner", which is used to keep the file owner information;-P is "perms" to maintain file permissions;
-G is a "group" that is used to maintain the group information of the file;
--progress is used to display the data mirroring synchronization process;
The--delete option specifies that data mirroring is synchronized based on the rsync server side, that is, to keep the rsync server-side directory fully consistent with the client directory;
The--exclude option is used to exclude file types that do not need to be transferred;
Advantages and disadvantages of rsync
Compared with the traditional methods of CP and Tar Backup, rsync has the advantages of high security, fast backup, support of incremental backup, and so on, rsync can solve the requirement of low-real-time data backup, for example, to back up file server data to remote server regularly, and to mirror the local disk periodically.
But as the scale of the system continues to expand, the shortcomings of rsync are gradually exposed. First, when Rsync does the data synchronization, it needs to scan all the files for comparison and then carry out the differential transmission. If the file is large, the sweep file is very time-consuming, and the changed files are often a very small part, so rsync is a very inefficient way. Second, rsync cannot monitor and synchronize the data in real time, although it can trigger the synchronization through the Linux daemon, but there must be a time difference between the two triggering actions, which may result in inconsistent server-side and client data.
After the rsync server configuration is complete, the next step is to issue the rsync command on the client side to back up the server's files to the client. Rsync is a very powerful tool, and its commands have a lot of feature options, and we have an analysis of its options below.
The command format for rsync can be in the following six ways:
rsync [OPTION] ... SRC DEST
rsync [OPTION] ... SRC [[Email protected]]host:dest
rsync [OPTION] ... [[email protected]] HOST:SRC DEST
rsync [OPTION] ... [[email protected]] HOST::SRC DEST
rsync [OPTION] ... SRC [[Email protected]]host::D EST
rsync [OPTION] ... rsync://[[email protected]]host[:P ort]/src [DEST]
There are six different modes of operation for Rsync, which corresponds to the above six command formats:
1) Copy the local file. This mode of operation is initiated when both the SRC and des path information do not contain a single colon ":" delimiter. 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 started when the DST path address contains a single colon ":" delimiter. 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 started when the SRC address path contains a single colon ":" delimiter. such as: Rsync-avz Foo:src/bar/data
4) Copy files from the remote rsync server to the local machine. This mode is started when the SRC path information contains the "::" delimiter. such as: rsync-av [email Protected]::www/databack
5) Copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" delimiter. such as: rsync-av/databack [email protected]::www
6) The list of files for the remote machine is listed. This is similar to the rsync transfer, but only if the local machine information is omitted from the command. such as: Rsync-v rsync://172.16.78.192/www
The specific explanations for the rsync parameters are as follows:
-V,--verbose verbose mode output
-Q,--quiet thin output mode
-C,--checksum turn on the check switch to force verification of file transfers
-A,--archive archive mode, which means to transfer files recursively and keep all file attributes equal to-rlptgod
-R,--recursive subdirectories in recursive mode
-R,--relative using relative path information
-B,--backup creates a backup, that is, the old file is renamed to ~filename when the same file name exists for the purpose. You can use the--suffix option to specify a different backup file prefix.
--backup-dir store backup files (such as ~filename) in the directory.
-suffix=suffix Defining backup File prefixes
-U,--update only updates, which is to skip all the files that already exist in DST, and the file time is later than the file to be backed up. (Does not overwrite the updated file)
-L,--links reserved Soft link
-L,--copy-links to handle soft links like regular files
--copy-unsafe-links only copies links to links outside the SRC Path directory tree
--safe-links ignoring links to the SRC Path directory tree
-H,--hard-links reserved Hard link
-P,--perms maintain file permissions
-O,--owner keep file owner information
-G,--group keep file group information
-D,--devices keep device file information
-T,--times keep file time information
-S,--sparse special processing of sparse files to save DST space
-N,--dry-run reality which files will be transmitted
-W,--whole-file copy files without incremental detection
-X,--one-file-system do not cross file system boundaries
-B, the block size used by the--block-size=size test algorithm, is 700 bytes by default
-E,--rsh=command specifies data synchronization using RSH and SSH
--rsync-path=path Specify the path information for the rsync command on the remote server
-C,--cvs-exclude uses the same method as CVs to automatically ignore files to exclude files that you do not want to transfer
--existing only updates those files that already exist in DST without backing up those newly created files
--delete Delete those files that are not in the DST SRC
--delete-excluded also deletes those files that are excluded by the option specified by the Receive side
--delete-after transfer ends after removal
--ignore-errors Timely IO errors are also deleted
--max-delete=num deleting NUM files up to a maximum
--partial retains files that are not fully transmitted for any reason, to expedite subsequent transmissions
--force forcibly delete a directory, even if it is not empty
--numeric-ids does not match the user and group ID of a number to a user name and group name
--timeout=time IP time-out, in seconds
-I,--ignore-times do not skip files that have the same time and length
--size-only when deciding whether to back up a file, just look at the file size regardless of file time
--modify-window=num determines whether the file is time-stamped with the time Stamp window, which defaults to 0
-t--temp-dir=dir creating temporary files in Dir
--compare-dest=dir also compares the files in DIR to determine if a backup is required
-p equivalent to--partial
--progress Show Backup process
-Z,--compress compress the backed-up files during transmission
--exclude=pattern specify to exclude file modes that do not need to be transferred
--include=pattern specifies file modes that need to be transferred without exclusion
--exclude-from=file exclude files in the specified schema in file
--include-from=file does not exclude files that specify pattern matching
--version Print version Information
--address binding to a specific address
--config=file specify a different configuration file, do not use the default rsyncd.conf file
--port=port Specify a different rsync service port
--blocking-io using blocking IO for remote shells
-stats gives the transfer status of some files
--progress in the transmission of the real-time transmission process
--log-format=format specifying the log file format
--password-file=file get the password from file
--bwlimit=kbps limit I/O bandwidth, Kbytes per second
-H,--help display Help information
The AZV option is generally used
The use of rsync under Linux