Lsyncd是一种轻量级的实时文件备份解决方案,很是容易安装和使用。node
能够用来同步两天机器之间的文件。git
更多使用方案可参阅: https://github.com/axkibe/lsyncdgithub
brew install lsyncd
brew install rsyncssh
~/MyApp/sync.luaide
settings { logfile = "/var/log/lsyncd.log", --日志路径 statusFile = "/var/log/lsyncd.status", --状态文件 pidfile = "/var/run/lsyncd.pid", --pid文件路径 statusInterval = 1, --状态文件写入最短期 nodaemon = true, --daemon运行 maxProcesses = 1, --最大进程 maxDelays = 1, --最大延迟 insist=true, } sourceList = {} sourceList['/Users/hncg/MyApp/service'] = '/home/cg/MyApp/service' sourceList['/Users/hncg/MyApp/sites.d'] = '/home/cg/MyApp/sites.d' for from_source, target_source in pairs(sourceList) do sync { default.rsync, source = from_source, delete = true, target = "cg@x.x.x.x:"..target_source, exclude = {".idea/*",".git/*","assets/*","node_modules/*","runtime/*","tmp/*","__pycache__/*"}, rsync = { binary = "/usr/local/bin/rsync", -- binary = "/usr/bin/rsync", archive = true, compress = true, bwlimit = 2000, rsh = "ssh -i /Users/hncg/.ssh/id_rsa" -- rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no" -- 若是要指定其它端口,请用上面的rsh } } end
sudo lsyncd ~/MyApp/sync.lualua
rsync可不安装,binary配置选择注释的那行便可。 brew install lsyncd 安装以后默认,rsync默认会安装到/usr/bin/rsync。 可是可能会报错 'rsync: -pstglozD: unknown option',应该是版本的问题。 因此解决方案是本身再经过 brew install rsync 安装一个rsync。 brew install rsync默认会安装到/usr/local/bin/rsync。