Rsync用法
rsync是一个功能非常强大的工具,其命令也有很多功能特色选项,我们下面就对它的选项一一进行分析说明

使用rsync –help,可以看到rsync的命令格式有以下七种:

Usage: rsync [OPTION]... SRC [SRC]... DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
or rsync [OPTION]... [USER@]HOST:SRC [DEST]
or rsync [OPTION]... [USER@]HOST::SRC [DEST]
or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
to an rsync daemon, and require SRC or DEST to start with a module name.
“:”是连接远程shell
“::”和”rsync”是连接远程的rsync服务

参数具体解释如下:

Options
-v, --verbose increase verbosity
# 显示过程
-q, --quiet suppress non-error messages
--no-motd suppress daemon-mode MOTD (see manpage caveat)
# 安静模式
-c, --checksum skip based on checksum, not mod-time & size
# 校验
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
# 归档
-r, --recursive recurse into directories
# 递归子目录
-R, --relative use relative path names
--no-implied-dirs don't send implied dirs with –relative
# 使用相对路径
-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX set backup suffix (default ~ w/o --backup-dir)
# 备份文件 rsync -b --backup-dir=back --suffix=2013 -a newfolder/ backfolder/
-u, --update skip files that are newer on the receiver
--inplace update destination files in-place (SEE MAN PAGE)
--append append data onto shorter files
--append-verify like --append, but with old data in file checksum
-d, --dirs transfer directories without recursing using
"-r --exclude='/*/*'" (rsync 2.6.x compatible)
# 目录下的内容不被复制,除非明确指定
--new-dirs transfer directories without recursing
(rsync 3.0.x compatible)
-l, --links copy symlinks as symlinks
# 软链接
-L, --copy-links transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the source tree
-k, --copy-dirlinks transform symlink to a dir into referent dir
-K, --keep-dirlinks treat symlinked dir on receiver as dir
-H, --hard-links preserve hard links
# 硬链接
-p, --perms preserve permissions
# 权限
-E, --executability preserve the file's executability
--chmod=CHMOD affect file and/or directory permissions
# 保留执行权限
-A, --acls preserve ACLs (implies --perms)
# 保留acl
-X, --xattrs preserve extended attributes
# 保留扩展属性
-o, --owner preserve owner (super-user only)
# 保留拥有者
-g, --group preserve group
--devices preserve device files (super-user only)
--specials preserve special files
# 保留拥有组
-D same as --devices –specials
# 保留设备文件信息
-t, --times preserve modification times
# 保留修改时间
-O, --omit-dir-times omit directories from --times
# 当带有-t参数时,忽略目录的修改时间
   --super receiver attempts super-user activities
