您的位置:首页 > 数据库 > Oracle

Oracle 备份恢复 31个实验 25-31

2012-10-07 13:18 309 查看
备份恢复实验之二十五

当前控制文件和日志文件全部损坏_备份时下线user表空间不完全恢复_用控制文件脚本(日志文件损坏,用控制文件脚本也得RESETLOGS)

写到这里,其实为了更加真实地模拟生产环境,你应该多插入些值,多ALTER SYSTEM SWITCH LOGFILE,也就是多切换几次日志,这样你的体会会更加深刻。)

RMAN> backupdatabase;

Starting backup at22-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=136 devtype=DISK

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

input datafilefno=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf

input datafilefno=00003 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

input datafilefno=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf

input datafilefno=00002 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

input datafilefno=00004 name=/home/oracle/app/oracle/oradata/orcl/users01.dbf

channelORA_DISK_1: starting piece 1 at 22-JAN-11

channelORA_DISK_1: finished piece 1 at 22-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T095134_6mng17qj_.bkptag=TAG20110122T095134
comment=NONE(注意这里,等会要将它手工注册进脚本创建的控制文件中,让RMAN能识别)

SQL> conn /assysdba

Connected.

SQL> alter userhr identified by hr account unlock default tablespace users;

User altered.

SQL> conn hr/hr

Connected.

SQL> createtable test(a number);

Table created.

SQL> insertinto test values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

1

SQL> conn /assysdba

Connected.

SQL> altersystem switch logfile;

System altered.

SQL> altersystem checkpoint;

System altered.

SQL> select *from v$log;

GROUP# THREAD#
SEQUENCE# BYTES MEMBERS ARC STATUS

-------------------- ---------- ---------- ---------- --- ----------------

FIRST_CHANGE#FIRST_TIME

-------------------------

1
1 5 52428800 1 NO
CURRENT

505843 22-JAN-11

2
1 3 52428800 1 YES INACTIVE

481868 21-JAN-11

3
1 4 52428800 1 YES INACTIVE

504584 22-JAN-11

SQL> conn hr/hr

Connected.

SQL> insertinto test values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

1

2

SQL> conn /assysdba

Connected.

SQL> altertablespace users offline;

Tablespacealtered.

SQL> alterdatabase backup controlfile to trace;

Database altered.

[oracle@ocpdbudump]$ cp orcl_ora_5379.trc /home/oracle/c2.sql

[oracle@ocpdb ~]$vi c2.sql

CREATE CONTROLFILEREUSE DATABASE "ORCL" RESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1'/home/oracle/app/oracle/oradata/orcl/redo01.log'
SIZE 50M,

GROUP 2'/home/oracle/app/oracle/oradata/orcl/redo02.log'
SIZE 50M,

GROUP 3 '/home/oracle/app/oracle/oradata/orcl/redo03.log'
SIZE 50M

-- STANDBY LOGFILE

DATAFILE

'/home/oracle/app/oracle/oradata/orcl/system01.dbf',

'/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf',

'/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf',

'/home/oracle/app/oracle/oradata/orcl/example01.dbf'

CHARACTER SETZHS16GBK

;

(这样子,还不够,方法其实可以有很多,你也可以像之前的恢复完控制文件再去ALTER DATABASE DATAFILE 4 ONLINE,总而言之,方法不只一种,我这里用我喜欢用的方法,仅此而已。看到这里,让我回忆起2009年的时候,我与晴哥的讨论,记忆犹新,那时老师讲完课,我和晴哥回去做实验,怎么敲怎么不对,讨论来讨论去,就去请教老师,原来是老师把步骤漏了一步,我们这种打破砂锅问到底的精神也得到了老师的赞扬,十分怀念那时大家一起为了一个现在看来是很简单的一个问题而争论不休的时光,那时一起学习ORACLE的朋友们,你们还好吗?)

你也看到了,又是漏了USERS表空间所对应的数据文件,我们把它加上。

CREATE CONTROLFILEREUSE DATABASE "ORCL" RESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 '/home/oracle/app/oracle/oradata/orcl/redo01.log'
SIZE 50M,

GROUP 2'/home/oracle/app/oracle/oradata/orcl/redo02.log'
SIZE 50M,

GROUP 3'/home/oracle/app/oracle/oradata/orcl/redo03.log'
SIZE 50M

-- STANDBY LOGFILE

DATAFILE

'/home/oracle/app/oracle/oradata/orcl/system01.dbf',

'/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf',

'/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf',

'/home/oracle/app/oracle/oradata/orcl/users01.dbf',

'/home/oracle/app/oracle/oradata/orcl/example01.dbf'

CHARACTER SETZHS16GBK

;

[oracle@ocpdborcl]$ rm -rf c*(删除控制文件,谨慎,这里是测试环境,一般不要用c*这种语法去删东西,很危险,我这么做,是因为我ls
c*已经确定c*都是控制文件,注意啊!)

[oracle@ocpdborcl]$ rm -rf r*(删除日志文件)

[oracle@ocpdborcl]$ ls

backup sysaux01.dbf
temp01.dbf users01.dbf

example01.dbf system01.dbf undotbs01.dbf

[oracle@ocpdborcl]$ pwd

/home/oracle/app/oracle/oradata/orcl

SQL> shutdownabort

ORACLE instanceshut down.

SQL> startup

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 130024080 bytes

DatabaseBuffers 318767104 bytes

Redo Buffers 2973696 bytes

ORA-00205: errorin identifying control file, check alert log for more info

SQL>@/home/oracle/c2.sql

Control filecreated.

[oracle@ocpdb ~]$rman target /

Recovery Manager:Release 10.2.0.1.0 - Production on Sat Jan 22 10:28:58 2011

