Oracle备份恢复测试

问题:

1.  10:54:00 backup Database
2.  10:55:00  Create Table test1
    10:57:01  Drop   Table test1
    Create Table test2; Insert Into ...
3.  10:59:00  Drop Table test2
4.  10:59:01  Backup Database
5.  此时发现test1 被DROP, 要求恢复到 10:57:00(drop table test1 之前), 恢复还原之后又发现需要test2, 因此要求恢复到10:58:34

1.  backup Database
        C:\Documents and Settings\jason>rman target sys/oracle@mydata catalog rman/rman@rmandb

        Recovery Manager: Release 9.2.0.1.0 - Production
        Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
        connected to target database: MYDATA (DBID=165830944)
        connected to recovery catalog database

        RMAN> run {
        2> allocate channel d1 type disk;
        3> backup format 'd:\dbbak\%U' database;
        4> sql 'alter system archive log current';
        5> backup archivelog all delete input;
        6> release channel d1;
        7> }

        allocated channel: d1
        channel d1: sid=15 devtype=DISK
        Starting backup at 12-APR-07
        channel d1: starting full datafile backupset
        channel d1: specifying datafile(s) in backupset
        input datafile fno=00001 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\SYSTEM01.DBF
        input datafile fno=00002 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\UNDOTBS01.DBF
        input datafile fno=00006 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\PERFSAT.DBF
        input datafile fno=00003 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\INDX01.DBF
        input datafile fno=00005 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\USERS01.DBF
        input datafile fno=00004 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\TOOLS01.DBF
        channel d1: starting piece 1 at 12-APR-07
        channel d1: finished piece 1 at 12-APR-07
        piece handle=D:\DBBAK\04IEVMDO_1_1 comment=NONE
        channel d1: backup set complete, elapsed time: 00:19:08
        Finished backup at 12-APR-07

        Starting Control File and SPFILE Autobackup at 12-APR-07
        piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-01 comment=NONE
        Finished Control File and SPFILE Autobackup at 12-APR-07

        sql statement: alter system archive log current
        Starting backup at 12-APR-07
        current log archived
        channel d1: starting archive log backupset
        channel d1: specifying archive log(s) in backup set
        input archive log thread=1 sequence=39 recid=1 stamp=619699767
        input archive log thread=1 sequence=40 recid=2 stamp=619699770
        channel d1: starting piece 1 at 12-APR-07
        channel d1: finished piece 1 at 12-APR-07
        piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\06IEVNHQ_1_1 comment=NONE
        channel d1: backup set complete, elapsed time: 00:00:02
        channel d1: deleting archive log(s)
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00039.001 recid=1 stamp=619699767
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00040.001 recid=2 stamp=619699770
        Finished backup at 12-APR-07

        Starting Control File and SPFILE Autobackup at 12-APR-07
        piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-02 comment=NONE
        Finished Control File and SPFILE Autobackup at 12-APR-07

        released channel: d1
        RMAN>

2.  Create Table test1, Drop Table test1;
    Create Table test2, Insert into test2

        C:\Documents and Settings\jason>set oracle_sid=mydata
        C:\Documents and Settings\jason>sqlplus /nolog

        SQL*Plus: Release 9.2.0.1.0 - Production on Thu Apr 12 10:52:43 2007
        Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

        SQL> connect perfstat/perfstat;
        Connected.

        SQL> set time on;
        10:53:37 SQL> create table test1 (field1 varchar2(10), field2 number(5));
        Table created.
        10:54:12 SQL>
        10:56:23 SQL>

        10:57:01 SQL> drop table test1;
        Table dropped.
        10:57:18 SQL>

        10:57:39 SQL> create table test2 (field1 varchar2(10), field2 number(5));
        Table created.

        10:58:07 SQL> insert into test2 values('name1', 10);
        1 row created.

        10:58:25 SQL> insert into test2 values('name2', 20);
        1 row created.

        10:58:31 SQL> commit;
        Commit complete.

        10:58:33 SQL>

