保持主目录与 Linux Box 同步
我有两台服务器,计算机 A 和计算机 B,都运行 Linux。我需要编写一个程序或 shell 脚本来持续监视计算机 A 上的主目录的内容,如果有任何更改,请将更改复制到计算机 B 上的主目录,以便两个主目录始终相同。 (对计算机 B 上的主目录所做的任何更改都将被安全地忽略。)
I have two servers, computer A and computer B, both running Linux. I need to write a program or a shell script which will continuously monitor the contents of my home directory on computer A and if anything changes, copy the changes to my home directory on computer B such that both home directories are always the same. (Any changes made to the home directory on computer B and safely be ignored.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否考虑过通过网络文件系统将
/home
从计算机 A 导出到计算机 B,例如 NFS ?您还可以以只读模式将导出的文件系统挂载在 B 上,这样您就无法根据需要修改 B 中的
/home
内容。Have you considered exporting
/home
from computer A to computer B via a network file system, e.g. NFS ?You could also mount the exported filesystem on B in read-only mode so you won't be able to modify the contents of
/home
from B if that's desired.假设有一个相当新的 Linux 内核(其中包括 inotify - 它自 2.6.13 起就存在),您可以按照所述使用 inotify-tools 此处 监视更改并在文件上调用 rsync 以更新计算机 B。这应该满足您的要求,并允许 B 上的更改不会传播到A,还有。
您可能可以使用 incron 完成相同的工作,它的工作方式类似于 cron 但基于文件系统事件而不是时间,但它似乎更适合与单个文件一起使用。
Assuming a reasonably recent Linux kernel (one including inotify - it's been present since 2.6.13), you could use inotify-tools as described here to monitor for changes and call rsync on the files to update computer B. That should do what you're asking for, and allow changes on B that don't propagate to A, as well.
You could probably do the same job with incron, which works like cron but based on filesystem events instead of times, but it seems more intended for use with single files.
使用rsync,这将解决您的问题。大多数发行版都已经预装了这个。
Use rsync, which will solve your problems. Most distributions would have this already pre-installed.