(方法一)
A主机10.10.1.101
B主机10.10.1.104
配置两台主机的对等性
在B主机
[oracle@localhost ~]$ mkdir .ssh
[oracle@localhost ~]$ chmod 700 .ssh
[oracle@localhost xxx]$ ssh-keygen -t rsa --生成rsa秘钥文件
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):回车
Enter same passphrase again:回车
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
35:f8:68:11:c7:24:69:35:02:89:8e:44:8b:56:06:e8 oracle@localhost.localdomain
[oracle@localhost ~]$ cd .ssh/
[oracle@localhost .ssh]$ ll
总计 16
-rw-r--r-- 1 oracle oinstall 410 2011-10-14 authorized_keys
-rw------- 1 oracle oinstall 1675 07-28 23:34 id_rsa --私钥
-rw-r--r-- 1 oracle oinstall 410 07-28 23:34 id_rsa.pub --公钥
[oracle@localhost .ssh]$ ssh-keygen -t dsa --生成dsa秘钥
Generating public/private dsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_dsa):回车
Enter passphrase (empty for no passphrase): 回车
Enter same passphrase again:回车
Your identification has been saved in /home/oracle/.ssh/id_dsa.
Your public key has been saved in /home/oracle/.ssh/id_dsa.pub.
The key fingerprint is:
9a:7c:ef:d0:38:d2:71:0c:c6:c9:91:25:6d:14:76:48 oracle@localhost.localdomain
[oracle@localhost .ssh]$ ls -al
总计 32
drwx------ 2 oracle oinstall 4096 07-28 23:38 .
drwx------ 21 oracle oinstall 4096 07-28 23:12 ..
-rw-r--r-- 1 oracle oinstall 410 2011-10-14 authorized_keys
-rw------- 1 oracle oinstall 668 07-28 23:38 id_dsa --私钥
-rw-r--r-- 1 oracle oinstall 618 07-28 23:38 id_dsa.pub --公钥
-rw------- 1 oracle oinstall 1675 07-28 23:34 id_rsa
-rw-r--r-- 1 oracle oinstall 410 07-28 23:34 id_rsa.pub
同理在A主机生成ssh的秘钥文件
用户名要一致,操作略
回到B主机
[oracle@localhost .ssh]$ cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys 把rsa的公钥放到家目录下的ssh下的authorized_keys
[oracle@localhost .ssh]$ cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys 把dsa也放进去
[oracle@localhost ~]$ ssh 10.10.1.101 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys --把101的rsa放进来
The authenticity of host '10.10.1.101 (10.10.1.101)' can't be established.
RSA key fingerprint is f7:79:23:3b:bc:f9:c7:c1:01:3b:16:d8:1e:45:81:16.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '10.10.1.101' (RSA) to the list of known hosts.
oracle@10.10.1.101's password: --输入A主机的oracle登陆密码
[oracle@localhost ~]$ ssh 10.10.1.101 cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys --把101的dsa放进来
oracle@10.10.1.101's password:--输入A主机的oracle登陆密码
[oracle@localhost .ssh]$ scp authorized_keys 10.10.1.101:/home/oracle/.ssh/authorized_keys --把生成完成的秘钥文件也放在A主机的.ssh文件夹下
oracle@10.10.1.101's password:--输入A主机的oracle登陆密码
首次传送需要密码验证
[oracle@localhost .ssh]$ ssh x101 date
The authenticity of host 'x101 (10.10.1.101)' can't be established.
RSA key fingerprint is f7:79:23:3b:bc:f9:c7:c1:01:3b:16:d8:1e:45:81:16.
Are you sure you want to continue connecting (yes/no)? yes --输入yes
Warning: Permanently added 'x101' (RSA) to the list of known hosts.
Mon Jul 28 23:59:11 CST 2014
[oracle@localhost .ssh]$ ssh x101 date 再次传输不用再次密码验证了
Mon Jul 28 23:59:17 CST 2014
[oracle@localhost .ssh]$
[oracle@localhost .ssh]$ scp x101:/home/oracle/xxx/xxx.txt ~/xxx/
[oracle@localhost xxx]$ cat xxx.txt
ceshi
验证成功
同理如果三台机建立互信关系,把各自的id_dsa.put文件放到 authorized_keys中来即可
(方法二)
在A主机,新建共享文件夹
mk -m 777 /home/oracle/xxx/Xshare
修改/etc/exports文件,添加一条 /home/oracle/xxx/Xshare *(rw), *为全部IP可以访问,也可以指定IP
重启nfs服务:service nfs restart
在B主机
建立对应挂载文件夹
mk -m 777 /home/oracle/xxx/Xshare
挂载
mount -t nfs 10.10.1.101: /home/oracle/xxx/Xshare /home/oracle/xxx/Xshare
编写复制脚本
[oracle@hnmtvcrm xxx]$ vi MoveBakData.sh
#!bin/sh
YESTERDAY=`date -d "yesterday" "+%Y%m%d"`
SID="hngdcrm"
DES_DIR="/home/oracle/xxx/Xshare/104databak"
BAK_DIR="/home/oracle/orabak"
#BAK_DIR="/app_crm/bakdata"
BAK_FILE=${BAK_DIR}/$SID${YESTERDAY}.dmp
LOG_FILE=${BAK_DIR}/$SID${YESTERDAY}.log
D_BAK_FILE=${DES_DIR}/$SID${YESTERDAY}.dmp
D_LOG_FILE=${DES_DIR}
#$SID${YESTERDAY}.log
cd $D_LOG_FILE
#echo BAK_FILE $BAK_FILE
#echo LOG_FILE $LOG_FILE
#echo D_LOG_FILE $D_LOG_FILE
#cat D_LOG_FILE
cp $LOG_FILE $D_LOG_FILE
cp $BAK_FILE $DES_DIR/
[oracle@hngdcrm 104Share]$ crontab -e
#################################异地备份
0 5 * * * /bin/bash /homr/oracle/xxx/MoveBakData.sh >>/home/oracle/xxx/log/copy.log 2>&1
注明:/BIN/bash 如果不添加,会没有权限执行脚本文件
/home/oracle/xxx/log/copy.log 记录运行日记
A主机
编写删除过期脚本
[oracle@localhost xxx]$ vi DelDataBak.sh
#!/bin/sh
SID="hngdcrm"
YESTERDAY=`date -d -4day "+%Y%m%d"`
DATA_DIR="/home/oracle/xxx/xshare"
DATA_FILE=$DATA_DIR/$SID${YESTERDAY}.dmp
LOG_FILE=$DATA_DIR/$SID${YESTERDAY}.log
#echo $LOG_FILE
#echo $DATA_FILE
rm -f $DATA_FILE
rm -f $LOG_FILE
[oracle@localhost xxx]$ crontab -e
###########################删除4天前备份数据
0 6 * * * /bin/bash /home/oracle/xxx/DelDataBak.sh >>/home/oracle/xxx/log/copy.log 2>&1