After the rsync server configuration is over, the next step is to issue an rsync command on the client to enable the server-side files to be backed up to the client. Rsync is a very powerful tool, and its commands have many feature options, and we'll analyze all of its options below.
The command format for rsync can be in the following six ways:
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::D EST
rsync [OPTION] ... rsync://[user@]host[:P ort]/src [DEST]
For each of the above six command formats, Rsync has six different working modes:
1 Copy Local files. This mode of work is started when both SRC and dest path information does 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 ":" Separator. such as: Rsync-avz *.c FOO:DST
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 ":" Separator. such as: Rsync-avz foo:src/zouch//data
4 Copy files from remote rsync server to local machine. This mode is started when the SRC path information contains the "::" delimiter. such as: Rsync-av root@172.16.78.192::www/Www.111cn.Net//databack
5 copy files from local machine to remote rsync server. This mode is started when the DST path information contains the "::" separator. such as: rsync-av/databack/root@172.16.78.192::www/www.111cn.net/
6 The list of files for the remote machine. This is similar to rsync transmission, but simply omitting the local machine information in the command. such as: Rsync-v Rsync://172.16.78.192/www/zouch
Attention:
1): And:: The difference is that the former use of the system with the SSH transmission, and:: Is the use of Rsync server protocol to transmit
2 Remote automatic synchronization can use the SSH Exchange key and configure the Rsync server password protection of two ways
2 If the source directory does not exist, it will automatically create a
3 The source directory with a slash to indicate the source directory and the target directory comparison, without a slash to represent the source directory and the directory under the target directory for comparison
1. Common mode:
#rsync-azv Src/zouch/dest/zouch
In general, Rsync uses the-avz single parameter to represent the archive mode, the compression transfer mode, and the verbose output mode.
It should be noted that the Rsync source directory has two ways of writing, that is, the directory with no slashes (this is not the same as the MV Directory operation), the target directory does not matter:
1) src/zouch/source directory with a slash, indicating the source directory and the target directory for comparison
2) Src/zouch source directory with no Slash, means that the source directory and the source directory in the target directory for the same name comparison, no directory with the same name to copy a full directory
2. Ignore files in the source directory
#rsync-avz–explude=parttern Src/zouch/dest/zouch
#rsync-avz–exclude-from=file Src/zouch/dest/zouch
You can use –explude to write directly to ignore string patterns when ignoring files, or you can specify a configuration file by using –explude-from, which allows you to define multiple string patterns, each of which requires a separate row, where the directory needs to be added with a slash.
–explude parameters can be multiple parallel
3. Remove unwanted files from target directory
#rsync-azv–delete Src/zouch/dest/zouch
4. Backup modified or deleted files
#rsync-azv–delete-–backup-–backup-dir=/webroot/backup/zouch/' Date +%y-%m-%d ' Src/zouch/dest/zouch
5. Specify the port of SSH to use when transmitting
#rsync-azv-e ' ssh-p 8021 ' Src/zouch/dest/zouch
6. Record the details of the synchronization operation
#rsync-azv src/zouch/dest/zouch 1>log/rsync/' Date +%y-%m-%d '. LOG
7. Log the error message for the sync operation
#rsync-azv src/zouch/dest/zouch 1>log/rsync/' Date +%y-%m-%d ' _error.log
The specific explanation for the rsync parameter is as follows:
-v,–verbose Verbose mode output
-q,–quiet Thin Output mode
-c,–checksum turn on the check switch to force the verification of File transfer
-a,–archive archive mode, which represents the transfer of files recursively and maintains all file attributes equal to-rlptgod
-r,–recursive in recursive mode for subdirectories
-r,–relative Using relative path information
-b,–backup creates a backup, which means that the old file is renamed to ~filename for the same file name as the destination already exists. You can use the –suffix option to specify different backup file prefixes.
–backup-dir store backup files (such as ~filename) in the directory.
-suffix=suffix defines the backup file prefix
-u,–update only updates, skipping over all files that already exist in DST, and that the file time is later than the file you want to back up. (Do not overwrite the updated file)
-l,–links retaining Soft link knot
-l,–copy-links want to treat soft links like regular files
–copy-unsafe-links only copies links that point beyond the src Path directory tree
–safe-links ignores links to the SRC path tree
-h,–hard-links Keep Hard Links
-p,–perms Keep file permissions
-o,–owner Keep File owner information
-g,–group Keep file group information
-d,–devices Maintain device file information
-t,–times Keep file time information
-s,–sparse Special handling 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,–block-size=size test algorithm uses block size, default is 700 bytes
-e,–rsh=command Specifies the use of rsh, SSH mode for data synchronization
–RSYNC-PATH=PATH Specifies the path information for the rsync command on the remote server
-c,–cvs-exclude use the same method as CVs to automatically ignore files to exclude files that you do not want to transfer
–existing updates only those files that already exist in DST, not the newly created files
–delete Delete files that are not in the DST SRC
–delete-excluded also deletes the receiving end of files that are excluded by the option specified
–delete-after after transmission is over
–ignore-errors in time IO errors are also deleted
–max-delete=num Delete NUM files up to
–partial retains files that are not fully transmitted for some reason, to expedite subsequent transmissions
–force forcibly deletes a directory, even if it is not empty
–numeric-ids does not match the user and group IDs of numbers to user and group names
–timeout=time IP timeout time in seconds
-i,–ignore-times don't 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 without considering the file time
–modify-window=num the time stamp window that determines whether a file is in the same time, default is 0
-t–temp-dir=dir Create temporary files in dir
–compare-dest=dir also compares files in DIR to determine whether a backup is required
-P equals to –partial
–progress Display backup process
-z,–compress compression of backed-up files on transfer
–EXCLUDE=PATTERN Specifies to exclude file modes that do not require transfer
–INCLUDE=PATTERN Specifies the file mode that is not excluded and needs to be transferred
–exclude-from=file exclude files in the specified mode in file
–include-from=file does not exclude files that match the file-specified pattern
–version Print version Information
–address bound to a specific address
–CONFIG=FILE specifies a different profile and does not use the default rsyncd.conf file
–PORT=PORT Specifies the other rsync service ports
–blocking-io blocking IO for a remote shell
-stats gives the transfer status of some files
–progress transmission process in real time
–log-format=format Specify log file format
–password-file=file gets the password from file
–bwlimit=kbps limit I/O bandwidth, Kbytes per second
-H,–HELP Display Help information