rsync同步脚本

#!/bin/sh
#自行管理权限
#输出同步日志
#可对比同步进度,同步好的数据,下次不再同步


daytime=$(/bin/date +%Y-%m-%d)
a=$1
b=$2
c=$3
passwd=’39IDIuh7e=s’
      echo “##################”`date`” $a begin rsync” >/var/log/rsync/$a.log1.$daytime
send_data_ssh(){
      expect -c “
      set timeout -1
      spawn ssh -n rsync_rs@$a ls -l $b
      expect {
       ”*yes/no*” {send ”yesr”; exp_continue}
       ”*password*” {send ”$passwdr”;}
         }
      expect eof;” > /var/log/rsync/i.txt 
}
send_data_ssh


cat /var/log/rsync/i.txt |grep rw|grep -v “lost+found”|awk ‘{print $NF}’ >/var/log/rsync/new.txt


ll |awk ‘{print $9}’ |grep -v ‘^$’ >/var/log/rsync/now.txt


diff /var/log/rsync/new.txt /var/log/rsync/now.txt |awk ‘{print $2}’ |grep -v ‘^$’ > /var/log/rsync/rsync.txt


if [ -s /var/log/rsync/rsync.txt ];then


for j in `cat /var/log/rsync/rsync.txt`
do
send_data(){
      expect -c “
      set timeout -1 
      spawn rsync -rtopgvl –delete –exclude “lost+found” rsync_rs@$a:$b/$j $c
      expect {
       ”*yes/no*” {send ”yesr”; exp_continue}
       ”*password*” {send ”$passwdr”;}
         }
      expect eof;” >> /var/log/rsync/$a.log1.$daytime
}
send_data
done
else
echo “same floder,no need to rsync”
echo “##################”`date`” $a end rsync” >>/var/log/rsync/$a.log1.$daytime

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>