oracle 歸檔管理

一、歸檔模式與非歸檔模式區別

非歸檔,聯機日誌文件循環覆蓋,數據庫執行recover時所需要的歸檔不存在,數據庫不能進行完全恢復。

二、更改數據庫的歸檔模式
1 shutdown the database instance
shutdown immediate;
2 start the database mount
startup mount
3 change the database archiving mode
alter database archivelog;
4 open the database
alter database open;

eg:

SQL> select log_mode from v$database;

LOG_MODE

NOARCHIVELOG

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /oracle/crm/disk2/archive
Oldest online log sequence 34
Current log sequence 36
SQL> select dest_name,status,destination from v$archive_dest;

DEST_NAME STATUS DESTINATION


LOG_ARCHIVE_DEST_1 VALID /oracle/archivelog
LOG_ARCHIVE_DEST_2 ALTERNATE /oracle/crm/disk2/archive
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 952020992 bytes
Fixed Size 2232208 bytes
Variable Size 578814064 bytes
Database Buffers 364904448 bytes
Redo Buffers 6070272 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/crm/disk2/archive
Oldest online log sequence 34
Next log sequence to archive 36
Current log sequence 36

三、 調整歸檔的進程數

SQL> alter system set log_archive_max_processes=6;

System altered.

四、設置歸檔目錄
1 參數LOG_ARCHIVE_DEST_n n由1到10用於指定本地或遠程歸檔目錄,n值由11到31僅用於指定遠程歸檔目錄
2 LOG_ARCHIVE_DEST_STATE_n (where n is an integer from 1 to 31)
enable:表示該目錄數據庫可以使用
defer:表示該目錄被臨時禁止
alternate:表示該目錄處於替換狀態,如果主目錄不可用,這該目錄變爲enable。同時需要注意的是alternate不能用於log_archive_dest_11 to log_archive_dest_31

eg
SQL> alter system set log_archive_dest_state_2=defer;

System altered.

SQL> col dest_name for a30
SQL> col status for a15
SQL> col destination for a50
SQL> select dest_name,status,destination from v$archive_dest;

DEST_NAME STATUS DESTINATION


LOG_ARCHIVE_DEST_1 VALID /oracle/archivelog
LOG_ARCHIVE_DEST_2 DEFERRED /oracle/crm/disk2/archive

3 指定歸檔目錄語句
alter system set LOG_ARCHIVE_DEST_1 = 'LOCATION = /disk1/archive'
alter system set LOG_ARCHIVE_DEST_2 = 'LOCATION = /disk2/archive'
alter system set LOG_ARCHIVE_DEST_3 = 'LOCATION = +RECOVERY'

4 指定歸檔名字
alter system set log_archiveformat='arch%t%s%r.arch' scope=spfile;
%t:thread number
%s:log sequence number
%r: the resetlogs ID

5 查詢數據庫當前設置的歸檔目錄
select dest_name,status,destination from v$archive_dest;
DEST_NAME STATUS DESTINATION


LOG_ARCHIVE_DEST_1 VALID /oracle/archivelog
LOG_ARCHIVE_DEST_2 ALTERNATE /oracle/crm/disk2/archive

五、歸檔的備份
1 在rman下備份歸檔

RMAN> backup archivelog from sequence 64 format '/backup/archbk%T%U.bak';

Starting backup at 18-MAY-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=64 RECID=65 STAMP=847887432
input archived log thread=1 sequence=65 RECID=66 STAMP=847887434
input archived log thread=1 sequence=66 RECID=67 STAMP=847887435
input archived log thread=1 sequence=67 RECID=68 STAMP=847887436
input archived log thread=1 sequence=68 RECID=69 STAMP=847887436
input archived log thread=1 sequence=69 RECID=70 STAMP=847887440
input archived log thread=1 sequence=70 RECID=71 STAMP=847887442
input archived log thread=1 sequence=71 RECID=72 STAMP=847887442
input archived log thread=1 sequence=72 RECID=73 STAMP=847887443
input archived log thread=1 sequence=73 RECID=74 STAMP=847887445
input archived log thread=1 sequence=74 RECID=75 STAMP=847887446
input archived log thread=1 sequence=75 RECID=76 STAMP=847887446
input archived log thread=1 sequence=76 RECID=77 STAMP=847887447
input archived log thread=1 sequence=77 RECID=78 STAMP=847887448
input archived log thread=1 sequence=78 RECID=79 STAMP=847887513
input archived log thread=1 sequence=79 RECID=80 STAMP=847888655
channel ORA_DISK_1: starting piece 1 at 18-MAY-14
channel ORA_DISK_1: finished piece 1 at 18-MAY-14
piece handle=/backup/archbk_20140518_0cp8jg8f_1_1.bak tag=TAG20140518T123735 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 18-MAY-14

