Lsync 如何从一个源同步到多个目标

个人学习笔记,谢绝转载!!!

原文:https://www.cnblogs.com/wshenjin/p/12504314.html


targets = {
    'rsy_user@127.0.0.1::data1',
    'rsy_user@127.0.0.1::data2',
    'rsy_user@127.0.0.1::data3',
}

for _, target in ipairs( targets )
do
    sync{ 
        default.rsync,
        source  = '/tmp/d/',
        target  = target,
        exclude = { ".*", "*.tmp", "*.bak" , "*.pid"},
        delete  = true,
        rsync   = {
            compress = false,
            archive  = true,
            verbose  = false,
            timeout  = 3600,
            password_file = "/etc/rsync.pass",
        }
    }
end

更复杂点的写法:

targets = {
    'rsy_user@127.0.0.1::data1',
    'rsy_user@127.0.0.1::data2',
    'rsy_user@127.0.0.1::data3',
}

sources = {
    '/aaa/bbb/ccc/',
    '/aa/bb/cc/',
    '/a/b/c/',
}

for _, target in ipairs(targets)
do
    for _, source in ipairs(sources)
    do
        sync{ 
            default.rsync,
            source  = '/tmp/d'..source,
            target  = target..source,
            exclude = { ".*", "*.tmp", "*.bak" , "*.pid"},
            delete  = true,
            rsync   = {
               compress = false,
               archive  = true,
               verbose  = false,
               timeout  = 3600,
               password_file = "/etc/rsync.pass",
            }
        }
    end
end

配置文件里可以用..来实现字符变量等的拼接。

参考:
https://axkibe.github.io/lsyncd/faq/multiple-targets/
https://axkibe.github.io/lsyncd/manual/config/layer1/
https://axkibe.github.io/lsyncd/manual/config/layer4/

posted @ 2020-03-16 15:43  wshenJin  阅读(362)  评论(0编辑  收藏  举报