一键还原数据库,一天恢复几套不是问题

经常做恢复验证,每次都有些小不同,想省点事,搞个一键还原可好?适用于不同实例,源端和目标端最好版本一致,平台一致,开始吧。

步骤介绍:
#适用oracle 11g单机环境
#备份在192.168.1.1的RESTORDIR目录下,采用rman备份的多个备份集文件,含参数文件(.par)、控制文件(c-xxx)、全库备份、归档备份
#先清理本地的验证库环境,传备份片过来
#恢复pfile文件后清理参数
#恢复控制文件,注册备份信息
#恢复数据库,调整重做日志
#去掉归档模式

#/bin/bash

restore database from rman

please first modify ORACLE_SID and RESTORDIR:

. ~/.bash_profile

RESTORDIR=/oradata/ORCL/20190131
ORACLE_SID=ORCL
export ORACLE_SID= O R A C L E S I D D B N A M E = ORACLE_SID DBNAME= ORACLE_SID
dbca -silent -deleteDatabase -sourceDB $DBNAME

RMANDIR=/oradata/rmanbak/$DBNAME
ssh [email protected] ln -s $RESTORDIR $RMANDIR

BAKDIR=/oradata/ D B N A M E / b a k D A T A D I R = / o r a d a t a / DBNAME/bak DATADIR=/oradata/ DBNAME/db
rm -fr $BAKDIR/*
rm -fr $DATADIR/*
rm -fr O R A C L E H O M E / d b s / ORACLE_HOME/dbs/* DBNAME*
mkdir -p $BAKDIR
mkdir -p D A T A D I R s c p 192.168.1.1 : DATADIR scp 192.168.1.1: RMANDIR/* $BAKDIR

CMDFILE=/tmp/rman1.txt
PARFILE=ls $BAKDIR/*.par
(cat << EOF
startup nomount
restore spfile to pfile ‘ D A T A D I R / i n i t . o r a f r o m DATADIR/init.ora&#x27; from &#x27; PARFILE’;
exit
EOF
)>$CMDFILE

rman target / cmdfile=$CMDFILE

grep -v “.__” D A T A D I R / i n i t . o r a g r e p v c l u s t e r d a t a b a s e g r e p v &quot; l i s t e n e r &quot; g r e p v &quot; . l o g a r c h i v e &quot; g r e p v p g a a g g r e g a t e t a r g e t g r e p v s g a m a x s i z e g r e p v s g a t a r g e t g r e p v t h r e a d g r e p v c o n t r o l f i l e s &gt; / t m p / i n i t 2. o r a g r e p v d b c a c h e s i z e / t m p / i n i t 2. o r a g r e p v d b c r e a t e f i l e d e s t g r e p v &quot; . f a l &quot; g r e p v i n s t a n c e n u m b e r g r e p v s h a r e d p o o l s i z e &gt; DATADIR/init.ora|grep -v cluster_database|grep -v &quot;_listener&quot;|grep -v &quot;*.log_archive&quot;|grep -v pga_aggregate_target|grep -v sga_max_size|grep -v sga_target|grep -v thread|grep -v control_files &gt;/tmp/init2.ora grep -v db_cache_size /tmp/init2.ora|grep -v db_create_file_dest|grep -v &quot;*.fal_&quot;|grep -v instance_number|grep -v shared_pool_size&gt; DATADIR/init.ora

echo “.control_files= D A T A D I R / c o n t r o l 01. d b f &quot; &gt; &gt; DATADIR/control01.dbf&quot; &gt;&gt; DATADIR/init.ora
echo "
.sga_max_size=4G” >> $DATADIR/init.ora
echo “*.sga_target=4G” >> $DATADIR/init.ora

mkdir -p grep audit_file_dest $DATADIR/init.ora |awk -F "'" '{print $2}'

CMDFILE=/tmp/rman2.txt

CTLFILE=ls $BAKDIR/c-*
(cat << EOF
startup nomount pfile=‘ D A T A D I R / i n i t . o r a f o r c e r e s t o r e c o n t r o l f i l e f r o m DATADIR/init.ora&#x27; force restore controlfile from &#x27; CTLFILE’;
alter database mount;
catalog start with ' B A K D I R / n o p r o m p t ; c r o s s c h e c k b a c k u p s e t ; d e l e t e n o p r o m p t e x p i r e d b a c k u p s e t ; e x i t E O F ) &gt; BAKDIR/&#x27; noprompt; crosscheck backupset; delete noprompt expired backupset; exit EOF )&gt; CMDFILE

rman target / cmdfile=$CMDFILE

RMANLOG=/tmp/rman_log_KaTeX parse error: Expected group after '_' at position 29: …DFILE=/tmp/rman_̲DBNAME.txt

(cat << EOF
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
set newname for database to 'KaTeX parse error: Expected 'EOF', got '}' at position 93: …over database; }̲ exit EOF )>CMDFILE

time nohup rman target / cmdfile= C M D F I L E l o g = CMDFILE log= RMANLOG &

(cat << EOF
set pagesize 9999 lin 250 echo off heading off verify off feedback off trims on
spool /tmp/rename_log.sql
select ‘ALTER DATABASE RENAME FILE ‘’’||member||’’’ to ‘||’’’’||' D A T A D I R s u b s t r ( m e m b e r , i n s t r ( m e m b e r , / , 1 ) + 1 ) ; c c f r o m v DATADIR&#x27; ||substr(member,instr(member,&#x27;/&#x27;,-1)+1)||&#x27;&#x27;&#x27;;&#x27; cc from v logfile;
spool off
@/tmp/rename_log.sql

spool /tmp/clear_log.sql
select ‘alter database clear logfile group ‘||group#||’;’ cc from v$log;
spool off
@/tmp/clear_log.sql

郑州无痛人流多少钱:https://yyk.familydoctor.com.cn/21521/
alter database open resetlogs;

–alter database disable thread 2;
–alter database drop logfile group 6,7,8,9,10;

create spfile from pfile=' D A T A D I R / i n i t . o r a ; s h u t d o w n i m m e d i a t e s t a r t u p m o u n t a l t e r d a t a b a s e n o a r c h i v e l o g ; a l t e r d a t a b a s e o p e n ; e x i t ) &gt; DATADIR/init.ora&#x27;; shutdown immediate startup mount alter database noarchivelog; alter database open; exit )&gt; CMDFILE

sqlplus / as sysdba @$CMDFILE

echo ‘game over!’

将上述代码保存为r.sh,放到目标端执行!

基本上修改2处即可:要恢复的实例名和备份文件位置(备份服务器IP地址通常是固定的),
如果没有配置信任关系执行时需要2次输入密码
然后就是喝茶时间啦。

猜你喜欢

转载自blog.csdn.net/cyxhjy1314/article/details/90769386
今日推荐