2 通過plus archivelog 備份歸檔
命令 backup database plus archivelog format '/backup/fullbk%U%T.bak';
該命令執行如下動作
1、 Runs the ALTER SYSTEM ARCHIVE LOG CURRENT statement
2、 Runs BACKUP ARCHIVELOG ALL. If backup optimization is enabled, then RMAN skips logs that it has already backed up to the specified device.

3 、Backs up the rest of the files specified in the BACKUP command

4、Backs up any remaining archived logs generated during the backup. If backup optimization is not enabled, then RMAN backs up the logs generated in Step 1
plus all the logs generated during the backup
/×備份所有剩餘的歸檔以及在備份時新生成的歸檔/

eg
RMAN> backup database plus archivelog format '/backup/fullbk%U%T.bak';

Starting backup at 18-MAY-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=64 RECID=115 STAMP=847890752
input archived log thread=1 sequence=65 RECID=118 STAMP=847890752
input archived log thread=1 sequence=66 RECID=119 STAMP=847890752
input archived log thread=1 sequence=67 RECID=120 STAMP=847890752
input archived log thread=1 sequence=68 RECID=121 STAMP=847890752
input archived log thread=1 sequence=69 RECID=117 STAMP=847890752
input archived log thread=1 sequence=70 RECID=122 STAMP=847890752
input archived log thread=1 sequence=71 RECID=123 STAMP=847890752
input archived log thread=1 sequence=72 RECID=124 STAMP=847890752
input archived log thread=1 sequence=73 RECID=125 STAMP=847890752
input archived log thread=1 sequence=74 RECID=126 STAMP=847890752
input archived log thread=1 sequence=75 RECID=127 STAMP=847890752
input archived log thread=1 sequence=76 RECID=128 STAMP=847890752
input archived log thread=1 sequence=77 RECID=129 STAMP=847890752
input archived log thread=1 sequence=78 RECID=116 STAMP=847890752
input archived log thread=1 sequence=79 RECID=114 STAMP=847890752
input archived log thread=1 sequence=80 RECID=113 STAMP=847889781
input archived log thread=1 sequence=81 RECID=130 STAMP=847898077
input archived log thread=1 sequence=82 RECID=131 STAMP=847898081
input archived log thread=1 sequence=83 RECID=132 STAMP=847898082
input archived log thread=1 sequence=84 RECID=133 STAMP=847898083
input archived log thread=1 sequence=85 RECID=134 STAMP=847898084
input archived log thread=1 sequence=86 RECID=135 STAMP=847898087
input archived log thread=1 sequence=87 RECID=136 STAMP=847898190
input archived log thread=1 sequence=88 RECID=137 STAMP=847898333
input archived log thread=1 sequence=89 RECID=138 STAMP=847898714
input archived log thread=1 sequence=90 RECID=139 STAMP=847899333
input archived log thread=1 sequence=91 RECID=140 STAMP=847900304
input archived log thread=1 sequence=92 RECID=141 STAMP=847900930
channel ORA_DISK_1: starting piece 1 at 18-MAY-14
channel ORA_DISK_1: finished piece 1 at 18-MAY-14
piece handle=/backup/fullbk_0dp8js84_1_1_20140518.bak tag=TAG20140518T160211 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 18-MAY-14

Starting backup at 18-MAY-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/test/system1.dbf
input datafile file number=00003 name=/oracle/test/sysaux01.dbf
input datafile file number=00010 name=/oracle/test/undotbs5.dbf
input datafile file number=00004 name=/oracle/test/users01.dbf
input datafile file number=00013 name=/oracle/test/test2.dbf
channel ORA_DISK_1: starting piece 1 at 18-MAY-14
channel ORA_DISK_1: finished piece 1 at 18-MAY-14
piece handle=/oracle/CRM2/app/product/11.2.0/db1/dbs/0ep8js89_1_1 tag=TAG20140518T160215 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:26
channel ORA_DISK_1: starting full 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 18-MAY-14
channel ORA_DISK_1: finished piece 1 at 18-MAY-14
piece handle=/oracle/CRM2/app/product/11.2.0/db1/dbs/0fp8jseo_1_1 tag=TAG20140518T160215 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 18-MAY-14