Copyright (c)1982, 2005, Oracle. All rights reserved.

connected totarget database: ORCL (DBID=1268825849, not open)

RMAN> listbackup;

using targetdatabase control file instead of recovery catalog

RMAN>catalog backuppiece'/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T095134_6mng17qj_.bkp';

catalogedbackuppiece

backup piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T095134_6mng17qj_.bkprecid=1
stamp=741090750

RMAN> restoredatabase;

Starting restoreat 22-JAN-11

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: starting datafile backupset restore

channelORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile00001 to /home/oracle/app/oracle/oradata/orcl/system01.dbf

restoring datafile00002 to /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

restoring datafile00003 to /home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

restoringdatafile 00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf

restoring datafile00005 to /home/oracle/app/oracle/oradata/orcl/example01.dbf

channelORA_DISK_1: reading from backup piece/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T095134_6mng17qj_.bkp

channelORA_DISK_1: restored backup piece 1

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T095134_6mng17qj_.bkptag=TAG20110122T095134

channelORA_DISK_1: restore complete, elapsed time: 00:00:46

Finished restoreat 22-JAN-11

(注意红色区域,你把USERS加进去,你RESTOREDATABASE时,它就会帮你拷回来。)

SQL> recoverdatabase until cancel using backup controlfile;

(你也可以让它自动应用,在空白处敲入auto即可。)

ORA-00279: change505326 generated at 01/22/2011 09:51:35 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_4

_%u_.arc

ORA-00280: change505326 for thread 1 is in sequence #4

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change505843 generated at 01/22/2011 10:03:21 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_5

_%u_.arc

ORA-00280: change505843 for thread 1 is in sequence #5

ORA-00278: logfile

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_

4_6mngq9yj_.arc'no longer needed for this recovery

ORA-27091: unableto queue I/O

ORA-27072: FileI/O error

Linux Error: 22:Invalid argument

Additionalinformation: 4

Additionalinformation: 1

ORA-27047: unableto read the header block of file

Linux Error: 22:Invalid argument

Additionalinformation: 1

ORA-27047: unableto read the header block of file

Linux Error: 22:Invalid argument

Additionalinformation: 1

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

ORA-00308: cannotopen archived log

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_

5_%u_.arc'

ORA-27037: unableto obtain file status

Linux Error: 2: Nosuch file or directory

Additionalinformation: 3

再来一遍

SQL> recoverdatabase until cancel using backup controlfile;

ORA-00279: change505843 generated at 01/22/2011 10:03:21 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_5

_%u_.arc

ORA-00280: change505843 for thread 1 is in sequence #5

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

cancel

Media recoverycancelled.

SQL> alterdatabase open;

alter databaseopen

*

ERROR at line 1:

ORA-01589: mustuse RESETLOGS or NORESETLOGS option for database open

SQL> alterdatabase open resetlogs;

Database altered.

(这里等待的越久,你就应该开心了,可以先去喝杯咖啡,额,我又是刚刚喝完一杯咖啡。我和A哥现在在动车上,A哥现在正在全神贯注地看STATSPACK,呵呵。)

SQL> conn hr/hr

Connected.

SQL> select *from test;

A

----------

1

(数据回来了!很遗憾,1哥在,2哥,哎,还是丢失了。)

备份恢复实验之二十六

当前控制文件和日志文件全部损坏_备份时只读user表空间不完全恢复_用控制文件二进制备份(到这里,已经很简单了,只读和下线时USERS表空间貌似可以不备份,你可以自己实验一下。不一一列举了。)

RMAN> backupdatabase;

Starting backup at22-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=148 devtype=DISK

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

input datafilefno=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf

input datafilefno=00003 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

input datafilefno=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf

input datafilefno=00002 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

input datafilefno=00004 name=/home/oracle/app/oracle/oradata/orcl/users01.dbf

channelORA_DISK_1: starting piece 1 at 22-JAN-11

channelORA_DISK_1: finished piece 1 at 22-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T171020_6mo7qydx_.bkptag=TAG20110122T171020
comment=NONE

SQL> alter userhr identified by hr account unlock default tablespace users;

User altered.

SQL> conn hr/hr

Connected.

SQL> createtable test(a number);

Table created.

SQL> insertinto test values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

1

SQL> conn /as sysdba

Connected.

SQL> altersystem switch logfile;

System altered.

SQL> altersystem checkpoint;

System altered.

SQL> select *from v$log;

GROUP# THREAD#
SEQUENCE# BYTES MEMBERS ARC STATUS

-------------------- ---------- ---------- ---------- --- ----------------

FIRST_CHANGE#FIRST_TIME

-------------------------

1
1 2 52428800 1 YES INACTIVE

472518 22-JAN-11

2 1 3
52428800 1 NO CURRENT

479814 22-JAN-11

3
1 1 52428800 1 YES INACTIVE

446075 22-JAN-11

SQL> conn hr/hr

Connected.

SQL> insertinto test values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

1

2

SQL> conn /assysdba

Connected.

SQL> altertablespace users read only;

Tablespacealtered.

RMAN> backupcurrent controlfile;

Starting backup at22-JAN-11

using channelORA_DISK_1

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

including currentcontrol file in backupset

channelORA_DISK_1: starting piece 1 at 22-JAN-11

channelORA_DISK_1: finished piece 1 at 22-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_ncnnf_TAG20110122T172007_6mo8b88v_.bkptag=TAG20110122T172007
comment=NONE

channelORA_DISK_1: backup set complete, elapsed time: 00:00:02

Finished backup at22-JAN-11

[oracle@ocpdborcl]$ rm -rf r*

