rsync for windows是一种非常高效、灵活的文件同步工具,它的增量复制和差异传输技术,使得它在文件备份、同步和远程数据传输中非常受欢迎。通过合适的命令行选项,用户可以定制同步操作以满足不同需求。

rsync

rsync download

github.com/RsyncProject/rsync

 

rsync 工具的功能分类,可以将其常用的选项按不同功能进行整理。以下是 rsync 的功能分类表格:

功能类别 选项 说明
基本功能 -v, --verbose 增加详细输出
  --info=FLAGS 细化信息输出的详细程度
  --debug=FLAGS 细化调试输出的详细程度
  -q, --quiet 抑制非错误信息
  --no-motd 抑制守护进程模式中的 MOTD(消息)
同步方式 --checksum, -c 基于校验和跳过,而不是基于修改时间和大小
  --archive, -a 存档模式,等价于 -rlptgoD(不包括 -A,-X,-U,-N,-H
  --no-OPTION 关闭隐式的 OPTION(例如 --no-D
目录传输 -r, --recursive 递归进入目录
  -R, --relative 使用相对路径
  --no-implied-dirs 不随 --relative 发送隐式目录
备份与更新 -b, --backup 创建备份(参见 --suffix 和 --backup-dir
  --backup-dir=DIR 将备份存储到 DIR 目录中的层次结构中
  --suffix=SUFFIX 备份文件后缀(默认 ~,如果没有 --backup-dir
  -u, --update 跳过接收端更新过的文件
直接更新 --inplace 直接在目标文件中更新
追加数据 --append 向较短的文件追加数据
  --append-verify 向文件追加数据并进行校验(基于旧数据的校验和)
目录传输控制 -d, --dirs 仅传输目录,不进行递归
  --old-dirs, --old-d 与旧版 rsync 通信时,行为如同 --dirs
  --mkpath 创建目标路径中缺失的部分
符号链接处理 -l, --links 复制符号链接为符号链接
  -L, --copy-links 将符号链接转换为引用的文件/目录
  --copy-unsafe-links 仅转换"不安全"的符号链接
  --safe-links 忽略指向树外的符号链接

其他选项

功能类别 选项 说明
路径设置 --relative 使用相对路径设置
远程连接 [user@]host:source 通过远程 shell 连接
  [user@]host::source 通过 rsync 守护进程连接
  rsync://[user@]host[:port]/source 通过 rsync 协议与远程主机进行连接

其他使用场景

  • 使用 rsync 可以通过命令行参数在本地和远程主机之间进行文件同步,同时支持对文件进行校验、备份、追加数据等操作。
  • 具体的参数组合,可以根据实际需求进行选择和使用。

 

C:\Users\Administrator\Downloads\rsync4win\rsync4win\rsync>rsync
rsync 版本 3.3.0 协议版本 31
版权 (C) 1996-2024 由 Andrew Tridgell、Wayne Davison 等人版权所有。
官方网站: https://rsync.samba.org/
功能:
    64位文件,64位i-nodes,64位时间戳,64位长整型,
    套接字对,符号链接,符号时间,硬链接,无硬链接特殊,
    硬链接符号链接,IPv6,访问时间,批处理文件,就地,附加,无ACL,
    无xattr, 可选的隔离参数,字符集转换,预分配,停止,创建时间
优化:
    无SIMD-滚动,无汇编-滚动,OpenSSL加密,无汇编-MD5
校验和列表:
    xxh128 xxh3 xxh64(xxhash)md5 md4 sha1 无
压缩列表:
    zstd lz4 zlibx zlib 无
守护进程认证列表:
    sha512 sha256 sha1 md5 md4

rsync不提供任何担保。这是自由软件,您可以在某些条件下重新分发它。详细信息请参见GNU通用公共许可证。

rsync 是一个能够通过快速差异算法高效进行远程更新的文件传输程序。

用法: rsync [选项]... 源 [源]... 目标
  或者 rsync [选项]... 源 [源]... [用户@]主机:目标
  或者 rsync [选项]... 源 [源]... [用户@]主机::目标
  或者 rsync [选项]... 源 [源]... rsync://[用户@]主机[:端口]/目标
  或者 rsync [选项]... [用户@]主机:源 [目标]
  或者 rsync [选项]... [用户@]主机::源 [目标]
  或者 rsync [选项]... rsync://[用户@]主机[:端口]/源 [目标]
':' 用法通过远程 shell 连接,而 '::' 和 'rsync://' 用法连接到 rsync 守护进程,并要求源或目标以模块名开头。

选项:
--verbose, -v            增加详细输出
--info=FLAGS             细化信息输出的详细程度
--debug=FLAGS            细化调试输出的详细程度
--stderr=e|a|c           更改标准错误输出模式(默认:错误信息)
--quiet, -q              抑制非错误信息
--no-motd                抑制守护进程模式中的MOTD(消息)
--checksum, -c           基于校验和跳过,而不是基于修改时间和大小
--archive, -a            存档模式等价于 -rlptgoD(不包括 -A,-X,-U,-N,-H)
--no-OPTION              关闭隐式的 OPTION(例如 --no-D)
--recursive, -r          递归进入目录
--relative, -R           使用相对路径
--no-implied-dirs        不随 --relative 发送隐式目录
--backup, -b             创建备份(参见 --suffix 和 --backup-dir)
--backup-dir=DIR         将备份存储到 DIR 目录中的层次结构中
--suffix=SUFFIX          备份文件后缀(默认 ~,如果没有 --backup-dir)
--update, -u             跳过接收端更新过的文件
--inplace                直接在目标文件中更新
--append                 向较短的文件追加数据
--append-verify          向文件追加数据并进行校验(基于旧数据的校验和)
--dirs, -d               仅传输目录,不进行递归
--old-dirs, --old-d      与旧版 rsync 通信时,行为如同 --dirs
--mkpath                 创建目标路径中缺失的部分
--links, -l              复制符号链接为符号链接
--copy-links, -L         将符号链接转换为引用的文件/目录
--copy-unsafe-links      仅转换"不安全"的符号链接
--safe-links             忽略指向树外的符号链接

  • --munge-links 修改符号链接,使其变得不可用和安全
  • --copy-dirlinks, -k 将符号链接指向的目录转换为实际目录
  • --keep-dirlinks, -K 将接收方符号链接的目录视为目录
  • --hard-links, -H 保留硬链接
  • --perms, -p 保留权限
  • --executability, -E 保留可执行权限
  • --chmod=CHMOD 修改文件和/或目录权限
  • --acls, -A 保留ACL(隐含 --perms
  • --xattrs, -X 保留扩展属性
  • --owner, -o 保留所有者(仅限超级用户)
  • --group, -g 保留用户组
  • --devices 保留设备文件(仅限超级用户)
  • --copy-devices 将设备内容复制为常规文件
  • --write-devices 将内容写入设备文件(隐含 --inplace
  • --specials 保留特殊文件
  • -D 与 --devices --specials 相同
  • --times, -t 保留修改时间
  • --atimes, -U 保留访问(使用)时间
  • --open-noatime 避免修改已打开文件的访问时间
  • --crtimes, -N 保留创建时间(新文件)
  • --omit-dir-times, -O 排除目录的修改时间
  • --omit-link-times, -J 排除符号链接的修改时间
  • --super 接收方尝试进行超级用户操作
  • --fake-super 使用扩展属性存储/恢复特权属性
  • --sparse, -S 将连续的零块转换为稀疏块
  • --preallocate 在写入文件之前预分配空间
  • --dry-run, -n 执行试运行,不进行任何更改
  • --whole-file, -W 直接复制整个文件(不使用增量传输算法)
  • --checksum-choice=STR 选择校验和算法(等同于 --cc
  • --one-file-system, -x 不跨越文件系统边界
  • --block-size=SIZE, -B 强制使用固定的校验和块大小
  • --rsh=COMMAND, -e 指定使用的远程 shell
  • --rsync-path=PROGRAM 指定在远程机器上运行的 rsync 程序
  • --existing 跳过创建接收方上已存在的文件
  • --ignore-existing 跳过更新接收方上已存在的文件
  • --remove-source-files 发送方删除同步后的文件(非目录)
  • --del --delete-during 的别名
  • --delete 从目标目录删除多余的文件
  • --delete-before 接收方在传输前删除文件
  • --delete-during 接收方在传输过程中删除文件
  • --delete-delay 在传输过程中查找删除文件,传输后删除
  • --delete-after 接收方在传输后删除文件
  • --delete-excluded 也删除排除的文件
  • --ignore-missing-args 忽略丢失的源参数而不报错
  • --delete-missing-args 从目标删除丢失的源参数
  • --ignore-errors 即使发生I/O错误也删除文件
  • --force 强制删除目录,即使目录不为空
  • --max-delete=NUM 限制删除文件的最大数量
  • --max-size=SIZE 不传输大于指定大小的文件
  • --min-size=SIZE 不传输小于指定大小的文件
  • --max-alloc=SIZE 更改与内存分配相关的限制
  • --partial 保留部分传输的文件
  • --partial-dir=DIR 将部分传输的文件存放在指定目录
  • --delay-updates 将所有更新的文件最后放置
  • --prune-empty-dirs, -m 删除文件列表中的空目录链
  • --numeric-ids 不按用户/组名称映射UID/GID值
  • --usermap=STRING 自定义用户名映射
  • --groupmap=STRING 自定义组名映射
  • --chown=USER:GROUP 简单的用户名/组名映射
  • --timeout=SECONDS 设置I/O超时时间(秒)
  • --contimeout=SECONDS 设置守护进程连接超时时间(单位:秒)
  • --ignore-times, -I 不跳过匹配大小和时间的文件
  • --size-only 仅跳过大小匹配的文件
  • --modify-window=NUM, -@ 设置修改时间比较的精度
  • --temp-dir=DIR, -T 在目录 DIR 中创建临时文件
  • --fuzzy, -y 如果目标文件不存在,则寻找相似文件作为基础
  • --compare-dest=DIR 也相对于 DIR 比较目标文件
  • --copy-dest=DIR ... 包括未更改文件的副本
  • --link-dest=DIR 对未更改的文件在 DIR 中创建硬链接
  • --compress, -z 在传输过程中压缩文件数据
  • --compress-choice=STR 选择压缩算法(即 --zc)
  • --compress-level=NUM 显式设置压缩级别(即 --zl)
  • --skip-compress=LIST 跳过压缩列表中后缀名的文件
  • --cvs-exclude, -C 自动忽略文件,方式与 CVS 相同
  • --filter=RULE, -f 添加文件过滤规则
  • -F 与 --filter='dir-merge /.rsync-filter' 相同,重复:--filter='- .rsync-filter'
  • --exclude=PATTERN 排除匹配模式的文件
  • --exclude-from=FILE 从文件 FILE 读取排除模式
  • --include=PATTERN 不排除匹配模式的文件
  • --include-from=FILE 从文件 FILE 读取包含模式
  • --files-from=FILE 从文件 FILE 读取源文件名列表
  • --from0, -0 所有 *-from/filter 文件以 0 字符分隔
  • --old-args 禁用现代参数保护方法
  • --secluded-args, -s 使用协议安全地发送参数
  • --trust-sender 信任远程发送方的文件列表
  • --copy-as=USER[:GROUP] 为副本指定用户和可选的组
  • --ignore-case 比较文件名时忽略大小写
  • --address=ADDRESS 绑定守护进程的出站套接字地址
  • --port=PORT 指定备用端口号
  • --sockopts=OPTIONS 指定自定义 TCP 选项
  • --blocking-io 使用阻塞 I/O 方式与远程 shell 通信
  • --outbuf=N|L|B 设置输出缓冲模式为 None、Line 或 Block
  • --stats 显示文件传输统计信息
  • --8-bit-output, -8 在输出中保留高位字符不转义
  • --human-readable, -h 以易于阅读的格式输出数字
  • --progress 在传输过程中显示进度
  • -P 与 --partial --progress 相同
  • --itemize-changes, -i 输出所有更新的更改摘要
  • --remote-option=OPT, -M 仅将 OPTION 发送到远程端
  • --out-format=FORMAT 使用指定格式输出更新
  • --log-file=FILE 将日志记录到指定文件 FILE
  • --log-file-format=FMT 使用指定格式记录日志更新
  • --password-file=FILE 从文件 FILE 读取守护进程访问密码
  • --early-input=FILE 使用 FILE 作为守护进程的早期执行输入
  • --list-only 仅列出文件而不复制
  • --bwlimit=RATE 限制套接字 I/O 带宽
  • --stop-after=MINS 在指定分钟数后停止 rsync
  • --stop-at=y-m-dTh:m 在指定的时间点停止 rsync
  • --fsync 对每个已写入的文件执行 fsync 操作
  • --write-batch=FILE 将批量更新写入文件 FILE
  • --only-write-batch=FILE 类似于 --write-batch,但不更新目标
  • --read-batch=FILE 从文件 FILE 读取批量更新
  • --protocol=NUM 强制使用较旧的协议版本
  • --iconv=CONVERT_SPEC 请求对文件名进行字符集转换
  • --tr=BAD/GOOD 转换文件名中的字符
  • --checksum-seed=NUM 设置块/文件校验和的种子(高级)
  • --ipv4, -4 优先使用 IPv4
  • --ipv6, -6 优先使用 IPv6
  • --version, -V 输出版本及其他信息并退出

--help, -h (*)           显示帮助信息 (* -h 单独使用时仅显示帮助)

使用 "rsync --daemon --help" 查看守护进程模式的命令行选项。
有关完整的文档,请参阅 rsync(1) 和 rsyncd.conf(5) 手册页。
请访问 https://rsync.samba.org/ 获取更新、错误报告和答案。
rsync 错误:语法或用法错误(错误代码 1),位于 main.c(1767) [client=3.3.0]

C:\Users\Administrator\Downloads\rsync4win\rsync4win\rsync>rsync
rsync  version 3.3.0  protocol version 31
Copyright (C) 1996-2024 by Andrew Tridgell, Wayne Davison, and others.
Web site: https://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, symlinks, symtimes, hardlinks, no hardlink-specials,
    hardlink-symlinks, IPv6, atimes, batchfiles, inplace, append, no ACLs,
    no xattrs, optional secluded-args, iconv, prealloc, stop-at, crtimes
Optimizations:
    no SIMD-roll, no asm-roll, openssl-crypto, no asm-MD5
Checksum list:
    xxh128 xxh3 xxh64 (xxhash) md5 md4 sha1 none
Compress list:
    zstd lz4 zlibx zlib none
Daemon auth list:
    sha512 sha256 sha1 md5 md4

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.

rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm.

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.

Options
--verbose, -v            increase verbosity
--info=FLAGS             fine-grained informational verbosity
--debug=FLAGS            fine-grained debug verbosity
--stderr=e|a|c           change stderr output mode (default: errors)
--quiet, -q              suppress non-error messages
--no-motd                suppress daemon-mode MOTD
--checksum, -c           skip based on checksum, not mod-time & size
--archive, -a            archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
--no-OPTION              turn off an implied OPTION (e.g. --no-D)
--recursive, -r          recurse into directories
--relative, -R           use relative path names
--no-implied-dirs        don't send implied dirs with --relative
--backup, -b             make backups (see --suffix & --backup-dir)
--backup-dir=DIR         make backups into hierarchy based in DIR
--suffix=SUFFIX          backup suffix (default ~ w/o --backup-dir)
--update, -u             skip files that are newer on the receiver
--inplace                update destination files in-place
--append                 append data onto shorter files
--append-verify          --append w/old data in file checksum
--dirs, -d               transfer directories without recursing
--old-dirs, --old-d      works like --dirs when talking to old rsync
--mkpath                 create destination's missing path components
--links, -l              copy symlinks as symlinks
--copy-links, -L         transform symlink into referent file/dir
--copy-unsafe-links      only "unsafe" symlinks are transformed
--safe-links             ignore symlinks that point outside the tree
--munge-links            munge symlinks to make them safe & unusable
--copy-dirlinks, -k      transform symlink to dir into referent dir
--keep-dirlinks, -K      treat symlinked dir on receiver as dir
--hard-links, -H         preserve hard links
--perms, -p              preserve permissions
--executability, -E      preserve executability
--chmod=CHMOD            affect file and/or directory permissions
--acls, -A               preserve ACLs (implies --perms)
--xattrs, -X             preserve extended attributes
--owner, -o              preserve owner (super-user only)
--group, -g              preserve group
--devices                preserve device files (super-user only)
--copy-devices           copy device contents as a regular file
--write-devices          write to devices as files (implies --inplace)
--specials               preserve special files
-D                       same as --devices --specials
--times, -t              preserve modification times
--atimes, -U             preserve access (use) times
--open-noatime           avoid changing the atime on opened files
--crtimes, -N            preserve create times (newness)
--omit-dir-times, -O     omit directories from --times
--omit-link-times, -J    omit symlinks from --times
--super                  receiver attempts super-user activities
--fake-super             store/recover privileged attrs using xattrs
--sparse, -S             turn sequences of nulls into sparse blocks
--preallocate            allocate dest files before writing them
--dry-run, -n            perform a trial run with no changes made
--whole-file, -W         copy files whole (w/o delta-xfer algorithm)
--checksum-choice=STR    choose the checksum algorithm (aka --cc)
--one-file-system, -x    don't cross filesystem boundaries
--block-size=SIZE, -B    force a fixed checksum block-size
--rsh=COMMAND, -e        specify the remote shell to use
--rsync-path=PROGRAM     specify the rsync to run on remote machine
--existing               skip creating new files on receiver
--ignore-existing        skip updating files that exist on receiver
--remove-source-files    sender removes synchronized files (non-dir)
--del                    an alias for --delete-during
--delete                 delete extraneous files from dest dirs
--delete-before          receiver deletes before xfer, not during
--delete-during          receiver deletes during the transfer
--delete-delay           find deletions during, delete after
--delete-after           receiver deletes after transfer, not during
--delete-excluded        also delete excluded files from dest dirs
--ignore-missing-args    ignore missing source args without error
--delete-missing-args    delete missing source args from destination
--ignore-errors          delete even if there are I/O errors
--force                  force deletion of dirs even if not empty
--max-delete=NUM         don't delete more than NUM files
--max-size=SIZE          don't transfer any file larger than SIZE
--min-size=SIZE          don't transfer any file smaller than SIZE
--max-alloc=SIZE         change a limit relating to memory alloc
--partial                keep partially transferred files
--partial-dir=DIR        put a partially transferred file into DIR
--delay-updates          put all updated files into place at end
--prune-empty-dirs, -m   prune empty directory chains from file-list
--numeric-ids            don't map uid/gid values by user/group name
--usermap=STRING         custom username mapping
--groupmap=STRING        custom groupname mapping
--chown=USER:GROUP       simple username/groupname mapping
--timeout=SECONDS        set I/O timeout in seconds
--contimeout=SECONDS     set daemon connection timeout in seconds
--ignore-times, -I       don't skip files that match size and time
--size-only              skip files that match in size
--modify-window=NUM, -@  set the accuracy for mod-time comparisons
--temp-dir=DIR, -T       create temporary files in directory DIR
--fuzzy, -y              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
--compress, -z           compress file data during the transfer
--compress-choice=STR    choose the compression algorithm (aka --zc)
--compress-level=NUM     explicitly set compression level (aka --zl)
--skip-compress=LIST     skip compressing files with suffix in LIST
--cvs-exclude, -C        auto-ignore files in the same way CVS does
--filter=RULE, -f        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
--from0, -0              all *-from/filter files are delimited by 0s
--old-args               disable the modern arg-protection idiom
--secluded-args, -s      use the protocol to safely send the args
--trust-sender           trust the remote sender's file list
--copy-as=USER[:GROUP]   specify user & optional group for the copy
--ignore-case            ignore case when comparing filenames
--address=ADDRESS        bind address for outgoing socket to daemon
--port=PORT              specify double-colon alternate port number
--sockopts=OPTIONS       specify custom TCP options
--blocking-io            use blocking I/O for the remote shell
--outbuf=N|L|B           set out buffering to None, Line, or Block
--stats                  give some file-transfer stats
--8-bit-output, -8       leave high-bit chars unescaped in output
--human-readable, -h     output numbers in a human-readable format
--progress               show progress during transfer
-P                       same as --partial --progress
--itemize-changes, -i    output a change-summary for all updates
--remote-option=OPT, -M  send OPTION to the remote side only
--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
--early-input=FILE       use FILE for daemon's early exec input
--list-only              list the files instead of copying them
--bwlimit=RATE           limit socket I/O bandwidth
--stop-after=MINS        Stop rsync after MINS minutes have elapsed
--stop-at=y-m-dTh:m      Stop rsync at the specified point in time
--fsync                  fsync every written file
--write-batch=FILE       write a batched update to FILE
--only-write-batch=FILE  like --write-batch but w/o updating dest
--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
--tr=BAD/GOOD            transliterate filenames
--checksum-seed=NUM      set block/file checksum seed (advanced)
--ipv4, -4               prefer IPv4
--ipv6, -6               prefer IPv6
--version, -V            print the version + other info and exit
--help, -h (*)           show this help (* -h is help only on its own)

Use "rsync --daemon --help" to see the daemon-mode command-line options.
Please see the rsync(1) and rsyncd.conf(5) manpages for full documentation.
See https://rsync.samba.org/ for updates, bug reports, and answers
rsync error: syntax or usage error (code 1) at main.c(1767) [client=3.3.0]

rsync 版本 3.3.0 协议版本 31
版权所有 (C) 1996-2024 Andrew Tridgell, Wayne Davison 及其他人。
官方网站:https://rsync.samba.org/
特性:
支持 64 位文件、64 位索引号、64 位时间戳、64 位长整数,
socketpairs, 符号链接, 时间戳符号链接, 硬链接, 不支持特殊硬链接,
支持符号链接的硬链接, IPv6, 访问时间戳, 批处理文件, 就地更新, 文件追加, 不支持 ACLs,
不支持 xattrs, 可选参数隔离, 字符集转换, 预分配, 停止时间点, 创建时间戳
优化:
不支持 SIMD-roll, 不支持 asm-roll, 使用 openssl 加密, 不支持 asm-MD5
校验和列表:
xxh128 xxh3 xxh64 (xxhash) md5 md4 sha1 none
压缩算法列表:
zstd lz4 zlibx zlib none
守护程序认证列表:
sha512 sha256 sha1 md5 md4

rsync 是一个文件传输程序,能够通过快速差异算法高效地远程更新文件。

用法: rsync [选项]... 源文件 [源文件]... 目标文件
或   rsync [选项]... 源文件 [源文件]... [用户@]主机:目标文件
或   rsync [选项]... 源文件 [源文件]... [用户@]主机::目标文件
或   rsync [选项]... 源文件 [源文件]... rsync://[用户@]主机[:端口]/目标文件
或   rsync [选项]... [用户@]主机:源文件 [目标文件]
或   rsync [选项]... [用户@]主机::源文件 [目标文件]
或   rsync [选项]... rsync://[用户@]主机[:端口]/源文件 [目标文件]

使用冒号 : 连接方式通过远程shell连接,而双冒号 :: 和 rsync:// 方式则连接到rsync守护进程,并要求源文件或目标文件以模块名称开头。

接下来是命令行选项的详细说明(由于篇幅较长,这里只列出部分选项的翻译):

--verbose, -v            提高输出的详细程度
--quiet, -q              抑制非错误信息的输出
--checksum, -c           根据校验和跳过文件,而不是根据修改时间和大小
--archive, -a            归档模式,等同于 -rlptgoD(不包括 -A,-X,-U,-N,-H)
--recursive, -r          递归进入目录
--links, -l              复制符号链接为符号链接
--hard-links, -H         保留硬链接
--perms, -p              保留权限
--owner, -o              保留所有者(仅超级用户可用)
--group, -g              保留组
--times, -t              保留修改时间
--dry-run, -n            进行试运行,不做任何实际更改
--compress, -z           在传输过程中压缩文件数据
--progress               显示传输进度
--bwlimit=RATE           限制套接字 I/O 带宽
--stop-at=y-m-dTh:m      在指定的时间点停止 rsync

rsync 是一种非常强大的文件同步工具,广泛用于在不同机器之间或本地文件系统之间同步文件和目录。它可以高效地将文件从一个位置同步到另一个位置,同时支持增量备份和网络传输。以下是对 rsync 的详细解释:

1. 是什么?

rsync 是一种开源的工具,通常用于备份和镜像数据。它可以在本地或通过网络同步文件和目录。与传统的文件复制工具不同,rsync 只会复制已经变化的部分,而不是每次都传输整个文件,这样可以显著减少数据传输量和时间。

2. 怎么样(工作原理)?

rsync 工作的核心原理是 增量复制。当你同步一个文件或目录时,rsync 会对比源文件和目标文件的差异,只传输那些发生变化的数据。它的基本流程是:

  1. 比较文件:rsync 首先计算源和目标文件的校验和,识别不同的部分。
  2. 差异传输:只将源文件与目标文件之间的差异部分传输,而不是整个文件。对于已经存在且没有变化的文件,rsync 会跳过,避免不必要的数据传输。
  3. 高效性:通过使用高效的算法(如 delta encoding 和 压缩),rsync 能够显著减少网络带宽的使用和时间开销。

3. 为什么使用 rsync

rsync 的优势在于:

  • 增量同步:只传输修改过的部分,节省带宽和时间。
  • 高效的算法:利用 rsync 特有的算法,能快速识别文件差异并传输。
  • 支持压缩:可以在传输过程中启用压缩功能,减少网络带宽的使用。
  • 支持远程同步:可以通过 SSH 或 RSync 协议在远程主机之间同步数据。
  • 灵活的选项:rsync 提供了丰富的命令行选项,允许用户灵活地控制同步行为,如排除某些文件、保留文件权限、时间戳等。
  • 常用于备份:因为它高效、可靠,rsync 常常被用于定期的增量备份操作。

4. 基本命令示例

  1. 本地同步(同步文件或目录到同一机器的另一个位置):

    bashCopy Code
    rsync -av source/ destination/

    解释:

    • -a:归档模式,表示保持文件权限、符号链接、时间戳等。
    • -v:详细输出模式,显示同步的文件信息。
  2. 远程同步(通过 SSH 从远程主机同步文件):

    bashCopy Code
    rsync -avz source/ user@remote_host:/path/to/destination/

    解释:

    • -z:启用压缩,在传输过程中减少带宽使用。
  3. 同步时排除特定文件或目录:

    bashCopy Code
    rsync -av --exclude 'dir_to_exclude' source/ destination/
  4. 只比较文件,不进行同步(用于测试):

    bashCopy Code
    rsync -av --dry-run source/ destination/

 

rsync 是一种非常高效、灵活的文件同步工具,它的增量复制和差异传输技术,使得它在文件备份、同步和远程数据传输中非常受欢迎。通过合适的命令行选项,用户可以定制同步操作以满足不同需求。

rsync 的功能可以从多个维度进行分类,主要包括以下几个方面:

1. 文件同步功能

  • 增量同步:仅传输变化的部分,而不是整个文件,节省带宽和时间。
  • 本地同步:将文件从一个位置同步到本地的另一个位置。
  • 远程同步:通过 SSH 或 RSync 协议在远程机器之间同步文件。

2. 备份功能

  • 增量备份:仅备份变化的文件,避免全量备份的冗余。
  • 镜像备份:创建源目录的完整镜像,包括权限、时间戳等元数据。
  • 时间戳和权限保留:通过 -a 选项保留源文件的时间戳、权限等信息。

3. 文件选择和排除功能

  • 排除文件:使用 --exclude 选项排除某些文件或目录。
  • 包括文件:通过 --include 精确指定需要同步的文件或目录。
  • 模式匹配:支持基于通配符或正则表达式的文件选择与排除。

4. 压缩和优化功能

  • 压缩:通过 -z 选项在传输过程中启用压缩,节省带宽。
  • 快速传输:通过 -c 选项使用校验和来判断文件是否变动,确保精确同步。

5. 网络传输优化

  • 远程传输:通过 SSH 协议或 RSync 协议实现远程主机之间的高效同步。
  • 带宽限制:通过 --bwlimit 限制传输过程中的带宽使用,避免影响其他网络活动。

6. 文件比较和模拟功能

  • 干跑模拟:使用 --dry-run 参数模拟同步过程,而不实际进行任何更改。
  • 文件比较:通过 -n(或 --dry-run)选项,仅显示将会执行的操作。

这些功能使得 rsync 成为一种强大且灵活的工具,适用于各种文件同步和备份需求。

posted @   suv789  阅读(194)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
点击右上角即可分享
微信分享提示