设为首页 加入收藏

TOP

rsync(二)
2023-07-23 13:34:02 】 浏览:43
Tags:rsync
ted directory '/root/etc/test' [root@135 ~]# rsync -avH --port 873 --progress --delete /root/etc/ admin@192.168.111.137::etc_from_client --password-file=/etc/rsync.pass sending incremental file list deleting vmware-root_933-3988752732/ ./ test/ sent 77 bytes received 58 bytes 270.00 bytes/sec total size is 0 speedup is 0.00 #安装inotify-tools工具,实时触发rsync进行同步 [root@135 ~]# ll /proc/sys/fs/inotify/ total 0 -rw-r--r--. 1 root root 0 Sep 22 18:53 max_queued_events -rw-r--r--. 1 root root 0 Sep 22 18:53 max_user_instances -rw-r--r--. 1 root root 0 Sep 22 18:53 max_user_watches 如果有这三个max开头的文件则表示服务器内核支持inotify #安装inotify-tools [root@135 ~]# yum -y install make gcc gcc-c++ --allowerasing [root@135 ~]# yum -y install inotify-tools #编写脚本 [root@135 ~]# mkdir /scripts [root@135 ~]# touch /scripts/inotify.sh [root@135 ~]# chmod 755 /scripts/inotify.sh [root@135 ~]# ll /scripts/inotify.sh -rwxr-xr-x. 1 root root 0 Sep 22 19:03 /scripts/inotify.sh [root@135 ~]# vim /scripts/inotify.sh host=192.168.111.137 src=/etc des=etc_from_clien password=/etc/rsync.pass user=admin inotifywait=/usr/bin/inotifywait $inotifywait -mrq --timefmt '%Y%m%d %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \ | while read files;do rsync -avzP --delete --timeout=100 --password-file=${password} $src $user@$host::$des echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done #启动脚本 [root@135 ~]# nohup bash /scripts/inotify.sh & [1] 198988 [root@135 ~]# nohup: ignoring input and appending output to 'nohup.out' [root@135 ~]# ps -ef|grep inotify root 198988 24963 0 19:11 pts/0 00:00:00 bash /scripts/inotify.sh root 198989 198988 0 19:11 pts/0 00:00:00 /usr/bin/inotifywait -mrq --timefmt %Y%m%d %H:%M --format %T %w%f%e -e modify,delete,create,attrib /etc root 198990 198988 0 19:11 pts/0 00:00:00 bash /scripts/inotify.sh root 200024 199782 0 19:11 pts/2 00:00:00 grep --color=auto inotify

测试脚本

//在源服务器上生成一个新文件
[root@135 ~]# touch /etc/123

#查看inotify生成的日志
[root@135 ~]# tail /tmp/rsync.log
20220922 19:15 /etc/123CREATE was rsynced
20220922 19:15 /etc/123ATTRIB was rsynced

#在目标服务器中也可以看见创建的123文件
[root@137 ~]# ls
etc  test
[root@137 ~]# ls etc/123
etc/123

设置脚本开机自动启动:

[root@135 ~]# chmod +x /etc/rc.d/rc.local
[root@135 ~]# vim /etc/rc.d/rc.local
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
nohup /bin/bash /scripts/inotify.sh &     //添加此行
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇版本控制gitlab 下一篇尝试阅读理解一份linux shell脚本

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目