sudo apt-get install rsync inotify-tools
mkdir /etc/rsync
cp /usr/share/doc/rsync/examples/rsyncd.conf /etc/rsync/
#secrets file=/etc/rsync/rsyncd.secrets
#motd file=/etc/rsync/rsyncd.motd
[linuxsirhome]
#path=/usr/share/nginx/html
path=/usr/share/nginx/html
log file=/var/log/rsyncd.log
pid file=/var/log/rsyncd.pid
lock file=/var/run/rsync.lock
read only=no
list=yes
uid=root
gid=root
use chroot=no
max connections=5
comment=share file
#ignore errors
mkdir /opt/rsyncdate
vim /etc/rsync/rsync.secrets
user:passwd
chmod 600 /etc/rsync/rsync.secrets
RSYNC_ENABLE=true
RSYNC_CONFIG_FILE= "/etc/rsync/rsyncd.conf"
/etc/init.d/rsync start
mkdir /etc/rsync
vim /etc/rsync/rsync.secrets
passwd
chmod 600 /etc/rsync/rsync.secrets
#!/bin/bash
path='/opt/rsyncdate/' #远程目录
mod1=rsyncdate #远程模块
host1='192.168.1.200' #远程主机ip
user1=www #远程用户
/usr/bin/inotifywait -mrq --timefmt '%y/%m/%d %H:%M' --format '%T %w %f' -e modify,delete,create,attrib $path | while read file
do
/usr/bin/rsync -avzP --delete --progress $path $user1@$host1::$mod1 --password-file=/etc/rsync/rsync.secrets
echo "${file} was rsyncd " >> /var/log/rsync.log 2 >&1
done
#!/bin/bash
#this script for start|stop rsync daemon service
status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
pidfile="/etc/rsync/rsyncd.pid"
start_rsync="rsync --daemon --config=/etc/rsync/rsyncd.conf"
function rsyncstart() {
if [ "${status1}X" == "X" ];then
rm -f $pidfile
${start_rsync}
status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
if [ "${status2}X" != "X" ];then
echo "rsync service start.......OK"
fi
else
echo "rsync service is running !"
fi
}
function rsyncrestart() {
if [ "${status1}X" == "X" ];then
echo "rsync service is not running..."
rsyncstart
else
rsyncstop
rsyncstart
fi
}
case $1 in
"start")
rsyncstart
;;
"stop")
rsyncstop
;;
"status")
rsyncstatus
;;
"restart")
rsyncrestart
;;
*)
echo
echo "Usage: $0 start|stop|restart|status"
echo
esac
#!/bin/bash
#src='/usr/share/nginx/html'
src='/usr/share/nginx/html'
#src='/tmp/nginx/html'
user='ubuntu'
host='34.192.231.27'
rsync_module='linuxsirhome'
/usr/bin/inotifywait -mrq --exclude=html/App/Runtime --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify,delete,create,attrib ${src} \
| while read DATE TIME DIR file
do
# /usr/bin/rsync -vzrtopg --delete --progress /usr/share/nginx/html [email protected]::linuxsirhome
#/usr/bin/rsync -vzrtopg --exclude-from=/etc/rsync/exclude.rule --include-from=/etc/rsync/include.rule --delete --progress ${src} ${user}@${host}::${rsync_module}
/usr/bin/rsync -vzrtopg --include-from=/etc/rsync/include.rule --exclude-from=/etc/rsync/exclude.rule --exclude=/* --delete --progress ${src} ${user}@${host}::${rsync_module}
echo "${file} was rsynced at ${DATE}_${TIME} in ${DIR}" >> /var/log/rsync.log 2>&1
done
# cat /etc/rsync/include.rule
html
在对一个大磁盘进行inotify监听时,爆出如下错误:
Failed to watch /mnt/;
upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches’.
cat /proc/sys/fs/inotify/max_user_watches
max_user_watches 这个文件,默认值是8192
echo 99999999 > /proc/sys/fs/inotify/max_user_watches
Linux系统重启inotify配置max_user_watches无效被恢复默认值8192的正确修改方法为:
sudo vim /etc/sysctl.conf
注意添加一行内容:
fs.inotify.max_user_watches=99999999 #(你想设置的值)