admin avatar

lsyncd同步排除目录和文件的两种方法

🕚 by admin

lsyncd同步排除目录和文件的两种方法

先看代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
settings {
    nodaemon = false,
    logfile = "/var/log/lsyncd.log",
    statusFile = "/tmp/log/lsyncd.status",
    -- # inotifyMode指定inotify监控的事件,默认是CloseWrite,还可以是Modify。
    inotifyMode = "CloseWrite",
    maxProcesses = 10
}

-- 可以有多个sync,各自的source,各自的target,各自的模式,互不影响。
sync {
    default.rsyncssh,
    source    = "/var/www/test1",
    host      = "192.168.0.25",
    targetdir = "/var/www/test1",
   -- excludeFrom = "/etc/lsyncd_exclude.lst",
    exclude = {
        ".db",
        "config/**",
        "static/**",
    },
    -- maxDelays = 5,
    delay = 0,
    -- init = false,
    rsync = {
        binary = "/usr/bin/rsync",
        archive = true,
        compress = true,
        verbose = true,
        _extra = {"--bwlimit=2000"},
    },
}

重点看下面的代码

1
2
3
4
5
6
7
8
9
-- excludeFrom = "/etc/lsyncd_exclude.lst",
-- 直接把需要排除的文件或目录写入到/etc/lsyncd_exclude.lst
    exclude = {
        ".db",
        "config/**",
        "static/**",
    },
--直接写入lsyncd同步配置文件中,排除所有.db的文件和config,static目录

启动lsyncd -log Exec /etc/lsycd_demo.conf

- - 是注释,线上代码要想实现相关功能记得取消

同步之前要配置密匙无密码登录

💘 相关文章

写一条评论