rsync 可以在同步之前验证内容吗
Rsync 可以配置为在同步文件之前验证文件内容吗?我听说过校验和,但我后来知道校验和只进行采样。我只想在内容更改而不是时间戳时传输文件,有没有办法使用任何 rsync 模式来完成此操作。 在我的场景中,假设文件sample.text每周都会创建,并且仅当sample.text的内容发生更改时我才想将其与远程服务器同步,因为它每周创建一次,时间戳显然会发生变化。但我只想在内容发生变化时进行转移。
Can Rsync be configured to verify the contents of the file before they are being synced. I have heard about checksum, but I came to know that checksum only does a sampling. I want to transfer a file only if it is contents are changed and not timestamp, is there a way to do it with any of the rsync modes.
In my scenario, say file sample.text will be created every week and I want to sync it with a remote server only if the contents of sample.text are changed, since it is created every week, the time stamp would obviously change. But I want the transfer only on a content change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的:
Rsync 相当复杂。我建议在将其用于任何重要的事情之前先花时间阅读手册页并尝试测试数据。
大多数时候,人们使用 rsync -ac source dest。
-rlptgoD
垃圾意味着:递归 (r
),将符号链接复制为符号链接 (l< /code>)、保留权限 (
p
)、保留时间 (t
)、保留组 (g
)、保留所有者 (o
)、保留设备文件 (D
,仅限超级用户),保留特殊文件(也是D
的一部分)。-c
或--checksum
确实是您正在寻找的(根据校验和跳过,而不是 mod-time 和大小)。您认为 rsync 仅对 mtime 和 size 进行采样的假设是错误的。Yes:
Rsync is pretty complicated. I recommend cuddle time with the man page and experimentation with test data before using it for anything remotely important.
Most of the time, people use
rsync -ac source dest
.And that
-rlptgoD
garbage means: recursive (r
), copy symlinks as symlinks (l
), preserve permissions (p
), preserve times (t
), preserve group (g
), preserve owner (o
), preserve device files (D
, super-user only), preserve special files (also part ofD
).The
-c
or--checksum
is really what you are looking for (skip based on checksum, not mod-time & size). Your supposition that rsync only samples mtime and size is wrong.请参阅 rsync 手册页上的
--checksum
选项。此外,如果您确定内容的更改也意味着大小的更改,则
--size-only
选项将是更快的选择。See the
--checksum
option on the rsync man page.Also, the
--size-only
option will be a faster choice if you know for sure that a change of contents also means a change of size.例子:
Example: