当前位置:网站首页>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;
有的还需要数据库改名,这些都可以用自动脚本来实现。
边栏推荐
- Cve-2015-1635 (ms15-034) Remote Code Execution Vulnerability recurrence
- MySQL index
- PIP install
- Sqli-labs customs clearance (less1)
- Sqli-labs customs clearance (less18-less20)
- SQLI-LABS通关(less15-less17)
- Thinkphp5中一个字段对应多个模糊查询
- Implement strstr() II
- Wechat applet Foundation
- Cve - 2015 - 1635 (ms15 - 034) réplication de la vulnérabilité d'exécution de code à distance
猜你喜欢
随机推荐
(the 100th blog) written at the end of the second year of doctor's degree -20200818
JS countdown case
Linux MySQL 5.6.51 community generic installation tutorial
Sqli-labs customs clearance (less15-less17)
[Zhang San learns C language] - deeply understand data storage
flex九宫格布局
Queue (linear structure)
mapreduce概念和案例(尚硅谷学习笔记)
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
Latex compilation error I found no \bibstyle &\bibdata &\citation command
Sqli labs customs clearance summary-page2
Common prototype methods of JS array
php中通过集合collect的方法来实现把某个值插入到数组中指定的位置
SQLI-LABS通关(less6-less14)
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
2021-07-19c CAD secondary development creates multiple line segments
Wechat applet Foundation
DeprecationWarning: . ix is deprecated. Please use. loc for label based indexing or. iloc for positi
JS judge whether the object is empty
UEditor .Net版本任意文件上传漏洞复现









