如果服务器上的文件不同,rsync 是否会忽略文件时间戳并在客户端上自动覆盖?

发布于 2024-09-18 00:50:13 字数 1117 浏览 3 评论 0原文

我正在尝试设置两台电脑来同步文件夹树,以便每台电脑都拥有该树的副本,其中包含每个文件的最新更新。

我考虑过设置 Mercurial,但意识到我并不真正关心版本控制(特别是因为我的磁盘空间不足),而且 rsync 听起来它可以做更多我想要的事情 - 只是保持文件最新,没有版本。

但是,页面 http://www.linuxjournal.com/content/synchronizing-your-生活说道:

使用 rsync,任何已经存在的文件 目的地不会存在 转移。这加快了 传输时间相当长。然而, 仍然存在问题 双方都进行了修改。经过 默认情况下,rsync 程序只查找 查看文件是否不同 大小和时间戳。它不在乎 哪个文件较新(如果是) 不同,它会被覆盖。

您可以将“--update”标志传递给 rsync 这将导致它跳过文件 目的地(如果它们更新于) 源上的文件,但仅此而已 只要它们是同一类型 文件。这意味着如果对于 例如,源文件是常规的 文件和目标是符号链接, 目标文件将是 被覆盖,无论时间戳如何。 即使不考虑它的怪癖, --update 标志不能解决问题,因为它所做的只是跳过 目标上的文件(如果有) 较新,它不会进行这些更改 到源计算机。

这是正确的吗?

如果是这样,我想它使得 rsync 实际上只适用于将一台主(“源”)机器备份到一台或多台从机上,无论时间戳如何,这些从机都会从主机获取更改。而我真正想要解决的问题是让两台机器成为“对等机”,并且同样从另一台机器获取最近更新的文件。

或者你认为我只能硬着头皮使用 git 或 Mercurial,尽管有额外的磁盘空间用于跟踪版本?

(是的,我了解 Dropbox;我远远超出了 2GB 免费帐户限制,当我不需要云存储和这种简单的东西时,我对每年花费 120-240 美元并不感兴趣。必须之前已经使用免费和开放的工具完成了。)

PC 都运行 XP,但我打算使用 Cygwin 的 rsync 和完成工作所需的任何其他 Unixy 工具。

I'm trying to set up two PCs to sync a folder tree so that each PC will have a copy of the tree with the most recent updates to each file.

I considered setting up Mercurial but realized I don't really care about versioning (especially since I'm low on disk space), and that rsync sounds like it does more of what I want - just keeping files up to date, no versions.

However, the page at http://www.linuxjournal.com/content/synchronizing-your-life says the following:

With rsync, any files that already
exist at the destination will not be
transferred. This speeds up the
transfer time considerably. However,
there is still the problem of having
modifications made on both sides. By
default, the rsync program only looks
to see if the files are different in
size and timestamp. It doesn't care
which file is newer, if it is
different, it gets overwritten.

You can pass the '--update' flag to rsync
which will cause it to skip files on
the destination if they are newer than
the file on the source, but only so
long as they are the same type of
file. What this means is that if, for
example, the source file is a regular
file and the destination is a symlink,
the destination file will be
overwritten, regardless of timestamp.
Even looking past its quirks, the
--update flag does not solve the problem because all it does is skip
files on the destination if they are
newer, it doesn't pull those changes
down to the source computer.

Is this correct?

If so, I guess it makes rsync really only useful for backing up one master ("source") machine onto one or more slaves that will get the changes from the master regardless of timestamps. Whereas the problem I'm really trying to solve is having two machines be "peers" and equally just get the most recently updated files from the other.

Or do you think I'll just have to bite the bullet and use git or Mercurial despite the extra disk space for tracking versions?

(Yes I know about Dropbox; I'm well above the 2GB free account limit and not really interested in spending $120-$240 a year when I don't need the cloud storage and something this simple has to have been done before with free & open tools.)

The PCs are both running XP but I was going to use Cygwin's rsync and any other Unixy tools necessary to get the job done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

失去的东西太少 2024-09-25 00:50:13
rsync av --update /loc1 /loc2

