1、Doc Ref: 数据库备份方案 作者: PCCW Consulting Services 文档创建日期: Jan 31 , 2011 最近变更日期: Jan 31 , 2011 文档引用: 版本号: v1.0 Note: Title, Subject, Last Updated Date, Reference Number, and Version are marked by a Word Bookmark so that they can be easily reproduced in the header a
2、nd footer of documents. When you change any of these values, be careful not to accidentally delete the bookmark. You can make bookmarks visible by selecting Tools->Options…View and checking the Bookmarks option in the Show region.
审批:
3、val lines, Press [Tab] from the last cell in the table above. Copy Number _____ Note: You can delete any elements of this cover page that you do not need for your document. For example, Copy Number is only required if this is a controlled document and you need to track each copy that you distri
4、bute. 文档控制 变更记录 15 日期 作者 版本号 变更参考文件 Jan 31, 2011 xxxx Draft 1a 审阅 姓名 职位 发行 拷贝号 姓名 地址 1 2 3 4 Note: The copy numbers referenced above should be written into the Copy Number space on the c
5、over of each distributed copy. If the document is not controlled, you can delete this table and the Copy Number label from the cover page. 目录 文档控制 2 RMAN备份概述 4 在线热备份 4 多级增量备份 4 并行备份,恢复 5 减少所需要的备份数据量 5 使用简单 5 配置RMAN 6 CATALOG数据库 6 磁带接口 7 多级备份策略 7 维护RMAN 12 检查RMAN备份信息 12 RMAN信息同步 12
6、 使用RMAN进行恢复 13 恢复整个数据库 13 恢复单个表空间 13 其他 15 archive 方式 15 Note: To update the table of contents, put the cursor anywhere in the table and press [F9]. To change the number of levels displayed, select the menu option Insert>Index and Tables, make sure the Table of Contents tab is active, and c
7、hange the Number of Levels to a new value. RMAN备份概述 采用数据库提供的RMAN备份工具有以下的优点: 支持在线热备份 支持多级增量备份 支持并行备份,恢复 减小所需要备份量 备份,恢复使用简单 在线热备份 是指备份不需要关闭数据库进行,在备份的同时可以进行正常的数据库的各种操作,满足了7*24的系统的需要,对于本系统而言,数据库的备份将不会影响INTERNET或INTRANET用户对数据库的访问。 多级增量备份 多级增量备份是指第N级的备份只需要备份最后一次同级或N-1级备份以后发生
8、的改变的数据。可以通过下图来说明: 上图是一个增量备份的例子,即在第一个星期天做一个增量的0级备份,然后在星期一,星期二做一个增量的2级备份,在星期三做一个增量的1级备份,然后类推。假设现在在星期五数据库需要做恢复,则可以先恢复第一个星期天的0级备份,,然后恢复星期三的1级备份,再恢复星期四和星期五的2级备份就可以完成数据库的恢复。 因为在本系统录入后的数据进入数据库后将大部分变为只读状态,所以采用对这些表空间只备份一次或比经常改变的表空间备份次数更少的方法,将能够很大地减少备份的数据量。具体的方案如下: 对于表PROD_CONTENT_CN_TBL,PROD_VALUE
9、TBL由于做了关于序列号的分区,采取的当一个分区满了以后,在数据库里把该分区改成只读状态,然后做一个该表空间的备份,然后在做数据库的日常增量备份时忽略该表空间的数据则能够大大减少要备份的数据量。 并行备份,恢复 RMAN是通过启动数据库的SERVER进程来进行备份和恢复,而且支持启动多个SERVER进程来进行备份和恢复,在同一个SERVER进程内还支持多个BACKUPSET(备份集)的同时产生。主要是通过设置多个通道及filesperset参数来达到并行的目的。 分配多个通道的语句(以下语句分配两个通道) Allocate channel ‘dev_1’ type dis
10、k; Allocate channel ‘dev_2’ type disk; 设置在一个通道同时打开的备份文件语句(以下语句设置在一个通道下同时打开3个文件) backup filesperset 3。。。 减少所需要的备份数据量 因为RMAN是工作在数据块一级,所以能够只备份分配的数据块,这样就大大地减少了所需要的备份的数据量,特别是对于预先分配空间的数据库而言。 使用简单 RMAN的使用特别简单,在进行备份和恢复时都不需要指定需要备份或需要恢复的数据文件,RMAN会自动地把备份或恢复所需要的数据文件进行备份或进行恢复。减少了人为操作可能产生的错误。
11、如以下是备份整个数据库的语句 backup full tag 'basicdb' format '/bak/bak/basic/basic%u_%p_%c' database ; 以下是备份一个表空间的语句 backup tag 'tsusers' format '/bak/bak/basic/basic%u_%p_%c' tablespace users ; 以下是备份归档文件的语句 backup filesperset 3 archivelog all delete input; 归档文件会在备份后自动删除。 配置RMAN 配置RMAN包括配置CATALOG
12、数据库,配置数据库与媒体管理软件的接口,制定RMAN的多级备份方案,写RMAN备份脚本 CATALOG数据库 因为RMAN自动维护备份和恢复所需要的各种信息,所以RMAN必须把这些以某种形式保存。RMAN支持两种形式保存这些信息,数据库的控制文件或创建一个单独的数据库来保存RMAN的信息。 当选择把RMAN的信息存储在控制文件时,控制文件的丢失时将导致备份将不能进行恢复。所以若采用RMAN做备份,推荐一定采用RMAN CATALOG数据库来单独存放备份信息。这个单独的数据库(称为CATALOG数据库)只需要很小的空间,既可以和被备份的数据库(E10K)放在同一主机上,也可以单独
13、放在另一台主机上(如果条件允许,推荐放在一台单独的主机上来确保最大的可恢复性)。 备份CATALOG数据库:因为CATALOG数据库包含了所有的备份信息,所以该数据库本身也是需要通过某种方法进行备份,但因为该数据库很小(一年内可能才增加十几二十兆),所以既可以对它进行冷备份,也可以进行逻辑的输出(EXPORT)。 配置CATALOG数据库: 1. 用db assist创建数据库。 2. 在该数据库创建RMAN数据库用户: create user rman identified by rman default tablespace ts_rman temporary tab
14、lespace temp; grant connect ,resource , RECOVERY_CATALOG_OWNER to rman. 3. 连接到目标数据库和CATALOG数据库 rman target system/manager@target_tnsname rcvcat rman/rman@catalog_tnsname 4. 创建CATALOG用户的表: rman>create catalog 5. 登记目标数据库: rman>register database 这样就可以利用该RMAN数据库来备份目标数据库了。 磁带接口 当使用专用的磁带管
15、理工具时,必须配置数据库与磁带的接口,一般是管理工具提供一个动态连接库与数据库进行连接。 以下是一个测试的RMAN脚本: run { allocate channel 'dev1' type disk resync catalog; backup format ‘/archive/ctl%u_%p_%c ‘ current controlfile; release channel dev1; } 多级备份策略 采用多级备份是为了减少了恢复所需要的时间和减少每天备份所需要的时间,而又保证系统有很好的恢复性。但是在恢复时间和备份时间要有一个权衡。比如只要开始的一个全备份和
16、备份所有产生的归档文件就可以保证把数据库恢复到最新的状态,但是一般来说实际上并不会这么进行(因为在恢复时将需要很长的时间),多级备份就是为了解决这样的问题。以下是一种建议的方案。 每半年做一个数据库的全备份(包含只读表空间) 每个月做一次零级备份(不包含只读表空间) 每个星期做一次一级备份 每天做一个二级备份 任何表空间改成只读状态后做一个该表空间的备份。 当需要时(如四个小时归档文件系统就要接近满了)备份归档文件 数据库全备份脚本: run { allocate channel 'dev1' type disk ; allocate channel 'dev2
17、' type disk ; allocate channel 'dev3' type disk ; backup full tag 'dbfull' format '/o9i/testrman/full%u_%p_%c' database ; sql 'alter system archive log current' ; backup filesperset 3 archivelog all delete input; release channel dev1; release channel dev2; release channel dev3; } 零级备份脚
18、本(只读表空间除外) run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate channel 'dev3' type disk ; backup incremental level 0 tag 'dbL0' format '/o9i/testrman/basic%u_%p_%c' database skip readonly; sql 'alter system archive log current' ; backup filesperset 3 ar
19、chivelog all delete input; release channel dev1; release channel dev2; release channel dev3; } 一级备份脚本 run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate channel 'dev3' type disk ; backup incremental level 1 tag 'dbL1' format '/o9i/testrman/basic%u_%p_
20、c' ddatabase skip readonly; sql 'alter system archive log current' ; backup filesperset 3 archivelog all delete input; release channel dev1; release channel dev2; release channel dev3; } 二级备份脚本 run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate c
21、hannel 'dev3' type disk ; backup incremental level 2 tag 'dbL2' format '/o9i/testrman/basic%u_%p_%c' ddatabase skip readonly; sql 'alter system archive log current' ; backup filesperset 3 archivelog all delete input; release channel dev1; release channel dev2; release channel dev3; } 表空间备
22、份脚本(以users表空间为例) run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate channel 'dev3' type disk ; backup tag 'tsusers' format '/o9i/testrman/basic%u_%p_%c' tablespace users; sql 'alter system archive log current' ; backup filesperset 3 archivelog all dele
23、te input; release channel dev1; release channel dev2; release channel dev3; } 归档文件备份脚本 run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate channel 'dev3' type disk ; backup filesperset 3 archivelog all delete input; release channel dev1; release c
24、hannel dev2; release channel dev3; } 则每天所需要备份的数据量只有一天的改变量。而做恢复时最多只要恢复当月的一个零级备份+三个一级备份+6个二级备份+当天的归档文件。如果不能接受这样的恢复时间,就只能够减少零级备份之间的时间间隔(如可以每个星期做一个零级备份,这样恢复时最多只需要恢复一个星期的数据量)。 备份CATALOG数据库(数据库逻辑输出) exp pafile=exp.dat 其中exp.dat如下 userid=rman/rman file=rmanexp.dmp 维护RMAN RMAN的维护工作主要是: 1. 查看备
25、份信息 2. 因为手工删除了备份文件或归档文件需要把RMAN CATALOG数据库的信息与手工删除的信息同步。 检查RMAN备份信息 列出已经过时的备份: RMAN>report obsolete; 删除过时的备份信息 RMAN> allocate channel for maintenance type disk; RMAN> change backupset id delete; RMAN> release channel; RMAN信息同步 当手工删除了数据库的归档文件后,要执行以下脚本进行同步: RMAN> allocate channel
26、 for maintenance type disk; RMAN> change archivelog all crosscheck; RMAN> release channel; 当手工删除了数据库的RMAN备份文件后,要执行以下脚本进行同步: RMAN> allocate channel for maintenance type disk; RMAN> crosscheck backup; RMAN> delete expired backup; RMAN> release channel; 使用RMAN进行恢复 数据库的的恢复比较复杂,有许多不同的情况必须在
27、了解ORACLE数据库结构的条件下用不同的方法处理,RMAN的好处在于大部分情况不需要理解数据库的结构而使用一些最简单语句来进行恢复,这里只讨论了最常用最普通的恢复情况 恢复整个数据库 在恢复整个数据库之前必须让数据库处于安装的状态(mount状态) svrmgrl>startup mount rman> run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate channel 'dev3' type disk ; restore databa
28、se ; recover database ; release channel dev1 ; release channel dev2 ; release channel dev3 ; } 恢复单个表空间 在恢复该表空间之前让该表空间处于脱机的状态(offline状态) svrmgrl>alter tablespace users offline; rman> run { allocate channel 'dev1' type disk ; allocate channel 'dev2' type disk ; allocate channel 'dev3' type disk ; restore tablespace users ; recover tablespace users ; release channel dev1 ; release channel dev2 ; release channel dev3 ; } 其他 数据库要使用RMAN必须符合一些条件 archive 方式 数据库要运行在归档模式下,这样数据库将有很好的可恢复性 15 其他 File Ref: Company Confidential - For internal use only






