修改 lsyncd 的默认配置,不直接执行rsync 进行同步,而是改用自己的脚本。
binary 指定我们的脚本
vim /usr/local/lsyncd/etc/lsyncd.conf
settings {
logfile = "/usr/local/lsyncd/logs/lsyncd.log",
statusFile = "/usr/local/lsyncd/logs/lsyncd.status",
maxDelays = 100,
statusInterval = 5,
delay = 5,
exitcodes = {[0] = "ok", [1] = "again", [2] = "die"}
}
sync {
default.rsync,
source = "/data/logs/nginx",
target = "sync_user@192.168.31.140::sync_test",
exclude = { ".*", "*.tmp", "*.bak" , "*.pid"},
delete = true,
rsync = {
binary = "/data/sh/mysync.sh",
compress = false,
archive = true,
verbose = false,
timeout = 3600,
password_file = "/usr/local/lsyncd/etc/rsync.pass"
}
}
编写自己的脚本
vim /data/sh/mysync.sh
#!/bin/bash
/usr/bin/rsync "$@"
result=$?
args="$@"
(
if [ $result -eq 0 ]; then
echo "argument:$args" >> /tmp/lsync_test.txt
fi
) >/dev/null 2>/dev/null </dev/null
exit $result