rman初級知識(讀書筆記)

《三思筆記》--rman

進入rman,我自己本地就一個實例,那麼進入rman有兩種方式

[oracle@cindy ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Aug 30 04:55:59 2014

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

connected to target database: ORA11G (DBID=4252637343)

RMAN> exit


Recovery Manager complete.

這種等價於下面

[oracle@cindy ~]$ rman

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Aug 30 04:57:03 2014

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

RMAN> connect target /

connected to target database: ORA11G (DBID=4252637343)

如果想暫時退出rman進入操作系統,則如下

RMAN> host;

[oracle@cindy ~]$ exit
exit
host command complete

RMAN> 

需要批處理一些命令的時候,可以將命令放在run{}中,保存爲一個腳本,直接調用

-------------------------------------------------華麗的分割線------------------------上面是簡單的操作方式----------------------------------------------

下面開始介紹備份的初級演練

1、整庫的備份

只需要一條命令,可以同format參數來定義備份片段的路徑(絕對路徑)

建一個文件夾用來放備份的內容

RMAN> host;

[oracle@cindy ~]$ pwd
/u01/oracle
[oracle@cindy ~]$ rmdir rman_test
[oracle@cindy ~]$ ls
app  autorman  database  Desktop  ldr_case1.ctl  ldr_case1.log  p10404530_112030_Linux-x86-64_1of7.zip  p10404530_112030_Linux-x86-64_2of7.zip  rmanjiaoben
[oracle@cindy ~]$ mkdir rman_test
[oracle@cindy ~]$ exit
exit
host command complete

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

Starting backup at 30-AUG-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=/u02/oradata/ora11g/system01.dbf
input datafile file number=00002 name=/u02/oradata/ora11g/sysaux01.dbf
input datafile file number=00005 name=/u02/oradata/ora11g/example01.dbf
input datafile file number=00003 name=/u02/oradata/ora11g/undotbs01.dbf
input datafile file number=00004 name=/u02/oradata/ora11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/bak_15ph7hli_1_1 tag=TAG20140830T051426 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:48
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-01 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14

查看創建的全庫備份,用list命令查看

RMAN> list backup of database;


List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
36      Full    1.21G      DISK        00:03:43     30-AUG-14      
        BP Key: 36   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T051426
        Piece Name: /u01/oracle/rman_test/bak_15ph7hli_1_1
  List of Datafiles in backup set 36
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1497515    30-AUG-14 /u02/oradata/ora11g/system01.dbf
  2       Full 1497515    30-AUG-14 /u02/oradata/ora11g/sysaux01.dbf
  3       Full 1497515    30-AUG-14 /u02/oradata/ora11g/undotbs01.dbf
  4       Full 1497515    30-AUG-14 /u02/oradata/ora11g/users01.dbf
  5       Full 1497515    30-AUG-14 /u02/oradata/ora11g/example01.dbf

RMAN> 
明顯通過看piece name即可看到備份集所在的位置

2、表空間的備份

(備份USERS表空間)
建一個目錄用來放表空間備份的東西,大致步驟同上

RMAN> host;

[oracle@cindy ~]$ cd /u01/oracle/rman_test
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1
[oracle@cindy rman_test]$ mkdir rman_tablespace
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_tablespace
[oracle@cindy rman_test]$ exit
exit
host command complete

RMAN> backup tablespace users format '/u01/oracle/rman_test/rman_tablespace/tbls_%U';

Starting backup at 30-AUG-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=00004 name=/u02/oradata/ora11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_tablespace/tbls_17ph7irl_1_1 tag=TAG20140830T053445 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-02 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14

RMAN> list backup of tablespace users;


List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
36      Full    1.21G      DISK        00:03:43     30-AUG-14      
        BP Key: 36   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T051426
        Piece Name: /u01/oracle/rman_test/bak_15ph7hli_1_1
  List of Datafiles in backup set 36
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 1497515    30-AUG-14 /u02/oradata/ora11g/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
38      Full    24.87M     DISK        00:00:06     30-AUG-14      
        BP Key: 38   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T053445
        Piece Name: /u01/oracle/rman_test/rman_tablespace/tbls_17ph7irl_1_1
  List of Datafiles in backup set 38
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 1498329    30-AUG-14 /u02/oradata/ora11g/users01.dbf
顯然,可以看到,USERS表空間存在兩份備份,

一份目錄是

/u01/oracle/rman_test/bak_15ph7hli_1_1

一份目錄是

/u01/oracle/rman_test/rman_tablespace/tbls_17ph7irl_1_1
是因爲在前面執行過全庫備份,所以這裏,可以刪除一份備份,命令如下

RMAN> delete backupset 38;

using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
38      38      1   1   AVAILABLE   DISK        /u01/oracle/rman_test/rman_tablespace/tbls_17ph7irl_1_1

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

Do you really want to delete the above objects (enter YES or NO)? Y
deleted backup piece
backup piece handle=/u01/oracle/rman_test/rman_tablespace/tbls_17ph7irl_1_1 RECID=38 STAMP=856935285
Deleted 1 objects

3、數據文件的備份

有兩種方式指定數據文件的名稱,即數據文件的詳細路徑和file_id,這兩個信息可以從數據字典DBA_DATA_FILES中查到,也可以通過觀察,在前面的全庫備份中,已經顯示了數據文件名和序號

備份users表空間的數據文件

基本操作也同上

RMAN> host;

[oracle@cindy ~]$ cd /u01/oracle/rman_test
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_tablespace
[oracle@cindy rman_test]$ mkdir rman_datafile
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_datafile  rman_tablespace
[oracle@cindy rman_test]$ exit
exit
host command complete
RMAN> backup datafile 4 format'/u01/oracle/rman_test/rman_datafile/bak_%U';

Starting backup at 30-AUG-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=00004 name=/u02/oradata/ora11g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_datafile/bak_1aph7k6t_1_1 tag=TAG20140830T055749 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-03 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14
這裏的4可以替換成'/u02/oradata/ora11g/users01.dbf'
RMAN> list backup of datafile 4;


List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
36      Full    1.21G      DISK        00:03:43     30-AUG-14      
        BP Key: 36   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T051426
        Piece Name: /u01/oracle/rman_test/bak_15ph7hli_1_1
  List of Datafiles in backup set 36
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 1497515    30-AUG-14 /u02/oradata/ora11g/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
40      Full    24.87M     DISK        00:00:06     30-AUG-14      
        BP Key: 40   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T055749
        Piece Name: /u01/oracle/rman_test/rman_datafile/bak_1aph7k6t_1_1
  List of Datafiles in backup set 40
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 1499208    30-AUG-14 /u02/oradata/ora11g/users01.dbf

4、控制文件的備份

操作步驟即命令也同上類似

RMAN> host;

[oracle@cindy ~]$ cd /u01/oracle/rman_test
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_datafile  rman_tablespace
[oracle@cindy rman_test]$ mkdir rman_ctl
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_ctl  rman_datafile  rman_tablespace
[oracle@cindy rman_test]$ exit
exit
host command complete
RMAN> backup current controlfile format '/u01/oracle/rman_test/rman_ctl/bak_%U';

Starting backup at 30-AUG-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
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_ctl/bak_1dph7m0t_1_1 tag=TAG20140830T062845 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-04 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14

在執行backup命令的時候,可以指定include current controlfile子句

例如backuo database include current controlfile;

不僅限於database,執行backup命令備份任何文件時都可以指定include current controlfile子句,甚至是backup current controlfile

RMAN> backup current controlfile include current controlfile format '/u01/oracle/rman_test/rman_ctl/bak_%U';

Starting backup at 30-AUG-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
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_ctl/bak_1hph7m9o_1_1 tag=TAG20140830T063328 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-06 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14

RMAN> host;

[oracle@cindy ~]$ cd /u01/oracle/rman_test/rman_ctl
[oracle@cindy rman_ctl]$ ls
bak_1hph7m9o_1_1
[oracle@cindy rman_ctl]$ exit
exit
host command complete

RMAN> list backup of controlfile;

5、歸檔文件的備份

rman中備份歸檔日誌文件有兩種方式

(1)利用backup archivelog命令備份

RMAN> host;

[oracle@cindy ~]$ cd /u01/oracle/rman_test
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_ctl  rman_datafile  rman_tablespace
[oracle@cindy rman_test]$ mkdir rman_archive
[oracle@cindy rman_test]$ ls
bak_15ph7hli_1_1  rman_archive  rman_ctl  rman_datafile  rman_tablespace
[oracle@cindy rman_test]$ exit
exit
host command complete
RMAN>  backup archivelog all format '/u01/oracle/rman_test/rman_archive/bak_%U';

Starting backup at 30-AUG-14
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=59 device type=DISK
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=37 RECID=30 STAMP=856917213
input archived log thread=1 sequence=38 RECID=31 STAMP=856939417
input archived log thread=1 sequence=39 RECID=32 STAMP=856939529
input archived log thread=1 sequence=40 RECID=33 STAMP=856939605
input archived log thread=1 sequence=41 RECID=34 STAMP=856939761
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_archive/bak_1nph7n7i_1_1 tag=TAG20140830T064921 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-08 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14

backup archivelog命令比較靈活,all是指備份當前所有可訪問到的歸檔文件,還可以通過until,scn,time,sequence等參數靈活指定要備份的歸檔區間

(2)執行backup命令時指定plus archiverlog子句

RMAN> backup current controlfile plus archivelog format '/u01/oracle/rman_test/rman_archive/plus_%U';


Starting backup at 30-AUG-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=37 RECID=30 STAMP=856917213
input archived log thread=1 sequence=38 RECID=31 STAMP=856939417
input archived log thread=1 sequence=39 RECID=32 STAMP=856939529
input archived log thread=1 sequence=40 RECID=33 STAMP=856939605
input archived log thread=1 sequence=41 RECID=34 STAMP=856939761
input archived log thread=1 sequence=42 RECID=35 STAMP=856940080
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_archive/plus_1pph7nhg_1_1 tag=TAG20140830T065440 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 30-AUG-14

Starting backup at 30-AUG-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
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/app/oracle/fast_recovery_area/ORA11G/backupset/2014_08_30/o1_mf_ncnnf_TAG20140830T065444_b0215o57_.bkp tag=TAG20140830T065444 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 30-AUG-14

Starting backup at 30-AUG-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=43 RECID=36 STAMP=856940088
channel ORA_DISK_1: starting piece 1 at 30-AUG-14
channel ORA_DISK_1: finished piece 1 at 30-AUG-14
piece handle=/u01/oracle/rman_test/rman_archive/plus_1rph7nho_1_1 tag=TAG20140830T065448 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-AUG-14

Starting Control File and SPFILE Autobackup at 30-AUG-14
piece handle=/u02/rmanbak/c-4252637343-20140830-09 comment=NONE
Finished Control File and SPFILE Autobackup at 30-AUG-14

backup......plus archiverlog命令在備份過程中會依次執行下列步驟:

1)運行alter system archive log current 語句對當前redolog進行歸檔

