1. 程式人生 > >Oracle RMAN 學習

Oracle RMAN 學習

 

Oracle RMAN 學習:三思筆記

1 進入rman

 

Rman--物理備份結構/資料

1 本地db

Cmd

set oracle_sid=orcl

1 rman target /

Rman>

      2 也可以先直接進入rman

    然後>connect  target /

     2 遠端db(有效的service_name,本地的tns中有該service的正確配置)

      Cmd

      Rman target sys/xxxxx@orcl111

     3 退出rman

     直接exit

     在啟用rman時,可以指定日誌輸出

     Rman target / log f:\mydb\rman_log.txt

2 熟悉rman操作

  Rman的備份跟恢復,db都必須啟動例項並載入資料庫

 Nomount---mount---open

 Oracle如果是db處於open狀態open read write),則db要處於歸檔狀態,否則在備份操作的時候有可能出現ora—19602錯誤

1 啟動和關閉資料庫

  Rman target /

 Rman>shutdown immediate;

 Rman>startup;

 啟動關閉命令跟sqlplus環境下 相同

2 執行作業系統命令

  Rman支援在rman命令下使用host命令暫時退出rman

 Rman>host;

執行完作業系統命令後,可以通過exit命令切換到rman提示符

3 執行sql語句

  rman提示符下,

RMAN

[ TARGET connectStringSpec

| { CATALOG connectStringSpec }

| LOG ['] filename ['] [ APPEND ]

.

.

.

]...

connectStringSpec::=

['] [userid] [/ [password]] [@net_service_name] [']

 

 Rman> sql ‘select sysdate from dual’ 此時執行不會有結果輸出

 Rman>sql ‘alter system archive log all’

 可以通過host命令切換到作業系統,然後conn / as sysdba等進行操作,然後exit到rman

Linux下:

Last login: Wed Oct 23 09:47:15 2013 from 192.168.2.187

[[email protected] ~]# su - oracle

[[email protected] ~]$ rman target/

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 24 09:51:20 2013

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

connected to target database: GRS (DBID=325518186)

RMAN> host;

