我想在 lsyncd 进程中包含一些目录并排除所有目录的其余部分。
我一个目录下有这么多目录multisource
。我只想包含lsyncd 中的目录temp
并temp1
排除其余所有目录。
/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 = {"/*"}
}
}