3. backup database
        RMAN> run {
        2> allocate channel d1 type disk;
        3> backup format 'd:\dbbak\%U' database;
        4> sql 'alter system archive log current';
        5> backup format 'd:\dbbak\al_%s_%p_%t' archivelog all delete input;
        6> release channel d1;
        7> }

        allocated channel: d1
        channel d1: sid=15 devtype=DISK
        Starting backup at 12-APR-07
        channel d1: starting full datafile backupset
        channel d1: specifying datafile(s) in backupset
        input datafile fno=00001 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\SYSTEM01.DBF
        input datafile fno=00002 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\UNDOTBS01.DBF
        input datafile fno=00006 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\PERFSAT.DBF
        input datafile fno=00003 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\INDX01.DBF
        input datafile fno=00005 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\USERS01.DBF
        input datafile fno=00004 name=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\TOOLS01.DBF
        channel d1: starting piece 1 at 12-APR-07
        channel d1: finished piece 1 at 12-APR-07
        piece handle=D:\DBBAK\08IEVO78_1_1 comment=NONE
        channel d1: backup set complete, elapsed time: 00:00:26
        Finished backup at 12-APR-07

        Starting Control File and SPFILE Autobackup at 12-APR-07
        piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-03 comment=NONE
        Finished Control File and SPFILE Autobackup at 12-APR-07

        sql statement: alter system archive log current
        Starting backup at 12-APR-07
        current log archived
        channel d1: starting archive log backupset
        channel d1: specifying archive log(s) in backup set
        input archive log thread=1 sequence=41 recid=3 stamp=619700485
        input archive log thread=1 sequence=42 recid=4 stamp=619700489
        channel d1: starting piece 1 at 12-APR-07
        channel d1: finished piece 1 at 12-APR-07
        piece handle=D:\DBBAK\AL_10_1_619700489 comment=NONE
        channel d1: backup set complete, elapsed time: 00:00:02
        channel d1: deleting archive log(s)
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00041.001 recid=3 stamp=619700485
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00042.001 recid=4 stamp=619700489
        Finished backup at 12-APR-07

        Starting Control File and SPFILE Autobackup at 12-APR-07
        piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-04 comment=NONE
        Finished Control File and SPFILE Autobackup at 12-APR-07
        released channel: d1
        RMAN>