[oracle@ocpdborcl]$ rm -rf c*

[oracle@ocpdborcl]$ ls

backup sysaux01.dbf
temp01.dbf users01.dbf

example01.dbf system01.dbf undotbs01.dbf

[oracle@ocpdborcl]$ pwd

/home/oracle/app/oracle/oradata/orcl

SQL> shutdownabort

ORACLE instanceshut down.

SQL> startup

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

ORA-00205: errorin identifying control file, check alert log for more info

RMAN> restorecontrolfile from'/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_ncnnf_TAG20110122T172007_6mo8b88v_.bkp';

Starting restoreat 22-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: restoring control file

channelORA_DISK_1: restore complete, elapsed time: 00:00:02

outputfilename=/home/oracle/app/oracle/oradata/orcl/control01.ctl

outputfilename=/home/oracle/app/oracle/oradata/orcl/control02.ctl

outputfilename=/home/oracle/app/oracle/oradata/orcl/control03.ctl

Finished restoreat 22-JAN-11

RMAN> alterdatabase mount;

database mounted

released channel:ORA_DISK_1

RMAN> restoredatabase;

Starting restoreat 22-JAN-11

Starting implicitcrosscheck backup at 22-JAN-11

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

Crosschecked 2objects

Finished implicitcrosscheck backup at 22-JAN-11

RMAN>restore tablespace users;(把USERS也要拷回来。)

Starting restoreat 22-JAN-11

using channelORA_DISK_1

channelORA_DISK_1: starting datafile backupset restore

channelORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf

channelORA_DISK_1: reading from backup piece/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T174717_6mo9x6bl_.bkp

channelORA_DISK_1: restored backup piece 1

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T174717_6mo9x6bl_.bkptag=TAG20110122T174717

channelORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished restoreat 22-JAN-11

SQL> recoverdatabase until cancel using backup controlfile;

ORA-00279: change479280 generated at 01/22/2011 17:10:20 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_2

_%u_.arc

ORA-00280: change479280 for thread 1 is in sequence #2

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change479814 generated at 01/22/2011 17:16:24 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_3

_%u_.arc

ORA-00280: change479814 for thread 1 is in sequence #3

ORA-00278: logfile

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_

2_6mo838sn_.arc'no longer needed for this recovery

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

ORA-00308: cannotopen archived log

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_

3_%u_.arc'

ORA-27037: unableto obtain file status

Linux Error: 2: Nosuch file or directory

Additionalinformation: 3

ORA-27091: unableto queue I/O

ORA-27072: FileI/O error

Linux Error: 22:Invalid argument

Additionalinformation: 4

Additionalinformation: 1

ORA-27047: unableto read the header block of file

Linux Error: 22:Invalid argument

Additionalinformation: 1

ORA-27047: unableto read the header block of file

Linux Error: 22:Invalid argument

Additionalinformation: 1

SQL> recoverdatabase until cancel using backup controlfile;

ORA-00279: change479814 generated at 01/22/2011 17:16:24 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_3

_%u_.arc

ORA-00280: change479814 for thread 1 is in sequence #3

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

cancel

Media recoverycancelled.

SQL> alterdatabase open resetlogs;

Database altered.

SQL> select *from hr.test;

A

----------

1

(有了,我之前忘了把USERS拷回来,所以又做了一遍。)

备份恢复实验之二十七

当前控制文件和日志文件全部损坏_备份时只读user表空间不完全恢复_用控制文件脚本(没啥可说的,控制文件脚本)

RMAN> backupdatabase;

Starting backup at22-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=143 devtype=DISK

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

input datafilefno=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf

input datafilefno=00003 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

input datafilefno=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf

input datafilefno=00002 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

input datafilefno=00004 name=/home/oracle/app/oracle/oradata/orcl/users01.dbf

channelORA_DISK_1: starting piece 1 at 22-JAN-11

channelORA_DISK_1: finished piece 1 at 22-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T182310_6mod0hm5_.bkptag=TAG20110122T182310
comment=NONE

SQL> conn /assysdba

Connected.

SQL> alter userhr identified by hr account unlock default tablespace users;

User altered.

SQL> conn hr/hr

Connected.

SQL> createtable test(a number);

Table created.

SQL> insertinto test values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

1

SQL> conn /assysdba

Connected.

SQL> altersystem switch logfile;

System altered.

SQL> altersystem checkpoint;

System altered.

SQL> select *from v$log;

GROUP# THREAD#
SEQUENCE# BYTES MEMBERS ARC STATUS

-------------------- ---------- ---------- ---------- --- ----------------

FIRST_CHANGE#FIRST_TIME

-------------------------

1
1 2 52428800 1 YES INACTIVE

472467 22-JAN-11

2
1 3 52428800 1 NO
CURRENT

478826 22-JAN-11

3
1 1 52428800 1 YES INACTIVE

446075 22-JAN-11

SQL> conn hr/hr

Connected.

SQL> insertinto test values(2);

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

1

2

SQL> conn / assysdba

Connected.

SQL> altertablespace users read only;

Tablespacealtered.

SQL> alterdatabase backup controlfile to trace;

Database altered.

[oracle@ocpdbudump]$ cp orcl_ora_8874.trc /home/oracle/c2.sql

CREATE CONTROLFILEREUSE DATABASE "ORCL" RESETLOGS ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1'/home/oracle/app/oracle/oradata/orcl/redo01.log'
SIZE 50M,

GROUP 2'/home/oracle/app/oracle/oradata/orcl/redo02.log'
SIZE 50M,

GROUP 3 '/home/oracle/app/oracle/oradata/orcl/redo03.log'
SIZE 50M

-- STANDBY LOGFILE

DATAFILE

