资源描述
数据库备份方案
作者: Oracle Consulting Services
文档创建日期: Aug 1,
最近变更日期: Mar 5 ,
文档引用:
版本号: 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 and 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.
审批:
<Approver 1>
<Approver 2>
Note: To add additional approval lines, Press [Tab] from the last cell in the table above.
Copy Number _____
Note:
Note:
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 distribute.
文档控制
变更统计
20
日期
作者
版本号
变更参考文件
审阅
姓名
职位
发行
拷贝号
姓名
地址
1
2
3
4
Note: The copy numbers referenced above should be written into the Copy Number space on the cover 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
使用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 change the Number of Levels to a new value.
RMAN备份概述
采取数据库提供RMAN备份工含有以下优点:
支持在线热备份
支持多级增量备份
支持并行备份,恢复
减小所需要备份量
备份,恢复使用简单
在线热备份
是指备份不需要关闭数据库进行,在备份同时能够进行正常数据库多种操作,满足了7*24系统需要,对于本系统而言,数据库备份将不会影响INTERNET或INTRANET用户对数据库访问。
多级增量备份
多级增量备份是指第N级备份只需要备份最终一次同级或N-1级备份以后发生改变数据。能够经过下图来说明:
上图是一个增量备份例子,即在第一个星期天做一个增量0级备份,然后在星期一,星期二做一个增量2级备份,在星期三做一个增量1级备份,然后类推。假设现在在星期五数据库需要做恢复,则能够先恢复第一个星期天0级备份,,然后恢复星期三1级备份,再恢复星期四和星期五2级备份就能够完成数据库恢复。
因为在本系统录入后数据数据进入数据库后将大部分变为只读状态,所以采取对这些表空间只备份一次或比常常改变表空间备份次数更少方法,将能够很大地降低备份数据量。具体方案以下:
对于表PROD_CONTENT_CN_TBL,PROD_VALUE_TBL因为做了相关序列号分区,采取当一个分区满了以后,在数据库里把该分区改成只读状态,然后做一个该表空间备份,然后在做数据库日常增量备份时忽略该表空间数据则能够大大降低要备份数据量。
并行备份,恢复
RMAN是经过开启数据库SERVER进程来进行备份和恢复,而且支持开启多个SERVER进程来进行备份和恢复,在同一个SERVER进程内还支持多个BACKUPSET(备份集)同时产生。关键是经过设置多个通道及filesperset参数来达成并行目标。
分配多个通道语句(以下语句分配两个通道)
Allocate channel ‘dev_1’ type disk;
Allocate channel ‘dev_2’ type disk;
设置在一个通道同时打开备份文件语句(以下语句设置在一个通道下同时打开3个文件)
backup filesperset 3。。。
降低所需要备份数据量
因为RMAN是工作在数据快一级,所以能够只备份分配数据快,这么就大大地降低了所需要备份数据量,尤其是对于预先分配空间数据库而言。
使用简单
RMAN使用尤其简单,在进行备份和恢复时全部不需要指定需要备份或需要恢复数据文件,RMAN会自动地把备份或恢复所需要数据文件进行备份或进行恢复。降低了人为操作可能产生错误。
如以下是备份整个数据库语句
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数据库,配置数据库和媒体管理软件接口,制订RMAN多级备份方案,写RMAN备份脚本
CATALOG数据库
因为RMAN自动维护备份和恢复所需要多种信息,所以RMAN必需把这些以某种形式保留。RMAN支持两种形式保留这些信息,数据库控制文件或创建一个单独数据库来保留RMAN信息。
当选择把RMAN信息存放在控制文件时,控制文件丢失时将造成备份将不能进行恢复。所以若采取RMAN做备份,推荐一定采取RMAN CATALOG数据库来单独存放备份信息。这个单独数据库(称为CATALOG数据库)只需要很小空间,既能够和被备份数据库(E10K)放在同一主机上,也能够单独放在另一台主机上(假如条件许可,推荐放在一台单独主机上来确保最大可恢复性)。
备份CATALOG数据库:因为CATALOG数据库包含了全部备份信息,所以该数据库本身也是需要经过某种方法进行备份,但因为该数据库很小(十二个月内可能才增加十几二十兆),所以既能够对它进行冷备份,也能够进行逻辑输出(EXPORT)。
配置CATALOG数据库:
1. 用dbassist创建数据库。
2. 创建表空间
create tablespace ts_rman
datafile=’d:\oratest\rman.dbf’
size=100M;
3. 在该数据库创建RMAN数据库用户:
create user rman identified by rman default tablespace ts_rman
temporary tablespace temp;
grant connect ,resource , RECOVERY_CATALOG_OWNER to rman.
4. 连接到目标数据库和CATALOG数据库
rman target system/manager@target_tnsname rcvcat rman/rman@catalog_tnsname
5. 创建CATALOG用户表:
rman>create catalog
6. 登记目标数据库:
rman>register database
这么就能够利用该RMAN数据库来备份目标数据库了。
解除登记数据库
开启rman并连接到目标数据库。
% rman target sys/change_on_install@prod1 nocatalog
RMAN-06005: connected to target database: RMAN (DBID=)
List the copies and backup sets recorded in the control file and then issue change ... delete statements to delete them from the O/S. See "Generating Lists" and "Deleting Backups and Copies and Updating Their Status in the RMAN Metadata".
Use SQL*Plus to connect to your recovery catalog database and execute the following query in the recovery catalog to find the correct row of the DB table, setting DB_ID equal to the value you obtained from step 1. For example, enter:
SQL> SELECT db_key, db_id FROM db WHERE db_id = ;
This query should return exactly one row.
DB_KEY DB_ID
---------- ----------
1
1 row selected.
While still connected to the recovery catalog, enter the following, where DB_KEY and DB_ID are the corresponding columns from the row you got from the query in step 2:
SQL> EXECUTE dbms_rcvcat.unregisterdatabase(db_key, db_id)
For example, enter:
SQL> EXECUTE dbms_rcvcat.unregisterdatabase(1 , )
磁带接口
当使用专用磁带管理工具时,必需配置数据库和磁带接口,通常是管理工具提供一个动态连接库和数据库进行连接。
以下是一个测试RMAN脚本:
run {
allocate channel 'dev1' type disk
resync catalog;
backup format ‘/archive/ctl%u_%p_%c ‘ current controlfile;
release channel dev1;
}
多级备份策略
采取多级备份是为了降低了恢复所需要时间和降低天天备份所需要时间,而又确保系统有很好恢复性。不过在恢复时间和备份时间要有一个权衡。比如只要开始一个全备份和备份全部产生归档文件就能够确保把数据库恢复到最新状态,不过通常来说实际上并不会这么进行(因为在恢复时将需要很长很长时间),多级备份就是为了处理这么问题。以下是一个提议方案。
每六个月做一个数据库全备份(包含只读表空间)
每个月做一次零级备份(不包含只读表空间)
每个星期做一次一级备份
天天做一个二级备份
任何表空间改成只读状态后做一个该表空间备份。
当需要时(如四个小时归档文件系统就要靠近满了)备份归档文件
数据库全备份脚本:
run {
allocate channel 'dev1' type disk ;
allocate channel 'dev2' 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;
}
零级备份脚本(只读表空间除外)
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 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 channel 'dev3' type disk ;
backup incremental level 1 tag 'dbL1' 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;
}
二级备份脚本
run {
allocate channel 'dev1' type disk ;
allocate channel 'dev2' type disk ;
allocate channel '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;
}
表空间备份脚本(以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 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 filesperset 3 archivelog all delete input;
release channel dev1;
release channel dev2;
release channel dev3;
}
则天天所需要备份数据量只有一天改变量。而做恢复时最多只要恢复当月一个零级备份+三个一级备份+6个二级备份+当日归档文件。假如不能接收这么恢复时间,就只能够降低零级备份之间时间间隔(如能够每个星期做一个零级备份,这么恢复时最多只需要恢复一个星期数据量)。
备份CATALOG数据库(数据库逻辑输出)
exp pafile=exp.dat
其中exp.dat以下
userid=rman/rman
file=rmanexp.dmp
维护RMAN
RMAN维护工作关键是:
1. 查看备份信息
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 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进行恢复
数据库恢复比较复杂,有很多不一样情况必需在了解ORACLE数据库结构条件下用不一样方法处理,RMAN好处于于大部分情况不需要了解数据库结构而使用部分最简单语句来进行恢复,这里只讨论了最常见最一般恢复情况
恢复整个数据库
在恢复整个数据库之前必需让数据库处于安装状态(mount状态)
svrmgrl>startup mount
rman>
run {
allocate channel 'dev1' type disk ;
allocate channel 'dev2' type disk ;
allocate channel 'dev3' type disk ;
restore database ;
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 方法
数据库要运行在归档模式下,这么数据库将有很好可恢复性
展开阅读全文