Synchronize Files Using Unison
Posted on Oct 22, 2015 in Software
Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.
** Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives. **
https://incumbent.org/post/unison-sync-and-launchd/
- Unison对版本要求很高,进行同步的两台主机需要相同版本的unison, 所以这里使用和windows一致的版本2.13.16,unison-2.13.16.tar.gz
Configuration
默认的配置文件夹位于~currentuser/.unison,即当前用户的home目录下, windows则位于C:Documents and Settingscurrentuser.unison,默认的配置文件名是default.prf.
运行这样的命令:
unison config
Unison将读取~currentuser/.unison/config.prf文件里的配置。
下面是一个简单的配置文件例子(用于bbs应用中两个文件夹同步):
root = /var/www/bbsnew
root = ssh://support@192.168.239.172//var/www/bbsnew
force = /var/www/bbsnew
ignore = Path WEB-INF/tmp
ignore = Path WEB-INF/work*
auto = true
log = true
logfile = /home/support/.unison/itbbs_239.172.log
两个root表示需要同步的文件夹。
force表示以本地的/var/www/bbsnew文件夹为标准,将该目录同步到远端。
ignore = Path表示忽略root下面的WEB-INF/tmp目录,即同步时不同步它。
Auto表示自动应用默认的更新规则。应为这里是以本地文件夹为准,不会出现更新冲突现象,可以使用默认更新规则。
log = true表示在终端输出运行信息。
logfile则指定了同时将输出写入log文件。
# Unison preferences file
# Sync between these too folders
# .prf file cannot recoginize ~, and NOTICE // in ssh address
root = /home/fwolf/
root = ssh://address_of_company_pc//home/fwolf/
# Only process these sub-directories
path = mail
path = .muttrc
path = .unison/default.prf
path = .unison/mail2home.prf
# Include another perference file(.prf)
#Include foo
# ignore all .mp3 files anywhere
ignore = Name *.mp3
# ignore all files with .unison somewhere in their full path
#ignore = Path .unison
# Fastcheck can be open if both side are linux
#fastcheck = yes
log = true
logfile = /home/fwolf/log/unison.log
# imports settings from default.prf
include default