架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9697|回复: 8

[windows] Windows 使用 cwRsync(Rsync)同步两个磁盘文件

[复制链接]
发表于 2021-9-19 12:46:35 | 显示全部楼层 |阅读模式
由于,准备装重装 Windows 11 系统,想将原来磁盘的文件备份到新的磁盘里面,然后,将所有的磁盘进行格式化。

最简单的方式,就是复制粘贴了,今天利用  cwRsync(Rsync)实现两个文件夹的同步(如果实现了两个文件夹的同步,也就是实现了两个磁盘的同步),cwRsync 可以实现增量备份,也就是源备份到目标,只会将目标没有的文件从源复制粘贴,如果源和目标存在相同文件名,内容不同,cwRsync 会将源的文件覆盖到目标

rsync 是 Linux 上的一款文件同步工具,他可以以其特有的算法,对两个目录进行本机或跨机器同步。这款十分好用的工具,在 Windows 也可以使用,叫做 cwRsync。

下载 cwRsync

地址:https://www.itefix.net/cwrsync

QQ截图20210919123207.jpg

备用下载地址:https://down.itsvse.com/item/wrnjkx.html

解压和设置环境变量

我将下载的压缩包解压至 D:\dev_tools\cwrsync_client_6.2.2_x64_free 目录,下面,然后使用如下命令行将 rsync.exe 永久添加至环境变量:

cmd 设置永久环境变量命令
https://www.itsvse.com/thread-9230-1-1.html

QQ截图20210919123654.jpg

命令行参数如下:

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; equals -rlptgoD (no -H,-A,-X)
--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
--mkpath                 create the destination's path component
--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)
--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
--write-devices          write to devices as files (implies --inplace)
--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
--protect-args, -s       no space-splitting; wildcard chars only
--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
--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) man pages for full documentation.
See https://rsync.samba.org/ for updates, bug reports, and answers

使用说明

举例,将a目录文件同步至b目录,本例中的目录使用相对路径。


-av -a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD;-v,--verbose 详细模式输出。
--progress 显示传输过程。
--delete-after 传输完成后删除。
--exclude 跳过文件或目录。

a/ 源目录, b/ 目标目录。这里可以使用相对路径,也可以使用绝对路径。

第一次同步时会同步所有文件,以后每次同步只会同步有差异的文件。

文件夹内容同步

将 D:\itsvse\source 文件夹内容同步至 D:\itsvse\target 文件夹,并且排除 .svn、.git 目录,命令如下:

因为这是从Linux移植过来的工具,跨磁盘同步时,目录写法与windows常规写法不同。

例如:c盘,应该以这样的格式 /cygdrive/c/,c盘下的abc目录,应该这样写 /cygdrive/c/abc/。

QQ截图20210919122340.jpg

可以将命令保存一个 bat 批处理文件,如下:

(完)





上一篇:Java 获取完整的异常信息(调用堆栈)
下一篇:CentOS 7 安装 ASP.NET Core 3.1 的运行时环境
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2021-9-19 12:58:31 | 显示全部楼层
--delete-after   删除目标在源中不存在的文件,推荐加上此参数。
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2021-9-19 19:07:10 | 显示全部楼层
现在要回复才能看了啊
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2022-1-2 22:54:10 | 显示全部楼层
用途: rsync [OPTION]... SRC [SRC]... DEST
通过远程shell访问方式:
rsync [选项]... [用户名@]HOST:SRC [DEST]
rsync [选项]... SRC [SRC]... [用户名@]HOST:DEST
通过rsync daemon访问方式:
rsync [选项]... [用户名@]HOST::SRC [DEST]
rsync [选项]... SRC [SRC]... [用户名@]HOST::DEST
rsync [选项]... SRC [SRC]... rsync://[用户名@]HOST[:PORT]/DEST
rsync [选项]... rsync://[USER@]HOST[:PORT]/SRC [DEST]

请注意,':'会使用ssh来远程连接,而'::'以及'rsync://'则用于以tcp方式连接一个rsync daemon服务器,这个需要SRC(源),以及包含模块名字的DEST(目的)

