rsync同步

来源:互联网 发布:java 枚举接口 编辑:程序博客网 时间:2024/05/01 23:00

  环境:

             vmwara两台linux虚拟机 

             系统:SUSE linux 11 SP3

             A机:172.27.34.210    B机:172.27.34.211

             主机配置这里略过,IP配好基本ok



  第一步:SSH配置

          AB 两台主机开启SSHD服务,一般默认安装了,开启服务,并且禁用防火墙就行。


   第二步:rsync服务

         开启rsync服务 在  vi /etc/xinetd.d/rsync中 将 “disable=yes”改为“disable=no”

             chkconfig rsync检验

 

   第三步:运行rsync脚本

           #!/bin/bash
           

backupf='/home/qwt/bckup.txt'

echo "Shell Script Backup Your Files / Directories Using rsync"

while [ x$desthost = "x" ]; do

read -p "Destination backup Server : " desthost

done

while [ x$destpath = "x" ]; do

read -p "Destination Folder : " destpath

done        

for line in `cat $backupf`

do            

echo "Copying $line ... " 

rsync -ar "$line" "$desthost":"$destpath"

echo "DONE"

done

      其中bckup.txt中包含需要同步的文件以及路径如:

                      /home/qwt/1.txt

/home/qwt/2.sh

/home/qwt/docs

这里会报一个错误:Copying /home/qwt/1.txt ... 
The authenticity of host '172.27.34.211 (172.27.34.211)' can't be established.
ECDSA key fingerprint is 40:c2:34:00:0a:1e:51:c1:57:85:cb:01:7e:2d:2e:f8 [MD5].
Are you sure you want to continue connecting (yes/no)? 


查阅网上资料,在绝对信任的主机之间可以采用以下方法屏蔽该错误提示

修改/etc/ssh/ssh_config文件

在最后加上         StrictHostKeyChecking no
                              UserKnownHostsFile /dev/null


再次运行  bash rsync.sh 

先提示输入目的IP:

再提示输入目的路径:

DONE

Shell Script Backup Your Files / Directories Using rsync
Destination backup Server : 172.27.34.211
Destination Folder : /home/qwt

Copying /home/qwt/1.txt ... 
Warning: Permanently added '172.27.34.211' (ECDSA) to the list of known hosts.
Password: 
DONE
Copying /home/qwt/2.sh ... 
Warning: Permanently added '172.27.34.211' (ECDSA) to the list of known hosts.
Password: 
DONE
Copying /home/qwt/docs ... 
Warning: Permanently added '172.27.34.211' (ECDSA) to the list of known hosts.
Password: 
DONE

这里一共同步了三个文件,所以输入了三次密码。。。












1 0
原创粉丝点击