昨天弄oracle的备份,脚本中用到了scp,需要把服务器的数据cp到备份服务器上,需要配置oracle数据库服务器可以通过db_backup用户无密码登陆到备份服务器上,随便把ssh无密码登陆的配置步骤记下来了,下面是具体工程:
环境:
oracle数据库服务器:10.20.220.247
备份服务器:10.20.220.25
备份用户:db_backup
步骤:
1.在10.20.220.25上新建db_backup用户,指定家目录为/data/backup并设置密码
[root@localhost ~]# useradd db_backup -d /data/backup [root@localhost ~]# passwd db_backup Changing password for user db_backup. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.2.确认sshd的配置文件的认证模块已打开
vi /etc/ssh/sshd_config
#RSAAuthentication yes
#PubkeyAuthentication yes #AuthorizedKeysFile .ssh/authorized_keys把上面三行的注释去掉
重启ssh服务
3.在10.20.220.247上
A.#ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
Generating public/private dsa key pair. Your identification has been saved in /root/.ssh/id_dsa. Your public key has been saved in /root/.ssh/id_dsa.pub. The key fingerprint is: a4:a2:8e:58:e5:d3:38:92:00:c4:bf:a5:f9:67:af:ed root@localhost.localdomainB.#cd .ssh/
#mv id_dsa.pub authorized_keys
#chmod 600 authorized_keys
4.在10.20.220.25上以db_backup登陆执行ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
[db_backup@localhost ~]$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
Generating public/private dsa key pair. Created directory '/data/backup/.ssh'. Your identification has been saved in /data/backup/.ssh/id_dsa. Your public key has been saved in /data/backup/.ssh/id_dsa.pub. The key fingerprint is: 13:03:fd:46:2a:70:1d:a8:01:33:7b:c6:00:59:d2:a9 db_backup@localhost5.在10.20.220.247上执行
scp -p authorized_keys db_backup@10.20.220.25:~/.ssh/authorized_keys
把db_backup的公钥拷贝到备份服务器上
6.测试
[root@localhost ~]# ssh db_backup@10.20.220.25
Last login: Mon Apr 2 03:14:34 2012 from 10.20.220.247 [db_backup@localhost ~]$ pwd /data/backupok,成功了,
现在把的备份oracle脚本和备份文件的脚本加到crontab,每天晚1点二十上执行备份
[root@localhost ~]# crontab -e
20 1 * * * /data/SoftMgr_backup/db_bak.sh >/dev/null 20 1 * * * /data/SoftMgr_backup/file_bak.sh >/dev/nulloracle备份脚本内容:
[root@localhost SoftMgr_backup]# cat db_bak.sh
a=`date "+%Y_%m%d_%H%M"` echo 'begin wcm database backup' dmp_file=/data/SoftMgr_backup/db_back/$a.dmp log_file=/data/SoftMgr_backup/db_back/$a.log echo $dmp_file echo $log_file su - oracle -c "exp smdatadba/wpswps@smdata owner=smdatadba file=$dmp_file log=$log_file" echo 'databse backup success,begin tar file' cd /data/SoftMgr_backup/db_back tar zcfP $a.dmp.tar.gz $a.dmp tar zcfP $a.log.tar.gz $a.log echo 'begin databse backup success,begin upload file to 10.20.220.25 /data/backup' scp $a.dmp.tar.gz db_backup@10.20.220.25:~ scp $a.log.tar.gz db_backup@10.20.220.25:~ echo 'scp file end' echo 'begin delete local file' cd /data/SoftMgr_backup/db_back pwd rm -rf $a.dmp rm -rf $a.log rm -rf $a.dmp.tar.gz rm -rf $a.log.tar.gz echo 'operate end.'#END