Starting backup at 18-MAY-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=93 RECID=142 STAMP=847901149
channel ORA_DISK_1: starting piece 1 at 18-MAY-14
channel ORA_DISK_1: finished piece 1 at 18-MAY-14
piece handle=/backup/fullbk_0gp8jseu_1_1_20140518.bak tag=TAG20140518T160550 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 18-MAY-14

六、 關於archivelog delete input 和delete all input區別
1 rman的歸檔位置定義兩個
log_archive_dest_1 string LOCATION=/oracle/archive
log_archive_dest_2 string LOCATION=/oracle/archive2/
2 執行alter system switch logfile命令後兩個歸檔目錄下的歸檔日誌
[oracle@oracle archive]$ ls -lt
total 2648
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:29 1_38_791488634.dbf
-rw-r----- 1 oracle oinstall 1536 Aug 17 16:29 1_37_791488634.dbf
-rw-r----- 1 oracle oinstall 1536 Aug 17 16:29 1_35_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:29 1_36_791488634.dbf
-rw-r----- 1 oracle oinstall 5120 Aug 17 16:26 1_34_791488634.dbf
-rw-r----- 1 oracle oinstall 59392 Aug 17 16:23 1_33_791488634.dbf

[root@oracle archive2]# ls -lt
total 88
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:29 1_38_791488634.dbf
-rw-r----- 1 oracle oinstall 1536 Aug 17 16:29 1_37_791488634.dbf
-rw-r----- 1 oracle oinstall 1536 Aug 17 16:29 1_35_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:29 1_36_791488634.dbf
-rw-r----- 1 oracle oinstall 5120 Aug 17 16:26 1_34_791488634.dbf
-rw-r----- 1 oracle oinstall 59392 Aug 17 16:23 1_33_791488634.dbf
3 執行
RMAN> backup database plus archivelog delete input; 查看日誌可以發現oracle刪除的歸檔日誌僅僅是其備份過的。
archived log file name=/oracle/archive2/1_33_791488634.dbf RECID=321 STAMP=791569408
archived log file name=/oracle/archive/1_34_791488634.dbf RECID=322 STAMP=791569592
archived log file name=/oracle/archive/1_35_791488634.dbf RECID=324 STAMP=791569775
archived log file name=/oracle/archive2/1_36_791488634.dbf RECID=327 STAMP=791569775
archived log file name=/oracle/archive2/1_37_791488634.dbf RECID=329 STAMP=791569778
archived log file name=/oracle/archive/1_38_791488634.dbf RECID=330 STAMP=791569780
archived log file name=/oracle/archive/1_39_791488634.dbf RECID=332 STAMP=791570012
archived log file name=/oracle/archive/1_40_791488634.dbf RECID=334 STAMP=791570187
注意刪除的歸檔日誌位置隨機有archive2 也有archive。
4 重新切換生成歸檔日誌
[oracle@oracle archive]$ ls -lt
total 2684
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_46_791488634.dbf
-rw-r----- 1 oracle oinstall 1536 Aug 17 16:53 1_44_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_45_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_42_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_43_791488634.dbf
-rw-r----- 1 oracle oinstall 32768 Aug 17 16:53 1_41_791488634.dbf

