| 关键词: Client Rsync etc 脚本 path conf pass passw root os |
网上有很多实时同步的文章,采用触发式同步,不过给我感觉用的不爽,这样配置那样也要配置太麻烦,自己花了1小时写了两脚本全自动下,只要在脚本里面对应改下目录,及IP就OK。不懂的可以留言。 作用于Server的脚本! #!/usr/bin/python #Rsync service configution import os,sys #Check program is or not installation. pro = '/usr/bin/rsync' if not os.path.isfile(pro): os.system('yum install -y rsync*') #Direct change the start the way for the program. rs = '/etc/xinetd.d/rsync' os.system("sed -i '6s/yes/no/g' %s" % rs) #set up configuration conf = '/etc/rsyncd.conf' path = 'path = /var/www/test' #rsync directory! os.remove(conf) if not os.path.isfile(conf): os.mknod(conf) info = ['uid = root','gid = root','use chroot = no',\ 'max connections = 0','[web]',path,'ignore errors ',\ 'read only = no','list = yes','hosts allow = 192.168.1.0/24 ',\ 'auth users = root','secrets file = /etc/server.pass '] for i in info: men = open(conf,'a').write(i+' ') passw = '/etc/server.pass' #socket password if not os.path.isfile(passw): os.mknod(passw) data = open(passw).read() if len(data) == 0: open(passw,'w').write('root:*o1>sSD.df') #Start the program command = 'service xinetd restart' if os.system(command) == 0: print 'Promgram installtion is succeed' 作用于Client的脚本! #!/bin/sh #set -x src="/var/www/test" ip="192.168.1.216" env="nohup sh -c '/shell/rsync_client.sh' >/dev/null &" ck=`cat "/etc/rc.local"|grep 'client'` if [ -z "${ck}" ];then echo $env 》 '/etc/rc.local' fi if [ ! -f "/etc/client.pass" ];then echo "*o1>sSD.df" > /etc/client.pass chmod 600 /etc/client.pass fi while : do sleep 10 rsync -zrtopg --delete --password-file=/etc/client.pass root@$ip::web $src done |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|