'/home/oracle/app/oracle/oradata/orcl/system01.dbf',

'/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf',

'/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf',

'/home/oracle/app/oracle/oradata/orcl/users01.dbf',(这一行要加入)

'/home/oracle/app/oracle/oradata/orcl/example01.dbf'

CHARACTER SETZHS16GBK

;

[oracle@ocpdborcl]$ rm -rf c*

[oracle@ocpdborcl]$ rm -rf r*

[oracle@ocpdborcl]$ ls

backup sysaux01.dbf
temp01.dbf users01.dbf

example01.dbf system01.dbf undotbs01.dbf

[oracle@ocpdborcl]$ pwd

/home/oracle/app/oracle/oradata/orcl

SQL> shutdownabort

ORACLE instanceshut down.

SQL> startup

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

ORA-00205: errorin identifying control file, check alert log for more info

SQL>@/home/oracle/c2.sql

Control filecreated.

RMAN> catalogbackuppiece'/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T182310_6mod0hm5_.bkp';

catalogedbackuppiece

backup piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T182310_6mod0hm5_.bkprecid=1
stamp=741119790

RMAN> restoredatabase;

Starting restoreat 22-JAN-11

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1:specifying datafile(s) to restore from backup set

restoring datafile00001 to /home/oracle/app/oracle/oradata/orcl/system01.dbf

restoring datafile00002 to /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

restoring datafile00003 to /home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

restoringdatafile 00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf

restoring datafile00005 to /home/oracle/app/oracle/oradata/orcl/example01.dbf

channelORA_DISK_1: reading from backup piece /home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_nnndf_TAG20110122T182310_6mod0hm5_.bkp

接下来的RECOVER阶段,我用的全都是SQLPLUS,可能是因为我很喜欢USING
BACKUP CONTROLFILE吧,你可以试一下RMAN,语法类似

Run {

Set until sequence?;

recover database;

}

RMAN无需USING
BACKUP CONTROLFILE,不过UNTIL到哪个SEQUENCE就要注意了,不如你敲SETUNTIL
SEQUENCE 6它会帮你应用到SEQUENCE 5,明白?)--USINGBACKUP
CONTROLFILE就是采集,一个陌生人到了一个新的环境,肯定要先“采集”,认识一下嘛。

SQL> recoverdatabase until cancel using backup controlfile;

ORA-00279: change478756 generated at 01/22/2011 18:23:10 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_2

_%u_.arc

ORA-00280: change478756 for thread 1 is in sequence #2

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change478826 generated at 01/22/2011 18:26:50 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_3

_%u_.arc

ORA-00280: change478826 for thread 1 is in sequence #3

ORA-00278: logfile

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_

2_6mod7byq_.arc'no longer needed for this recovery

ORA-27091: unableto queue I/O

ORA-27072: FileI/O error

Linux Error: 22:Invalid argument

Additionalinformation: 4

Additionalinformation: 1

ORA-27047: unableto read the header block of file

Linux Error: 22:Invalid argument

Additionalinformation: 1

ORA-27047: unableto read the header block of file

Linux Error: 22:Invalid argument

Additionalinformation: 1

Specify log: {<RET>=suggested| filename | AUTO | CANCEL}

ORA-00308: cannotopen archived log

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_

3_%u_.arc'

ORA-27037: unableto obtain file status

Linux Error: 2: Nosuch file or directory

Additionalinformation: 3

SQL> recoverdatabase until cancel using backup controlfile;

ORA-00279: change478826 generated at 01/22/2011 18:26:50 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_22/o1_mf_1_3

_%u_.arc

ORA-00280: change478826 for thread 1 is in sequence #3

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

cancel

Media recoverycancelled.

SQL> alterdatabase open resetlogs;

Database altered.

SQL> select *from hr.test;

A

----------

1

备份恢复实验之二十八

当前控制文件损坏_新建tbsocp05_test2表空间不完全恢复_用控制文件二进制备份_数据不丢_不需备份(只要在线日志在,一切皆有可能)

RMAN> backupcurrent controlfile;

Starting backup at22-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channel ORA_DISK_1:sid=142 devtype=DISK

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

including currentcontrol file in backupset

channelORA_DISK_1: starting piece 1 at 22-JAN-11

channelORA_DISK_1: finished piece 1 at 22-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_ncnnf_TAG20110122T201921_6moltb9j_.bkptag=TAG20110122T201921
comment=NONE

channelORA_DISK_1: backup set complete, elapsed time: 00:00:02

Finished backup at22-JAN-11

SQL> conn /as sysdba

Connected.

SQL> createtablespace tbsocp05_test2 datafile'/home/oracle/app/oracle/oradata/orcl/tbsocp05_test2.dbf' size 10m;

Tablespacecreated.

SQL> alter userhr identified by hr account unlock default tablespace tbsocp05_test2;

User altered.

SQL> conn hr/hr

Connected.

SQL> createtable test(a varchar2(10));

Table created.

SQL>insert into test values('OCM');

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

OCM

[oracle@ocpdborcl]$ rm -rf c*

[oracle@ocpdborcl]$ pwd

/home/oracle/app/oracle/oradata/orcl

[oracle@ocpdborcl]$ ls

backup redo02.log
system01.dbf undotbs01.dbf

example01.dbf redo03.log tbsocp05_test2.dbf
users01.dbf

redo01.log sysaux01.dbf temp01.dbf

SQL> conn /assysdba

Connected.

SQL> shutdownabort

ORACLE instanceshut down.

SQL> startup

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

ORA-00205: errorin identifying control file, check alert log for more info

RMAN> restorecontrolfile from '/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_ncnnf_TAG20110122T201921_6moltb9j_.bkp';