因此只有较新的文件才会从 loc1 同步到 loc2。
逻辑表明 loc2 上任何较新的文件都将保持不变。
因此,由于 loc1,loc2 上的所有过时文件都将是最新的。

rsync av --update /loc2 /loc1

现在我们知道 loc1 拥有的所有较新文件都已复制到 loc2。
loc1 上较旧的文件(loc2 上有较新的文件)保持不变。
第二个 rsync 命令现在将使用 loc2 上较新的文件更新 loc1

等瞧!在此示例中,两个位置都是同步的。

rsync av --update /loc1 /loc2

so only files that are NEWER will be synced from loc1 to loc2.
Logic dictates that any files that are NEWER on loc2 will be untouched.
Therefore all the outdated files on loc2 will be up-to-date thanks to loc1

rsync av --update /loc2 /loc1

Now we know that all the files that loc1 had that were newer were copied to loc2.
Any files that were older on loc1 (that had newer ones on loc2) remained unchanged.
The second rsync command now will update loc1 with files newer on loc2

Et Voila! both locations are synchronised in this example.

最好是你 2024-09-25 00:50:13

如果您在 rsync 和时间戳方面遇到问题,也许您需要研究在同步涉及的各种文件系统上存储时间戳的精度。

使用 fstat 来发现这一点:如果您同步文件,并且原始文件的时间戳为 2012-01-10 23:41:04.348724000,同步文件时间戳为 2012-01-10 23:41:04.000000000那么这是精度差异的标志。

rsync 的选项 --modify-window=1 可以通过允许微小的差异来处理这种精度差异。

If you have problems with rsync and timestamps, perhaps you need to look into the precision with which timestamps are stored on your various filesystems involved in the synchronization.

Use fstat to spot this: if you sync a file and the original has a timestamp of 2012-01-10 23:41:04.348724000 and the synced file timestamp 2012-01-10 23:41:04.000000000 then this is a sign of a difference in precision.

rsync's option --modify-window=1 can deal with this difference in precision by allowing for a small difference.

生寂 2024-09-25 00:50:13

经过测试,我相信这个问题的答案是肯定的。

至于为什么我在提问之前不首先测试一下,我误解了 rsync 的工作方式,并认为你总是需要在服务器上设置一个 rsync 守护进程。

但是,如果您使用 ssh 作为传输机制,则不需要在服务器上运行 rsync 守护进程,只需一个 ssh 守护进程,这更为常见。

在我的测试中,本地计算机上的较新的、已更改的文件被服务器上的较旧文件覆盖(即使我使用了 --update 选项)。

我的结论是,rsync 更适合主从复制/更新,而不是真正的双向、基于对等的同步。

我将不得不研究 Mercurial 或可能的 Microsoft SyncToy(因为两台机器都运行 XP);我可能会选择后者,因为它是一个简单的家庭网络。

After testing, I believe the answer to this is yes.

As for why I didn't just test this in the first place before asking, I'd misunderstood the way rsync worked and thought that you always needed to set up an rsync daemon on the server.

However if you use ssh as the transfer mechanism then there doesn't need to be an rsync daemon running on the server, just an ssh daemon, which is a lot more common.

In my testing, a newer, changed file on my local machine was overwritten by the older file on the server (even though I had used the --update option).

My conclusion is that rsync is better for master-slave copying/updating, rather than true bidirectional, peer-based synchronization.

I will have to look into Mercurial or possibly Microsoft SyncToy (since both machines are running XP); I will probably go with the latter since it's a simple home network.

挽梦忆笙歌 2024-09-25 00:50:13

您是否尝试过执行 rsync --update 两次。我可能是错的,但我认为以下内容
一对命令将实现双向同步。

rsync -avz --stats --update geezer/ merlin

rsync -avz --stats --update merlin/ geezer

这里它只是同步 2 个目录 geezer 和 merlin,但我认为它应该表现相同
如果源和目录是包含计算机名称的完整路径。

Have you tried executing rsync --update twice. I might be wrong but I think the following
pair of commands would achieve a bi-directional sync.

rsync -avz --stats --update geezer/ merlin

rsync -avz --stats --update merlin/ geezer

here it is just syncing 2 directories geezer and merlin, but I think it should behave the same
if the source and dir were full paths including machine names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文