选项
-v, --verbose 详细模式输出
--info=FLAGS 输出INFO级别
--debug=FLAGS 输出DEBUG级别
--msgs2stderr 用于调试的特殊输出处理
-q, --quiet 忽略非error的输出
--no-motd 忽略Daemon模式的MOTD
-c, --checksum 让自动跳过基于校验和而非默认的修改时间以及文件大小
-a, --archive 归档(压缩)模式,表示以递归方式传输文件,并保持所有文件属性等同于-rlptgoD(无 -H,-A,-X)
--no-OPTION 关闭隐含的选项(例如 --no-D)
-r, --recursive 对子目录以递归模式处理
-R, --relative 使用相对路径信息
--no-implied-dirs 不使用--relative发送隐含的目录
-b, --backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename.可以使用--suffix选项来指定不同的备份文件前缀
--backup-dir=DIR 将备份文件(如~filename)存放在指定目录下
--suffix=SUFFIX 定义备份文件前缀,默认是~
-u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件(不覆盖更新的文件)
--inplace update destination files in-place (SEE MAN PAGE)
--append 将数据附加到较短的文件
--append-verify 类似--append,但是对旧数据会计算校验和
-d, --dirs 不使用递归传输目录
-l, --links 不处理符号链接(保留符号链接)
-L, --copy-links 将符号链接处理为具体的文件或者文件夹
--copy-unsafe-links 只处理不安全的符号链接
--safe-links 忽略不在SRC源目录的符号链接
--munge-links munge符号链接使它们更安全(但会无法使用)
-k, --copy-dirlinks 把指向文件夹的符号链接转换为文件夹
-K, --keep-dirlinks 把接收端的指向文件夹的符号链接当做文件夹
-H, --hard-links 保留硬链接
-p, --perms 保留权限
-E, --executability 保留文件的可执行属性
--chmod=CHMOD 影响文件或文件夹的属性
-A, --acls 保留ACLs (代表--perms)
-X, --xattrs 保留扩展属性
-o, --owner 保留所有者(仅限superuser)
-g, --group 保留组
--devices 保留设备文件(仅限superuser)
--copy-devices 把设备文件内容当做文件一样进行复制处理
--specials 保留特殊文件
-D 和--devices --specials一样
-t, --times 保留修改时间
-O, --omit-dir-times 忽略文件夹的修改时间
-J, --omit-link-times 忽略符号链接的修改时间
--super 接收端尝试使用superuser进行操作
--fake-super 使用xattrs来存储和恢复权限属性
-S, --sparse 对稀疏文件进行特殊处理以节省空间
--preallocate 在写入前预分配DST文件
-n, --dry-run 执行一个没有实际更改的试运行,只会显示文件会被如何操作
-W, --whole-file 拷贝文件,不进行增量检测
-x, --one-file-system 不要跨越文件系统边界
-B, --block-size=SIZE 检验算法使用的块尺寸,默认是700字节
-e, --rsh=COMMAND 指定使用rsh,ssh方式进行数据同步
--rsync-path=PROGRAM 指定远程服务器上的rsync命令所在路径
--existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件
--ignore-existing 跳过更新已存在于DST的文件
--remove-source-files 发送方删除非文件夹的源文件
--del --delete-during的一个alias
--delete 删除那些DST中SRC没有的文件
--delete-before 传输前删除,而非传输过程中
--delete-during 在传输过程中删除
--delete-delay 在传输过程中确定要删除的,在传输结束后进行删除
--delete-after 在传输结束后删除,而非传输过程中
--delete-excluded 同样删除接收端那些被该选项指定排除的文件
--ignore-missing-args 忽略丢失的源参数不输出错误
--delete-missing-args 从DEST删除丢失的源参数
--ignore-errors 即使出现I/O错误也进行删除
--force 即使文件夹非空也强制删除
--max-delete=NUM 不删除超过指定数量的文件
--max-size=SIZE 不传输超过指定大小的文件
--min-size=SIZE 不传输小于指定大小的文件
--partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输(即断点续传)
--partial-dir=DIR 将因故没有完全传输的文件放到指定文件夹
--delay-updates 在传输末尾把所有更新的文件放到位
-m, --prune-empty-dirs 从文件列表中删除空目录链
--numeric-ids 不要把uid/gid值映射为用户/组名
--usermap=STRING 自定义用户名映射
--groupmap=STRING 自定义组名映射
--chown=USER:GROUP 简单的用户/组名映射
--timeout=SECONDS 设置I/O超时,单位为秒
--contimeout=SECONDS 设置Daemon连接超时,单位为秒
-I, --ignore-times 不跳过那些有同样的时间和大小的文件
-M, --remote-option=OPTION 只把指定选项发送到远端
--size-only 只跳过大小相同的文件
--modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0
-T, --temp-dir=DIR 在指定文件夹中创建临时文件
-y, --fuzzy 如果DEST没有任何文件,查找类似的文件
--compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份
--copy-dest=DIR 和上面的类似,但是还会复制指定文件夹中的没有改变的文件
--link-dest=DIR 和上面类似,只是没有改变的文件会被硬链接到DST
-z, --compress 在传输过程中进行压缩
--compress-level=NUM 指定压缩级别0-9,默认为6
--skip-compress=LIST 跳过压缩文件后缀在指定列表中的文件
-C, --cvs-exclude 自动跳过CVS的生成文件
-f, --filter=RULE 添加一个文件过滤规则
-F 等于--filter='dir-merge /.rsync-filter'
    重复的: --filter='- .rsync-filter'
