【RMAN】利用备份片还原数据库(下)

【RMAN】利用备份片还原数据库

【RMAN】利用备份片还原数据库(上): http://blog.itpub.net/26736162/viewspace-1621581/

【RMAN】利用备份片还原数据库(中):http://blog.itpub.net/26736162/viewspace-1621661/

在上2篇blog中介绍了备份片中含有控制文件的备份的情况下,如何从备份集中找回控制文件的备份并恢复数据库,本篇blog来介绍下在备份片中没有控制文件的备份的情况下如何恢复数据库。

1.1  备份集中无控制文件情况下的数据库恢复

如果采用本文中所描述的3种方式均判断没有控制文件的备份的时候,那么我们唯一能做的就是重建控制文件了,而resetlogs方式重建控制文件之前需要控制文件脚本中的所有数据文件到位才能重建控制文件。

[[email protected] 2015_05_02]# ll -h

total 1.2G

-rw-r----- 1 oracle oinstall  30M May  2 15:49 o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

-rw-r----- 1 oracle oinstall 4.0K May  2 15:49 o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

-rw-r----- 1 oracle oinstall 1.1G May  2 15:49 o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

[[email protected] 2015_05_02]# pwd

/tmp/2015_05_02

[[email protected] dbs]$ cd $ORACLE_HOME/dbs

[[email protected] dbs]$ more  inittmp.ora

db_name=tmp

[[email protected] dbs]$ ORACLE_SID=tmp

[[email protected] dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun May 3 14:45:45 2015

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

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area  217157632 bytes

Fixed Size                  2211928 bytes

Variable Size             159387560 bytes

Database Buffers           50331648 bytes

Redo Buffers                5226496 bytes

SQL> DECLARE

2   devtype varchar2(256);

3   done boolean;

4  BEGIN

5   devtype:=sys.dbms_backup_restore.deviceAllocate (type=>‘‘,ident=>‘t1‘);

6   sys.dbms_backup_restore.restoreSetDatafile;

7   sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>01,toname=>‘/tmp/2015_05_02/datafile1.dbf‘);

8   sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>‘/tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp‘, params=>null);

9   sys.dbms_backup_restore.deviceDeallocate;

10  END;

11  /

PL/SQL procedure successfully completed.

SQL> SQL> ! ls -lh /tmp/2015_05_02/

total 1.9G

-rw-r----- 1 oracle asmadmin 721M May  3 14:46 datafile1.dbf

-rw-r----- 1 oracle oinstall  30M May  2 15:49 o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

-rw-r----- 1 oracle oinstall 4.0K May  2 15:49 o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

-rw-r----- 1 oracle oinstall 1.1G May  2 15:49 o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

SQL> CREATE CONTROLFILE REUSE DATABASE "tmp" NORESETLOGS ARCHIVELOG

2  MAXLOGFILES 16

3  MAXLOGMEMBERS 3

4  MAXDATAFILES 100

5  MAXINSTANCES 8

6  MAXLOGHISTORY 292

7  LOGFILE

8  GROUP 1 ‘/tmp/2015_05_02/redo01.log‘ SIZE 50M,

9  GROUP 2 ‘/tmp/2015_05_02/redo02.log‘ SIZE 50M

10  DATAFILE

11  ‘/tmp/2015_05_02/datafile1.dbf‘

12  CHARACTER SET ZHS16GBK

13  ;

CREATE CONTROLFILE REUSE DATABASE "tmp" NORESETLOGS ARCHIVELOG

*

ERROR at line 1:

ORA-01503: CREATE CONTROLFILE failed

ORA-01161: database name ORA11G in file header does not match given name of TMP

ORA-01110: data file 1: ‘/tmp/2015_05_02/datafile1.dbf‘

由此可以看出备份集中的db_name为ORA11G,其实这些都是没有必要的,哪个dba不晓得数据库名呢?好吧,我们将pfile文件中的db_name修改一下,采用RESETLOGS创建控制文件,注意必须是RESETLOGS,NORESETLOGS需要online log文件在位,如下:

[[email protected] dbs]$ more inittmp.ora

db_name=ORA11G

[[email protected] dbs]$ echo $ORACLE_SID

tmp