[[email protected] ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 24 09:51:51 2013

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

SQL> conn /as sysdba

Connected.

SQL> select sysdate from dual;

SYSDATE

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

24-OCT-13

SQL> exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

[[email protected] ~]$ exit

exit

host command complete

RMAN>

12c rman

RMAN> select sysdate from dual;

 

SYSDATE            

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

2015-08-05 00:03:27

 

4 rman備份型別

  1 映象複製:copy,將一一系列檔案copy

  2備份集:優勢(備份時只讀取資料庫中已使用的資料塊)

5 rman命令執行方式

 1 單個執行命令

   Rman>backup database;

 2 批處理方式

  Rman>run{

      ………..},將多個單個命令組合到一起,其中任何一個命令失敗都將停止(後面的命令不在執行),有些特殊命令不能放到批處理中(list ,report。)

   3 執行指令碼

     A 用命令方式呼叫os中儲存的指令碼

     Rman target / @backup_db.rman

     或者 rman target / cmdfile=backup_db.rman

     B rman中執行指令碼

Rman> @backup_db.rman

 C 執行儲存在catalog中的指令碼(首先為rman建立恢復目錄)

 Rman> run {execute script backup_db};

3 rman 初級演練

1 整個庫的備份

  Rman>backup database;--對所有資料檔案進行備份,

  Rman>backup database format ‘f:\mydb\backup\back_db%u’;

   此時沒歸檔,報錯ora-19602,改為archived模式,正常執行

  alter system set log_archive_dest_1='location= /data/u02/app/frarea';

  shutdown immediate;

  startup mount;

  alter database archivelog;

  alter database open;

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

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

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

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

 

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/24/2013 10:34:34

ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

   可以用list backup of database;來檢視全部備份的檔案

     RMAN> backup database format '/u01/oracle/backup/back_%U';

Starting backup at 24-OCT-13

using channel ORA_DISK_1

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/24/2013 10:56:39

ORA-01013: user requested cancel of current operation

continuing other job steps, job failed will not be re-run

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/oracle/backup/back_04on6v77_1_1 tag=TAG20131024T105639 comment=NONE

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

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

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

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

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/24/2013 10:56:39

ORA-01013: user requested cancel of current operation

RMAN> exit

Recovery Manager complete.

[[email protected] ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 24 10:57:04 2013

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

connected to target database: GRS (DBID=325518186)

RMAN> list backup of database;

using target database control file instead of recovery catalog

RMAN> backup database format '/u01/oracle/backup/back_%U';

Starting backup at 24-OCT-13

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=/u01/app/oracle/oradata/grs/system01.dbf

input datafile fno=00007 name=/u01/app/oracle/oradata/grs/cmask01.dbf

input datafile fno=00003 name=/u01/app/oracle/oradata/grs/sysaux01.dbf

input datafile fno=00005 name=/u01/app/oracle/oradata/grs/example01.dbf

input datafile fno=00006 name=/u01/app/oracle/oradata/grs/yyhhqq.dbf

input datafile fno=00002 name=/u01/app/oracle/oradata/grs/undotbs01.dbf

input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/oracle/backup/back_05on6v94_1_1 tag=TAG20131024T105740 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:02:37

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/oracle/backup/back_06on6ve1_1_1 tag=TAG20131024T105740 comment=NONE

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

Finished backup at 24-OCT-13

RMAN> list backup of database;

List of Backup Sets

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

3       Full    645.97M    DISK        00:02:35     24-OCT-13      

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

        Piece Name: /u01/oracle/backup/back_05on6v94_1_1

  List of Datafiles in backup set 3

  File LV Type Ckp SCN    Ckp Time  Name

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

  1       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/system01.dbf

  2       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/undotbs01.dbf

  3       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/sysaux01.dbf

  4       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/users01.dbf

  5       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/example01.dbf

  6       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf

  7       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/cmask01.dbf

RMAN>

2 表空間的備份

  只要db處於mount狀態,不論是否開啟,都可以進行rman 備份表空間

Rman> backup tablespace users;

  -----backup tablespace users format 'f:\mydb\backup\backup_tp_users';

  List backup of tablespace users; list backup檢視一下備份

  刪除備份:delete backupset 4(bs key)

RMAN> backup tablespace yyhhqq;-------沒有指定詳細路徑

Starting backup at 24-OCT-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00006 name=/u01/app/oracle/oradata/grs/yyhhqq.dbf

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T110255_96k3h019_.bkp tag=TAG20131024T110255 comment=NONE

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

Finished backup at 24-OCT-13

RMAN> list backup of tablespace yyhhqq;

List of Backup Sets

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

3       Full    645.97M    DISK        00:02:35     24-OCT-13      

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

        Piece Name: /u01/oracle/backup/back_05on6v94_1_1

  List of Datafiles in backup set 3

  File LV Type Ckp SCN    Ckp Time  Name

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

  6       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

5       Full    712.00K    DISK        00:00:09     24-OCT-13      

        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: TAG20131024T110255

        Piece Name: /u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T110255_96k3h019_.bkp

  List of Datafiles in backup set 5

  File LV Type Ckp SCN    Ckp Time  Name

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

  6       Full 988697     24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf

RMAN> backup tablespace yyhhqq;

3資料檔案的備份

2 種方式指定資料檔案(詳細路徑)和file_id,都可以從檢視dba_data_files中得到

select file_id,file_name from dba_data_files

4 /u01/app/oracle/oradata/grs/users01.dbf

3 /u01/app/oracle/oradata/grs/sysaux01.dbf

       在整庫備份和list時都會出現file_id和資料檔案的名稱

RMAN>  backup datafile '/u01/app/oracle/oradata/grs/users01.dbf' format '/u01/oracle/backup/backup_datafile_%U';

RMAN> backup datafile 6 format '/u01/oracle/backup/backup_data6_%p_%I_%t;

Piece Name: /u01/oracle/backup/backup_data6_1_325518186_830601460;

Starting backup at 24-OCT-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/oracle/backup/backup_datafile_09on7bsd_1_1 tag=TAG20131024T143245 comment=NONE

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

Finished backup at 24-OCT-13

  可以用file_id代替  backup datafile 6,7,8

RMAN> list backup of datafile 4;

List of Backup Sets

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

3       Full    645.97M    DISK        00:02:35     24-OCT-13      

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

        Piece Name: /u01/oracle/backup/back_05on6v94_1_1

  List of Datafiles in backup set 3

  File LV Type Ckp SCN    Ckp Time  Name

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

  4       Full 988527     24-OCT-13 /u01/app/oracle/oradata/grs/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

6       Full    8.94M      DISK        00:00:02     24-OCT-13      

        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20131024T143245

        Piece Name: /u01/oracle/backup/backup_datafile_09on7bsd_1_1

  List of Datafiles in backup set 6

  File LV Type Ckp SCN    Ckp Time  Name

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

  4       Full 995093     24-OCT-13 /u01/app/oracle/oradata/grs/users01.dbf

4控制檔案的備份

Rman>backup current controlfile;

backup current controlfile

      執行backup命令時指定include current controlfile

      Rman>backup database include current controlfile

      通過指定configure命令將controlfile autobackup置為on

Rman>configure controlfile autobackup on/off;  rman做任何備份操作都會備份控制檔案

 List backup of controlfile

RMAN>   backup current controlfile format '/u01/oracle/backup/backup_control_file';

Starting backup at 24-OCT-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/oracle/backup/backup_control_file tag=TAG20131024T144627 comment=NONE

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

Finished backup at 24-OCT-13

RMAN> list backup of controlfile;

List of Backup Sets

RMAN> configure controlfile autobackup on;----任何backup都會備份控制檔案

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

The RMAN BACKUP CURRENT CONTROLFILE command makes a binary backup of

the control file, as either a backup set or an image copy.

The SQL statement ALTER DATABASE BACKUP CONTROLFILE makes a binary

backup of the control file.

The SQL statement ALTER DATABASE BACKUP CONTROLFILE TO TRACE exports

the control file contents to a SQL script file. You can use the script to create a new

control file. Trace file backups have one major disadvantage: they contain no

records of archived redo logs, and RMAN backups and copies. For this reason,

binary backups are preferable.

使用alter database backup controlfile備份控制檔案

      SQL> alter database backup controlfile to trace;

       或者

 SQL> alter database backup controlfile to trace as '/data/controlfile1.cof';   (這樣你可以檢視controlfile的構成)

5歸檔檔案的備份

1  RMAN> backup archivelog all;

Starting backup at 24-OCT-13

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archive log backupset

channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=20 recid=1 stamp=829666475

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T145435_96kk1gpx_.bkp tag=TAG20131024T145435 comment=NONE

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

Finished backup at 24-OCT-13

Starting Control File and SPFILE Autobackup at 24-OCT-13

piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829666480_96kk1jj2_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 24-OCT-13

Backup archivelog命令比較靈活,all是指備份當前所有可訪問到的歸檔資料夾,

還可以通過until,scn,time,sequence等引數靈活指定備份的歸檔區間。

       2 執行backup時指定plus archivelog字句

      Rman>backup current controlfile plus archivelog

      在備份控制檔案之前先對歸檔檔案進行備份,

   Backup 。。。 plus archivelog,命令執行以下步驟

       A 執行alter system archive log current語句對當前redolog進行歸檔

       B 執行backup archivlelog all命令 備份所有歸檔檔案

       C 執行backup命令對指定項進行備份

       D 再次執行alter system archive log current對redolog進行歸檔

       E 對新生成的尚未備份的歸檔檔案進行備份

   完成了歸檔日誌的備份後,我們需要刪除過期的歸檔檔案的備份,

Rman,提供了delete all input引數,加在backup命令後,則會完成備份後自動刪除歸檔目錄中已備份的歸檔日誌,

RMAN> delete archivelog all like '/backup/archivelog1/%' backed up 1 times to device type disk;

  Rman>list backup of archivelog all;

--delete noprompt archivelog all completed before 'sysdate';   --->該命令清除所有的歸檔日誌

delete noprompt archivelog all;                              --->同上一命令

6初始化引數檔案的備份

通常在備份控制檔案時,rman會自動備份伺服器端的初始化引數檔案,並置於控制檔案相同的備份片中,/u01/app/oracle/product/10.2.0/db_1/dbs/spfilegrs.ora

Rman>backup spfile;單獨備份引數檔案

RMAN>  backup spfile format '/u01/oracle/backup/backup_spfile';

 

Starting backup at 24-OCT-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/oracle/backup/backup_spfile tag=TAG20131024T145840 comment=NONE

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

Finished backup at 24-OCT-13

 

Starting Control File and SPFILE Autobackup at 24-OCT-13

piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829666721_96kk91h7_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 24-OCT-13

 

RMAN> backup spfile format '/u01/oracle/backup

2> ';

 

Starting backup at 14-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK

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

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

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

RMAN-03002: failure of backup command at 03/14/2014 16:14:29

RMAN-06062: can not backup SPFILE because the instance was not started with SPFILE

7對備份集進行備份

備份所有備份集

Rman>backup backupset all;

指定備份備份集

Rman>backup backupset n1,n2..;也可以新增delete input引數

4 rman命令

1 顯示rman預設配置show

RMAN> show all;

 

RMAN configuration parameters are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

CONFIGURE BACKUP OPTIMIZATION OFF; # default

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_grs.f'; # default

配置項後面加了#default,表示該配置項沒有修改過,

Rman>show configure archivlelog deletion policy to none;

2 列出備份資訊list

 LIST BACKUP OF DATABASE BY BACKUP

 LIST BACKUP BY FILE

 LIST BACKUP SUMMARY

   LIST EXPIRED COPY

   LIST BACKUP RECOVERABLE

LIST FAILURE;

 ADVISE FAILURE;

REPAIR FAILURE;

 

RMAN> list backup;

List of Backup Sets

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

BS Key  Size       Device Type Elapsed Time Completion Time

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

1       176.85M    DISK        00:02:21     10-NOV-14      

        BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag: TAG20141110T165750

        Piece Name: /home/oracle/oracle_rman/rman_backup_01pn9a8g_1_1

 

  List of Archived Logs in backup set 1

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    3       480534     29-OCT-14 521206     30-OCT-14

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

2       Full    135.77M    DISK        00:04:17     10-NOV-14      

        BP Key: 2   Status: AVAILABLE  Compressed: YES  Tag: TAG20141110T170021

        Piece Name: /home/oracle/oracle_rman/rman_backup_02pn9ad5_1_1

  List of Datafiles in backup set 2

  File LV Type Ckp SCN    Ckp Time  Name

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

  1       Full 16926112   10-NOV-14 /u01/app/oracle/grs/system01.dbf

  2       Full 16926112   10-NOV-14 /u01/app/oracle/grs/undotbs01.dbf

  3       Full 16926112   10-NOV-14 /u01/app/oracle/grs/sysaux01.dbf

  4       Full 16926112   10-NOV-14 /u01/app/oracle/grs/users01.dbf

  5       Full 16926112   10-NOV-14 /u01/app/oracle/grs/example01.dbf

  6       Full 16926112   10-NOV-14 /u01/app/oracle/grs/grsv501.dbf

 

BS Key  Size       Device Type Elapsed Time Completion Time

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

3       1.11M      DISK        00:00:01     10-NOV-14      

        BP Key: 3   Status: AVAILABLE  Compressed: YES  Tag: TAG20141110T170448

        Piece Name: /home/oracle/oracle_rman/rman_backup_03pn9alg_1_1

  List of Archived Logs in backup set 3

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

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

  1    17      16926056   10-NOV-14 16926311   10-NOV-14

 

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

4       Full    6.80M      DISK        00:00:01     10-NOV-14      

        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20141110T170450

        Piece Name: /home/oracle/oracle_rman/rman_backup_c-360277547-20141110-00

  Control File Included: Ckp SCN: 16926317     Ckp time: 10-NOV-14

  SPFILE Included: Modification time: 07-NOV-14

 

 

List命令檢視rman生成的備份集,備份映象,歸檔檔案等

  List backup ;所有備份資訊

  List backup of controlfile;—所有控制檔案的備份資訊

List backup of datafile ‘f:\mydb\backup\......dbf’;

List backup of datafile 5;

List backup of archivelog all;---所有備份的歸檔檔案的資訊

List copy of tablespace ‘system’;----列出指定表空間的資訊

List device type disk backup;列出某個裝置上的所有資訊

List archivelog all;列出db當前所有歸檔

List expired backup;列出無效備份(---無效備份怎麼定義的??)

List backup summary

RMAN> list copy of database archivelog all

RMAN> list expired backup;

3 刪除備份delete

  用於刪除rman備份記錄以及相關物理檔案(有時候並不是刪除,而是打上標記),當使用rman執行備份操作時,會在rman資料庫中生成rman備份記錄,預設情況下rman備份記錄會被存放在目標資料庫的控制檔案中,如果配置了恢復目錄(recovery catalog),那麼該備份集也會存放到該恢復目錄中

  Delete obsolete;刪除過期備份----rman會根據冗餘策略確定備份是否過期

RMAN> delete obsolete;

Delete obsolete命令

     Note:1 如果被判斷為廢棄的備份是一個單獨資料檔案的映象複製,在delete時直接刪除

           2 如果是備份集中的一部分,則必須等整個備份集都廢棄了,才能刪除

RMAN retention policy will be applied to the command

RMAN retention policy is set to redundancy 1

using channel ORA_DISK_1

Deleting the following obsolete backups and copies:

Type                 Key    Completion Time    Filename/Handle

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

Backup Set           1      24-OCT-13    

  Delete expired backup;刪除無效備份,用此命令刪除無效的備份,

 首先執行crosscheck命令核對備份集,如果發現無效(比如備份對應的資料檔案損壞或丟失),rman會將該備份集標記為expired狀態,

RMAN> delete expired backup;

using channel ORA_DISK_1

  Delete expired copy;刪除expiry副本

  Delete backupset 9,1,2;刪除指定備份集

RMAN> delete backupset 43,47,48,49;

using channel ORA_DISK_1

 

List of Backup Pieces

BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name

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

43      43      1   1   UNAVAILABLE DISK        /u01/oracle/backup/full_1koo4kd1_1_1

47      47      1   1   UNAVAILABLE DISK        /u01/oracle/backup/rman1104_backup_c-325518186-20140312-00

48      48      1   1   UNAVAILABLE DISK        /u01/oracle/backup/backup_spfile

49      49      1   1   UNAVAILABLE DISK        /u01/oracle/backup/rman1104_backup_c-325518186-20140314-00

 

Do you really want to delete the above objects (enter YES or NO)? yes

  Delete backuppiece f:\myd\backup\....bak’;刪除特定備份片

  Delete backup;刪除所有備份集----狀態為expired的備份刪不掉,

  Delete datafile copy f……….bak;刪除特定映像副本

  Delete copy ;刪除所有映像副本

  Backup archivelog all delete input ;在備份後刪除輸入物件

RMAN> backup archivelog all delete input;

 

Starting backup at 24-OCT-13

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archive log backupset

channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=20 recid=1 stamp=829666475

input archive log thread=1 sequence=21 recid=2 stamp=829669679

channel ORA_DISK_1: starting piece 1 at 24-OCT-13

channel ORA_DISK_1: finished piece 1 at 24-OCT-13

piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T154800_96kn5k4j_.bkp tag=TAG20131024T154800 comment=NONE

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

channel ORA_DISK_1: deleting archive log(s)

archive log filename=/u01/app/oracle/flash_recovery_area/GRS/archivelog/2013_10_24/o1_mf_1_20_96kk1b3h_.arc recid=1 stamp=829666475

archive log filename=/u01/app/oracle/flash_recovery_area/GRS/archivelog/2013_10_24/o1_mf_1_21_96kn5hv3_.arc recid=2 stamp=829669679

Finished backup at 24-OCT-13

  Delete backupset 22 format =”f:\mydb\backup\backup_%bk” delete input;

4 報表顯示命令report

REPORT NEED BACKUP DATABASE

REPORT OBSOLETE

REPORT SCHEMA

REPORT UNRECOVERABLE

 

Report主要用於當前備份資訊的分析,如哪些備份已過期,哪些該備份,哪些備份不可用,哪些備份可刪除等,

  檢視7天前的資料庫的模式

   Rman>report schema at time ‘sysdate-7’;--此時模式資訊必須連線到catalog資料庫(目錄)

  檢視所需要備份的檔案

RMAN> report need backup;

RMAN retention policy will be applied to the command

RMAN retention policy is set to redundancy 1

Report of files with less than 1 redundant backups

File #bkps Name

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

  檢視指定表空間是否需要備份

   Report need backup tablespace yyhhqq;

  檢視過期備份

 

RMAN> report obsolete;

 

RMAN retention policy will be applied to the command

RMAN retention policy is set to recovery window of 7 days

Report of obsolete backups and copies

Type                 Key    Completion Time    Filen

 RMAN> delete obsolete;

 

RMAN retention policy will be applied to the command

RMAN retention policy is set to redundancy 1

using channel ORA_DISK_1

Deleting the following obsolete backups and copies:

Type                 Key    Completion Time    Filename/Handle

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

 

5 執行檢查crosscheck命令

   Crosscheck用來檢查備份或歸檔物理檔案的狀態,如果物理檔案儲存並且在控制檔案(或回覆目錄)有配匹記錄,則標記該物件的狀態為available(有效),如果檔案不存在,則標記為expired,

  檢查所有歸檔檔案

Rman>crosscheck archivelog all;

 當作業系統環境變數nls_lang指定為中文,執行crosscheck檢查失敗,而又確定檔案存在,顯示失敗說明成功,設定為american_america,英文環境檢查正常

檢查所有備份集

RMAN> crosscheck backup;

using channel ORA_DISK_1

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/oracle/backup/back_05on6v94_1_1 recid=3 stamp=829652260

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/oracle/backup/backup_datafile_09on7bsd_1_1 recid=6 stamp=829665165

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T145435_96kk1gpx_.bkp recid=8 stamp=829666478

crosschecked backup piece: found to be 'EXPIRED'

backup piece handle=/u01/oracle/backup/backup_spfile recid=12 stamp=829666720

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T154800_96kn5k4j_.bkp recid=14 stamp=829669681

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829669684_96kn5nok_.bkp recid=15 stamp=829669684

Crosschecked 6 objects

RMAN> delete expired backup;

using channel ORA_DISK_1

List of Backup Pieces

BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name

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

12      12      1   1   EXPIRED     DISK        /u01/oracle/backup/backup_spfile

 

Do you really want to delete the above objects (enter YES or NO)? yes

deleted backup piece

backup piece handle=/u01/oracle/backup/backup_spfile recid=12 stamp=829666720

Deleted 1 EXPIRED objects

 

6 修改狀態change命令

   Change命令用來修改備份檔案或歸檔檔案的狀態,不是指物理檔案,而是這些檔案在控制檔案(或恢復目錄)中對應記錄的狀態,available,unavailable,

   修改指定備份集狀態為unavailable

   Rman>change backupset n unavailable;n為指定備份集的備份集序號,指定的備份集必須存在,

RMAN> change backupset 47,48,46,43 unavailable;

changed backup piece unavailable

backup piece handle=/u01/oracle/backup/full_1koo4kd1_1_1 recid=43 stamp=830624161

changed backup piece unavailable

backup piece handle=/u01/oracle/backup/rman1104_backup_c-325518186-20131119-00 recid=46 stamp=831916246

changed backup piece unavailable

backup piece handle=/u01/oracle/backup/rman1104_backup_c-325518186-20140312-00 recid=47 stamp=842007923

changed backup piece unavailable

backup piece handle=/u01/oracle/backup/backup_spfile recid=48 stamp=842200054

Changed 4 objects to UNAVAILABLE status

   修改指定指定的表空間的備份集為unavailable;

Rman>change backup of tablespace users unavailable;

 修改指定歸檔檔案狀態為unavailable

 Rman>change archivelog logseq=n unavailable;

 Change 命令附帶了delete字句,

刪除某個歸檔檔案

 Rman>change archivelog logseq=n delete;