lsyncd - 如何包含特定目录并排除其余目录

lsyncd - 如何包含特定目录并排除其余目录

我想在 lsyncd 进程中包含一些目录并排除所有目录的其余部分。

我一个目录下有这么多目录multisource。我只想包含lsyncd 中的目录temptemp1排除其余所有目录。

/etc/lsyncd/lsyncd.conf.lua我尝试在文件中使用以下代码,

settings {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status"
}
sync {
        default.rsyncssh,
        source = "/var/www/html/multisource",
        host="user@<ip_address>",
        targetdir = "/var/www/html/multisource",
        delay     = 5,
        rsync = {
                perms = true,
                owner = true,
                group = true,
                --include = {"/temp", "/temp1"},
                --exclude = {"/*"}
        }
}

对此有什么想法吗?

答案1

假设您正在复制文件夹中存在的文件和文件夹/root/hive/data,但有一个/root/hive/data/logs您不想复制的文件夹,则:

您需要创建一个文件/etc/lsyncd/lsyncd.exclude并指定该文件中您希望在复制时忽略的文件夹/文件,在我们的例子中/etc/lsyncd/lsyncd.exclude应包含:

logs

确保提供相对路径。

sync{}中的指令应/etc/lsyncd.conf如下所示:

sync {
default.rsync,
source="/root/hive/data",
target="***.***.**.***:/root/hive/data",
excludeFrom="/etc/lsyncd.exclude",

rsync = {
compress = true,
acls = true,
verbose = true,
owner = true,
group = true,
perms = true,
rsh = "/usr/bin/ssh"
}
}

答案2

最好使用lsyncd.exlude下面的列表/etc/lsyncd/lsyncd.exclude

settings {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status"
}
sync {
        default.rsyncssh,
        source = "/var/www/html/multisource",
        host="user@<ip_address>",
        targetdir = "/var/www/html/multisource",
        delay     = 5,
        excludeFrom = "/etc/lsyncd/lsyncd.exclude",
        rsync = {
                perms = true,
                owner = true,
                group = true,
                --include = {"/temp", "/temp1"},
                --exclude = {"/*"}
        }
}

相关内容