当前位置:网站首页>Oracle rman自动恢复脚本(生产数据向测试迁移)
Oracle rman自动恢复脚本(生产数据向测试迁移)
2022-07-02 06:24:00 【贤时间】
生产环境向测试环境迁移数据的话,往往需要用到rman备份进行恢复。
高级点的有商业化的备份恢复工具,在UI界面上点几下就把生产的数据恢复到测试环境了,下面的脚本是穷人版的 ,配置好环境变量及rman备份存放位置,运行下脚本就可以了。
#!/bin/bash
##############################################
#NAME: rman_auto_restore.sh
#DESC:restore oracle db from prod environment to test environment very quickly.
#Note: Linux USER - execute as oracle instance user
#Use: nohup ./rman_auto_restore.sh > ./rman_auto_restore.sh.log &
#History:
# v1.0 2022-03-08 yangshixian
##############################################
. /home/${
USER}/.bash_profile
#
#define Oracle env 配置EBS环境变量
#
export ORACLE_SID=XXXPROD #针对linux的配置文件中实例名大小写敏感
export ORACLE_HOME=/u01/app/xxxx #目标环境ORACLE_HOME路径
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PERL5LIB=$ORACLE_HOME/perl/lib/5.10.0:$ORACLE_HOME/perl/lib/uate_perl/5.10.0:$ORACLE_HOME/appsutil/perl
export PATH=$ORACLE_HOME/perl/bin:$ORACLE_HOME/bin:$PATH
#
#rman env conf 配置rman环境变量#
#
RMAN_BAK_PATH=/data/ebs_rman_data/ #rman备份文件存放绝对路径
RMAN_CONTROLFILE=`ls $RMAN_BAK_PATH | grep C0_ |head -1` #控制文件绝对路径
TARGET_DATA_FILE_PATH=/data/ebs/uat/db/apps_st/data #目标环境数据文件位置
#
#unmount:execute rman restore scripts
#
echo "restore controlfile begin ..."
rman target / <<EOF run { startup nomount; RESTORE CONTROLFILE FROM '$RMAN_BAK_PATH$RMAN_CONTROLFILE'; alter database mount; catalog start with '$RMAN_BAK_PATH' noprompt; } exit EOF
echo "restore controlfile end Status $?"
#
#mount:execute rman restore scripts
#
echo "gen restore rman_scripts begin ...."
sqlplus -s / as sysdba <<EOF set heading off feed off verify off echo off pages 0 trimspool on set lines 132 pagesize 0 spo restore.rman select 'run{' from dual; select 'set newname for datafile ' || file# || ' to '|| '''' || '$TARGET_DATA_FILE_PATH' || substr(name,INSTR(name,'/',-1,1)) || '''' || ';' from v\$datafile; select 'restore database;' || chr(10) || 'switch datafile all;' || chr(10) || 'recover database until scn '|| controlfile_change# || ';' || chr(10) || '}' from v\$database; spo off exit; EOF
echo "gen restore rman_scripts end status $?"
echo "begin rman restore ....."
echo `date`
rman target / log rman_auto_restore_`date -I`.log @restore.rman
echo "begin rman restore over! status: $?"
echo `date`
待改进
脚本待改进地方,只是完成了耗时的恢复部分,后面还可以改进,例如在线日志的路径如果和生产不一致的话需要改路径,改完后还需要进行 alter database open resetlogs;
有的还需要数据库改名,这些都可以用自动脚本来实现。
边栏推荐
- js删除字符串的最后一位
- Deployment API_ automation_ Problems encountered during test
- js判断数组中对象是否存在某个值
- Promise中有resolve和无resolve的代码执行顺序
- How to debug wechat built-in browser applications (enterprise number, official account, subscription number)
- JS judge whether the object is empty
- The use of regular expressions in JS
- Sqli labs customs clearance summary-page4
- Underlying mechanism mvcc
- Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
猜你喜欢
SQLI-LABS通关(less15-less17)
Build FRP for intranet penetration
Huawei mindspire open source internship machine test questions
AWD learning
Latex compilation error I found no \bibstyle &\bibdata &\citation command
The table component specifies the concatenation parallel method
解决微信小程序swiper组件bindchange事件抖动问题
The default Google browser cannot open the link (clicking the hyperlink does not respond)
Self study table Au
Latex warning: citation "*****" on page y undefined on input line*
随机推荐
Deployment API_ automation_ Problems encountered during test
In depth study of JVM bottom layer (3): garbage collector and memory allocation strategy
pm2简单使用和守护进程
Brief analysis of PHP session principle
JS countdown case
2021-07-19C#CAD二次开发创建多线段
ts和js区别
js删除字符串的最后一位
SQLI-LABS通关(less6-less14)
Queue (linear structure)
In depth study of JVM bottom layer (V): class loading mechanism
Linux MySQL 5.6.51 community generic installation tutorial
The default Google browser cannot open the link (clicking the hyperlink does not respond)
sqli-labs通關匯總-page2
php中通过集合collect的方法来实现把某个值插入到数组中指定的位置
php中获取汉字拼音大写首字母
Common function writing method and set get writing method for calculating attributes
Explanation and application of annotation and reflection
Recursion (maze problem, Queen 8 problem)
js数组的常用的原型方法