mac[linux] uses lsyncd to synchronize multiple files of two machines in real time

What is Lsyncd?

Lsyncd is a lightweight real-time file backup solution, which is very easy to install and use.

It can be used to synchronize files between machines for two days.

Refer to: https://github.com/axkibe/lsyncd

install

brew install lsyncd
brew install rsync

configuration file

~/MyApp/sync.lua

settings {
    logfile = "/var/log/lsyncd.log",          --Log path
    statusFile = "/var/log/lsyncd.status",    --Status file
    pidfile = "/var/run/lsyncd.pid",          --pid File path
    statusInterval = 1,                       --Minimum write time of status file
    nodaemon = true,                         --daemon Function
    maxProcesses = 1,                         --Maximum process
    maxDelays = 1,                            --Maximum delay
    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"
            -- If you want to specify another port, use the rsh
        }
    }
end

Function

sudo lsyncd ~/MyApp/sync.lua

Tips

rsync does not need to be installed. binary configuration can select the comment line.
After brew install lsyncd is installed, rsync will be installed to / usr/bin/rsync by default.
But the error 'rsync: -pstglozD: unknown option' may be reported. It should be a version problem.
So the solution is to install an rsync through brew install rsync.
brew install rsync is installed to / usr/local/bin/rsync by default.

Tags: Linux rsync brew ssh github

Posted on Tue, 03 Dec 2019 20:39:49 -0500 by Kudose