如何保持两个文件夹自动同步? [英] How to keep two folders automatically synchronized?
问题描述
我想要一个文件夹及其所有子树的同步副本.
I would like to have a synchronized copy of one folder with all its subtree.
它应该以这种方式自动工作:每当我在原始文件夹中创建,修改或删除内容时,这些更改都将自动应用于同步文件夹.
It should work automatically in this way: whenever I create, modify, or delete stuff from the original folder those changes should be automatically applied to the sync-folder.
哪个是执行此任务的最佳方法?
Which is the best approach to this task?
顺便说一句:我在Ubuntu 12.04上
BTW: I'm on Ubuntu 12.04
最终目标是拥有单独的实时备份副本,而无需使用符号链接或安装. 我使用Ubuntu One在我的计算机之间同步数据,过了一会儿出现了问题,并且在同步期间所有数据都丢失了.
Final goal is to have a separated real-time backup copy, without the use of symlinks or mount. I used Ubuntu One to synchronize data between my computers, and after a while something went wrong and all my data was lost during a synchronization.
所以我想进一步增加一个步骤来保存我的数据的备份副本:
So I thought to add a step further to keep a backup copy of my data:
- 我将数据存储在文件夹A"上
- 我需要当前问题的答案才能创建文件夹A"到文件夹B"的单向同步(
cron
使用rsync
的脚本可能是吗?).我需要它只能是从A到B的单向方式,任何对B的更改都不得应用于A. - 我只是保持与Ubuntu One同步的文件夹B"
以这种方式,A中的任何更改都将被添加到B中,这将从U1中检测到并同步到云中.如果出现任何问题,并且U1删除了B上的数据,我总是将它们放在A上.
- I keep my data stored on a "folder A"
- I need the answer of my current question to create a one-way sync of "folder A" to "folder B" (
cron
a script withrsync
? could be?). I need it to be one-way only from A to B any changes to B must not be applied to A. - The I simply keep synchronized "folder B" with Ubuntu One
In this manner any change in A will be appled to B, which will be detected from U1 and synchronized to the cloud. If anything goes wrong and U1 delete my data on B, I always have them on A.
受lanzz的评论启发,另一个想法可能是在启动时运行rsync来备份Ubuntu One下的文件夹内容,并仅在rsync完成后才启动Ubuntu One.
Inspired by lanzz's comments, another idea could be to run rsync at startup to backup the content of a folder under Ubuntu One, and start Ubuntu One only after rsync is completed.
您对此有何看法? 如何知道rsync何时结束?
What do you think about that? How to know when rsync ends?
推荐答案
您可以使用inotifywait
(已启用modify,create,delete,move
标志)和rsync
.
You can use inotifywait
(with the modify,create,delete,move
flags enabled) and rsync
.
while inotifywait -r -e modify,create,delete,move /directory; do
rsync -avz /directory /target
done
这篇关于如何保持两个文件夹自动同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!