[[email protected] dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun May 3 14:56:44 2015

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

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area  217157632 bytes

Fixed Size                  2211928 bytes

Variable Size             159387560 bytes

Database Buffers           50331648 bytes

Redo Buffers                5226496 bytes

SQL> CREATE CONTROLFILE REUSE DATABASE "ORA11G" RESETLOGS DATAFILE ‘/tmp/2015_05_02/datafile1.dbf‘;

Control file created.

SQL>

SQL>  show parameter control_files

NAME                                 TYPE        VALUE

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

control_files                        string      /u01/app/oracle/product/11.2.0

/dbhome_1/dbs/cntrltmp.dbf

SQL>

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a50

SQL> select file#,name FILE_NAME,status from v$datafile;

FILE# FILE_NAME                                          STATUS

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

1 /tmp/2015_05_02/datafile1.dbf                      SYSTEM

SQL>

catalog 所有的backuppiece

[[email protected] dbs]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Sun May 3 15:40:32 2015

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

connected to target database: ORA11G (DBID=4270446895, not open)

RMAN> list backupset;

using target database control file instead of recovery catalog

specification does not match any backup in the repository

RMAN> catalog start with ‘/tmp/2015_05_02/‘;

searching for all files that match the pattern /tmp/2015_05_02/

List of Files Unknown to the Database

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

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

File Name: /tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

Do you really want to catalog the above files (enter YES or NO)? yes

cataloging files...

cataloging done

List of Cataloged Files

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

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

File Name: /tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

RMAN>

RMAN> list backupset;

List of Backup Sets

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

BS Key  Size       Device Type Elapsed Time Completion Time

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

1       3.50K      DISK        00:00:00     2015-05-02 15:44:51

BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20150502T154451

Piece Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

List of Archived Logs in backup set 1

Thrd Seq     Low SCN    Low Time            Next SCN   Next Time

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

1    17      1166181    2015-05-02 15:44:02 1166209    2015-05-02 15:44:51

BS Key  Size       Device Type Elapsed Time Completion Time

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

2       29.82M     DISK        00:00:00     2015-05-02 15:44:02

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

Piece Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

List of Archived Logs in backup set 2

Thrd Seq     Low SCN    Low Time            Next SCN   Next Time

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

1    16      1145812    2015-05-02 11:31:52 1166181    2015-05-02 15:44:02

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

3       Full    1.07G      DISK        00:00:00     2015-05-02 15:44:04

BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20150502T154404

Piece Name: /tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

List of Datafiles in backup set 3

File LV Type Ckp SCN    Ckp Time            Name

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

1       Full 1166189    2015-05-02 15:44:04 /tmp/2015_05_02/datafile1.dbf

2       Full 1166189    2015-05-02 15:44:04

3       Full 1166189    2015-05-02 15:44:04

4       Full 1166189    2015-05-02 15:44:04

5       Full 1166189    2015-05-02 15:44:04

6       Full 1166189    2015-05-02 15:44:04

RMAN>

RMAN> list backupset of spfile;

specification does not match any backup in the repository

RMAN> list backupset of controlfile;

specification does not match any backup in the repository

RMAN> list backupset of archivelog all;

List of Backup Sets

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

BS Key  Size       Device Type Elapsed Time Completion Time

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

1       3.50K      DISK        00:00:00     2015-05-02 15:44:51

BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20150502T154451

Piece Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

List of Archived Logs in backup set 1

Thrd Seq     Low SCN    Low Time            Next SCN   Next Time

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

1    17      1166181    2015-05-02 15:44:02 1166209    2015-05-02 15:44:51

BS Key  Size       Device Type Elapsed Time Completion Time

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

2       29.82M     DISK        00:00:00     2015-05-02 15:44:02

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

Piece Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

List of Archived Logs in backup set 2

Thrd Seq     Low SCN    Low Time            Next SCN   Next Time

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

1    16      1145812    2015-05-02 11:31:52 1166181    2015-05-02 15:44:02

RMAN> list backupset of database;

List of Backup Sets

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

3       Full    1.07G      DISK        00:00:00     2015-05-02 15:44:04

BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20150502T154404

Piece Name: /tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

List of Datafiles in backup set 3

File LV Type Ckp SCN    Ckp Time            Name

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

1       Full 1166189    2015-05-02 15:44:04 /tmp/2015_05_02/datafile1.dbf

2       Full 1166189    2015-05-02 15:44:04

3       Full 1166189    2015-05-02 15:44:04

4       Full 1166189    2015-05-02 15:44:04

5       Full 1166189    2015-05-02 15:44:04

6       Full 1166189    2015-05-02 15:44:04

由备份集我们可以看出,有16和17号的归档文件备份,有6个数据文件备份,这里我们使用dbms_backup_restore package 来restore datafile。请注意:datafile的名字不重要,只要对于要恢复的datafile,是唯一的名字即可。

[[email protected] dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun May 3 15:59:43 2015

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

SQL> DECLARE

2    devtype varchar2(256);

3    done boolean;

4  BEGIN

devtype := dbms_backup_restore.DeviceAllocate(type=>null, ident=>‘d1‘);

6    dbms_backup_restore.RestoreSetDatafile;

7    --dbms_backup_restore.RestoreDatafileTo(dfnumber => 1,toname => ‘/tmp/2015_05_02/datafile1.dbf‘);

8    dbms_backup_restore.RestoreDatafileTo(dfnumber => 2,toname => ‘/tmp/2015_05_02/datafile2.dbf‘);

9    dbms_backup_restore.RestoreDatafileTo(dfnumber => 3,toname => ‘/tmp/2015_05_02/datafile3.dbf‘);

10    dbms_backup_restore.RestoreDatafileTo(dfnumber => 4,toname => ‘/tmp/2015_05_02/datafile4.dbf‘);

11    dbms_backup_restore.RestoreDatafileTo(dfnumber => 5,toname => ‘/tmp/2015_05_02/datafile5.dbf‘);

12    dbms_backup_restore.RestoreDatafileTo(dfnumber => 6,toname => ‘/tmp/2015_05_02/datafile6.dbf‘);

13    dbms_backup_restore.RestoreBackupPiece(done => done,handle =>‘/tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp‘, params => null);

14    dbms_backup_restore.DeviceDeallocate;

15  END;

16  /

PL/SQL procedure successfully completed.

SQL>

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a50

SQL> select file#,name FILE_NAME,status from v$datafile;

FILE# FILE_NAME                                          STATUS

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

1 /tmp/2015_05_02/datafile1.dbf                      SYSTEM

SQL> shutdown abort;

ORACLE instance shut down.

SQL>

告警日志:

Sun May 03 15:59:44 2015

Full restore complete of datafile 6 to datafile copy /tmp/2015_05_02/datafile6.dbf.  Elapsed time: 0:00:00

checkpoint is 1166189

last deallocation scn is 995550

Full restore complete of datafile 4 to datafile copy /tmp/2015_05_02/datafile4.dbf.  Elapsed time: 0:00:02

checkpoint is 1166189

last deallocation scn is 3

Full restore complete of datafile 3 to datafile copy /tmp/2015_05_02/datafile3.dbf.  Elapsed time: 0:00:02

checkpoint is 1166189

last deallocation scn is 1157819

Undo Optimization current scn is 1157346

Sun May 03 16:00:30 2015

Full restore complete of datafile 5 to datafile copy /tmp/2015_05_02/datafile5.dbf.  Elapsed time: 0:00:44

checkpoint is 1166189

last deallocation scn is 1015098

Sun May 03 16:01:03 2015

Full restore complete of datafile 2 to datafile copy /tmp/2015_05_02/datafile2.dbf.  Elapsed time: 0:01:18

checkpoint is 1166189

last deallocation scn is 1090388

元数据显示只有datafile 1,不奇怪,刚刚创建控制文件的时候只带了一个sysem文件,那么我们就需要重建控制文件以便带上所有需要恢复的datafiles

STARTUP NOMOUNT

CREATE CONTROLFILE REUSE DATABASE "ORA11G" RESETLOGS  ARCHIVELOG

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100

MAXINSTANCES 8

MAXLOGHISTORY 292

LOGFILE

GROUP 1 ‘/tmp/2015_05_02/redo01.log‘  SIZE 50M BLOCKSIZE 512,

GROUP 2 ‘/tmp/2015_05_02/redo02.log‘  SIZE 50M BLOCKSIZE 512,

GROUP 3 ‘/tmp/2015_05_02/redo03.log‘  SIZE 50M BLOCKSIZE 512

-- STANDBY LOGFILE

DATAFILE

‘/tmp/2015_05_02/datafile1.dbf‘,

‘/tmp/2015_05_02/datafile2.dbf‘,

‘/tmp/2015_05_02/datafile3.dbf‘,

‘/tmp/2015_05_02/datafile4.dbf‘,

‘/tmp/2015_05_02/datafile5.dbf‘,

‘/tmp/2015_05_02/datafile6.dbf‘

CHARACTER SET ZHS16GBK

;

SQL> startup nomount;

ORACLE instance started.

Total System Global Area  217157632 bytes

Fixed Size                  2211928 bytes

Variable Size             159387560 bytes

Database Buffers           50331648 bytes

Redo Buffers                5226496 bytes

SQL>

SQL> CREATE CONTROLFILE REUSE DATABASE "ORA11G" RESETLOGS  ARCHIVELOG

2      MAXLOGFILES 16

3      MAXLOGMEMBERS 3

4      MAXDATAFILES 100

5      MAXINSTANCES 8

6      MAXLOGHISTORY 292

7  LOGFILE

8    GROUP 1 ‘/tmp/2015_05_02/redo01.log‘  SIZE 50M BLOCKSIZE 512,

9    GROUP 2 ‘/tmp/2015_05_02/redo02.log‘  SIZE 50M BLOCKSIZE 512,

10    GROUP 3 ‘/tmp/2015_05_02/redo03.log‘  SIZE 50M BLOCKSIZE 512

11  -- STANDBY LOGFILE

12  DATAFILE

13    ‘/tmp/2015_05_02/datafile1.dbf‘,

14    ‘/tmp/2015_05_02/datafile2.dbf‘,

15    ‘/tmp/2015_05_02/datafile3.dbf‘,

16    ‘/tmp/2015_05_02/datafile4.dbf‘,

17    ‘/tmp/2015_05_02/datafile5.dbf‘,

18    ‘/tmp/2015_05_02/datafile6.dbf‘

19  CHARACTER SET ZHS16GBK

20  ;

Control file created.

SQL>

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a50

SQL> select file#,name FILE_NAME,status from v$datafile;

FILE# FILE_NAME                                          STATUS

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

1 /tmp/2015_05_02/datafile1.dbf                      SYSTEM

2 /tmp/2015_05_02/datafile2.dbf                      RECOVER

3 /tmp/2015_05_02/datafile3.dbf                      RECOVER

4 /tmp/2015_05_02/datafile4.dbf                      RECOVER

5 /tmp/2015_05_02/datafile5.dbf                      RECOVER

6 /tmp/2015_05_02/datafile6.dbf                      RECOVER

6 rows selected.

SQL>

若是该备份不是冷备份,那么我们需要recover database,我们需要catalog 包括archivelog的backuppiece,然后restore archivelog,然后再recover

[[email protected] dbs]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Sun May 3 16:21:53 2015

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

connected to target database: ORA11G (DBID=4270446895, not open)

RMAN> list backupset;

using target database control file instead of recovery catalog

specification does not match any backup in the repository

RMAN> catalog start with ‘/tmp/2015_05_02/‘;

searching for all files that match the pattern /tmp/2015_05_02/

List of Files Unknown to the Database

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

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

File Name: /tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

Do you really want to catalog the above files (enter YES or NO)? yes

cataloging files...

cataloging done

List of Cataloged Files

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

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

File Name: /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154402_bn9022tb_.bkp

File Name: /tmp/2015_05_02/o1_mf_nnndf_TAG20150502T154404_bn9025w1_.bkp

RMAN> recover database;

Starting recover at 2015-05-03 16:23:31

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=96 device type=DISK

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=17

channel ORA_DISK_1: reading from backup piece /tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp

channel ORA_DISK_1: piece handle=/tmp/2015_05_02/o1_mf_annnn_TAG20150502T154451_bn903mln_.bkp tag=TAG20150502T154451

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_17_874246769.dbf thread=1 sequence=17

unable to find archived log

archived log thread=1 sequence=18

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

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

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

RMAN-03002: failure of recover command at 05/03/2015 16:23:34

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 18 and starting SCN of 1166209

RMAN> recover database until sequence 18;

Starting recover at 2015-05-03 16:23:44

using channel ORA_DISK_1

starting media recovery

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

Finished recover at 2015-05-03 16:23:44

RMAN> alter database open resetlogs;

database opened

RMAN>

RMAN> exit

Recovery Manager complete.

[[email protected] dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sun May 3 16:41:58 2015

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter name

NAME                                 TYPE        VALUE

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

db_file_name_convert                 string

db_name                              string      ORA11G

db_unique_name                       string      ORA11G

global_names                         boolean     FALSE

instance_name                        string      tmp

lock_name_space                      string

log_file_name_convert                string

processor_group_name                 string

service_names                        string      ORA11G

SQL>

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area  250560512 bytes

Fixed Size                  2227256 bytes

Variable Size             192938952 bytes

Database Buffers           50331648 bytes

Redo Buffers                5062656 bytes

Database mounted.

Database opened.

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a50

SQL> select file#,name FILE_NAME,status from v$datafile;

FILE# FILE_NAME                                          STATUS

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

1 /tmp/2015_05_02/datafile1.dbf                      SYSTEM

2 /tmp/2015_05_02/datafile2.dbf                      ONLINE

3 /tmp/2015_05_02/datafile3.dbf                      ONLINE

4 /tmp/2015_05_02/datafile4.dbf                      ONLINE

5 /tmp/2015_05_02/datafile5.dbf                      ONLINE

6 /tmp/2015_05_02/datafile6.dbf                      ONLINE

6 rows selected.

SQL>

SQL> col FILE_NAME format a50

SQL> select FILE_NAME,FILE_ID,a.TABLESPACE_NAME, b.status ts_status ,BYTES from dba_data_files a,dba_tablespaces b where a.TABLESPACE_NAME=b.TABLESPACE_NAME;

FILE_NAME                                             FILE_ID TABLESPACE_NAME                TS_STATUS      BYTES

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

/tmp/2015_05_02/datafile6.dbf                               6 AA                             ONLINE       5242880

/tmp/2015_05_02/datafile5.dbf                               5 EXAMPLE                        ONLINE     328335360

/tmp/2015_05_02/datafile4.dbf                               4 USERS                          ONLINE      15728640

/tmp/2015_05_02/datafile3.dbf                               3 UNDOTBS1                       ONLINE      99614720

/tmp/2015_05_02/datafile2.dbf                               2 SYSAUX                         ONLINE     576716800

/tmp/2015_05_02/datafile1.dbf                               1 SYSTEM                         ONLINE     754974720

6 rows selected.

SQL> select count(1) from lhr.test;

COUNT(1)

----------

75204

recover 过程告警日志:

Sun May 03 16:39:56 2015

alter database recover datafile list clear

Completed: alter database recover datafile list clear

alter database recover datafile list

1 , 2 , 3 , 4 , 5 , 6

Completed: alter database recover datafile list

1 , 2 , 3 , 4 , 5 , 6

alter database recover if needed

start until cancel using backup controlfile

Media Recovery Start

started logmerger process

Parallel Media Recovery started with 2 slaves

ORA-279 signalled during: alter database recover if needed

start until cancel using backup controlfile

...

alter database recover logfile ‘/u02/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_17_874246769.dbf‘

Media Recovery Log /u02/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_17_874246769.dbf

ORA-279 signalled during: alter database recover logfile ‘/u02/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_17_874246769.dbf‘...

alter database recover cancel

Media Recovery Canceled

Completed: alter database recover cancel

临时文件的处理:

SQL>

SQL> select * from v$tempfile;

no rows selected

SQL> create temporary tablespace TEMP01 tempfile  ‘/tmp/2015_05_02/temp01.dbf‘  size 100m autoextend on next 10m;

Tablespace created.

SQL> alter database default temporary tablespace temp01;

Database altered.

SQL>

SQL> col name for a100

SQL> select file#,name from  v$tempfile;

FILE# NAME

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

1 /tmp/2015_05_02/temp01.dbf

SQL>

接下来就是把数据文件命名格式化,执行如下代码:

shutdown immediate;

cp /tmp/2015_05_02/*.dbf /u02/app/oracle/oradata/ORA11G/

cp /tmp/2015_05_02/*.log /u02/app/oracle/oradata/ORA11G/

mv datafile1.dbf AA.dbf

mv datafile5.dbf EXAMPLE01.dbf

mv AA.dbf SYSTEM01.dbf

mv datafile4.dbf USERS01.dbf

mv datafile3.dbf UNDOTBS1.dbf

mv datafile2.dbf SYSAUX01.dbf

mv datafile6.dbf AA.dbf

startup mount

alter database rename file‘/tmp/2015_05_02/datafile6.dbf‘  to ‘/u02/app/oracle/oradata/ORA11G/AA.dbf‘;

alter database rename file‘/tmp/2015_05_02/datafile5.dbf‘  to ‘/u02/app/oracle/oradata/ORA11G/EXAMPLE01.dbf‘;

alter database rename file‘/tmp/2015_05_02/datafile4.dbf‘  to ‘/u02/app/oracle/oradata/ORA11G/USERS01.dbf‘;

alter database rename file‘/tmp/2015_05_02/datafile3.dbf‘  to ‘/u02/app/oracle/oradata/ORA11G/UNDOTBS1.dbf‘;

alter database rename file‘/tmp/2015_05_02/datafile2.dbf‘  to ‘/u02/app/oracle/oradata/ORA11G/SYSAUX01.dbf‘;

alter database rename file‘/tmp/2015_05_02/datafile1.dbf‘  to ‘/u02/app/oracle/oradata/ORA11G/SYSTEM01.dbf‘;

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a50

SQL> select file#,name FILE_NAME,status from v$datafile;

FILE# FILE_NAME                                          STATUS

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

1 /u02/app/oracle/oradata/ORA11G/SYSTEM01.dbf        SYSTEM

2 /u02/app/oracle/oradata/ORA11G/SYSAUX01.dbf        ONLINE

3 /u02/app/oracle/oradata/ORA11G/UNDOTBS1.dbf        ONLINE

4 /u02/app/oracle/oradata/ORA11G/USERS01.dbf         ONLINE

5 /u02/app/oracle/oradata/ORA11G/EXAMPLE01.dbf       ONLINE

6 /u02/app/oracle/oradata/ORA11G/AA.dbf              ONLINE

6 rows selected.

SQL> alter database open;

Database altered.

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a50

SQL> select file#,name FILE_NAME,status from v$datafile;

FILE# FILE_NAME                                          STATUS

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

1 /u02/app/oracle/oradata/ORA11G/SYSTEM01.dbf        SYSTEM

2 /u02/app/oracle/oradata/ORA11G/SYSAUX01.dbf        ONLINE

3 /u02/app/oracle/oradata/ORA11G/UNDOTBS1.dbf        ONLINE

4 /u02/app/oracle/oradata/ORA11G/USERS01.dbf         ONLINE

5 /u02/app/oracle/oradata/ORA11G/EXAMPLE01.dbf       ONLINE

6 /u02/app/oracle/oradata/ORA11G/AA.dbf              ONLINE

6 rows selected.

SQL> col FILE_NAME format a50

SQL> select FILE_NAME,FILE_ID,a.TABLESPACE_NAME, b.status ts_status ,BYTES from dba_data_files a,dba_tablespaces b where a.TABLESPACE_NAME=b.TABLESPACE_NAME;

FILE_NAME                                             FILE_ID TABLESPACE_NAME                TS_STATUS      BYTES

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

/u02/app/oracle/oradata/ORA11G/AA.dbf                       6 AA                             ONLINE       5242880

/u02/app/oracle/oradata/ORA11G/EXAMPLE01.dbf                5 EXAMPLE                        ONLINE     328335360

/u02/app/oracle/oradata/ORA11G/USERS01.dbf                  4 USERS                          ONLINE      15728640

/u02/app/oracle/oradata/ORA11G/UNDOTBS1.dbf                 3 UNDOTBS1                       ONLINE      99614720

/u02/app/oracle/oradata/ORA11G/SYSAUX01.dbf                 2 SYSAUX                         ONLINE     576716800

/u02/app/oracle/oradata/ORA11G/SYSTEM01.dbf                 1 SYSTEM                         ONLINE     754974720

6 rows selected.

SQL>

好了,至此,整个数据库恢复完成,至于修改INSTANCE_NAME,pfile文件,密码文件、tnsnames文件,这些都是基本功了,这里就不赘述了。

时间: 2024-10-05 17:42:47

【RMAN】利用备份片还原数据库(下)的相关文章

【RMAN】利用备份片还原数据库(中)

[RMAN]利用备份片还原数据库 [RMAN]利用备份片还原数据库(上): http://blog.itpub.net/26736162/viewspace-1621581/ 在上一篇blog中我们介绍了采用dbms_backup_restore来找回控制文件并恢复整个数据库的方法,本篇blog我们介绍采用创建临时库来找回控制文件的方法. 1.1.1  方法二:尝试采用创建临时库来找回控制文件 由于RMAN必须工作在MOUNT模式,所有的数据文件都丢失,无法通过只重建控制文件将其启动到MOUNT

【RMAN】利用备份片还原数据库(上)

[RMAN]利用备份片还原数据库 群里有同学说把ORACLE_BASE目录删掉了,现在只有备份片和归档文件了,试问如何恢复.坑,,,,咋能这么干,ORACLE_BASE都敢删,,试着恢复了下,并且记录下来,当然软件安装部分就不记录了. 我再说说目前的情况,只有备份片和归档文件,且从文件名称是看不出dbname和dbid的,在这种情况下其实恢复控制文件是很重要的了,但是鬼知道备份片里边是不是有控制文件的备份呢?我们可能碰到的就是这样的情况,只有备份文件,其它的什么都不知道.我们且看这样的情况下如何

【RMAN】利用备份片还原数据库(中)

[RMAN]利用备份片还原数据库       blog文档结构图:      [RMAN]利用备份片还原数据库(上): http://blog.itpub.net/26736162/viewspace-1621581/    在...yuedu.baidu.com/album/view/a9e914106c175f0e7cd13760/2015-05-11 yuedu.baidu.com/album/view/a9e914106c175f0e7cd13760.html/2015-05-11 yu

Linux下用dump实现备份和还原 ux下用dump实现备份和还原

对于系统而言,我们可以有很多种办法去备份(还原)系统或文件,之所以要去做备份,就是为了在系统或文件遭到损害时,能及时恢复,把损失减小到最小.当然,对于企业服务器而言,备份的重要性是举足轻重.咱们今天就详细讨论一下LINUX中如何用dump和restore实现备份和还原. 一,dump的原理,优点及限制 dump和restore默认已经安装在RHEL5中,如果你使用的Linux中没有,可以自己去google中搜一下并下载安装. 使用dump命令时,它会建立一份自上次备份操作以来进行修改过的文件列表

使用.net备份和还原数据库

原文:使用.net备份和还原数据库 CSDN网友的提问http://community.csdn.net/Expert/TopicView3.asp?id=4929678 C#实现SQLSERVER2000数据库备份还原的两种方法: 方法一(不使用SQLDMO): //////备份方法///SqlConnection conn = new SqlConnection("Server=.;Database=master;User ID=sa;Password=sa;"); SqlComm

在ASP.NET中备份和还原数据库

昨天看了<C#项目实录>中的进销存管理系统,和其他书里讲的案例一样,无非也就是数据库增删查改,但是这个进销存系统中有一个备份和还原数据库的功能,蛮有兴趣的,看了一下代码,原来如此,也就是通过SQL语句来进行备份和还原数据库,SQL语句如下: Sql代码   -- 备份数据库 backup database db_CSManage to disk='c:\backup.bak' -- 还原数据库,必须先备份该数据库的日志文件到原先的备份文件中 backup log db_CSManage to 

php168备份与还原数据库

数据对于每一个人而言都是非常重要的,因此我们会经常会进行数据的备份,包括程序和数据库.Php168是一款非常多人使用的一套程序,我们就来谈一谈php168数据库的备份.Php168的数据库备份不需要使用phpmyadmin.直接利用他的后台本身的备份数据库功能即可. 进入后台,点击系统功能,点击左下角的备份数据库 出现了备份的界面之后我们需要选择备份空间的所有数据库,因为默认是不是备份所有的数据库的. 一直移动到最下面,点击立即备份. 开始备份之后等待一会就备份好了.备份文件存放的目录是cach

异步备份和还原数据库:.NET发现之旅(六)

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://terryli.blog.51cto.com/704315/335062 信息系统是数据密集型的,数据的套帐,备份,还原是客户最希望有的功能,这一节课就讨论下C/S系统下数据库的异步备份和还原,B/S系统的数据备份和还原和这个类似. 既然是异步,首先会想到使用多线程技术..NET平台提供了一整套的线程处理技术,使用线程的好处是,可以让一个线程做一件事情,多个线程之间根据时间片机制

mysql备份和还原数据库

备份数据库:/usr/local/kkmail/service/mysql/bin/mysqldump -u kkmail -p --databases kkmail |gzip>20180309.sql.gz 还原数据库:停止和数据库相关的服务.解压备份的sql数据库文件.还原数据库.最后开启这些服务:for i in kkmail_app kkmail_nginx kkmail_apache kkmail_dovecot kkmail_redis kkmail_postfix;do /etc