当我使用 Unison 同步两个文件夹时,似乎只有一个根目录受到影响。以下是我认为有必要了解其工作原理的所有信息。
我在用着
$ unison -version
unison version 2.27.57
来自 Ubuntu 存储库。
我的工作笔记本电脑:
$ echo $UNISONLOCALHOSTNAME
worklaptop
$ pwd
/home/userfoo
$ ls -lAR .unison*
.unison:
total 8
drwxr-xr-x 2 userfoo userfoo 4096 2010-04-26 11:39 backups
-rw-r--r-- 1 userfoo userfoo 231 2010-04-26 11:38 default.prf
.unison/backups:
total 0
.unisonroot:
total 0
$ cat .unison/default.prf
# Roots of the synchronization
root = /home/userfoo/.unisonroot
root = ssh://devel//home/userbar/.unisonroot
path = *
backuplocation = central
backupdir = /home/.unison/backups
backupprefix = $VERSION.bak
$ mkdir .unisonroot/aDirectoryFrom-$UNISONLOCALHOSTNAME
$ echo something >.unisonroot/aFileFrom-$UNISONLOCALHOSTNAME
$ ls .unisonroot/
aDirectoryFrom-worklaptop aFileFrom-worklaptop
我想要同步的 Ubuntu 服务器:
$ echo $UNISONLOCALHOSTNAME
workcmpuserbardevel
$ pwd
/home/userbar
$ ls -lAR .unison*
.unison:
total 4
drwxr-xr-x 2 userbar userbar 4096 2010-04-26 11:38 .unison
.unison/.unison:
total 0
.unisonroot:
total 0
$ mkdir .unisonroot/aDirectoryFrom-$UNISONLOCALHOSTNAME
$ echo something >.unisonroot/aFileFrom-$UNISONLOCALHOSTNAME
$ ls .unisonroot/
aDirectoryFrom-workcmpuserbardevel aFileFrom-workcmpuserbardevel
我执行一致同步:
$ echo $UNISONLOCALHOSTNAME
worklaptop
$ unison
Contacting server...
Connected [//worklaptop//home/userfoo/.unisonroot -> //workcmpuserbardevel//home/userbar/.unisonroot]
Looking for changes
Warning: No archive files were found for these roots, whose canonical names are:
/home/userfoo/.unisonroot
//workcmpuserbardevel//home/userbar/.unisonroot
This can happen either
because this is the first time you have synchronized these roots,
or because you have upgraded Unison to a new version with a different
archive format.
Update detection may take a while on this run if the replicas are
large.
Unison will assume that the 'last synchronized state' of both replicas
was completely empty. This means that any files that are different
will be reported as conflicts, and any files that exist only on one
replica will be judged as new and propagated to the other replica.
If the two replicas are identical, then no changes will be reported.
If you see this message repeatedly, it may be because one of your machines
is getting its address from DHCP, which is causing its host name to change
between synchronizations. See the documentation for the UNISONLOCALHOSTNAME
environment variable for advice on how to correct this.
Donations to the Unison project are gratefully accepted:
http://www.cis.upenn.edu/~bcpierce/unison
Press return to continue.[<spc>] Waiting for changes from server
Reconciling changes
local workcmps...
dir ----> aDirectoryFrom-worklaptop [f]
file ----> aFileFrom-worklaptop [f]
Proceed with propagating updates? [] y
Propagating updates
UNISON 2.27.57 started propagating changes at 11:49:14 on 26 Apr 2010
[BGN] Copying aDirectoryFrom-worklaptop from /home/userfoo/.unisonroot to //workcmpuserbardevel//home/userbar/.unisonroot
[BGN] Copying aFileFrom-worklaptop from /home/userfoo/.unisonroot to //workcmpuserbardevel//home/userbar/.unisonroot
[END] Copying aDirectoryFrom-worklaptop
[END] Copying aFileFrom-worklaptop
UNISON 2.27.57 finished propagating changes at 11:49:14 on 26 Apr 2010
Saving synchronizer state
Synchronization complete (2 items transferred, 0 skipped, 0 failures)
然后检查我开始同步的计算机上的 .unisonroot 目录:
$ ls .unisonroot/
aDirectoryFrom-worklaptop aFileFrom-worklaptop
在服务器上:
$ echo $UNISONLOCALHOSTNAME
workcmpuserbardevel
$ ls .unisonroot/
aDirectoryFrom-worklaptop aFileFrom-worklaptop
aDirectoryFrom-workcmpuserbardevel aFileFrom-workcmpuserbardevel
如上所示,笔记本电脑 .unisonroot 的内容没有改变,而服务器 .unisonroot 的内容却发生了改变。理想的结果是两个文件夹最终会完全相同,保存两个根目录内容的并集。