使用rsync 同步文件夹笔记

 有6台内网机器,需要使用一些同样的目录和工具,比如tools,每个东西都单独传到6台机器太老土了,于是使用rsync来做文件自动同步。打算拿一台机器来当入口机器。如果后期发布代码在不考虑使用git的条件下,也可以做到统一入口:

安装参考:

    https://www.cnblogs.com/tomato0906/articles/7989222.html

我的rsyncd.conf 配置的写法:vim  /etc/rsyncd.conf

uid = root
gid = root
use chroot = yes
max connections = 5
pid file = /var/run/rsyncd.pid
port = 873
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
log file = /var/log/rsync.log

#limit access to private LANs
hosts allow=10.248.32.0/255.255.255.0
motd file = /etc/rsyncd.motd
[ftp1]
       path = /home/ftp1
       comment = ftp export area

[tools]
    path = /home/scapp/tools
    list = yes
    comment = This is tools backup
    secrets file = /etc/rsyncd/rsyncd.secrets
    exclude = easylife/  samba/

 

设置密码文件

mkdir /etc/rsyncd

vim /etc/rsyncd/rsyncd.secrets

chown root.root /etc/rsyncd/rsyncd.secrets

dhmod 600 /etc/rsyncd/rsyncd.secrets

设置欢迎内容

vim /etc/rsyncd.motd

打开服务端守护进程

rsync --daemon

ps:   修改rsyncd.conf 不需要重启服务器进程。

在另一台机器上使用命令列出文件:

rsync  --list-only root@10.248.32.131::tools

使用命令完成同步:

rsync -avzP root@10.248.32.131::tools /home/scapp/tools

接下来设置定时脚本自动同步:

!/bin/bash
source /etc/profile
date
rsync -avzP root@10.248.32.131::tools /home/scapp/tools

*/10 * * * * sh /root/autosh/tools_backup.sh >> /root/autosh/tools_backup.sh_log ;
# */10 * * * * /usr/bin/rsync -avzP root@10.248.32.131::tools /home/scapp/tools >> /root/autosh/backup.log  
 

最后记一个很棒的东西,没准以后用得上: inotify 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值