Orace入门之RMAN基于时间点的不完全恢复

本节将演示下rman基于时间点的不完全恢复,修改过的数据有执行commit操作的事务,只要备份文件和联机重做日志或者归档日志文件存在,理论上都是可以恢复的

1:使用rman备份test表空间,test在oracle里面是一个保留关键字,所以备份的时候要加双引号

RMAN> backup tablespace "TEST" format '/u01/backup/test_1216.dbf' tag ts;

2:使用yang用户连接数据库实例,进行数据操作,改用户的默认表空间即为test

yang SQL>select default_tablespace from dba_users where username='YANG';

DEFAULT_TABLESPACE
------------------------------
TEST

yang SQL>conn yang/yang
Connected.

yang SQL>col object_name format a30;
yang SQL>select object_name,object_type from user_objects;

OBJECT_NAME                    OBJECT_TYPE
------------------------------ -------------------
TEST                           TABLE

 
yang SQL>select * from test order by 1;

        ID NAME
---------- --------------------------------
         1 one
         2 two
         3 three

3:插入一条新数据,并提交事务

yang SQL>insert into test values (4,'four');

1 row created.

yang SQL>commit;

Commit complete.

4:使用sys用户登录数据库,查看当前的联机日志组为组1

yang SQL>show user;
USER is "SYS"

yang SQL>select group#,status from v$log;

    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 UNUSED
         3 UNUSED

yang SQL>!strings /u01/app/oracle/oradata/yang/redo01.log |grep 'four' //在lgwr进程发生之前,记录是保存在redolog buffer中

yang SQL>!strings /u01/app/oracle/oradata/yang/redo01.log |grep 'four' //commit后,记录保存在当前active状态的联机重做日志文件中
four

yang SQL>!strings /u01/app/oracle/oradata/yang/test01.dbf |grep 'four'

yang SQL>alter system checkpoint; //在checkpoint发生后,记录才真实可靠的写入到数据文件中

System altered.

yang SQL>!strings /u01/app/oracle/oradata/yang/test01.dbf |grep 'four'
four,

5:继续更新一条记录,但不执行提交操作
yang SQL>insert into test values (5,'five');

1 row created.

yang SQL>select count(*) from test;

  COUNT(*)
----------
         5

6:记录正常时刻的系统时间,后面用来做恢复操作时使用,生产环境下如果遇到类似的情况,可以根据实际情况进行估计,通常使用logminer工具获取这个时间
yang SQL>select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') as time from dual;

TIME
-------------------
2010-12-16:15:37:05

7:模拟数据丢失,这里就直接删除test表,在生产环境下,可能出现磁盘故障,用户误操作等情况使关键的数据丢失
yang SQL>drop table test;

Table dropped.

yang SQL>select count(*) from test;
select count(*) from test
                     *
ERROR at line 1:
ORA-00942: table or view does not exist

8:将数据库关闭,重新启动到mount状态,并使用rman进行恢复
yang SQL>conn /as sysdba
Connected.
yang SQL>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

[oracle@rhel6 oradata]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 16 16:01:43 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: YANG (DBID=3456695003, not open)

RMAN> startup mount;

Oracle instance started
database mounted

Total System Global Area    1068937216 bytes

Fixed Size                     2220200 bytes
Variable Size                801115992 bytes
Database Buffers             260046848 bytes
Redo Buffers                   5554176 bytes

RMAN> run {
2> allocate channel c1 type disk;    //分配三个通道,提高并发
3> allocate channel c2 type disk;
4> allocate channel c3 type disk;
5> set until time "to_date('2010-12-16:15:37:05','YYYY-MM-DD:HH24:MI:SS')"; //指定恢复数据库状态的时间点
6> restore database;                 //还原数据库文件
7> recover database;                 //恢复数据库文件
8> alter database open resetlogs;    //将数据库打到open状态,resetlogs参数将日志重新归位,使数据库的scn,检查点等保持一致
9> }


using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=6 device type=DISK

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

allocated channel: c3
channel c3: SID=8 device type=DISK

executing command: SET until clause

Starting restore at 16-DEC-10

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /u01/app/oracle/oradata/yang/system01.dbf
channel c1: restoring datafile 00002 to /u01/app/oracle/oradata/yang/sysaux01.dbf
channel c1: restoring datafile 00003 to /u01/app/oracle/oradata/yang/undotbs01.dbf
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/yang/users01.dbf
channel c1: restoring datafile 00006 to /u01/app/oracle/oradata/yang/backup_test1.dbf
channel c1: reading from backup piece /u01/backup/full_bak1216.dbf
channel c2: starting datafile backup set restore
channel c2: specifying datafile(s) to restore from backup set
channel c2: restoring datafile 00005 to /u01/app/oracle/oradata/yang/test01.dbf
channel c2: reading from backup piece /u01/backup/test_1216.dbf
channel c2: piece handle=/u01/backup/test_1216.dbf tag=TS
channel c2: restored backup piece 1
channel c2: restore complete, elapsed time: 00:00:03
channel c1: piece handle=/u01/backup/full_bak1216.dbf tag=FULL_BACKUP
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:45
Finished restore at 16-DEC-10

Starting recover at 16-DEC-10

starting media recovery

archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/flash_recovery_area/YANG/archivelog/2010_12_16/o1_mf_1_1_6jmc341s_.arc
archived log file name=/u01/app/oracle/flash_recovery_area/YANG/archivelog/2010_12_16/o1_mf_1_1_6jmc341s_.arc thread=1 sequence=1
media recovery complete, elapsed time: 00:00:08
Finished recover at 16-DEC-10

database opened
released channel: c1
released channel: c2
released channel: c3

9:测试恢复数据
 SQL>conn yang/yang
Connected.
yang SQL>desc test;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER(38)
 NAME                                               VARCHAR2(32)

yang SQL>select * from test;


        ID NAME
---------- --------------------------------
         3 three
         1 one
         2 two
         4 four


 

你可能感兴趣的:(oracle,职场,休闲)