我全心全意推荐rsync。与源相比,它可以自动检测目标上缺少哪些文件并仅复制它们。IIUC,它是您用例的最佳解决方案。在您的情况下cp是无用的,因为它会始终复制所有文件并且比rsync. 如果您了解它的rsync工作原理,它将被证明是在任何情况下复制大量数据的最佳解决方案。
请注意,如果您决定rsync将来通过网络使用,则必须在源计算机和目标计算机上都安装它。这是rsync我知道的唯一缺点。
编辑:
rsync用法很简单。通常归结为以下命令:
$ rsync -avz <SOURCE> <DESTINATION>
Run Code Online (Sandbox Code Playgroud)
-a表示存档模式 - 递归复制目录并重新创建符号链接,保存权限,修改时间,组 ownerhsip,所有者,-v表示详细,-z表示压缩
下载时,临时文件名前面带有.. 下次相同的命令将仅运行已在本地更改的文件,并且出现的新文件DESTINATION将从 下载DESTINATION到SOURCE。
它易于使用rsync过ssh:
$ rsync -avz -e ssh hosting:/home1/rkumvbrh/mail/drabczyk.org/arkadiusz .
Run Code Online (Sandbox Code Playgroud)
-e ssh 可以省略,因为 ssh 是默认值:
$ rsync -avz hosting:/home1/rkumvbrh/mail/drabczyk.org/arkadiusz .
Run Code Online (Sandbox Code Playgroud)
rsync通过网络使用时,它必须安装在两端:
$ rsync -avz -e "ssh" router:<FILE> .
ash: rsync: not found
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: remote command not found (code 127) at io.c(226) [Receiver=3.1.0]
Run Code Online (Sandbox Code Playgroud)
编辑:
好的,起初我以为您想用外部磁盘中的文件替换本地磁盘上损坏的所有文件,并从外部磁盘复制所有新文件。但是,如果您只想将新文件从内部磁盘复制到外部磁盘,则必须添加--ignore-existing选项,以便将新文件复制到外部磁盘,但不会将损坏的文件:
$ rsync -avz --ignore-existing <PATH/TO/INTERNAL_HDD> <PATH/TO/EXTARNAL_HDD>
Run Code Online (Sandbox Code Playgroud)
来自man rsync:
--ignore-existing 这告诉 rsync 跳过更新目标上已经存在的文件(这不会忽略现有目录,否则什么都不做)。另见--existing。
Run Code Online (Sandbox Code Playgroud)This option is a transfer rule, not an exclude, so it doesn't affect the data that goes into the file-lists, and thus it doesn't affect deletions. It just limits the files that the receiver requests to be transferred. This option can be useful for those doing backups using the --link-dest option when they need to continue a backup run that got interrupted. Since a --link-dest run is copied into a new directory hierarchy (when it is used properly), using --ignore existing will ensure that the already-handled files don't get tweaked (which avoids a change in permissions on the hard-linked files). This does mean that this option is only looking at the existing files in the destination hierarchy itself.
| 归档时间: |
|
| 查看次数: |
318 次 |
| 最近记录: |