RMAN备份详解2

一、备份的其它特性

1.并发:主要用于提高备份的速度,可以分为手动并发或自动并发

 1 手动并发:通过分配多个通道并将文件指定到特定的通道,0级备份

 2 

 3       RMAN> run {

 4       2>  allocate channel ch1 device type disk;

 5       3>  allocate channel ch2 device type disk;

 6       4>  allocate channel ch3 device type disk;

 7       5> backup incremental level=0

 8       6>  format '/u01/rmanbak/df_%d_%U'

 9       7>  (datafile 1 channel ch1 tag='sys')

10       8>  (datafile 3 channel ch2 tag='aux')

11       9>  (datafile 2,4,5,6 channel ch3 tag='other');

12       10> sql 'alter system archive log current';--备份后进行日志归档

13       11> release channel ch1;

14       12> release channel ch2;

15       13> release channel ch3;

16       14> }   

17 

18 

19 自动并发:使用configure配置并发度即可

20       RMAN> configure device type disk parallelism 3 backup type to backupset;

21 

22       --下面的备份将自动启用个通道执行并发

23       RMAN>  backup database format '/u01/app/oralce/rmanbak/p3_%U';

2.复用备份:即将一个备份集复制多份,同一备份集,Oracle最多可复用4个

1 手工指定:

2     RMAN> backup copies 2 datafile 4

3     2> format '/u01/rmanbak/d1/df_%U',

4     3>        '/u01/rmanbak/d2/df_%U';   

5     

6 自动指定:配置下列参数

7     RMAN> configure datafile backup copies for device type disk to 2;  --指定备份数据文件副本数

8     RMAN> configure archivelog backup copies for device type disk to 2;--指定备份日志文件副本数

3.备份备份集(具体查看文档)

  bacup backupset

4.镜像备份:镜像备份时会检查数据文件中是否存在坏块,可以使用nochecksum来跳过坏块的检测,也可以指定maxcorrupt判断有多少个坏块时,Oracle将停止该镜像备份。注,使用具体详情建议查文档

 1 RMAN> backup as copy

 2 2> datafile 4 format '/u01/app/oracle/rmanbak/users.dbf' tag='users'

 3 

 4 --以下命令等同于上一条

 5 RMAN> copy datafile 4 to '/u01/app/oracle/rmanbak/user01.dbf';

 6 

 7 --备份归档日志

 8 RMAN> backup as copy

 9 2> archivelog like 'o1_mf_1_118_6chl1byd_.arc'

10 3> format '/u01/app/oracle/rmanbak/arch_1015.bak';

11 

12 --使用下面的configure命令将backup type设置为copy之后,则缺省的备份为镜像副本

13 RMAN> configure device type disk parallelism 1 backup type to copy;

14 

15 RMAN> backup datafile 4  --由于上面的设置,则此命令备份的将是镜像副本

16 2> format '/u01/app/oracle/rmanbak/users.dbf.bak' tag=users;    

17 

18 --使用并行度来执行镜像拷贝

19 RMAN> configure device type disk parallelism 4;

20 

21 RMAN> backup as copy #3 files copied in parallel

23 2> (datafile 1 format '/u01/app/oracle/rmanbak/df1.bak')

24 3> (datafile 2 format '/u01/app/oracle/rmanbak/df2.bak')

25 4> (datafile 3  format '/u01/app/oracle/rmanbak/df3.bak');

26 

27 

28 --镜像备份时指定子句DB_FILE_NAME_CONVERT来实现镜像路径转移,该子句也是一个初始化参数,用于primary db 到standby db的数据文件的转换           

29 --用string2替换string1,string4替换string3

30 DB_FILE_NAME_CONVERT = ('string1' , 'string2' , 'string3' , 'string4' ...)

31 

32 RMAN> backup as copy device type disk

33 2> db_file_name_convert('oradata/orcl','bk/rmbk')

34 3> tablespace users;

35       

5.压缩备份集

 1 RMAN> configure channel device type disk format '/u01/app/oracle/rmanbak/%d_%U.bak';

 2 

 3 --下面的命令使用了参数as compressed来实现手动压缩

 4 RMAN> backup as compressed backupset database;

 5 

 6 RMAN> backup as compressed backupset datafile 4,5,6;

 7 

 8 --下面使用configure命令配置自动压缩备份集功能,则后续的备份会自动使用压缩功能

 9 RMAN> configure device type disk parallelism 4 backup type to compressed backupset;

10 

11 --由于设置了自动压缩,则下面的命令将压缩备份的system表空间及控制文件、参数文件

12 RMAN> backup tablespace system tag=system;

6.使用tag标记:tag标记可以为备份集或映像副本指定一个有意义的名字,以备后续使用。

 其优点如下:

 a.为备份集或映像副本提供描述信息;

 b.能够在list 命令中使用更好的定位备份文件;

 c.能够在restore和switch命令中使用

 d.同一个tag在多个备份集或多个映像副本中使用;

 e.当未指定tag标记时,则系统产生缺省的tag标记,其格式为:TAGYYYYMMDDTHHMMSS

1 RMAN> backup as compressed backupset datafile 1,2,3 tag='Monthly_full_bak';

2 

3 RMAN> backup as compressed backupset tablespace users tag='Weekly_full_bak';

4 

5 RMAN> list backupset tag=monthly_full_bak;

7.增量备份:差异增量备份将备份自上次增量备份以来所有发生改变的数据块;累积增量备份将备份自上次级增量备份以来所有改变过的数据块

 1 --下面启用0级增量备份

 2 RMAN> run{

 3 

 4 2> allocate channel ch1 type disk;

 5 

 6 3> backup incremental level 0 database

 7 

 8 4> format '/u01/app/oracle/rmanbak/db_%d_%U'

 9 

10 5> tag=db_inc_0;

11 

12 6> release channel ch1;

13 

14 7> }

15 

16 

17 --查询备份情况

18 SQL> select sid,sofar,totalwork from v$session_longops;  

19 

20 

21 --下面启用级差异增量备份

22 RMAN> run{

23 

24 2> allocate channel ch1 type disk;

25 

26 3> backup incremental level 1 database

27 

28 4> format '/u01/rmanbak/db1_%d_%U'

29 

30 5> tag=db_inc_1;

31 

32 6> release channel ch1;

33 

34 7> }

35 

36 

37 

38 --下面启用累积计增量备份

39 RMAN> run{

40 

41 2> allocate channel ch1 type disk;

42 

43 3> backup incremental level 1 cumulative database

44 

45 4> format '/u01/rmanbak/dbc_%d_%U'

46 

47 5> tag=db_inc_c_1;

48 

49 6> release channel ch1;

50 

51 7> }

8.启用块变化跟踪:启用块变化跟踪即是指定一个文件用于记录数据文件中哪些块发生了变化,在RAMN进行增量备份时,仅仅需读取该文件来备份这些发生变化的块,从而减少了备份时间和I/O资源。使用下面的命令来启用块变化跟踪:ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '<dir>'

 1 SQL> alter database enable block change tracking

 2 

 3   2  using file '/u01/orcl/blk_ch_trc.trc';

 4 

 5 

 6 SQL> ho ls -lht /u01/orcl/blk_ch_trc.trc

 7 

 8 -rw-r----- 1 oracle oinstall 12M Oct 15 19:41 /u01/orcl/blk_ch_trc.trc

 9 

10 

11 SQL> select * from v$block_change_tracking;

12 

13 STATUS     FILENAME                                           BYTES

14 ---------- --------------------------------------------- ----------

15 

16 ENABLED    /u01/orcl/blk_ch_trc.trc     11599872

17 

18 

19 --disable后块变化跟踪文件被自动删除

20 SQL> alter database disable block change tracking; 

21 

22 SQL>  select * from v$block_change_tracking;

23 

24 STATUS     FILENAME                                           BYTES

25 ---------- --------------------------------------------- ----------

26 

27 DISABLED  


9.建议:备份特性最好用手工分配,其优点是灵活,影响面小。

二、备份相关的动态性能监控

1.查看channel对应的server sessions

使用set command id命令,查询v$process和v$session判断哪一个会话与之对应的RMAN通道

SQL> select sid,username,client_info from v$session

  2  where client_info is not null;



       SID USERNAME                       CLIENT_INFO

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



       146 SYS                            rman channel=ORA_DISK_1



       148 SYS                            rman channel=ORA_DISK_2



       150 SYS                            rman channel=ORA_DISK_3





--下面使用了set command id命令

RMAN> run{



2> allocate channel ch1 type disk;



3> set command id to 'rman';



4> backup as copy datafile 4



5> format '/u01/app/oracle/rmanbak/dd_%U';



6> }

    



SQL> select sid,username,client_info from v$session



  2   where client_info is not null;



       SID USERNAME                       CLIENT_INFO

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

       140 SYS                            id=rman



   

SQL> select sid,spid,client_info



  2  from v$process p ,v$session s



  3  where p.addr = s.paddr



  4  and client_info like '%id=%';





       SID SPID         CLIENT_INFO

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

       140 5002         id=rman 

2.查看rman完整的进度 

 1 SQL> select sid,serial#,context,sofar,totalwork,

 2 

 3   2  round(sofar/totalwork*100,2) "% Complete" 

 4 

 5   3  from v$session_longops

 6 

 7   4  where opname like 'RMAN:%'

 8 

 9   5  and opname not like 'RMAN:aggregate%'

10 

11   6  and totalwork!=0;  

3.通过如下SQL获得rman用来完成备份操作的服务进程的SID与SPID信息:

1 select sid, spid, client_info

2 

3 from v$process p, v$session s

4 

5 where p.addr = s.paddr and client_info like '%id=rman%'

 

 

你可能感兴趣的:(rman)