备份与恢复系列 八 丢失所有数据文件的还原与恢复

33 篇文章 0 订阅
30 篇文章 0 订阅
RMAN运行块中用于恢复的set选项

为数据文件设置新名称
为特定的数据文件制定新的文件名和路径。如果没有定义该项,则RMAN将文件还原到其当前的路径和文件名。

设置归档日志路径
为还原和恢复命令的归档日志文件定义不同的路径。如果没有定义该项,RMAN使用目标init.ora文件定义的第一个归档存储的路径。

set until
为恢复定义停止点。不完全恢复可以完成到指定时间、日志序列号或者SCN。如果没有定义该项,RMAN将还原基准备份,并用增量备份和重做将所有的数据文件恢复到当前状态

环境变量对还原和恢复起着重要的作用。有时候需要设置环境变量使回话的字符集与数据库的字符集保持一致。设置NLS_LANG环境变量使它与目标数据库的字符集匹配。如果在RMAN的LIST, REPORT, SET UNTIL等命令中要使用特定的时间,则应该设置NLS_DATE环境变量与命令的日期字符串匹配。也可以在脚本中使用TO_DATE函数指向特定的日期。
export NLS_LANG=AMERICA_AMERICA.WE8ISO8859P1
export NLS_DATE_FORMAT=YYYY-MM-DD:HH24:DD:SS

校准当前的操作系统日期
date -s "2014-08-27 09:26:00"

练习1 还原整个数据库

假设场景如下:
全部数据文件丢失
控制文件存在
联机重做日志存在
实验步骤如下:
执行整个数据库备份
模拟PRACTICE数据文件丢失
还原与恢复数据库
验证还原与恢复的数据库
1,执行整个数据库备份
export ORACLE_SID=PRACTICE
rman target /

run{
allocate channel c1 type disk maxpiecesize 1000m;
allocate channel c2 type disk maxpiecesize 1000m;
backup incremental level 0
tag = 'whole_in0' 
format = '/backup/%d_in0_%s_%p_%t' database;
sql 'alter system archive log current';
backup archivelog all 
tag 'arch_bak' 
format = '/backup/%d_arch_%t_%U.bak';
backup current controlfile 
tag 'auto_ctl'
format ='/backup/%d_auto_ctl_%t_%U.bak';
release channel c1;
release channel c2;
}

sqlplus / as sysdba
conn snow/snow
insert into date_log values(sysdate+10,'Mini');
commit;

run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level 1
format '/backup/db_in1_%d_%s_%p_%t'
tag='whole_inc1'
database;
release channel c1;
release channel c2;
}

确认date_log表所在表空间
conn snow/snow
select TABLE_NAME,TABLESPACE_NAME from user_tables where table_name='DATE_LOG';

TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
DATE_LOG                       TOOLS

确认数据文件位置
select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/PRACTICE/system01.dbf
/oradata/PRACTICE/sysaux01.dbf
/oradata/PRACTICE/undotbs01.dbf
/oradata/PRACTICE/users01.dbf
/oradata/PRACTICE/example01.dbf
/oradata/tools01.dbf
/oradata/indx01.dbf

2 模拟数据库失效
RMAN> shutdown abort
RMAN> host;
[oracle@practice3 ~]$ rm /oradata/PRACTICE/*.dbf
[oracle@practice3 ~]$ ls -l /oradata/PRACTICE/
total 173436
drwxr-xr-x 2 oracle oinstall     4096 Jul 30 12:00 archive
drwxr-xr-x 2 oracle oinstall     4096 Jul 30 12:00 backup
-rw-r----- 1 oracle oinstall 10043392 Aug 27 09:36 control01.ctl
-rw-r----- 1 oracle oinstall 52429312 Aug 17 02:28 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Aug 27 09:36 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Aug 17 02:28 redo03.log
-rw-r----- 1 oracle oinstall 10043392 Aug 27 09:30 snap_PRACTICE.ctl
[oracle@practice3 ~]$ exit

RMAN> startup

connected to target database (not started)
Oracle instance started
database mounted
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 08/27/2014 09:38:51
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/oradata/PRACTICE/system01.dbf'

3,还原与恢复数据库
RMAN>shutdown abort;
RMAN>startup mount;
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
recover database;
}

allocated channel: c1
channel c1: SID=133 device type=DISK

allocated channel: c2
channel c2: SID=10 device type=DISK

Starting restore at 2014/08/27 09:40:25

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00002 to /oradata/PRACTICE/sysaux01.dbf
channel c1: restoring datafile 00003 to /oradata/PRACTICE/undotbs01.dbf
channel c1: restoring datafile 00006 to /oradata/tools01.dbf
channel c1: restoring datafile 00007 to /oradata/indx01.dbf
channel c1: reading from backup piece /backup/PRACTICE_in0_48_1_855800878  
channel c2: starting datafile backup set restore
channel c2: specifying datafile(s) to restore from backup set
channel c2: restoring datafile 00001 to /oradata/PRACTICE/system01.dbf
channel c2: restoring datafile 00004 to /oradata/PRACTICE/users01.dbf
channel c2: restoring datafile 00005 to /oradata/PRACTICE/example01.dbf
channel c2: reading from backup piece /backup/PRACTICE_in0_47_1_855800878
channel c1: piece handle=/backup/PRACTICE_in0_48_1_855800878 tag=WHOLE_IN0
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:15
channel c2: piece handle=/backup/PRACTICE_in0_47_1_855800878 tag=WHOLE_IN0
channel c2: restored backup piece 1
channel c2: restore complete, elapsed time: 00:00:15
Finished restore at 2014/08/27 09:40:41

Starting recover at 2014/08/27 09:40:41
channel c1: starting incremental datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /oradata/PRACTICE/sysaux01.dbf
destination for restore of datafile 00003: /oradata/PRACTICE/undotbs01.dbf
destination for restore of datafile 00006: /oradata/tools01.dbf
destination for restore of datafile 00007: /oradata/indx01.dbf
channel c1: reading from backup piece /backup/db_in1_PRACTICE_56_1_856690214  <==
channel c2: starting incremental datafile backup set restore
channel c2: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /oradata/PRACTICE/system01.dbf
destination for restore of datafile 00004: /oradata/PRACTICE/users01.dbf
destination for restore of datafile 00005: /oradata/PRACTICE/example01.dbf
channel c2: reading from backup piece /backup/db_in1_PRACTICE_55_1_856690214
channel c1: piece handle=/backup/db_in1_PRACTICE_56_1_856690214 tag=WHOLE_INC1
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
channel c2: piece handle=/backup/db_in1_PRACTICE_55_1_856690214 tag=WHOLE_INC1
channel c2: restored backup piece 1
channel c2: restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 2014/08/27 09:40:43
released channel: c1
released channel: c2

RMAN> alter database open;

RMAN> host;

4, 验证还原与恢复的数据库
[oracle@practice3 ~]$ sqlplus snow/snow
SNOW@PRACTICE >select * from date_log order by create_time;
CREATE_TIME         NAME
------------------- ------------------------------
2014/08/27 09:44:54 --
2014/08/27 09:45:54 --
2014/08/27 09:46:54 --
2014/08/27 09:47:54 --
2014/09/06 09:29:26 Mini

验证结果

--未完待续--
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值