Starting restoreat 22-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: restoring control file

channelORA_DISK_1: restore complete, elapsed time: 00:00:04

outputfilename=/home/oracle/app/oracle/oradata/orcl/control01.ctl

outputfilename=/home/oracle/app/oracle/oradata/orcl/control02.ctl

outputfilename=/home/oracle/app/oracle/oradata/orcl/control03.ctl

Finished restoreat 22-JAN-11

RMAN> alterdatabase mount;

database mounted

released channel:ORA_DISK_1

RMAN> recoverdatabase;

Starting recoverat 22-JAN-11

Starting implicitcrosscheck backup at 22-JAN-11

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

Finished implicitcrosscheck backup at 22-JAN-11

Starting implicitcrosscheck copy at 22-JAN-11

using channelORA_DISK_1

Finished implicitcrosscheck copy at 22-JAN-11

searching for allfiles in the recovery area

catalogingfiles...

cataloging done

List of CatalogedFiles

=======================

File Name:/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_22/o1_mf_ncnnf_TAG20110122T215057_6mor627t_.bkp

using channelORA_DISK_1

starting mediarecovery

archive log thread1 sequence 2 is already on disk as file/home/oracle/app/oracle/oradata/orcl/redo01.log

archive logfilename=/home/oracle/app/oracle/oradata/orcl/redo01.log thread=1 sequence=2

creating datafilefno=6 name=/home/oracle/app/oracle/oradata/orcl/tbsocp05_test2.dbf

RMAN-00571:===========================================================

RMAN-00569:=============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571:===========================================================

RMAN-03002:failure of recover command at 01/22/2011 21:54:40

ORA-01119: errorin creating database file'/home/oracle/app/oracle/oradata/orcl/tbsocp05_test2.dbf'

ORA-27038:created file already exists

Additionalinformation: 1

SQL> alterdatabase create datafile 6 as'/home/oracle/app/oracle/oradata/orcl/tbsocp05_test2';

Database altered.

SQL> alterdatabase open;

alter databaseopen

*

ERROR at line 1:

ORA-01589: mustuse RESETLOGS or NORESETLOGS option for database open

SQL> alterdatabase open resetlogs;

alter databaseopen resetlogs

*

ERROR at line 1:

ORA-01153: anincompatible media recovery is active

(看到这里,我是相当无奈,做了好几遍,最后没招了)

只能

SQL> shutdownimmediate

ORA-01109:database not open

Databasedismounted.

ORACLE instanceshut down.

SQL> startup mount

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

Database mounted.

SQL> alterdatabase open resetlogs;

Database altered.

SQL> select *from test;

A

----------

OCM

(可以了!)为什么,我是这么想的,它说an incompatible media recovery is active,那我关库再开总不会还ACTIVE吧,所以就OK了,你可以试一下。

备份恢复实验之二十九

当前控制文件损坏_新建tbsocp05_test3表空间完全恢复_用控制文件脚本_不需备份(跟之前的实验一样,什么叫新建,就是旧的控制文件里面没有这个表空间的信息,用脚本会好做一点。)

SQL> alterdatabase backup controlfile to trace;

Database altered.

[oracle@ocpdbudump]$ cp orcl_ora_22607.trc /home/oracle/c1.sql

SQL> createtablespace tbsocp05_test3 datafile'/home/oracle/app/oracle/oradata/orcl/tbsocp05_test3.dbf' size 10m;

Tablespacecreated.

SQL> createtable test(a varchar2(10)) tablespace tbsocp05_test3;

Table created.

SQL> insertinto test values('liujie');

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

liujie

[oracle@ocpdborcl]$ rm -rf c*

[oracle@ocpdborcl]$ ls

example01.dbf redo02.log sysaux01.dbf tbsocp05_test3.dbf undotbs01.dbf

redo01.log redo03.log system01.dbf
temp01.dbf users01.dbf

SQL> shutdownabort

ORACLE instanceshut down.

SQL> startup

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 130024080 bytes

DatabaseBuffers 318767104 bytes

Redo Buffers 2973696 bytes

ORA-00205: errorin identifying control file, check alert log for more info

[oracle@ocpdb ~]$vi c1.sql

这里控制文件脚本中用的是SET #1,无需RESETLOGS。

CREATE CONTROLFILEREUSE DATABASE "ORCL"NORESETLOGS
ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 '/home/oracle/app/oracle/oradata/orcl/redo01.log'
SIZE 50M,

GROUP 2'/home/oracle/app/oracle/oradata/orcl/redo02.log'
SIZE 50M,

GROUP 3'/home/oracle/app/oracle/oradata/orcl/redo03.log'
SIZE 50M

-- STANDBY LOGFILE

DATAFILE

'/home/oracle/app/oracle/oradata/orcl/system01.dbf',

'/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf',

'/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf',

'/home/oracle/app/oracle/oradata/orcl/users01.dbf',

'/home/oracle/app/oracle/oradata/orcl/example01.dbf',

'/home/oracle/app/oracle/oradata/orcl/tbsocp05_test3.dbf'(加进去)

CHARACTER SETZHS16GBK

;

SQL>@/home/oracle/c1.sql

Control filecreated.

SQL> recoverdatabase using backup controlfile;

ORA-00279: change478368 generated at 01/23/2011 10:41:57 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2

_%u_.arc

ORA-00280: change478368 for thread 1 is in sequence #2

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

ORA-00308: cannotopen archived log

'/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_

2_%u_.arc'

ORA-27037: unableto obtain file status

Linux Error: 2: Nosuch file or directory

Additionalinformation: 3(这里你敲回车几本是报错的,没关系,你要手工抓一个在线日志喂给它吃,看下面)

