ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 学习rman的使用,受益非浅

学习rman的使用,受益非浅

原创 Linux操作系统 作者:winsonblog 时间:2011-05-15 00:29:36 0 删除 编辑

学习RMAN的备份、恢复的概念、用法和做了一个完全备份恢复测试,感觉还好,没有我想象中难使用。


rman target / nocatalog
backup database plus archivelog;


Starting backup at 14-MAY-11
ORACLE error from target database:
ORA-00258: manual archiving in NOARCHIVELOG mode must identify log

allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
specification does not match any archive log in the recovery catalog
backup cancelled because all files were skipped
Finished backup at 14-MAY-11

Starting backup at 14-MAY-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/14/2011 00:01:26
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 14-MAY-11
channel ORA_DISK_1: finished piece 1 at 14-MAY-11
piece handle=/home/oracle/app/oracle/flash_recovery_area/RAC1/backupset/2011_05_14/o1_mf_ncsnf_TAG20110514T000125_6wwb6b9c_.bkp tag=TAG20110514T000125 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:10
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup plus archivelog command at 05/14/2011 00:01:36

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 05/14/2011 00:01:26
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

 
sql>archive log start

根据ORA-19809的提示信息,可知是由于flash_recovery_area空间不足所致。

SQL> select * from v$flash_recovery_area_usage;
SQL> show parameter db_recovery


1、加大闪回恢复目录的大小(加大参数db_recovery_file_dest_size值)

SQL>ALTER SYSTEM SET db_recovery_file_dest_size=2G SCOPE=BOTH;

2、更改RMAN备份目录,在备份时指定备份目录。

RMAN> backup datafile 1 format '/u01/rmanbk/%U';


configure controlfile autobackup on;
set controlfile autobackup format for device type disk to '/home/oracle/app/oracle/flash_recovery_area/RAC1/backupset/2011_05_14/%F';
 

 

过程中遇到了controlfile无法恢复的情况; 应该是格式不对;恢复的时候说找不到文件;

因此在备份前,先设置好备份目录和格式比较重要。

 

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

总结:(下面的内容是来自网上转贴,具体作者已经不记得,原作者写得好,所以就摘录了下来)

Recovery Manager(RMAN)是一种用于备份(backup)、还原(restore)和恢复(recover)数据库的Oracle 工具。RMAN只能用于ORACLE8或更高的版本中,它能够备份整个数据库或数据库部件,如表空间、数据文件、控制文件、归档文件以及Spfile参数文件。

RMAN有如下特征特性:
·自动的备份与恢复
·方便的备份归档日志
·自动检测新的数据文件
·支持增量备份
·最大限度的减少备份与恢复的错误
·减少恢复的时间
·在热备份中不会产生额外的redo日志
·腐烂数据块的自动检测·并行的备份与恢复操作
·在线备份时,表空间不用置于备份模式

以上功能的实现,
是因为RMAN是块级别的备份与恢复,备份与恢复发生在数据库块级别,可以通过比较数据
块而获得一致性的数据块,可以避免备份没有用过的块,可以检验块是否腐烂等块级别的问
题。


   在使用rman备份分为使用恢复目录和不使用恢复目录两种形式,如果使用恢复目录,那恢复目
录最好建另外一台机器上才更有意义,因为如果同生产库建在一起了,当此机器出现故障时,恢
复目录数据库可以也无法使用,那么rman就不能得到先前的备份信息了,也就不能进行恢复了。

   下面介绍不使用恢复目录的备份与恢复方法,由于没有使用恢复目录那么相关的备份信息将保
存在控制文件中,所以配置rman为自动备份控制文件,每次执行backup时就自动备份一个控制文
件,默认保存在/opt/ora9/product/9.2.0.4/dbs/ 也可更改备份位置。

Oracle10g中,不管是否启用FLASHBACK,但只要设置了db_recovery_file_dest和db_recovery_file_dest_size参数值,
那么RMAN默认会将备份集存储db_recovery_file_dest参数所指定的目录。

启动控制文件自动备份configure controlfile autobackup on;
设置自动备份控制文件格式configure controlfile autobackup format for device type disk to '/backup/cf_%F'
设置备份优化configure backup optimization on;
自动备份控制文件默认保存路径/opt/ora9/product/9.2.0.4/dbs/

连连接数据库
rman>connect target / 或 rman target /
备份数据库
RMAN>  run {
2>  allocate channel dev1 type disk;
3> backup
4> format '/tmp/hotbak/bak'
5> database;
6> release channel dev1;
7> }
备份表空间
RMAN>  run {
2>  allocate channel dev1 type disk;
3> backup
4> format '/tmp/hotbak/tablespace_users'
5> tablespace users;
6> release channel dev1;
7> }

备份单独数据文件
RMAN>  run {
2>  allocate channel dev1 type disk;
3> backup
4> format '/tmp/hotbak/datafile_users'
5> datafile '/opt/ora9/oradata/oradb/users01.dbf';
6> release channel dev1;
7> }

