⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 备份恢复实验.txt

📁 oracle数据库备份与恢复的详细资料集合
💻 TXT
📖 第 1 页 / 共 3 页
字号:
1.2.2 lab6
Cancel-based recovery:用cancel代替归档日志名的输入。可以恢复到具体的某一个归档日志
Scenario:
The current time is 12:00 p.m. on March 9,2002.
The EMPLOYEES table was dropped while someone was trying to fix bad blocks.
Log files exist on the same disk.
The table was dropped at approximately 11:45 a.m.
Staff are currently in a meeting.

简单的说,就是当前的redo log 坏了

准备
SQL> create table scott.test1(n1 number);
SQL> insert into scott.test1 values(1);
SQL> insert into scott.test1 values(2);
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into scott.test1 values(3);
SQL> insert into scott.test1 values(4);
SQL> commit;
SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME         
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- -------------------
         1          1          1    1048576          1 YES INACTIVE                247234 2004-09-25:16:24:03
         2          1          2    1048576          1 YES ACTIVE                  267451 2004-09-25:17:00:56
         3          1          3    1048576          1 NO  CURRENT                 267609 2004-09-25:17:02:27


SQL> shutdown abort

三号组为当前日志,可将其删除或者重命名


恢复
OS 中将所有的数据文件拿回来(除了control file 和redo log file)

SQL> startup mount


SQL> recover database until cancel                                      
ORA-00279: 更改 247235 (在 09/25/2004 16:24:05 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:\ORACLE\ORADATA\ARCHIVE00\AWU1.ARC                   
ORA-00280: 更改 247235 对于线程 1 是按序列 # 1 进行的                   
                                                                        
                                                                        
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}                  
                                                                        
ORA-00279: 更改 267451 (在 09/25/2004 17:13:15 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:\ORACLE\ORADATA\ARCHIVE00\AWU2.ARC                   
ORA-00280: 更改 267451 对于线程 1 是按序列 # 2 进行的                   
ORA-00278: 此恢复不再需要日志文件 'D:\ORACLE\ORADATA\ARCHIVE00\AWU1.ARC'
                                                                        
                                                                          
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}                    
                                                                        
ORA-00279: 更改 267595 (在 09/25/2004 17:13:58 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:\ORACLE\ORADATA\ARCHIVE00\AWU3.ARC                   
ORA-00280: 更改 267595 对于线程 1 是按序列 # 3 进行的                   
ORA-00278: 此恢复不再需要日志文件 'D:\ORACLE\ORADATA\ARCHIVE00\AWU2.ARC'
                                                                        
                                                                        
指定日志: {<RET>=suggested | filename | AUTO | CANCEL}                  
cancel                                                                  
介质恢复已取消。 


SQL> select * from scott.test1;        
                               
             N1                     
     ----------                                                          
              1                     
              2                  
test1 中的  3,4因为没有及时归档,结果丢失


1.2.3 lab7
恢复时,使用备份的控制文件
The current time is 12:00 p.m. on March 9, 2002.
The tablespace containing the EMPLOYEES table has been dropped.
The error occurred around 11:45 a.m.
Many employee records were updated this morning, but not since 11:00 a.m.
Backups are taken every night.(教材的描述)

我制造的情景

SQL> create table scott.test2(n1 number) tablespace users;
SQL> alter system switch logfile;
SQL> insert into scott.test2 values(1);
SQL> commit;
SQL> alter system switch logfile;
SQL> drop tablespace users including contents and datafiles;
SQL> create table scott.test3(n1 number) tablespace tools;
SQL> insert into scott.test3 values(1);
SQL> commit;
SQL> alter system switch logfile;

现在需要把 test2给找回来

SQL> shutdown immediate;
OS: 把datafile和control file都copy回来

打开 D:\oracle\admin\a00215\bdump\alert_a00215.log 

找到最近一次drop tablespace
Sat Sep 25 23:26:54 2004
drop tablespace users including contents and datafiles

应将数据库恢复到
2004-09-25:23:26:53 的样子

SQL> startup
提示日志不匹配
ORA-00314: 日志 3 (线程 1),预计序号 1 与 4 不匹配
ORA-00312: 联机日志 3 线程 1: 'D:\ORACLE\ORADATA\A00215\REDO03.LOG'

SQL> recover database until time '2004-09-25:23:26:53' using backup controlfile;
ORA-00279: 更改 267597 (在 09/25/2004 17:17:23 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:\ORACLE\ORADATA\ARCHIVE00\AWU1.ARC
ORA-00280: 更改 267597 对于线程 1 是按序列 # 1 进行的


指定日志: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: 更改 294226 (在 09/25/2004 23:25:58 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:\ORACLE\ORADATA\ARCHIVE00\AWU2.ARC
ORA-00280: 更改 294226 对于线程 1 是按序列 # 2 进行的
ORA-00278: 此恢复不再需要日志文件 'D:\ORACLE\ORADATA\ARCHIVE00\AWU1.ARC'


ORA-00279: 更改 294368 (在 09/25/2004 23:26:35 生成) 对于线程 1 是必需的
ORA-00289: 建议: D:\ORACLE\ORADATA\ARCHIVE00\AWU3.ARC
ORA-00280: 更改 294368 对于线程 1 是按序列 # 3 进行的
ORA-00278: 此恢复不再需要日志文件 'D:\ORACLE\ORADATA\ARCHIVE00\AWU2.ARC'


已应用的日志。
完成介质恢复。

SQL> alter database open resetlogs;
SQL> select * from scott.test2;        
                               
             N1                     
     ----------                                                          
              1                     
             
SQL> select * from scott.test3;
select * from scott.test3
                    *
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

rman管理的

将上述七个实验基本再做一遍

准备工作: 用catalog和不用catalog(恢复目录数据库)
不用catalog 的方式,采用目标数据库控制文件(control file)

必须是归档模式
用写字板打开initSID.ora 编辑这个静态参数文件           
	加三行代码                                        
	*.log_archive_start=true                          
	*.log_archive_dest='D:\oracle\oradata\archive00\' 
	*.log_archive_format='awu%s.arc'                  
   OS保存                                                 


还用scott用户
SQL> drop user scott cascade
创建scott用户,供实验用 
SQL> @D:\oracle\ora92\rdbms\admin\scott.sql 

D:\>rman target sys/oracle nocatalog
RMAN> startup mount
RMAN> backup database
2> format 'D:\oracle\oradata\rmanbackup00\a00215_%s_%p.rmn';

这样就准备了一个备份,数据库必须在mount状态进行

2.1.1 lab8
数据库关闭状态,需要恢复System datafiles,Undo segment datafiles,Whole database
在这里,我们给scott用户创建一个表,然后破坏undo,恢复后,看看表中的数据还在不在
1) SQL>  conn sys/oracle as sysdba
   SQL> startup
2) SQL> create table scott.com1(n1 number);
   SQL> insert into scott.com1 values(1);
   SQL> commit;
   SQL> alter system switch logfile;
   SQL> insert into scott.com1 values(2);
   SQL> shutdown abort
3) 此时,把undo破坏
   在‘服务‘中,将OracleServiceA00215停止
    删除(OS)undo文件
4) 在‘服务‘中,将OracleServiceA00215启动
5) conn / as sysdba
startup
ORACLE 例程已经启动。
Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 9 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 9: 'D:\ORACLE\ORADATA\A00215\UNDO01.DBF'

(不发的话,可以看警告日志D:\oracle\admin\a00215\bdump\alert_a00215.log,
Sat Sep 25 14:18:18 2004
Errors in file d:\oracle\admin\a00215\bdump\a00215_dbw0_1552.trc:
ORA-01157: cannot identify/lock data file 9 - see DBWR trace file
ORA-01110: data file 9: 'D:\ORACLE\ORADATA\A00215\UNDO01.DBF'
ORA-27041: unable to open file
OSD-04002: 无法打开文件
O/S-Error: (OS 2) 系统找不到指定的文件。)


恢复


RMAN> RESTORE DATABASE;
RMAN>  RECOVER DATABASE;
RMAN> alter database open;
SQL> select * from scott.com1;

        N1
----------
         1


2.1.2 lab9

数据库打开的时候,并且恢复的时候数据库也开启,此时受损的文件不能是system或者undo文件    

如下操作,都在数据库open时进行                                                                
1) SQL> create table scott.com2 (n1 number) tablespace users;                                 
   SQL> insert into scott.com2 values(1);                                                     
   SQL> commit;                                                                               
   SQL> alter system switch logfile;                                                          
                                                                                              
2) 破坏users01.dbf (users 表空间)                                                             
   我这里采取的办法是先将users 表空间offline,再造一个同名(0字节)的覆盖,也可以采取其他办法。
   
SQL> select * from scott.com2;
select * from scott.com2
                    *
ERROR 位于第 1 行:
ORA-00376: 此时无法读取文件 7
ORA-01110: 数据文件 7: 'D:\ORACLE\ORADATA\A00215\USERS01.DBF'
                                                                                                                           
3)恢复

RMAN> run {
2>  sql "alter tablespace users offline immediate";
3>  set newname for datafile 7 to 'D:\oracle\oradata\a00215\users02.dbf';
4>  restore tablespace users;
5>  switch datafile 7;
6>  recover tablespace users;
7>  sql "alter tablespace users online";}

SQL>  select * from scott.com2;

        N1
----------
         1
         
2.1.3 lab10
描述
和实验二类似,不同之处在于数据库损坏时为关闭状态,此时受损的文件不能是system或者undo文件
1)数据库关闭时,删除users02.dbf

恢复
SQL> startup
ORA-01157: 无法标识/锁定数据文件 7 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 7: 'D:\ORACLE\ORADATA\A00215\USERS02.DBF'

RMAN> 
 run {
 set newname for datafile 7 to 'D:\oracle\oradata\a00215\users01.dbf';
 restore tablespace users;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -