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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章