Oracle冷备迁移脚本(文件系统)

Oracle冷备迁移脚本(文件系统)

两个脚本:

  1. 配置文件生成脚本dbinfo.sh
  2. 网络拷贝到目标服务器的脚本cpdb16.sh

1. 配置文件生成脚本

#!/bin/bash
#Usage: create db.config file which includes datafile,tempfile,controlfile and logfile.
#You need reset these environment variables: $ORACLE_SID $ORACLE_BASE $ORACLE_HOME $PATH
#ex: sh dbinfo.sh
#Author: Alfred Zhao
#Vertion: 1.0.0 #ENV
ORACLE_SID="jyzhao"
ORACLE_BASE="/u01/app/oracle"
ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1"
PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin:/u01/app/oracle/product/11.2.0/db_1/bin:." #EXPORT
export ORACLE_SID=$ORACLE_SID
export ORACLE_BASE=$ORACLE_BASE
export ORACLE_HOME=$ORACLE_HOME
export PATH=$PATH #CREATE db.config
sqlplus / as sysdba <<EOF > /tmp/dbtemp.config
set linesize 200 pagesize 8888
select name from v\$datafile union all
select name from v\$tempfile union all
select name from v\$controlfile union all
select member from v\$logfile;
EOF cat /tmp/dbtemp.config | grep / > /tmp/db.config
rm -f /tmp/dbtemp.config

注:需要根据你实际环境配置对应的环境变量。

执行上述脚本生成配置文件/tmp/db.config

2. 网络拷贝到目标服务器的脚本

#!/bin/bash
#Usage: copy db files after DB shutdown immediate!! ssh login without password is needed.
#You need redefine these variables:$IP $Destination
#ex: nohup sh cpdb16.sh &
#Author: Alfred Zhao
#Version: 1.0.0 #Define Variables
IP="192.168.9.149"
Destination="/var/run/sr-mount/df66f479-3da0-05cc-210c-00bc9c5a65cc/db16/" #SCP
while read line
do
scp $line $IP:$Destination
done < /tmp/db.config

注:这里scp需要配置ssh无密码登录才可以后台运行。

ssh无密码登录配置可参考:http://www.cnblogs.com/jyzhao/p/3781072.html

关注进程信息掌控迁移进度

```
# ps -ef | grep cpdb | grep -v grep
root 31638 1 0 16:39 ? 00:00:00 sh cpdb16.sh
# ps -ef | grep scp | grep -v grep
root 31639 31638 0 16:39 ? 00:00:03 scp /opt/app/oracle/trail/system01.dbf 192.168.9.149 /var/run/sr-mount/df66f479-3da0-05cc-210c-00bc9c5a65cc/db16/
root 31640 31639 14 16:39 ? 00:01:00 /usr/bin/ssh -x -oForwardAgent no -oPermitLocalCommand no -oClearAllForwardings yes 192.168.9.149 scp -t /var/run/sr-mount/df66f479-3da0-05cc-210c-00bc9c5a65cc/db16/
```

上一篇:mysql+mycat搭建稳定高可用集群,负载均衡,主备复制,读写分离


下一篇:201621123008 《Java程序设计》第六周实验总结