SQL> recoverdatabase using backup controlfile;

ORA-00279: change478368 generated at 01/23/2011 10:41:57 needed for thread 1

ORA-00289:suggestion :

/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2

_%u_.arc

ORA-00280: change478368 for thread 1 is in sequence #2

Specify log:{<RET>=suggested | filename | AUTO | CANCEL}

/home/oracle/app/oracle/oradata/orcl/redo01.log

Log applied.

Media recoverycomplete.

(为什么是REDO01.LOG?没有为什么,你三个都去试一下,总有一个正好是它需要的那个在线日志)

SQL> alterdatabase open;

alter databaseopen

*

ERROR at line 1:

ORA-01589: mustuse RESETLOGS or NORESETLOGS option for database open

SQL> alterdatabase open resetlogs;(我之前选取的控制文件的脚本是NORESETLOGS的,可是它这里却必须要RESETLOGS,也许应该选取的是RESETLOGS那个吧,可能我选取的那个NORESETLOGS如果之后是RESETLOGS不会影响吧(它会盖掉之前的选择),以上这段话听不懂就跳过。)

Database altered.

SQL> select *from test;

A

----------

liujie

(这应该是用不完全恢复的方法实现完全恢复吧,你可以测试一下,我的不一定对,发现我的做法是错的,请告知于我。)

RMAN> listincarnation of database;

using targetdatabase control file instead of recovery catalog

List of DatabaseIncarnations

DB Key Inc Key DB Name
DB ID STATUS Reset SCN Reset Time

------- --------------- ---------------- --- ---------- ----------

1 1 ORCL
1268958262 PARENT 446075 23-JAN-11

2 2 ORCL
1268958262 CURRENT 479183 23-JAN-11(多了一个INCARNATION)

备份恢复实验之三十

删除表空间不完全恢复(这里的表空间我觉得应该是特指新建的表空间的删除,因为原先的表空间如USERS,SYSTEM之类的,没有更旧的控制文件能识别了(这句话很难讲),原先建库完之后就会有的表空间已经成为数据库的属性了(我只能这么讲了),看我的实验)

SQL> conn /assysdba

Connected.

SQL> createtablespace test datafile '/home/oracle/app/oracle/oradata/orcl/test01.dbf' size20m;

Tablespacecreated.

RMAN> backupdatabase;

Starting backup at23-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=147 devtype=DISK

channel ORA_DISK_1:starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

input datafilefno=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf

input datafilefno=00003 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

input datafilefno=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf

input datafilefno=00002 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

input datafilefno=00006 name=/home/oracle/app/oracle/oradata/orcl/test01.dbf

input datafile fno=00004name=/home/oracle/app/oracle/oradata/orcl/users01.dbf

channelORA_DISK_1: starting piece 1 at 23-JAN-11

channelORA_DISK_1: finished piece 1 at 23-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T113032_6mq86s2z_.bkptag=TAG20110123T113032
comment=NONE

BACKUP DATABASE在最后会帮你备份一下能识别此次备份的控制文件。

这里

BS Key Type LV Size
Device Type Elapsed Time Completion Time

------- ---- ------------ ----------- ------------ ---------------

2 Full 6.80M
DISK 00:00:05 23-JAN-11

BP Key: 2
Status: AVAILABLE Compressed: NO Tag: TAG20110123T113032

Piece Name:
/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_ncsnf_TAG20110123T113032_6mq88bq9_.bkp

Control FileIncluded: Ckp SCN: 478762 Ckp time: 23-JAN-11

SPFILE Included: Modification time: 23-JAN-11

SQL> createtable test(a varchar(50)) tablespace test;

Table created.

SQL> insertinto test values('it is time to say goodbye');

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

--------------------------------------------------

it is time to saygoodbye

SQL> altersystem switch logfile;

System altered.

SQL> altersystem checkpoint;

System altered.(没有为什么,不想碰到一些极端的情况,你可以不敲,没事)

SQL> select *from v$log;

GROUP# THREAD#
SEQUENCE# BYTES MEMBERS ARC STATUS

-------------------- ---------- ---------- ---------- --- ----------------

FIRST_CHANGE#FIRST_TIME

-------------------------

1 1 2
52428800 1 YES INACTIVE

472348 23-JAN-11

2
1 3 52428800 1 NO
CURRENT

478872 23-JAN-11

3
1 1 52428800 1 YES INACTIVE

446075 23-JAN-11

SQL> droptablespace test;

drop tablespacetest

*

ERROR at line 1:

ORA-01549:tablespace not empty, use INCLUDING CONTENTS option

SQL> droptablespace test including contents and datafiles;

Tablespacedropped.

SQL> shutdown abort

ORACLE instanceshut down.

SQL> startupnomount

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

(不可以STARTUP MOUNT,因为目前的控制文件太新了,它里面已经记录的是TEST被删的情况了,要用之前备份的旧的(有TEST表空间)控制文件。)

RMAN> restorecontrolfile from'/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_ncsnf_TAG20110123T113032_6mq88bq9_.bkp';

Starting restoreat 23-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: restoring control file

channelORA_DISK_1: restore complete, elapsed time: 00:00:19

output filename=/home/oracle/app/oracle/oradata/orcl/control01.ctl

outputfilename=/home/oracle/app/oracle/oradata/orcl/control02.ctl

outputfilename=/home/oracle/app/oracle/oradata/orcl/control03.ctl

Finished restoreat 23-JAN-11

RMAN> alterdatabase mount;

database mounted

released channel:ORA_DISK_1

RMAN>run {

2>set until sequence 3;

3>restore database;

4>recover database;

5> }

executing command:SET until clause

