NOARCHIVELOG 模式下使用增量備份恢復資料庫

skyin_1603發表於2016-11-08

----使用增量備份恢復處於NOARCHIVELOG 模式的資料庫

---撤銷資料庫archivelog模式

sys@PROD>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

sys@PROD>

sys@PROD>startup mount;

ORACLE instance started.

Total System Global Area  835104768 bytes

Fixed Size                  2257840 bytes

Variable Size             507513936 bytes

Database Buffers          322961408 bytes

Redo Buffers                2371584 bytes

Database mounted.

sys@PROD>alter database noarchivelog;

Database altered.

 

--檢視資料庫的歸檔模式

sys@PROD>archive log list;

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     1

Current log sequence           1

sys@PROD>
  

---建立測試表:

sys@PROD>alter database open;

Database altered.

--插入第一條資料:

sys@PROD>create table t(x int) tablespace users;

Table created.

 

---noarchivelog模式下,0級備份

run{

shutdown immediate;

startup mount;

backup as backupset incremental level 0 database;

alter database open;

}

#這是草稿# 

[oracle@enmo ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 17:57:54 2016

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

connected to target database: PROD (DBID=338469376)

 

RMAN> run{

2> shutdown immediate;

3> startup mount;

4> backup as backupset incremental level 0 database;

5> alter database open;

6> }

using target database control file instead of recovery catalog

database closed

database dismounted

Oracle instance shut down

connected to target database (not started)

Oracle instance started

database mounted

Total System Global Area     835104768 bytes

Fixed Size                     2257840 bytes

Variable Size                507513936 bytes

Database Buffers             322961408 bytes

Redo Buffers                   2371584 bytes

 

Starting backup at 07-NOV-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=18 device type=DISK

channel ORA_DISK_1: starting incremental level 0 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/ts_xxf_01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf

input datafile file number=00007 name=/u01/app/oracle/oradata/PROD/ts_ctl01.dbf

channel ORA_DISK_1: starting piece 1 at 07-NOV-16

channel ORA_DISK_1: finished piece 1 at 07-NOV-16

piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd0_TAG20161107T175851_d20n2vry_.bkp tag=TAG20161107T175851 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:03:52

channel ORA_DISK_1: starting incremental level 0 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 07-NOV-16

channel ORA_DISK_1: finished piece 1 at 07-NOV-16

piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn0_TAG20161107T175851_d20nb469_.bkp tag=TAG20161107T175851 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 07-NOV-16

 

--插入第二條資料:

sys@PROD>conn / as sysdba

Connected.

sys@PROD>

sys@PROD>insert into t values(2);

1 row created.

 

sys@PROD>commit;

Commit complete.

--noarchivelog模式下,1級備份

[oracle@enmo ~]$ rman target / 

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 7 18:06:37 2016 

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

connected to target database: PROD (DBID=338469376)

 

RMAN> run{

2> shutdown immediate;

3> startup mount;

4> backup as backupset incremental level 1 database;

5> alter database open;

6> } 

using target database control file instead of recovery catalog

database closed

database dismounted

Oracle instance shut down

 

connected to target database (not started)

Oracle instance started

database mounted

Total System Global Area     835104768 bytes 

Fixed Size                     2257840 bytes

Variable Size                507513936 bytes

Database Buffers             322961408 bytes

Redo Buffers                   2371584 bytes

 

Starting backup at 07-NOV-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=18 device type=DISK

channel ORA_DISK_1: starting incremental level 1 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/ts_xxf_01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf

input datafile file number=00007 name=/u01/app/oracle/oradata/PROD/ts_ctl01.dbf

channel ORA_DISK_1: starting piece 1 at 07-NOV-16

channel ORA_DISK_1: finished piece 1 at 07-NOV-16

piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd1_TAG20161107T180734_d20nm6l6_.bkp tag=TAG20161107T180734 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55

channel ORA_DISK_1: starting incremental level 1 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 07-NOV-16

channel ORA_DISK_1: finished piece 1 at 07-NOV-16

piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp tag=TAG20161107T180734 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 07-NOV-16

database opened

#1級增量備份完成。

 

---刪除所有控制檔案、日誌檔案、資料檔案、引數檔案

--刪除控制檔案:

sys@PROD>!rm /u01/app/oracle/oradata/PROD/control01.ctl

sys@PROD>!rm /u01/app/oracle/fast_recovery_area/PROD/control02.ctl

--刪除日誌檔案與資料檔案:

[oracle@enmo ~]$ cd /u01/app/oracle/oradata/PROD/

[oracle@enmo PROD]$ ls

example01.dbf  redo02.log  sysaux01.dbf  temp01.dbf    ts_xxf_01.dbf  users01.dbf

redo01.log     redo03.log  system01.dbf  ts_ctl01.dbf  undotbs01.dbf

[oracle@enmo PROD]$ rm *

--刪除引數檔案:

[oracle@enmo ~]$ cd $ORACLE_HOME/dbs

[oracle@enmo dbs]$ ls

hc_PROD.dat  init.ora  lkPROD  orapwPROD  PROD.ora.bck  snapcf_PROD.f  spfilePROD.ora

[oracle@enmo dbs]$

[oracle@enmo dbs]$ rm PROD.ora.bck

[oracle@enmo dbs]$ cp spfilePROD.ora  PROD.ora.bck

[oracle@enmo dbs]$ rm spfilePROD.ora

[oracle@enmo dbs]$ ls

hc_PROD.dat  init.ora  lkPROD  orapwPROD  PROD.ora.bck  snapcf_PROD.f

[oracle@enmo dbs]$

 

---執行恢復:

--強制開啟到nomount狀態:

RMAN> startup force nomount;

startup failed: ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initPROD.ora'

starting Oracle instance without parameter file for retrieval of spfile

Oracle instance started 

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes

Variable Size                281019272 bytes

Database Buffers             780140544 bytes

Redo Buffers                   5517312 bytes

--恢復引數檔案:

RMAN> restore spfile from

"/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp";


Starting restore at 07-NOV-16

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp

channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete

Finished restore at 07-NOV-16

[oracle@enmo dbs]$ ls spfile*

spfilePROD.ora

[oracle@enmo dbs]$

#引數恢復完成。

--恢復控制檔案:

--完成引數檔案的恢復,利用恢復的引數檔案啟動到nomount模式:

RMAN> shutdown abort;

Oracle instance shut down

RMAN>

--再次啟動nomount狀態:

RMAN> startup nomount;

connected to target database (not started)

Oracle instance started

 

Total System Global Area     835104768 bytes

Fixed Size                     2257840 bytes

Variable Size                507513936 bytes

Database Buffers             322961408 bytes

Redo Buffers                   2371584 bytes

restore controlfile from "/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp";


--
恢復控制檔案:

RMAN> restore controlfile from "/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_ncsn1_TAG20161107T180734_d20npwpw_.bkp";

Starting restore at 07-NOV-16

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 device type=DISK 

channel ORA_DISK_1: restoring control file

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

output file name=/u01/app/oracle/oradata/PROD/control01.ctl

output file name=/u01/app/oracle/fast_recovery_area/PROD/control02.ctl

Finished restore at 07-NOV-16

#以上的引數檔案與控制檔案都是從最新的自動備份檔案恢復。

 

---控制檔案恢復完成,資料庫啟動到mount模式:

RMAN> alter database mount;

database mounted

released channel: ORA_DISK_1

---執行全庫的還原:

RMAN> restore database;

Starting restore at 07-NOV-16

using channel ORA_DISK_1

 

channel ORA_DISK_1: starting datafile backup set restore

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

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/PROD/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD/example01.dbf

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD/ts_xxf_01.dbf

channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/PROD/ts_ctl01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd0_TAG20161107T175851_d20n2vry_.bkp

channel ORA_DISK_1: piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd0_TAG20161107T175851_d20n2vry_.bkp tag=TAG20161107T175851

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:03:05

Finished restore at 07-NOV-16

 

---恢復資料庫,由於是非歸檔模式所以使用無日誌恢復方式:

RMAN> recover database noredo; 

Starting recover at 07-NOV-16

using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backup set restore

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

destination for restore of datafile 00001: /u01/app/oracle/oradata/PROD/system01.dbf

destination for restore of datafile 00002: /u01/app/oracle/oradata/PROD/sysaux01.dbf

destination for restore of datafile 00003: /u01/app/oracle/oradata/PROD/undotbs01.dbf

destination for restore of datafile 00004: /u01/app/oracle/oradata/PROD/users01.dbf

destination for restore of datafile 00005: /u01/app/oracle/oradata/PROD/example01.dbf

destination for restore of datafile 00006: /u01/app/oracle/oradata/PROD/ts_xxf_01.dbf

destination for restore of datafile 00007: /u01/app/oracle/oradata/PROD/ts_ctl01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd1_TAG20161107T180734_d20nm6l6_.bkp

channel ORA_DISK_1: piece handle=/u01/app/FRA/PROD/backupset/2016_11_07/o1_mf_nnnd1_TAG20161107T180734_d20nm6l6_.bkp tag=TAG20161107T180734

channel ORA_DISK_1: restored backup piece 1

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

 

Finished recover at 07-NOV-16

  

---恢復完成,resetlogs方式開啟資料庫,完成所有檔案丟失的恢復:

RMAN> alter database open resetlogs;

database opened

#已完成恢復併成功開啟資料庫。


---恢復後,檢視t表的資料是否丟失:

sys@PROD>select * from t;

         X

----------

         1

         2

#非歸檔模式下恢復成功,使用兩個兩級(0級備份與1級增量備份)的備份完成了完全恢復。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2128011/,如需轉載,請註明出處,否則將追究法律責任。

相關文章