在Frontend机器上生成密钥:
1. cd ~/.ssh/
2. ssh-keygen
3. ls -l
total 32 -rw——- 1 root root 1671 Jul 31 11:27 id_rsa -rw——- 1 root root 395 Jul 31 11:27 id_rsa.pub -rw-r–r– 1 root root 10323 Jul 31 16:07 known_hosts
将公共密钥复制到需要同步的服务器上:
1. scp id_rsa.pub root@ondosrv:/root/.ssh/authorized_keys2
在Frontend机器上测试:
1. ssh root@ondosrv
注释:应该不需要输入密码。
编写同步程序
在Frontend机器上编写同步程序:
1. cd /backup
2. vi sync.sh
3. chmod 700 sync.sh
rsync -avlR –delete -e ssh root@192.168.100.1:/usr/share/tomcat5/ /backup/ondo/
rsync -avlR –delete /home/utstar/ /backup/frontend/ rsync -avlR –delete /var/named/ /backup/frontend/ rsync -avlR –delete /etc/ /backup/frontend/
参数意义如下: -a, –archive It is a quick way of saying you want recursion and want to preserve almost everything. -v, –verbose This option increases the amount of information you are given during the transfer. -l, –links When symlinks are encountered, recreate the symlink on the destination. -R, –relative Use relative paths. 保留相对路径…才不让子目录跟 parent 挤在同一层… –delete 是指如果Server端h除了一文件,那客舳艘蚕嘤Π颜庖晃募h除,保持真正的一致。 -e ssh 建立起加密的连接。
rsync命令的使用请参照:http://hi.baidu.com/finet/blog/item/e43dd8f2df3fb412b07ec5ca.html
备份根目录: /backup
按机器名称建立子目录: /backup/ondosrv /backup/frontend /backup/mailsrv ……
1. crontab -e
0 2 * * * /backup/sync.sh
注释:每天凌晨2点运行进行同步。
RSS feed for comments on this post · TrackBack URI
Leave a reply