[root@oracle archive2]# ls -lt
total 92
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_46_791488634.dbf
-rw-r----- 1 oracle oinstall 1536 Aug 17 16:53 1_44_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_45_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_42_791488634.dbf
-rw-r----- 1 oracle oinstall 1024 Aug 17 16:53 1_43_791488634.dbf
-rw-r----- 1 oracle oinstall 32768 Aug 17 16:53 1_41_791488634.dbf
5 執行backup database plus archivelog delete all input ;查看日誌發現oracle刪除的歸檔日誌 發現刪除了兩個目錄下的所有日誌
archived log file name=/oracle/archive2/1_40_791488634.dbf RECID=335 STAMP=791570187
archived log file name=/oracle/archive/1_41_791488634.dbf RECID=336 STAMP=791571221
archived log file name=/oracle/archive2/1_41_791488634.dbf RECID=337 STAMP=791571221
archived log file name=/oracle/archive2/1_42_791488634.dbf RECID=339 STAMP=791571222
archived log file name=/oracle/archive/1_42_791488634.dbf RECID=338 STAMP=791571222
archived log file name=/oracle/archive/1_43_791488634.dbf RECID=340 STAMP=791571222
archived log file name=/oracle/archive2/1_43_791488634.dbf RECID=341 STAMP=791571222
archived log file name=/oracle/archive/1_44_791488634.dbf RECID=342 STAMP=791571228
archived log file name=/oracle/archive2/1_44_791488634.dbf RECID=343 STAMP=791571228
archived log file name=/oracle/archive/1_45_791488634.dbf RECID=344 STAMP=791571228
archived log file name=/oracle/archive2/1_45_791488634.dbf RECID=345 STAMP=791571228
archived log file name=/oracle/archive2/1_46_791488634.dbf RECID=347 STAMP=791571229
archived log file name=/oracle/archive/1_46_791488634.dbf RECID=346 STAMP=791571229
archived log file name=/oracle/archive/1_47_791488634.dbf RECID=348 STAMP=791571526
archived log file name=/oracle/archive2/1_47_791488634.dbf RECID=349 STAMP=791571526
oracle官方文檔提示:
If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN would have only deleted the specific archived redo log files that it backed up. For
example, RMAN would delete the logs in /arc_dest1 if these files were used as the source of the backup, but leave the contents of the /arc_dest2 intact
如果指定delete input ,則rman將僅刪除已備份的歸檔日誌,例如對於有兩個歸檔目錄 /arc_dest1 和 /arc_dest2 如果把/arc_dest1做爲backup的源,delete input將刪除 /arc_dest1 中的內容,保留dest2中的歸檔日誌,通過實驗可以看出,就算有兩個歸檔位置,rman備份的時候貌似是以日誌文件爲源,備份過的日誌刪除。

If you had specified DELETE ALL INPUT RMAN backs up only one copy of each log sequence number in these archiving locations.it deletes all copies of any log that it backed up from the other archiving destinations
如果指定delete all input RMAN對於所有歸檔目錄中的日誌序列號只備份一次,同時rman會刪除dest1 和dest2 中所有歸檔日誌。
結論:對於僅有一個歸檔目錄 delete input 和delet all input 沒啥區別。

六 rman備份恢復對歸檔位置的說明

注意:
1 當需要執行恢復時,rman會自動從備份恢復歸檔日誌,如果歸檔備份的的話。
2 參數 log_archive_format 和 log_archive_dest_n 決定了rman恢復時獲取歸檔的路徑和名字。
eg
SQL> show parameter log_archive_dest_1;

NAME TYPE VALUE


log_archive_dest_1 string LOCATION=/oracle/archive

SQL> show parameter log_archive_format;

NAME TYPE VALUE


log_archiveformat string %t%s_%r.dbf

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 13 - see DBWR trace file
ORA-01110: data file 13: '/oracle/test/test2.dbf'

SQL> select * from v$recoverfile;
FILE# ONLINE ONLINE
ERROR CHANGE# TIME


    13 ONLINE  ONLINE  FILE NOT FOUND                0

[oracle@oracle ~]$ rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Sun May 18 13:10:18 2014

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

connected to target database: CRM (DBID=3601019238, not open)

RMAN> run{
2> restore datafile 13;
3> recover datafile 13;
4> sql'alter database open';
5> }

Starting restore at 18-MAY-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=85 device type=DISK

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 00013 to /oracle/test/test2.dbf
channel ORA_DISK_1: reading from backup piece /backup/fullbk_20140518_09p8jeov_1_1.bk
channel ORA_DISK_1: piece handle=/backup/fullbk_20140518_09p8jeov_1_1.bk tag=TAG20140518T121214
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 18-MAY-14