Starting restoreat 23-JAN-11

Starting implicitcrosscheck backup at 23-JAN-11

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

Crosschecked 1objects

Finished implicitcrosscheck backup at 23-JAN-11

Starting implicitcrosscheck copy at 23-JAN-11

using channelORA_DISK_1

Finished implicitcrosscheck copy at 23-JAN-11

searching for allfiles in the recovery area

catalogingfiles...

cataloging done

List of CatalogedFiles

=======================

File Name:/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2_6mq8nccl_.arc

File Name:/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_ncsnf_TAG20110123T113032_6mq88bq9_.bkp

using channelORA_DISK_1

channelORA_DISK_1: starting datafile backupset restore

channelORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile00001 to /home/oracle/app/oracle/oradata/orcl/system01.dbf

restoring datafile00002 to /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

restoring datafile00003 to /home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

restoring datafile00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf

restoring datafile00005 to /home/oracle/app/oracle/oradata/orcl/example01.dbf

restoringdatafile 00006 to /home/oracle/app/oracle/oradata/orcl/test01.dbf

channelORA_DISK_1: reading from backup piece /home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T113032_6mq86s2z_.bkp

channelORA_DISK_1: restored backup piece 1

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T113032_6mq86s2z_.bkptag=TAG20110123T113032

channelORA_DISK_1: restore complete, elapsed time: 00:03:58

Finished restoreat 23-JAN-11

Starting recoverat 23-JAN-11

using channelORA_DISK_1

starting mediarecovery

archive log thread1 sequence 2 is already on disk as file/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2_6mq8nccl_.arc

archive logfilename=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2_6mq8nccl_.arcthread=1 sequence=2

media recoverycomplete, elapsed time: 00:00:04

Finished recoverat 23-JAN-11

RMAN> alterdatabase open resetlogs;

database opened

SQL> select *from test;

A

--------------------------------------------------

it is time to saygoodbye

(有了)

select * fromdba_tablespaces t where t.tablespace_name='TEST';

TABLESPACE_NAMEBLOCK_SIZE
INITIAL_EXTENT

TEST
8192 65536

(TEST表空间回来了)

RMAN> listincarnation of database;

List of DatabaseIncarnations

DB Key Inc Key DB Name
DB ID STATUS Reset SCN Reset Time

------- --------------- ---------------- --- ---------- ----------

1 1 ORCL
1268960250 PARENT 1 30-JUN-05

2 2 ORCL
1268960250 PARENT 446075 23-JAN-11

3 3 ORCL
1268960250 CURRENT 478873 23-JAN-11

(INCARNATION又多了一个)

备份恢复实验之三十一

穿越incarnation不完全恢复(10G的新特性,实质上就是归档日志那多记了一个%r,r就是incarnation的代号,也就是我可以从这个时代回到上一个时代,当然,有个前提,上一个时代的归档日志可不能删掉啊,得留着!)

SQL> showparameter log_archive_format

NAME TYPE

----------------------------------------------------------

VALUE

------------------------------

log_archive_format string

%t_%s_%r.dbf

第一个%t是THREAD号,第二个%s是SEQUENCE号,第三个%r就是INCARNATION号。9I的归档日志就是少了这个(%r),所以9I无法穿越INCARNATION。但正如我最最开始说的那样,不是说有了这个功能你就能高枕无忧了,平时还是应该做好备份,你为什么不备份,为什么要把事情搞得如此复杂,穿越INCARNATION会出现“孤儿”INCARNATION,也就是ORPHAN的INCARNATION,总而言之,不要把事情搞得如此复杂,天天都做好备份,泡茶,上网,喝咖啡,人生岂不快哉!

我们从头开始,一步一步来,举个例子。

RMAN> backupdatabase;

Starting backup at23-JAN-11

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=141 devtype=DISK

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

input datafilefno=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf

input datafilefno=00003 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

input datafilefno=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf

input datafilefno=00002 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

input datafilefno=00004 name=/home/oracle/app/oracle/oradata/orcl/users01.dbf

channelORA_DISK_1: starting piece 1 at 23-JAN-11

channelORA_DISK_1: finished piece 1 at 23-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T211249_6mrbblrf_.bkptag=TAG20110123T211249
comment=NONE

channelORA_DISK_1: backup set complete, elapsed time: 00:00:36

channelORA_DISK_1: starting full datafile backupset

channelORA_DISK_1: specifying datafile(s) in backupset

including currentcontrol file in backupset

including currentSPFILE in backupset

channelORA_DISK_1: starting piece 1 at 23-JAN-11

channelORA_DISK_1: finished piece 1 at 23-JAN-11

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_ncsnf_TAG20110123T211249_6mrbcqbc_.bkptag=TAG20110123T211249
comment=NONE

channelORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at23-JAN-11

SQL> createtable test(a varchar2(10)) tablespace users;

Table created.

SQL> insertinto test values('liujie');

1 row created.

SQL> commit;

Commit complete.

SQL> select *from test;

A

----------

liujie

SQL> altersession set nls_date_format='yyyy-mm-dd:hh24:mi:ss';

Session altered.

SQL> selectsysdate from dual;

SYSDATE

-------------------

2011-01-23:21:25:39

SQL> altersystem switch logfile;

System altered.

SQL> altersystem switch logfile;

System altered.

SQL> altersystem checkpoint;

System altered.

SQL> select *from v$log;

GROUP# THREAD#
SEQUENCE# BYTES MEMBERS ARC STATUS

-------------------- ---------- ---------- ---------- --- ----------------

FIRST_CHANGE#FIRST_TIME

--------------------------------

1
1 2 52428800 1 YES INACTIVE

472427 2011-01-23:21:09:31

