|
windows下我经常使用某一个软件让我的U盘和硬盘上某个目录同步。在Linux下,rsync只能实现单向同步,如果同一个文件在两处都被修改,使用rsync是一件危险的事情。除此之外,还有这样的需求,某个被删除的文件,也希望在另一端被删除。
键入unison dir1 dir2就能完成同步。
SUSE Linux ships with Unison (simply install the package unison), but be aware that you need to be running the same version on each of the machines you want to synchronize. For example, Unison 2.9.1 (shipped with SUSE 10.0) will not interoperate with Unison 2.13.16 (shipped with SUSE 10.1). Fortunately, upgrading the older one is easy: copy across the executable /usr/bin/unison from the machine with the newer copy. Alternatively, you can download a prebuilt Linux executable from http://www.cis.upenn.edu/~bcpierce/unison. There is no installation procedure, as such; it simply needs to be uncompressed and copied into /usr/bin.
Once you have Unison installed, try these commands on the local machine as a simple test:
$ unison -version
$ ssh remote_host unison -version
This test will confirm whether the SSH connection is working and that Unison is on the SSH search path on the remote machine. You should also verify that the version number reported by the remote host matches the version number reported locally.
Unison works by synchronizing two replicas. Usually one is local and one is remote. It's important to note that the synchronization is bidirectional: files that have been created or changed on the local replica will propagate to the remote replica, and files that have been created or changed on the remote replica will propagate to the local replica. Unison will detect and flag cases where the same file has been updated (differently) on the two replicas. It makes no attempt to resolve such conflicts automatically.
You can run Unison very simply from the command line. For example:
$ unison /home/chris ssh:/happy.example.com/
This command synchronizes /home/chris (my home directory on the local machine) with my home directory on the machine happy.example.com, using SSH as the transport. You will be prompted for your password or SSH passphrase. The two arguments supplied here are examples of what Unison calls a root, which simply means the top-level directory of a replica. Instead of this simple usage, you can also build named profiles and specify the profile name on the command line. A profile can specify, among other things, the names of the two roots, an explicit list of files and folders to be synchronized, and a list (using wildcards) of files that should be ignored.
You can also run Unison with a graphical interface. Unison will report the updates it believes are necessary, showing new files, changed files, and conflicts, as shown in Figure 4-10. From this screen, you can manually select exactly which updates you want to propagate. |
|