Starting recover at 18-MAY-14
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 80 is already on disk as file /oracle/archive/1_80_839187351.dbf
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=64
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=65
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=66
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=67
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=68
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=69
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=70
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=71
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=72
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=73
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=74
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=75
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=76
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=77
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=78
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=79
channel ORA_DISK_1: reading from backup piece /backup/archbk_20140518_0cp8jg8f_1_1.bak
channel ORA_DISK_1: piece handle=/backup/archbk_20140518_0cp8jg8f_1_1.bak tag=TAG20140518T123735
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/oracle/archive/1_64_839187351.dbf thread=1 sequence=64
archived log file name=/oracle/archive/1_65_839187351.dbf thread=1 sequence=65
archived log file name=/oracle/archive/1_66_839187351.dbf thread=1 sequence=66
archived log file name=/oracle/archive/1_67_839187351.dbf thread=1 sequence=67
archived log file name=/oracle/archive/1_68_839187351.dbf thread=1 sequence=68
archived log file name=/oracle/archive/1_69_839187351.dbf thread=1 sequence=69
archived log file name=/oracle/archive/1_70_839187351.dbf thread=1 sequence=70
archived log file name=/oracle/archive/1_71_839187351.dbf thread=1 sequence=71
archived log file name=/oracle/archive/1_72_839187351.dbf thread=1 sequence=72
archived log file name=/oracle/archive/1_73_839187351.dbf thread=1 sequence=73
archived log file name=/oracle/archive/1_74_839187351.dbf thread=1 sequence=74
archived log file name=/oracle/archive/1_75_839187351.dbf thread=1 sequence=75
media recovery complete, elapsed time: 00:00:01
Finished recover at 18-MAY-14

sql statement: alter database open

RMAN> exit

Recovery Manager complete.
[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sun May 18 13:13:11 2014

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from v$recover_file;

no rows selected

SQL> select open_mode from v$database;

OPEN_MODE

READ WRITE

1 從歸檔備份恢復歸檔到新的位置
run{
set archivelog destination to '/oracle/archive/test/';
restore archivelog from sequence 64;
}
eg

RMAN> run{
2> set archivelog destination to '/oracle/archive/test/';
3> restore archivelog from sequence 64;
4> }

executing command: SET ARCHIVELOG DESTINATION

Starting restore at 18-MAY-14
using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log restore to user-specified destination
archived log destination=/oracle/archive/test/
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=64
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=65
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=66
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=67
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=68
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=69
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=70
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=71
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=72
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=73
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=74
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=75
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=76
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=77
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=78
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=79
channel ORA_DISK_1: reading from backup piece /backup/archbk_20140518_0cp8jg8f_1_1.bak
channel ORA_DISK_1: piece handle=/backup/archbk_20140518_0cp8jg8f_1_1.bak tag=TAG20140518T123735
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 18-MAY-14

2 調用新位置的歸檔進行數據庫恢復
run{
set archivelog destination to '/oracle/archive/test/';
restore datafile 13;
recover datafile 13;
sql'alter database open';
}
eg
SQL> startup
ORACLE instance started.

Total System Global Area 1043886080 bytes
Fixed Size 2233088 bytes
Variable Size 327159040 bytes
Database Buffers 708837376 bytes
Redo Buffers 5656576 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 13 - see DBWR trace file
ORA-01110: data file 13: '/oracle/test/test2.dbf'

SQL> select * from v$recover_file;

 FILE# ONLINE  ONLINE_ ERROR                       CHANGE# TIME

    13 ONLINE  ONLINE  FILE NOT FOUND                0

QL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@oracle ~]$ rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Sun May 18 12:56:03 2014

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

connected to target database: CRM (DBID=3601019238, not open)

RMAN> run{
2> set archivelog destination to '/oracle/archive/test/';
3> restore datafile 13;
4> recover datafile 13;
5> sql'alter database open';
6> }

executing command: SET ARCHIVELOG DESTINATION
using target database control file instead of recovery catalog

Starting restore at 18-MAY-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=85 device type=DISK

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 00013 to /oracle/test/test2.dbf
channel ORA_DISK_1: reading from backup piece /backup/fullbk_20140518_09p8jeov_1_1.bk
channel ORA_DISK_1: piece handle=/backup/fullbk_20140518_09p8jeov_1_1.bk tag=TAG20140518T121214
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 18-MAY-14