备份控制文件
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4>  format '/tmp/hotbak/controlfile'
5> (current controlfile);
6> release channel dev1;
7> }

恢复表空间
rman target / nocatalog
RMAN> startup mount
RMAN> restore tablespace users;
RMAN> recover tablespace users;
RMAN> exit

Datafile recovery 数据文件恢复
        RMAN> run {
       2> allocate channel dev1 type disk;
       3> sql "alter tablespace users offline immediate";
       4> restore datafile 4;
       5> recover datafile 4;
       6> sql "alter tablespace users online";
       7> release channel dev1;
       8> }
恢复控制文件

rman>startup nomount;
rman>set dbid=2347671489
rman>restore controlfile from autobackup 或 rman>restore controlfile from
'/opt/arch/ct_c-2347671489-20060630-00'
rman>alter database open resetlogs;
RMAN> startup mount;
恢复数据库
RMAN> restore database;
RMAN> recover database;
RMAN>alter database open resetlogs;
恢复完毕。

   上面从恢复控制文件开始,讲述的是,只要你有数据库的备份文件和备份时控制文件,才可以
进行恢复,就算重装也可以。
再说几个rman常用命令:
list backup  查看备份信息
List backup summary  查看备份汇总信息
List backup of datafile ‘file name’
list incarnation of database;   查看具体的备份信息
Crosscheck命令
检查磁盘或磁带上的备份或拷贝是否正确,并更新备份或者拷贝的状态
Crosscheck backup;
Crosscheck archivelog all;
Delete [noprompt] expired backup命令删除过期备份
也可以用List来查看相应的报告
LIST EXPIRED BACKUP;
LIST EXPIRED BACKUP SUMMARY;

Delete 命令
Delete命令可以用来删除指定的备份或者用来删除废弃或者是过期的备份集
如删除指定的备份集与备份片
RMAN> DELETE BACKUPPIECE 101;
RMAN> DELETE CONTROLFILECOPY '/tmp/control01.ctl';
RMAN> DELETE BACKUP OF TABLESPACE users DEVICE TYPE sbt;
删除过期或者废弃了的备份
RMAN> DELETE EXPIRED BACKUP;
RMAN> DELETE NOPROMPT OBSOLETE;
RMAN> DELETE OBSOLETE REDUNDANCY = 3;
RMAN> DELETE OBSOLETE RECOVERY WINDOW OF 7 DAYS;

删除指定的备份归档
RMAN> DELETE NOPROMPT ARCHIVELOG UNTIL SEQUENCE = 300;

再贴几个备份脚本:
全库备份脚本:
#!/bin/sh
date=`date +%Y%m%d`
export ORACLE_BASE=/opt/ora9
export ORACLE_HOME=/opt/ora9/product/9.2.0.4
export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin
export ORACLE_OWNER=oracle
export ORACLE_SID=oradb
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
/opt/ora9/product/9.2.0.4/bin/rman target / <run {
backup
tag 'dbfull'
format '/tmp/dbfull%u_%s_%p_%T'
database;
}
exit;
EOF
rm /opt/arch/* -rf
  下面为增量备份脚本,增量备份分为0级,1级,2级,0级为基础备份,1级为0级增量,恢复时
恢复0级,再恢复1级,oracle9i增量备份也要进行全库扫描,oracle10G在这方面有专门的改善。
增量备份的好处是减小备份文件大小,但同样也增加恢复时的时间和复杂度,我更加适合数据量
特别的数据库。
   
0级备份脚本
#!/bin/sh
date=`date +%Y%m%d`
export ORACLE_BASE=/opt/ora9
export ORACLE_HOME=/opt/ora9/product/9.2.0.4
export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin
export ORACLE_OWNER=oracle
export ORACLE_SID=oradb
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
/opt/ora9/product/9.2.0.4/bin/rman target / <run {
backup
incremental level 0
tag 'db0'
format '/tmp/db0%u_%s_%p_%T'
database;
#plus archivelog
#delete all input;
}
exit;
EOF
rm /opt/arch/* -rf

1级备份
#!/bin/sh
date=`date +%Y%m%d`
export ORACLE_BASE=/opt/ora9
export ORACLE_HOME=/opt/ora9/product/9.2.0.4
export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin
export ORACLE_OWNER=oracle
export ORACLE_SID=oradb
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
/opt/ora9/product/9.2.0.4/bin/rman target / <run{
backup
incremental level 1
tag 'db1'
format '/tmp/db1%u_%s_%p_%T'
database;
#plus archivelog
#delete all input;
}
exit;
EOF
  如果出现故障,恢复的方法参考上面的就可以了,把相应该的备份文件控制文件和归档日志都
放在相对的位置就可以进恢复了。

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

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

注册时间:2011-05-04

  • 博文量
    9
  • 访问量
    13844