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。