![lsyncd - 如何包含特定目录并排除其余目录](https://linux22.com/image/153829/lsyncd%20-%20%E5%A6%82%E4%BD%95%E5%8C%85%E5%90%AB%E7%89%B9%E5%AE%9A%E7%9B%AE%E5%BD%95%E5%B9%B6%E6%8E%92%E9%99%A4%E5%85%B6%E4%BD%99%E7%9B%AE%E5%BD%95.png)
我想在 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 = {"/*"}
}
}