Starting recover at 18-MAY-14
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 64 is already on disk as file /oracle/archive/test/1_64_839187351.dbf
archived log for thread 1 with sequence 65 is already on disk as file /oracle/archive/test/1_65_839187351.dbf
archived log for thread 1 with sequence 66 is already on disk as file /oracle/archive/test/1_66_839187351.dbf
archived log for thread 1 with sequence 67 is already on disk as file /oracle/archive/test/1_67_839187351.dbf
archived log for thread 1 with sequence 68 is already on disk as file /oracle/archive/test/1_68_839187351.dbf
archived log for thread 1 with sequence 69 is already on disk as file /oracle/archive/test/1_69_839187351.dbf
archived log for thread 1 with sequence 70 is already on disk as file /oracle/archive/test/1_70_839187351.dbf
archived log for thread 1 with sequence 71 is already on disk as file /oracle/archive/test/1_71_839187351.dbf
archived log for thread 1 with sequence 72 is already on disk as file /oracle/archive/test/1_72_839187351.dbf
archived log for thread 1 with sequence 73 is already on disk as file /oracle/archive/test/1_73_839187351.dbf
archived log for thread 1 with sequence 74 is already on disk as file /oracle/archive/test/1_74_839187351.dbf
archived log for thread 1 with sequence 75 is already on disk as file /oracle/archive/test/1_75_839187351.dbf
archived log for thread 1 with sequence 76 is already on disk as file /oracle/archive/test/1_76_839187351.dbf
archived log for thread 1 with sequence 77 is already on disk as file /oracle/archive/test/1_77_839187351.dbf
archived log for thread 1 with sequence 78 is already on disk as file /oracle/archive/test/1_78_839187351.dbf
archived log for thread 1 with sequence 79 is already on disk as file /oracle/archive/test/1_79_839187351.dbf
archived log file name=/oracle/archive/test/1_64_839187351.dbf thread=1 sequence=64
archived log file name=/oracle/archive/test/1_65_839187351.dbf thread=1 sequence=65
archived log file name=/oracle/archive/test/1_66_839187351.dbf thread=1 sequence=66
archived log file name=/oracle/archive/test/1_67_839187351.dbf thread=1 sequence=67
archived log file name=/oracle/archive/test/1_68_839187351.dbf thread=1 sequence=68
archived log file name=/oracle/archive/test/1_69_839187351.dbf thread=1 sequence=69
archived log file name=/oracle/archive/test/1_70_839187351.dbf thread=1 sequence=70
archived log file name=/oracle/archive/test/1_71_839187351.dbf thread=1 sequence=71
archived log file name=/oracle/archive/test/1_72_839187351.dbf thread=1 sequence=72
archived log file name=/oracle/archive/test/1_73_839187351.dbf thread=1 sequence=73
archived log file name=/oracle/archive/test/1_74_839187351.dbf thread=1 sequence=74
media recovery complete, elapsed time: 00:00:01
Finished recover at 18-MAY-14

sql statement: alter database open

RMAN> exit

Recovery Manager complete.
[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sun May 18 12:57:06 2014

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from v$recover_file;

no rows selected

八、 刪除歸檔
1 如何正確的刪除歸檔
刪除數據庫歸檔前,應該對數據庫做一次全備份,爲何這樣說呢,舉個簡單的例子 當前oracle有6組日誌組,seq號分別是 33、34、35、36、37、38,當前日誌組seq號是38,
歸檔日誌seq號從1到37,此時我們對數據庫做全備份,當數據庫需要進行恢復時,restore後數據文件頭部的rba seq號爲38,之後執行recover這個動作數據庫會從seq號爲38號的歸檔或者聯機日誌開始。seq號爲38之前的歸檔,恢復時已經不需要了。這也就是我們爲啥說對數據庫做一次全備份後
即可刪除所有歸檔的原因。

2 如何正確的在操作系統上刪除歸檔
需要明確的一點就是,通過操作系統命令刪除歸檔,rman資料庫裏面記錄該歸檔的狀態爲A即爲avaliable,這樣就造成了rman資料庫歸檔條目狀態不一致性,因此當
我們在操作系統上刪除了歸檔後,還應該發起一個crosscheck archivelog all 命令,用於校驗rman資料庫中的每一條歸檔記錄在數據庫上是否存在,如果不存在則更改
改歸檔條目的記錄狀態爲expired。之後我們便可用命令delete noprompt expired archivelog all 刪除rman資料庫中所有標記爲EXPIRED狀態的條目。
eg 命令如下:
rm -rf ×
rman target /
crosscheck archivelog all;
delete noprompt expired archivelog all;

3 在rman下如何刪除歸檔
刪除系統內的所有歸檔:delete noprompt archivelog all
刪除7天內以外的所有歸檔:delete noprompt archivelog all completed before 'SYSDATE - 7';

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章