2)執行backup archivelog all命令備份所有已歸檔的日誌

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

4)再次運行alter system archive log current 語句對當前redolog歸檔

5)對新生成的尚未備份的歸檔文件進行備份

完成歸檔日誌文件備份後,需要刪除已備份過的歸檔文件。

命令backup ...............delete all input,會在完成備份後自動刪除歸檔目錄中已備份的歸檔日誌

RMAN> list backup of archivelog all;


List of Backup Sets
===================
BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
50      32.17M     DISK        00:00:06     30-AUG-14      
        BP Key: 50   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T064921
        Piece Name: /u01/oracle/rman_test/rman_archive/bak_1nph7n7i_1_1

  List of Archived Logs in backup set 50
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    37      1484568    30-AUG-14 1484590    30-AUG-14
  1    38      1484590    30-AUG-14 1504942    30-AUG-14
  1    39      1504942    30-AUG-14 1505018    30-AUG-14
  1    40      1505018    30-AUG-14 1505065    30-AUG-14
  1    41      1505065    30-AUG-14 1505155    30-AUG-14

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
52      32.33M     DISK        00:00:03     30-AUG-14      
        BP Key: 52   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T065440
        Piece Name: /u01/oracle/rman_test/rman_archive/plus_1pph7nhg_1_1

  List of Archived Logs in backup set 52
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    37      1484568    30-AUG-14 1484590    30-AUG-14
  1    38      1484590    30-AUG-14 1504942    30-AUG-14
  1    39      1504942    30-AUG-14 1505018    30-AUG-14
  1    40      1505018    30-AUG-14 1505065    30-AUG-14
  1    41      1505065    30-AUG-14 1505155    30-AUG-14
  1    42      1505155    30-AUG-14 1505416    30-AUG-14

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
54      2.50K      DISK        00:00:00     30-AUG-14      
        BP Key: 54   Status: AVAILABLE  Compressed: NO  Tag: TAG20140830T065448
        Piece Name: /u01/oracle/rman_test/rman_archive/plus_1rph7nho_1_1

  List of Archived Logs in backup set 54
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    43      1505416    30-AUG-14 1505427    30-AUG-14

明顯看到plus_開頭的比bak_開頭的scn多兩個

6、初始化參數文件的備份

通常在備份控制文件時,rman也會自動備份服務器端的初始化參數文件,並置於控制文件相同的備份片段中,因此極少需要單獨對spfile進行備份,如果確實想單獨備份也簡單,直接使用backup spfile命令即可

操作過程同上





發佈了50 篇原創文章 · 獲贊 4 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章