--exclude=PATTERN 排除符合匹配规则的文件
--exclude-from=FILE 从指定文件中读取需要排除的文件
--include=PATTERN 包含(不排除)符合匹配规则的文件
--include-from=FILE 从指定文件中读取需要包含(不排除)的文件
--files-from=FILE 从指定文件中读取SRC源文件列表
-0, --from0 从文件中读取的文件名以'\0'终止
-s, --protect-args 没有空格分隔;只有通配符的特殊字符
--address=ADDRESS 绑定到指定的地址
--port=PORT 指定其他的rsync服务端口
--sockopts=OPTIONS 指定自定义的TCP选项
--blocking-io 对远程shell使用阻塞IO
--stats 提供某些文件的传输状态
-8, --8-bit-output 在输出中留下高比特的字符
-h, --human-readable 用人类可读的格式输出数字
--progress 在传输过程中显示进度
-P 等同于--partial --progress
-i, --itemize-changes 输出对所有更新的变更摘要
--out-format=FORMAT 用指定格式输出更新
--log-file=FILE 将日志保存到指定文件
--log-file-format=FMT 用指定格式更新日志
--password-file=FILE 从文件读取Daemon服务器密码
--list-only 不复制而是只列出
--bwlimit=RATE 限制套接字I/O带宽
--outbuf=N|L|B 设置输出缓冲,为None,Line或者Block
--write-batch=FILE 写入批量更新到指定文件
--only-write-batch=FILE 和上面类似,但是对DST进行只写的更新
--read-batch=FILE 从指定文件读取一个批量更新
--protocol=NUM 强制使用指定的老版本协议
--iconv=CONVERT_SPEC 对文件名进行字符编码转换
--checksum-seed=NUM 设置块/文件的校验和种子
-4, --ipv4 偏向于使用IPv4
-6, --ipv6 偏向于使用IPv6
--version 打印版本号
(-h) --help 显示帮助信息
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2022-1-3 20:19:55 | 显示全部楼层
Restricted不允许chmod使用非平凡的 ACL 更改文件或目录。如果 ACL 可以完全表示为文件模式而不会丢失任何访问规则,则 ACL 是微不足道的。将 ACL 模式设置为受限通常用于优化数据集以进行 SMB 共享,但可能需要进一步优化。例如,使用此数据集配置 rsync 任务可能需要添加--no-perms作为任务的额外选项。

https://www.truenas.com/docs/core/storage/pools/permissions/

码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2022-10-9 16:12:45 | 显示全部楼层
感谢楼主的分享!
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2023-8-27 10:55:27 | 显示全部楼层
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2023-8-30 18:37:56 | 显示全部楼层
实测如下命令比鼠标右键复制粘贴快10倍:

码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2023-12-7 18:31:24 | 显示全部楼层
学习
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-3-29 04:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表