# 在接收服务器上尝试使用超级用户
--fake-super store/recover privileged attrs using xattrs
# 模拟超级用户来保留或回复文件的属性
-S, --sparse handle sparse files efficiently
# 对稀疏的文件进行梳理以节省DST的 磁盘空间
-n, --dry-run perform a trial run with no changes made
# 测试命令的执行,并不真正执行命令
-W, --whole-file copy files whole (without delta-xfer algorithm)
# 不使用增量偏移算法,而把源当成一整个文件拷贝
-x, --one-file-system don't cross filesystem boundaries
# 不能跨越文件系统边界
-B, --block-size=SIZE force a fixed checksum block-size
# 强制拷贝的block size
-e, --rsh=COMMAND specify the remote shell to use
# 远程的shell命令
--rsync-path=PROGRAM specify the rsync to run on the remote machine
# 远程rsync程序路径
--existing skip creating new files on receiver
# 不在接收端创建新文件
--ignore-existing skip updating files that already exist on receiver
# 不在接收端更新已经存在的文件
--remove-source-files sender removes synchronized files (non-dirs)
# 发送端排除那些文件
--del an alias for --delete-during
--delete delete extraneous files from destination dirs
--delete-before receiver deletes before transfer, not during
# 传输前删除
--delete-during receiver deletes during transfer (default)
# 传输中删除
--delete-delay find deletions during, delete after
# 传输中延迟删除
--delete-after receiver deletes after transfer, not during
# 传输结束后删除
--delete-excluded also delete excluded files from destination dirs.
# 删除排除的其他源目标没有的文件
--ignore-errors delete even if there are I/O errors
# 忽略I/O错误
--force force deletion of directories even if not empty
# 强制删除,即使是非空目录
--max-delete=NUM don't delete more than NUM files
# 最多删除NUM个文件
--max-size=SIZE don't transfer any file larger than SIZE
# 不传输比SIZE大的文件
--min-size=SIZE don't transfer any file smaller than SIZE
# 不传输比SIZE小的文件
--partial keep partially transferred files
# 特殊传输的文件(比如优先的文件)
--partial-dir=DIR put a partially transferred file into DIR
# 将这些特殊文件放置的目录
--delay-updates put all updated files into place at transfer's end
# 把更新动作放在传输的末尾
-m, --prune-empty-dirs prune empty directory chains from the file-list
--numeric-ids don't map uid/gid values by user/group name
# 不将用户/组的ID匹配为用户/组名
--timeout=SECONDS set I/O timeout in seconds
# I/O超时时间
--contimeout=SECONDS set daemon connection timeout in seconds
# 服务连接超时世界
-I, --ignore-times don't skip files that match in size and mod-time
# 不要跳过有同样时间戳和大小的文件
--size-only skip files that match in size
# 当备份文件是仅仅考虑文件的大小而不考虑时间戳
--modify-window=NUM compare mod-times with reduced accuracy
# 比较时间戳的起始值,默认为0
-T, --temp-dir=DIR create temporary files in directory DIR
# 创建临时文件的位置
-y, --fuzzy find similar file for basis if no dest file
# 如果没有目标文件将用类似和相同的源文件替代
--compare-dest=DIR also compare destination files relative to DIR
# 比较目标目录
--copy-dest=DIR ... and include copies of unchanged files
# 拷贝目标比较没有改变的文件
--link-dest=DIR hardlink to files in DIR when unchanged
# 拷贝目标比较没有改变的硬连接文件
-z, --compress compress file data during the transfer
# 在传输的过程中压缩
--compress-level=NUM explicitly set compression level
# 压缩等级
--skip-compress=LIST skip compressing files with a suffix in LIST
# 不要压缩的列表
-C, --cvs-exclude auto-ignore files the same way CVS does
# 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件
-f, --filter=RULE add a file-filtering RULE
# 指定文件过滤规则
-F same as --filter='dir-merge /.rsync-filter'
repeated: --filter='- .rsync-filter'
--exclude=PATTERN exclude files matching PATTERN
# 排除匹配的模式
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don't exclude files matching PATTERN
# 包含匹配的模式
--include-from=FILE read include patterns from FILE
--files-from=FILE read list of source-file names from FILE
# 源文件列表文件
-0, --from0 all *-from/filter files are delimited by 0s
# 读取到空规则或空文件名终止
-s, --protect-args no space-splitting; only wildcard special-chars
--address=ADDRESS bind address for outgoing socket to daemon
# 指定服务器Ip
--port=PORT specify double-colon alternate port number
# 指定服务器端口
--sockopts=OPTIONS specify custom TCP options
--blocking-io use blocking I/O for the remote shell
# 对远程shell使用阻塞I/O
--stats give some file-transfer stats
# 显示传输的结果状态
-8, --8-bit-output leave high-bit chars unescaped in output
# 不使用高位的非转义字符显示
-h, --human-readable output numbers in a human-readable format
# 使用方便阅读的方式显示
--progress show progress during transfer
# 显示传输的过程进度
-P same as --partial --progress
-i, --itemize-changes output a change-summary for all updates
# 输出更新的文件汇总
--out-format=FORMAT output updates using the specified FORMAT
# 输出格式
--log-file=FILE log what we're doing to the specified FILE
# 定义日志文件
--log-file-format=FMT log updates using the specified FMT
# 日志文件格式
--password-file=FILE read daemon-access password from FILE
# 存放密码文件位置
--list-only list the files instead of copying them
# 仅仅列出文件
--bwlimit=KBPS limit I/O bandwidth; KBytes per second
# 限制I/O带宽
--write-batch=FILE write a batched update to FILE
--only-write-batch=FILE like --write-batch but w/o updating destination
--read-batch=FILE read a batched update from FILE
# 批量处理的文件
--protocol=NUM force an older protocol version to be used
# 强制使用的协议版本
--iconv=CONVERT_SPEC request charset conversion of filenames
# 转换文件名的字符编码
-4, --ipv4 prefer IPv4
# 偏向ipv4传输
-6, --ipv6 prefer IPv6、
# 偏向ipv6传输
--version print version number
# 显示程序版本
(-h) --help show this help (-h works with no other options)

Use "rsync --daemon --help" to see the daemon-mode command-line options.
Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.
See http://rsync.samba.org/ for updates, bug reports, and answers

示例
删除批量文件
rsync --delete-before --delete-excluded /root/oldfolder/data -a -H -v --progress --stats /root/oldfolder /root/newfolder