2
1 3 52428800 1 YES INACTIVE

479055 2011-01-23:21:26:41

3
1 4 52428800 1 NO
CURRENT

479059 2011-01-23:21:26:55

SQL> drop tabletest purge;

Table dropped.

(我们首先,通过备份将数据库恢复到TEST表还在的时候。)

SQL> shutdownabort

ORACLE instanceshut down.

SQL> startupmount

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

Database mounted.

RMAN>run {

2>set until time '2011-01-23:21:25:39';

3>restore database;

4>recover database;

5> }

executing command:SET until clause

using targetdatabase control file instead of recovery catalog

Starting restoreat 2011-01-23:21:36:27

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: starting datafile backupset restore

channelORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile00001 to /home/oracle/app/oracle/oradata/orcl/system01.dbf

restoring datafile00002 to /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

restoring datafile00003 to /home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

restoring datafile00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf

restoring datafile00005 to /home/oracle/app/oracle/oradata/orcl/example01.dbf

channelORA_DISK_1: reading from backup piece/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T211249_6mrbblrf_.bkp

channelORA_DISK_1: restored backup piece 1

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T211249_6mrbblrf_.bkptag=TAG20110123T211249

channelORA_DISK_1: restore complete, elapsed time: 00:00:46

Finished restoreat 2011-01-23:21:37:13

Starting recoverat 2011-01-23:21:37:13

using channelORA_DISK_1

starting mediarecovery

media recoverycomplete, elapsed time: 00:00:02

Finished recoverat 2011-01-23:21:37:15

RMAN> alterdatabase open resetlogs;

database opened

SQL> select *from test;

A

----------

liujie

RMAN> listincarnation of database;

List of DatabaseIncarnations

DB Key Inc Key DB Name
DB ID STATUS Reset SCN Reset Time

------- --------------- ---------------- --- ---------- ----------

1 1 ORCL
1268995992 PARENT 1 2005-06-30:19:09:40

2 2 ORCL
1268995992 PARENT 446075 2011-01-23:21:07:41

3 3 ORCL
1268995992 CURRENT 478854 2011-01-23:21:37:57

现在我们再把TEST删除,那如何恢复呢?回到上一个INCARNATION,有TEST这张表。

SQL> drop tabletest purge;

Table dropped.

SQL> select *from test;

select * from test

*

ERROR at line 1:

ORA-00942: tableor view does not exist

RMAN> resetdatabase to incarnation 2;

RMAN-00571:===========================================================

RMAN-00569:=============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571:===========================================================

RMAN-03009:failure of reset command on default channel at 01/23/2011 21:44:37

ORA-19910: can notchange recovery target incarnation in control file

(没事,先关库,再到MOUNT状态)

SQL> shutdownimmediate

Database closed.

Databasedismounted.

ORACLE instanceshut down.

SQL> startupmount

ORACLE instancestarted.

Total SystemGlobal Area 452984832 bytes

Fixed Size 1219952 bytes

Variable Size 134218384 bytes

DatabaseBuffers 314572800 bytes

Redo Buffers 2973696 bytes

Database mounted.

RMAN> resetdatabase to incarnation 2;

database reset toincarnation 2

RMAN>run {

2>set until time '2011-01-23:21:25:39';

3>restore database;

4>recover database;

5> }

executing command:SET until clause

Starting restoreat 2011-01-23:21:49:11

allocated channel:ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1:specifying datafile(s) to restore from backup set

restoring datafile00001 to /home/oracle/app/oracle/oradata/orcl/system01.dbf

restoring datafile00002 to /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf

restoring datafile00003 to /home/oracle/app/oracle/oradata/orcl/sysaux01.dbf

restoring datafile00004 to /home/oracle/app/oracle/oradata/orcl/users01.dbf

restoring datafile00005 to /home/oracle/app/oracle/oradata/orcl/example01.dbf

channelORA_DISK_1: reading from backup piece /home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T211249_6mrbblrf_.bkp

channelORA_DISK_1: restored backup piece 1

piecehandle=/home/oracle/app/oracle/flash_recovery_area/ORCL/backupset/2011_01_23/o1_mf_nnndf_TAG20110123T211249_6mrbblrf_.bkptag=TAG20110123T211249

channelORA_DISK_1: restore complete, elapsed time: 00:00:45

Finished restoreat 2011-01-23:21:49:58

Starting recoverat 2011-01-23:21:49:59

using channelORA_DISK_1

starting mediarecovery

archive log thread1 sequence 2 is already on disk as file/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2_6mrc4l2n_.arc

archive logfilename=/home/oracle/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_23/o1_mf_1_2_6mrc4l2n_.arcthread=1 sequence=2

media recoverycomplete, elapsed time: 00:00:04

Finished recoverat 2011-01-23:21:50:04

RMAN> alterdatabase open resetlogs;

database opened

SQL> select *from test;

A

----------

liujie

RMAN> listincarnation of database;

List of DatabaseIncarnations

DB Key Inc Key DB Name
DB ID STATUS Reset SCN Reset Time

------- --------------- ---------------- --- ---------- ----------

1 1 ORCL
1268995992 PARENT 1 2005-06-30:19:09:40

2 2 ORCL 1268995992
PARENT 446075 2011-01-23:21:07:41

3 3 ORCL
1268995992 ORPHAN 478854 2011-01-23:21:37:57

4 4 ORCL
1268995992 CURRENT 478854 2011-01-23:21:51:24

(看到没,出现了“孤儿”的INCARNATION也就是ORPHANINCARNATION。这种INCARNATION越多,是不是就越复杂,是吧,所以每天都做好备份才是最重要的。)

----------------------- THE END ----------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: