冷备手工完全恢复(recover database,recover tablespace,recover datafile)

冷备手工完全恢复

1.   手工完全恢复三种级别: 
recover database: 所有或大部分datafile丢失,一般是在mount状态完成。
recover tablespace:    非关键表空间损坏,表空间下某些数据文件不能访问,一般是在open下完成。
recover datafile: 单一或少数数据文件损坏,可以在mount或open 状态完成。
四个关键文件:1)system01.dbf, 2) undo tablespace,3)control file 4)current log file

2.  手工完全恢复前提: 1)有一套datafile全备, 2)使用当前控制文件, 3)自上次备份以来的归档日志和当前联机日志是完整的

3.  实验1:(recover database )

3.1  查看数据库当前状态,准备好冷备。
SQL> select * from andy;

ID
----------
1

--生成冷备脚本
SQL> select ‘ho cp ‘ || name || ‘ /home/oracle/coldbak‘ from v$controlfile;

‘HOCP‘||NAME||‘/HOME/ORACLE/COLDBAK‘
--------------------------------------------------------------------------------
ho cp /home/oracle/app/oradata/orcl/control01.ctl /home/oracle/coldbak
ho cp /home/oracle/app/flash_recovery_area/orcl/control02.ctl /home/oracle/coldbak

SQL> select ‘ho cp ‘ || name || ‘ /home/oracle/coldbak‘ from v$datafile;

‘HOCP‘||NAME||‘/HOME/ORACLE/COLDBAK‘
--------------------------------------------------------------------------------
ho cp /home/oracle/app/oradata/orcl/system01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/sysaux01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/undotbs01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/users01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/tbtb01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/ogg01.dbf /home/oracle/coldbak

6 rows selected.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

--冷备
SQL> ho cp /home/oracle/app/oradata/orcl/control01.ctl /home/oracle/coldbak
SQL> ho cp /home/oracle/app/flash_recovery_area/orcl/control02.ctl /home/oracle/coldbak
SQL> ho cp /home/oracle/app/oradata/orcl/system01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/sysaux01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/undotbs01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/users01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/tbtb01.dbf /home/oracle/coldbak
ho cp /home/oracle/app/oradata/orcl/ogg01.dbf /home/oracle/coldbak

--检查冷备
[[email protected] coldbak]$ ll
total 1997776
-rw-r-----. 1 oracle oinstall   9748480 Dec 10 06:22 control01.ctl
-rw-r-----. 1 oracle oinstall   9748480 Dec 10 06:25 control02.ctl
-rw-r-----. 1 oracle oinstall 408748032 Dec 10 06:32 ogg01.dbf
-rw-r-----. 1 oracle oinstall 639639552 Dec 10 06:31 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 734011392 Dec 10 06:31 system01.dbf
-rw-r-----. 1 oracle oinstall 104865792 Dec 10 06:32 tbtb01.dbf
-rw-r-----. 1 oracle oinstall  99622912 Dec 10 06:32 undotbs01.dbf
-rw-r-----. 1 oracle oinstall  39329792 Dec 10 06:32 users01.dbf

SQL> startup;
ORACLE instance started.

SQL> insert into andy values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from andy;

ID
----------
1
2

3.2  模拟介质失败,所有数据文件丢失

[[email protected] orcl]$ rm -rf *.dbf  //数据库在打开的情况下就删掉

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size    2220200 bytes
Variable Size  729812824 bytes
Database Buffers  331350016 bytes
Redo Buffers    5554176 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: ‘/home/oracle/app/oradata/orcl/system01.dbf‘

3.3  完全恢复流程

--查看需要恢复的文件
SQL> select file#,error from v$recover_file;

FILE# ERROR
---------- -----------------------------------------------------------------
1 FILE NOT FOUND
2 FILE NOT FOUND
3 FILE NOT FOUND
4 FILE NOT FOUND
5 FILE NOT FOUND
6 FILE NOT FOUND

6 rows selected.

SQL> select file#,checkpoint_change# from v$datafile;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
1      1969481
2      1969481
3      1969481
4      1969481
5      1969481
6      1969481

6 rows selected.

SQL> select file#,checkpoint_change# from v$datafile_header;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
1    0
2    0
3    0
4    0
5    0
6    0

6 rows selected.

a  首先还原所有数据文件
[[email protected] orcl]$ cp /home/oracle/coldbak/*.dbf  /home/oracle/app/oradata/orcl/

b  恢复database
SQL> recover database;
Media recovery complete.

c  打开数据库
SQL>  alter database open;

Database altered.

d  验证
SQL> select * from andy;

ID
----------
1
2

实验2: recover tablespace (状态:database open)

说明:针对的是非关键表空间的损坏,基于表空间的完全恢复实际上还是对其下的datafile的恢复

模拟这种情形非常实用,通常是某个非关键表空间下的数据文件受损,但并没有造成Oracle崩溃, 我们只需针对个别有问题的tablespace去做单独的在线恢复操作,也就是说恢复时数据库整体是online的,而局部表空间是offline的,数据库不需要shutdown。

1)了解一下当前状态,有个 LZY 表空间
SQL> col file_name for a60
SQL> select file_id,file_name,tablespace_name from dba_data_files;

FILE_ID FILE_NAME                                                    TABLESPACE_NAME
---------- ------------------------------------------------------------ -------------------------
         4 /home/oracle/app/oradata/orcl/users01.dbf                    USERS
         3 /home/oracle/app/oradata/orcl/undotbs01.dbf                  UNDOTBS1
         2 /home/oracle/app/oradata/orcl/sysaux01.dbf                   SYSAUX
         1 /home/oracle/app/oradata/orcl/system01.dbf                   SYSTEM
         5 /home/oracle/app/oradata/orcl/tbtb01.dbf                     LZY
         6 /home/oracle/app/oradata/orcl/ogg01.dbf                      GOLDGATE

6 rows selected.

2)准备实验数据

SQL> create table andy.andydemo(id int) tablespace lzy;

Table created.

SQL> inset into andy.andydemo values(1);
SP2-0734: unknown command beginning "inset into..." - rest of line ignored.
SQL> insert into andy.andydemo values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from andy.andydemo;

ID
----------
         1
3)模拟表空间损坏,数据库open下,直接删除表空间下的数据文件

SQL> ho rm -rf /home/oracle/app/oradata/orcl/tbtb01.dbf

4)查证该表空间上的表不可访问了

SQL> alter system flush buffer_cache;   --清除data buffer

System altered.

SQL> select * from andydemo;
select * from andydemo
              *
ERROR at line 1:
ORA-01116: error in opening database file 5
ORA-01110: data file 5: ‘/home/oracle/app/oradata/orcl/tbtb01.dbf‘
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

5)看看scn的情况
SQL> select file#,checkpoint_change# from v$datafile;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            1969484
         2            1969484
         3            1969484
         4            1969484
         5            1969484
         6            1969484

6 rows selected.

SQL> select file#,checkpoint_change# from v$datafile_header;

FILE# CHECKPOINT_CHANGE#
---------- ------------------
         1            1969484
         2            1969484
         3            1969484
         4            1969484
         5                  0
         6            1969484

6 rows selected.

说明:
v$datafile是查看来自控制文件里记录的数据文件scn信息。 
v$datafile_header是查看数据文件头中数据文件scn信息。

6)表空间offline   --immediate使表空间能立即脱机,不等Oracle对任何数据文件做检查

SQL> alter tablespace lzy offline immediate;

Tablespace altered.

7)数据库open下,使用备份还原这个表空间下的所有数据文件。

SQL> ho cp /home/oracle/coldbak/tbtb01.dbf /home/oracle/app/oradata/orcl/

8)恢复tablespace

SQL> recover tablespace lzy;
Media recovery complete.

9)使表空间online

SQL> alter tablespace lzy online;

Tablespace altered. //注意:此时数据库状态一直是open的。

10) 检验

SQL> select * from andydemo;

ID
----------
1

实验3: (recover datafile,database mount或open状态)

恢复datafile, 同实验2不同的是模拟UNDO文件损坏: 因UNDO数据文件也是关键文件,所以只能在mount状态下恢复。

1) 模拟环境:

SQL> delete andy.andy; //注意:删掉了andy并提交,老值在UNDO里。
3 rows deleted.
SQL>commit;

2)在open 状态下删除datafile
SQL> ho rm -rf /home/oracle/app/oradata/orcl/undotbs01.dbf

SQL> insert into andy.andy values(4);  /undo文件已经不在了,dbwr未来得及刷新,此条记录在redo里
SQL>commit;
                                                                                     
3)关闭数据库
SQL> shutdown abort;
ORACLE instance shut down. //abort埋下伏笔,等到完全恢复时会做UNDO回滚。

4) 启动数据库mount
SQL> startup;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size    2220200 bytes
Variable Size  729812824 bytes
Database Buffers  331350016 bytes
Redo Buffers    5554176 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: ‘/home/oracle/app/oradata/orcl/undotbs01.dbf‘

5)还原并恢复UNDO数据文件

SQL> ho cp /home/oracle/coldbak/undotbs01.dbf /home/oracle/app/oradata/orcl/undotbs01.dbf

SQL> recover datafile 3
Media recovery complete.

6)打开数据库(会完成UNDO表空间数据的回滚)

SQL> alter database open;

Database altered.

7) 验证
SQL> select * from andy;

ID
----------
4

总结:有全冷备条件下三种级别恢复流程。    (相应文件名视自己的环境而定)

recover database:

SQL> select file#,error from v$recover_file;
SQL> select file#,checkpoint_change# from v$datafile;
SQL> select file#,checkpoint_change# from v$datafile_header; 
SQL> ho cp /home/oracle/coldbak/*.dbf  /home/oracle/app/oradata/orcl/
SQL> recover database;
SQL>  alter database open;

recover tablespace:

SQL> select file#,error from v$recover_file;
SQL> select file_id,file_name,tablespace_name from dba_data_files;
SQL> select file#,checkpoint_change# from v$datafile;
SQL> select file#,checkpoint_change# from v$datafile_header;
SQL> alter tablespace lzy offline immediate;
SQL> ho cp /home/oracle/coldbak/tbtb01.dbf /home/oracle/app/oradata/orcl/
SQL> recover tablespace lzy;
SQL> alter tablespace lzy online;

recover datafile:

SQL> select file#,error from v$recover_file;
SQL> select file#,checkpoint_change# from v$datafile;
SQL> select file#,checkpoint_change# from v$datafile_header;
SQL> ho cp /home/oracle/coldbak/undotbs01.dbf /home/oracle/app/oradata/orcl/undotbs01.dbf
SQL> recover datafile 3
SQL> alter database open;

OK,转载请标明出处。

时间: 2024-11-08 17:30:17

冷备手工完全恢复(recover database,recover tablespace,recover datafile)的相关文章

人工手动冷备不完全恢复介绍(purge表不完全恢复)

不完全恢复 不完全恢复的基本类型:1)基于时间点 (until time): 使整个数据库恢复到过去的一个时间点前2)基于scn (until change): 使整个数据库恢复到过去的某个SCN前3)基于cancel (until cancel): 使整个数据库恢复到归档日志或当前日志的断点前 不完全恢复(Incomplete recover) 适用环境:1)在过去的某个时间点重要的数据被破坏.2)在做完全恢复时,丢失了归档日志或当前online redo log3)当误删除了表空间时(有控制

How to recover a skipped tablespace after an incomplete recovery? (Doc ID 1561645.1)

APPLIES TO: Oracle Database - Enterprise Edition - Version 11.2.0.1 and laterOracle Database Cloud Schema Service - Version N/A and laterOracle Database Exadata Express Cloud Service - Version N/A and laterOracle Database Exadata Cloud Machine - Vers

oracle备份恢复之recover database的四条语句区别

1  recover database using backup controlfile2  recover database until cancel3  recover database using backup controlfile until cancel;4  recover database until cancel using backup controlfile; 本文主要介绍以下四种恢复方式的含义与区别: 1. recover database using backup co

oracle 11g 手工冷备

查看数据库是否处于非归档模式关闭数据库shutdown immediate备份控制文件和数据文件(没有备份日志文件,建议一起备份) [[email protected] PROD]$ ll total 2014624 -rw-r----- 1 oracle oinstall 9748480 Jan 24 21:49 control01.ctl -rw-r----- 1 oracle oinstall 9748480 Jan 24 21:49 control02.ctl -rw-r----- 1

Recover database using backup controlfile until cancel

http://searchoracle.techtarget.com/answer/Recover-database-using-backup-controlfile-until-cancel What is checked or what happens when we "run recover database using backup controlfile until cancel;"? What does this command do and when do we use

冷备下模拟rm -rf *.dbf恢复案例

关于备份恢复一直是所有关系型数据库的重头戏.下面会介绍冷备数据库,并模拟破坏数据文件进行恢复数据库,并涉及到其他相关内容. [[email protected] ~]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.5 (Tikanga) SQL> select * from v$version where rownum<2; BANNER ----------------------------------

冷备搭建DG

1.主库开启归档 SQL> archive log list;(查询当前归档状态) SQL> shutdown immediate; SQL> startup mount;(启动到mount状态) SQL> archive log list;(开启归档) 2.开启强制写日志 SQL> alter database force logging; 3..关闭闪回 SQL> alter database flashback off; 4.创建standby logfile.(

数据库备份之热备,冷备,温备

备份和恢复 备份类型: 完全备份,部分备份 完全备份:整个数据集 1 部分备份:只备份数据子集,如部分库或表 完全备份.增量备份.差异备份 2增量备份:仅备份最近一次完全备份或增量备份(如果存在增量)以来变化的数据,备份较快,还原复杂 3差异备份:仅备份最近一次完全备份以来变化的数据,备份较慢,还原简单 注意:二进制日志文件不应该与数据文件放在同一磁盘 备份和恢复 冷.温.热备份 冷备:读写操作均不可进行 温备:读操作可执行:但写操作不可执行 热备:读写操作均可执行 MyISAM:温备,不支持热

oracle 11g下冷备数据库

1.关闭数据库 [email protected]>shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down. 2.退出[email protected]>exitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning,