只需60秒Rsync实时一站式同步

  作用于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

你可能感兴趣的:(职场,rsync,休闲)