4. 按要求恢复.....
        SQL> connect / as sysdba
        Connected.
        SQL> shutdown immediate;
        Database closed.
        Database dismounted.
        ORACLE instance shut down.

        SQL> startup mount;
        ORACLE instance started.
        Total System Global Area  101784276 bytes
        Fixed Size                   453332 bytes
        Variable Size              75497472 bytes
        Database Buffers           25165824 bytes
        Redo Buffers                 667648 bytes
        Database mounted.
        SQL>

    恢复到10:57:00
        RMAN> run {
        2> set until time "to_date('20070412105700','yyyymmddhh24miss')";
        3> restore database;
        4> recover database;
        5> }

        executing command: SET until clause
        Starting restore at 12-APR-07
        allocated channel: ORA_DISK_1
        channel ORA_DISK_1: sid=14 devtype=DISK
        channel ORA_DISK_1: starting datafile backupset restore
        channel ORA_DISK_1: specifying datafile(s) to restore from backup set
        restoring datafile 00001 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\SYSTEM01.DBF
        restoring datafile 00002 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\UNDOTBS01.DBF
        restoring datafile 00003 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\INDX01.DBF
        restoring datafile 00004 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\TOOLS01.DBF
        restoring datafile 00005 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\USERS01.DBF
        restoring datafile 00006 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\PERFSAT.DBF
        channel ORA_DISK_1: restored backup piece 1
        piece handle=D:\DBBAK\04IEVMDO_1_1 tag=TAG20070412T103016 params=NULL
        channel ORA_DISK_1: restore complete
        Finished restore at 12-APR-07

        Starting recover at 12-APR-07
        using channel ORA_DISK_1
        starting media recovery
        channel ORA_DISK_1: starting archive log restore to default destination
        channel ORA_DISK_1: restoring archive log
        archive log thread=1 sequence=39
        channel ORA_DISK_1: restoring archive log
        archive log thread=1 sequence=40
        channel ORA_DISK_1: restored backup piece 1
        piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\06IEVNHQ_1_1 tag=TAG20070412T104930 params=NULL
        channel ORA_DISK_1: restore complete
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00039.001 thread=1 sequence=39
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00040.001 thread=1 sequence=40
        channel ORA_DISK_1: starting archive log restore to default destination
        channel ORA_DISK_1: restoring archive log
        archive log thread=1 sequence=41
        channel ORA_DISK_1: restored backup piece 1
        piece handle=D:\DBBAK\AL_10_1_619700489 tag=TAG20070412T110129 params=NULL
        channel ORA_DISK_1: restore complete
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00041.001 thread=1 sequence=41
        media recovery complete
        Finished recover at 12-APR-07
        RMAN>

    打开数据库
        SQL> alter database open resetlogs;
        Database altered.

        SQL> connect perfstat/perfstat;
        Connected.

        SQL> select * from test1;
        no rows selected

    恢复还原完成, 但发现test2已没有!      

        SQL> select * from test2;
        select * from test2
                      *
        ERROR at line 1:
        ORA-00942: table or view does not exist

        SQL>

    先将test1导出
        C:\Documents and Settings\jason>set oracle_sid=mydata
        C:\Documents and Settings\jason>exp perfstat/perfstat file=d:\dbbak\test1.dmp log=test1.log tables=(test1)

        Export: Release 9.2.0.1.0 - Production on Thu Apr 12 11:42:23 2007
        Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
        Connected to: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
        With the Partitioning, OLAP and Oracle Data Mining options
        JServer Release 9.2.0.1.0 - Production
        Export done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
        About to export specified tables via Conventional Path ...
        . . exporting table                          TEST1          0 rows exported
        Export terminated successfully without warnings.

   准备把库恢复到10:59:00

        C:\Documents and Settings\jason>sqlplus /nolog
        SQL*Plus: Release 9.2.0.1.0 - Production on Thu Apr 12 11:42:31 2007
        Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
        SQL> connect / as sysdba;
        Connected.
 
        SQL> shutdown immediate;
        Database closed.
        Database dismounted.
        ORACLE instance shut down.

        SQL> startup mount;
        ORACLE instance started.
        Total System Global Area  101784276 bytes
        Fixed Size                   453332 bytes
        Variable Size              75497472 bytes
        Database Buffers           25165824 bytes
        Redo Buffers                 667648 bytes
        Database mounted.

    恢复到10:59:00
        C:\Documents and Settings\jason>rman target sys/oracle@mydata catalog rman/rman@rmandb
        Recovery Manager: Release 9.2.0.1.0 - Production
        Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
        connected to target database: MYDATA (DBID=165830944)
        connected to recovery catalog database

        RMAN> run {
        2> set until time "to_date('20070412105900','yyyymmddhh24miss')";
        3> restore database;
        4> recover database;
        5> }

        executing command: SET until clause
        RMAN-00571: ===========================================================
        RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
        RMAN-00571: ===========================================================
        RMAN-03002: failure of set command at 04/12/2007 11:44:47
        RMAN-06004: ORACLE error from recovery catalog database: RMAN-20003: target database incarnation not found in recovery catalog
        RMAN>

   ******此时发现原来的备份集不能用,  问题出现!!!!!!

        重新启动到nomount状态
        SQL> shutdown immediate;
        ORA-01109: database not open
        Database dismounted.
        ORACLE instance shut down.

        SQL> startup nomount;
        ORACLE instance started.
        Total System Global Area  101784276 bytes
        Fixed Size                   453332 bytes
        Variable Size              75497472 bytes
        Database Buffers           25165824 bytes
        Redo Buffers                 667648 bytes

    从指定的备份中恢复控制文件
        C:\Documents and Settings\jason>rman target sys/oracle@mydata catalog rman/rman@rmandb

        Recovery Manager: Release 9.2.0.1.0 - Production
        Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
        connected to target database: mydata (not mounted)
        connected to recovery catalog database

        RMAN> restore controlfile from 'C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-01';
        Starting restore at 12-APR-07
        allocated channel: ORA_DISK_1
        channel ORA_DISK_1: sid=14 devtype=DISK
        channel ORA_DISK_1: restoring controlfile
        channel ORA_DISK_1: restore complete
        replicating controlfile
        input filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\CONTROL01.CTL
        output filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\CONTROL02.CTL
        Finished restore at 12-APR-07

        RMAN>

    启动到mount状态
        SQL> alter database mount;
        Database altered.
        SQL>

       
  12.
        RMAN> run {
        2> set until time "to_date('20070412105834','yyyymmddhh24miss')";
        3> restore database;
        4> recover database;
        5> }

        executing command: SET until clause
        Starting restore at 12-APR-07
        using channel ORA_DISK_1
        channel ORA_DISK_1: starting datafile backupset restore
        channel ORA_DISK_1: specifying datafile(s) to restore from backup set
        restoring datafile 00001 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\SYSTEM01.DBF
        restoring datafile 00002 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\UNDOTBS01.DBF
        restoring datafile 00003 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\INDX01.DBF
        restoring datafile 00004 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\TOOLS01.DBF
        restoring datafile 00005 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\USERS01.DBF
        restoring datafile 00006 to C:\SOFTWARE\ORACLE\ORADATA\MYDATA\PERFSAT.DBF
        channel ORA_DISK_1: restored backup piece 1
        piece handle=D:\DBBAK\04IEVMDO_1_1 tag=TAG20070412T103016 params=NULL
        channel ORA_DISK_1: restore complete
        Finished restore at 12-APR-07

        Starting recover at 12-APR-07
        using channel ORA_DISK_1
        starting media recovery

        archive log thread 1 sequence 39 is already on disk as file C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00039.001
        archive log thread 1 sequence 40 is already on disk as file C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00040.001
        archive log thread 1 sequence 41 is already on disk as file C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00041.001
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00039.001 thread=1 sequence=39
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00040.001 thread=1 sequence=40
        archive log filename=C:\SOFTWARE\ORACLE\ORADATA\MYDATA\ARCHIVE\ARC00041.001 thread=1 sequence=41
        media recovery complete
        Finished recover at 12-APR-07
        RMAN>

    *****做完 resetlogs 后, C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-01  里面的控制文件是最新的了, -----从时间上可以看出,
    不能利用这个来恢复到 10:58:34 左右的数据了!!!!!!!!
    *****如果还要用这个文件来做恢复试验, 最好先将它备份一下!!!!!!!!

        RMAN> sql 'alter database open resetlogs';
        sql statement: alter database open resetlogs
        RMAN>

        RMAN> reset database;
        new incarnation of database registered in recovery catalog
        starting full resync of recovery catalog
        full resync complete

        RMAN> report obsolete;
        RMAN retention policy will be applied to the command
        RMAN retention policy is set to redundancy 1
        Report of obsolete backups and copies
        Type                 Key    Completion Time    Filename/Handle
        -------------------- ------ ------------------ --------------------
        Backup Set           58     12-APR-07
          Backup Piece       59     12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-01
        Backup Set           74     12-APR-07
          Backup Piece       75     12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-02
        Backup Set           79     12-APR-07
          Backup Piece       80     12-APR-07          D:\DBBAK\08IEVO78_1_1
        Backup Set           88     12-APR-07
          Backup Piece       89     12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-03
        Backup Set           104    12-APR-07
          Backup Piece       105    12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-04

        RMAN> delete obsolete;
        RMAN retention policy will be applied to the command
        RMAN retention policy is set to redundancy 1
        allocated channel: ORA_DISK_1
        channel ORA_DISK_1: sid=12 devtype=DISK
        Deleting the following obsolete backups and copies:

        Type                 Key    Completion Time    Filename/Handle
        -------------------- ------ ------------------ --------------------
        Backup Set           58     12-APR-07
          Backup Piece       59     12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-01
        Backup Set           74     12-APR-07
          Backup Piece       75     12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-02
        Backup Set           79     12-APR-07
          Backup Piece       80     12-APR-07          D:\DBBAK\08IEVO78_1_1
        Backup Set           88     12-APR-07
          Backup Piece       89     12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-03
        Backup Set           104    12-APR-07
          Backup Piece       105    12-APR-07          C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-04

        Do you really want to delete the above objects (enter YES or NO)? yes
        deleted backup piece
        backup piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-02 recid=5 stamp=619699773
        deleted backup piece

        backup piece handle=D:\DBBAK\08IEVO78_1_1 recid=6 stamp=619700457
        deleted backup piece
        backup piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-03 recid=7 stamp=619700482
        deleted backup piece
        backup piece handle=C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-04 recid=9 stamp=619700492
        Deleted 4 objects

        RMAN-06207: WARNING: 1 objects could not be deleted for DISK channel(s) due
        RMAN-06208:          to mismatched status.  Use CROSSCHECK command to fix status
        List of Mismatched objects

        ==========================
          Object Type   Filename/Handle
        --------------- ---------------------------------------------------
        Backup Piece    C:\SOFTWARE\ORACLE\ORA92\DATABASE\C-165830944-20070412-01

        RMAN>

    验证恢复结果
        SQL> connect perfstat/perfstat
        Connected.

        SQL> select * from test2;
        FIELD1         FIELD2
        ---------- ----------
        name1              10
        name2              20
     
        SQL> select * from test1;
        select * from test1
                      *
        ERROR at line 1:
        ORA-00942: table or view does not exist

        SQL> exit
        Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
        With the Partitioning, OLAP and Oracle Data Mining options
        JServer Release 9.2.0.1.0 - Production

    导入test1
        C:\Documents and Settings\jason>imp perfstat/perfstat file=d:\dbbak\test1.dmp log=d:\dbbak\test1_imp.log tables=(test1)
        Import: Release 9.2.0.1.0 - Production on Thu Apr 12 12:07:03 2007
        Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
        Connected to: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
        With the Partitioning, OLAP and Oracle Data Mining options
        JServer Release 9.2.0.1.0 - Production
        Export file created by EXPORT:V09.02.00 via conventional path
        import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
        . importing PERFSTAT's objects into PERFSTAT
        . . importing table                        "TEST1"          0 rows imported
        Import terminated successfully without warnings.

        C:\Documents and Settings\jason>sqlplus /nolog
        SQL*Plus: Release 9.2.0.1.0 - Production on Thu Apr 12 12:07:08 2007
        Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

        SQL> connect perfstat/perfstat
        Connected.

        SQL> select * from test1;
        no rows selected

        SQL>

你可能感兴趣的:(oracle)