ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle暂时结束有计划地学习RMAN,以后根据需要再总结

Oracle暂时结束有计划地学习RMAN,以后根据需要再总结

原创 Linux操作系统 作者:louloueva 时间:2009-01-19 22:55:30 0 删除 编辑

临近春节,年前也开始陆续把家里归置一下
估计这几天体力劳动要比脑力劳动多些
也好,调节一下,老在电脑前坐着,腰酸背痛的
(腿倒是没抽筋,看来不用补钙)

昨天接触了一下利用catalog来记录RMAN相关信息
使用catalog,可以将多个target的备份信息保存起来
还有众多相应视图帮助查看
还有一个较重要的好处,最近在RMAN的时候没怎么练习
记录run块,run块中包含了一个或多个RMAN脚本
将run块命名并保存在catalog中,可以方便以后调用执行
举例说明
RMAN> create script. sc_test1{
2> configure CONTROLFILE AUTOBACKUP off;
3> SET BACKUP COPIES 2;
4> backup as copy datafile 4;
5> configure CONTROLFILE AUTOBACKUP on; }
上面创建了一个sc_test1的rman脚本
功能是先将自动备份控制文件设置为off
再设置备份会生成两份
然后对4号数据文件进行副本拷贝
之后再将自动备份控制文件设为on
SET BACKUP COPIES 2;这句仅仅作用于run块内
如果要在全局设置此参数,方法如下
RMAN> configure datafile backup copies for device type disk to 2;
这个命令是针对数据文件备份的,把datafile换成archivelog就是设置归档日志的
RMAN> configure datafile backup copies for device type disk clear;
是将此设置还原为默认值,clear参数可以用在多种设置上

继续脚本试验,执行刚才创建的脚本
RMAN> RUN {EXECUTE SCRIPT. sc_test1;}
如果脚本内容可以正确执行,将实现刚才解释的那些功能,否则中途会报错

删除脚本
RMAN> delete script. sc_test1;

显示已经创建的脚本
RMAN> list all script. names;

再说一些命令
RMAN> backup datafile 4,5 FILESPERSET=1;
功能是备份4号、5号数据文件,每个备份集中含有1个数据文件
此命令将会生长两个备份集,filesperset指定备份集包含文件数

建立一个通道1
RMAN> configure channel 1 device type disk format '/home/oracle/dumptest/%U_%I';
如果不需要的时候用下面命令清除
RMAN> configure channel 1 device type disk clear;
看一段run块脚本
RMAN> run{
2> allocate channel c1 device type disk format '/home/oracle/dumptest/c1_%U';
3> allocate channel c2 device type disk format '/home/oracle/dumptest/test2/c2_%U';
4> allocate channel c3 device type disk format '/home/oracle/bktest/c3_%U';
5> set backup copies 3;
6> backup datafile 4,5,6 filesperset=1;
7> release channel c1;
8> release channel c2;
9> release channel c3; }
在run块中分配了三个通道,分别保存于不同目录
设定备份生成3份副本,备份数4、5、6号据文件,每个数据文件生成一个备份集
结束前释放了三个通道(我在10gR2中,没加release,RMAN会自动释放,后面会演示)
具体执行过程如下
released channel: ORA_DISK_1
allocated channel: c1
channel c1: sid=137 devtype=DISK
allocated channel: c2
channel c2: sid=143 devtype=DISK
allocated channel: c3
channel c3: sid=159 devtype=DISK
executing command: SET BACKUP COPIES
Starting backup at 19-JAN-09
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00005 name=/home/oracle/oracle/oradata/test/example01.dbf
channel c1: starting piece 1 at 19-JAN-09
channel c2: starting full datafile backupset
channel c2: specifying datafile(s) in backupset
input datafile fno=00006 name=/home/oracle/oracle/oradata/test/ts_test.dbf
channel c2: starting piece 1 at 19-JAN-09
channel c3: starting full datafile backupset
channel c3: specifying datafile(s) in backupset
input datafile fno=00004 name=/home/oracle/oracle/oradata/test/users01.dbf
channel c3: starting piece 1 at 19-JAN-09
channel c3: finished piece 1 at 19-JAN-09 with 3 copies and tag TAG20090119T165203
piece handle=/home/oracle/bktest/c3_29k57bhl_1_1 comment=NONE
piece handle=/home/oracle/bktest/c3_29k57bhl_1_2 comment=NONE
piece handle=/home/oracle/bktest/c3_29k57bhl_1_3 comment=NONE
channel c3: backup set complete, elapsed time: 00:00:05
channel c2: finished piece 1 at 19-JAN-09 with 3 copies and tag TAG20090119T165203
piece handle=/home/oracle/dumptest/test2/c2_28k57bhk_1_1 comment=NONE
(省略)
channel c2: backup set complete, elapsed time: 00:00:10
channel c1: finished piece 1 at 19-JAN-09 with 3 copies and tag TAG20090119T165203
piece handle=/home/oracle/dumptest/c1_27k57bhk_1_1 comment=NONE
(省略)
channel c1: backup set complete, elapsed time: 00:00:25
Finished backup at 19-JAN-09
released channel: c1
released channel: c2
released channel: c3
从上面过程可以看出,RMAN自动将三个数据文件分派到三个通道进行备份
如果每个通道连接的路径是在不同硬盘或磁带上,可能会提高备份效率
(之所以说可能,是因为自己这边没试验)
用list backupset看看生成的备份集情况
BS Key  Type LV Size
------- ---- -- ----------
1868    Full    2.13M
  List of Datafiles in backup set 1868
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 943892     19-JAN-09 /home/oracle/oracle/oradata/test/users01.dbf
  Backup Set Copy #1 of backup set 1868
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:00:04     19-JAN-09       NO         TAG20090119T165203
    List of Backup Pieces for backup set 1868 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    1871    1   AVAILABLE   /home/oracle/bktest/c3_29k57bhl_1_1
  Backup Set Copy #2 of backup set 1868
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:00:04     19-JAN-09       NO         TAG20090119T165203
    List of Backup Pieces for backup set 1868 Copy #2
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    1872    1   AVAILABLE   /home/oracle/bktest/c3_29k57bhl_1_2
  Backup Set Copy #3 of backup set 1868
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:00:04     19-JAN-09       NO         TAG20090119T165203
    List of Backup Pieces for backup set 1868 Copy #3
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    1873    1   AVAILABLE   /home/oracle/bktest/c3_29k57bhl_1_3
(另外两个数据文件备份信息省略)
此命令生成的备份集有多个备份片(因为设置了copies 3)
删除备份集会将三个备份片都删除,要删除单一备份片,用如下命令
RMAN> delete backuppiece 1879;

再看一个run块
RMAN> run{
2> allocate channel ch1 device type disk
3> format '/home/oracle/bktest/%U','/home/oracle/dumptest/b_%U';
4> set backup copies 2;
5> backup datafile 4;}
执行过程
released channel: ORA_DISK_1
allocated channel: ch1
channel ch1: sid=137 devtype=DISK
executing command: SET BACKUP COPIES
Starting backup at 19-JAN-09
channel ch1: starting full datafile backupset
channel ch1: specifying datafile(s) in backupset
input datafile fno=00004 name=/home/oracle/oracle/oradata/test/users01.dbf
channel ch1: starting piece 1 at 19-JAN-09
channel ch1: finished piece 1 at 19-JAN-09 with 2 copies and tag TAG20090119T173119
piece handle=/home/oracle/bktest/2bk57dr8_1_1 comment=NONE
piece handle=/home/oracle/dumptest/b_2bk57dr8_1_2 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:05
Finished backup at 19-JAN-09
released channel: ch1  (注意这里RMAN自动释放通道,但还是建议填写上释放语句)
此run块脚本,是利用backup copies设置,以及为通道设置多个路径,来分别保存备份
如果copies设置的数超过了format定义的路径数,将会轮流使用各个路径
比如设置copies为4,路径为bktest和dumptest,就可能产生下面结果
(主要注意最后一个数字,它表示备份片号)
/home/oracle/bktest/2ek57ept_1_1
/home/oracle/dumptest/b_2ek57ept_1_2
/home/oracle/bktest/2ek57ept_1_3
/home/oracle/dumptest/b_2ek57ept_1_4

再总结一个RMAN中很重要的备份方式,分级备份
利用分级备份可以更灵活的制定备份策略
其中,增量备份可以有效节省备份所需时间
增量备份可以根据数据块的SCN来判断自上次父级备份以来,其是否发生变化
有变化则备份,无变化则跳过
先来介绍level 0备份,它相当于一个全备份
但全备份无法用来作为level 1增量备份的基础
level 0增量备份命令如下
RMAN> backup incremental level=0 database [plus archivelog];#归档日志选项非必须
增量备份中,还有两种
差异备份(differential backup),备份自上次同级或更高级增量备份后所有变化的数据块
累积备份(cumulative backup),备份自上次更高级增量备份后所有变化数据块
对比两者,差异备份所需要的磁盘空间较少,累计备份所用的恢复时间较少
继续试验
来到数据库这边,增加一些数据库对象或数据,我是建立了一个新表
SQL> create table t_test1 tablespace ts_test as select * from all_tables;
SQL> commit;
回到RMAN,执行一个level 1的差异增量备份
RMAN> BACKUP INCREMENTAL LEVEL 1 [DIFFERENTIAL] DATABASE;
[DIFFERENTIAL]不是必须的
执行后,可以到相应目录查看生成备份文件
2fk57gid_1_1_1969292173,这个是level 0的,超过600M
2hk57hm7_1_1_1969292173,这个是level 1的,1M多
再改变一些数据,再来分别做差异和累积level 1备份
SQL> create table t_test2 as select * from emp;
SQL> commit;
为了减少RMAN比对数据块是否发生改变的时间
上面的表,是在users表空间建立的,先进行一次level 1的差异增量
RMAN> BACKUP INCREMENTAL LEVEL 1 TABLESPACE USERS;
生成了一个不到100K的备份集,再来做个level 1的累积增量备份
再改变users表空间,用类似方法增加t_test3表
然后再进行差异增量,命令略,因为两次增加的表内容一直,备份集还是不到100K
好,来一次累积增量备份
RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE TABLESPACE USERS;
这次生成了一个120K的备份集
(不是两个差异备份集的和,因为某些数据块可能所剩空间较大,还能继续加入数据)

来简单走一下利用增量备份进行恢复,先把users数据文件删除,模拟故障
shutdown abort强行关闭,再startup mount数据库(无法open),先来restore相应表空间
RMAN> restore tablespace users;
执行过程信息略,RMAN利用刚才的level 0备份来还原了表空间,再来recover
RMAN> recover tablespace users;
Starting recover at 19-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /home/oracle/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/2ok57iii_1_1_1969292173
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/2ok57iii_1_1_1969292173 tag=TAG20090119T185201
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
starting media recovery
media recovery complete, elapsed time: 00:00:02
Finished recover at 19-JAN-09
此时数据库已经可以open了
备份文件2ok57iii_1_1_196929217是刚才生成的累积增量备份
再试验一次,这次先把累积增量备份删除,其它步骤略,recover过程如下
RMAN> recover tablespace users;
Starting recover at 19-JAN-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /home/oracle/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/2hk57hm7_1_1_1969292173
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/2hk57hm7_1_1_1969292173 tag=TAG20090119T183653
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /home/oracle/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/2mk57icq_1_1_1969292173
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/2mk57icq_1_1_1969292173 tag=TAG20090119T184857
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /home/oracle/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/dumptest/2nk57ih5_1_1_1969292173
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/dumptest/2nk57ih5_1_1_1969292173 tag=TAG20090119T185117
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 19-JAN-09
数据库可以open,此过程中用到的文件都是差异增量备份生成的
嗯,这些就是今天要练习的内容

RMAN作为Oracle主要的备份恢复工具,其功能岂是个人几天学习就能全部涉及的呢?
最近对RMAN的练习,也不过是属于初级程度的接触
主要目的是为了对RMAN的使用有个大概的了解,对一些相关概念有个初步认识
每天具体地学习RMAN的过程到此告一段落
今后如果碰到不太理解或有必要总结的地方,会再进行记录
(个人觉得闪回功能和其相关设置不算是包换在RMAN中)
至于明天开始的计划……目前还没有确定
随着春节临近,要开始准备一些非学习的事情
而春节期间,个人也会用更多的时间放松、整理一下
也许每天Oracle的学习或实践会比较杂,没有一个相对固定的计划吧 ◎◎"

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/556359/viewspace-541493/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-01-02

  • 博文量
    134
  • 访问量
    118526