lsyncd 本地双硬盘实时同步文件目录
lsyncd本地目录同步,有多种工作模式可以选择,本地目录cp,本地目录rsync,远程目录rsyncssh。本文内容为本地目录的同步配置
AkkunYo需求:本服务器有kod网盘,同时对于网盘资料进行多硬盘同步备份
源文件夹/var/www/html/
备份位置/data/html
#### 1.手动或定时同步
```sh
[root@akkun ~]# yum install rsync -y
# 默认增量更新 添加--detele表示同步删除增加文件
[root@akkun ~]# rsync -avz --delete /var/www/html/ /data/html/
#定时任务
[root@akkun ~]# echo "*/5 * * * * rsync -avz --delete /var/www/html/ /data/html/ >/dev/null 2>&1" > /var/spool/cron/root
#去除定时任务的mail邮件提醒
[root@akkun ~]# echo "unset MAILCHECK" >> /etc/profile
```
#### 2.自动lsyncd监控同步
```sh
[root@akkun ~]# yum install lua lua-devel
[root@akkun ~]# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@akkun ~]# yum install lsyncd rsync -y
#开启lsyncd服务
[root@akkun ~]# /etc/init.d/lsyncd start
#设置lsyncd服务自启动
[root@akkun ~]# chkconfig lsyncd on
#配置conf
[root@akkun ~]# cat > /etc/lsyncd.conf << EOF
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
-- create by sh
-- For more examples, see /usr/share/doc/lsyncd*/examples/
-- 本次启用II
-- I. 本地目录同步,direct:cp/rm/mv。 适用:500+万文件,变动不大
-- sync {
-- default.direct,
-- source = "/tmp/src",
-- target = "/tmp/dest",
-- delay = 1
-- maxProcesses = 1
-- }
-- II. 本地目录同步,rsync模式:rsync
sync {
default.rsync,
source = "/var/www/html/",
target = "/data/html/",
excludeFrom = "/etc/rsync_exclude.lst",
-- exclude = "a.txt",
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = false,
-- bwlimit = 2000
}
}
EOF
```
至此本地目录同步备份配置完成