ITPub博客

首页 > Linux操作系统 > Linux操作系统 > RMAN Complete

RMAN Complete

原创 Linux操作系统 作者:hjianping 时间:2011-04-24 14:11:31 0 删除 编辑

RMAN权限
使用catalog模式授予recovery_catalog_owner权限即可,使用nocatalog模式,就得sysdba权限

backup database plus archivelog;
===========================================================================
使用alter system archive log current命令来完成一个日志切换操作;
进程备份现存的所有归档的重做日志;
开始执行实际的数据库备份操作;
使用alter system archive log current命令完成另一个日志切换操作;
使用backup archivelog all命令备份剩余的归档的重做日志;
执行控制文件和参数文件的自动备份操作。
===========================================================================

全库归档一起备,策略为份数冗余,保留2份备份,删除所有归档日志,删除陈旧备份
$ rman target sys/password@ora10 catalog scott/password@oratest
----------------------------------------------------------------------------------
run {
      configure retention policy to redundancy 2;
      allocate channel ch1 type disk;
      backup database
      format '/backup/rmanfiles/%d_dbfile_%I_%T_%s'
      include current controlfile
      plus archivelog format='/backup/rmanfiles/%d_arcfile_%I_%T_%s' delete input;
      delete noprompt obsolete;
      release channel ch1;
    }
----------------------------------------------------------------------------------
执行过程是:
1、归档日志
2、备份归档
3、删除归档
4、全备数据库(含control and spfile)
5、归档日志
6、备份归档
7、删除归档
8、删除陈旧备份

保留2份备份,删除上次备份前的归档日志,删除陈旧备份
$ rman target sys/password@ora10 nocatalog log=/backup/rmanfiles/rman.log
------------------------------------------------------------------------------------
run {
      configure retention policy to redundancy 2;
      allocate channel ch1 type disk;
      backup database
      format '/backup/rmanfiles/%d_dbfile_%I_%T_%s'
      include current controlfile
      plus archivelog format='/backup/rmanfiles/%d_arcfile_%I_%T_%s';
      delete noprompt obsolete;
      release channel ch1;
    }
------------------------------------------------------------------------------------

只删除上次备份前的归档日志,#每个备份集最多三个文件
----------------------------------------------------------------------
run {
      configure retention policy to redundancy 5;
      # configure retention policy to recovery window of 7 days;
      allocate channel ch1 type disk;
      backup database
      # filesperset 3
      format '/backup/rmanfiles/%d_dbfile_%I_%T_%s'
      include current controlfile
      plus archivelog format='/backup/rmanfiles/%d_arcfile_%I_%T_%s';
      delete noprompt obsolete;
      release channel ch1;
    }
----------------------------------------------------------------------


不完全恢复数据库(删除全部数据文件、日志文件、控制文件、参数文件、密码文件)
----------------------------------------------------------------------------------
1、重建密码文件
$ cd $ORACLE_HOME/dbs
$ $ORACLE_HOME/bin/orapwd file=orapwora10 password=password entries=3

2、恢复spfile文件
$ rman target sys/password@ora10 catalog scott/password@oratest
RMAN> startup nomount;
RMAN> restore spfile from '/backup/rmanfiles/ORA10_dbfile_723011933_20110117_26';
RMAN> shutdown immediate
RMAN> exit

3、恢复控制文件
$ sqlplus / as sysdba
SQL> shutdown immediate;
SQL> exit
$ rman target sys/password@ora10 catalog scott/password@oratest
RMAN> startup nomount;
RMAN> restore controlfile from '/backup/rmanfiles/ORA10_dbfile_723011933_20110117_26';
RMAN> alter database mount;
RMAN> exit;

4.1、恢复数据库(不完全)
$ sqlplus / as sysdba
SQL> shutdown immediate;
SQL> exit
$ rman target sys/password@ora10 catalog scott/password@oratest
run {
      startup mount
      restore database;
      recover database;
    }
RMAN> sql 'alter database open resetlogs';

4.2、恢复数据库到指定时间(不完全)
$ sqlplus / as sysdba
SQL> shutdown immediate;
SQL> exit
$ rman target sys/password@ora10 catalog scott/password@oratest
run {
      startup mount
      sql "alter session set nls_date_format=''yyyy-mm-dd hh24:mi:ss'' ";
      set until time='2011-01-17 07:50:00';
      restore database;
      recover database;
      sql 'alter database open resetlogs';
    }
----------------------------------------------------------------------------------


RMAN增量备份脚本

备份策略
------------------------------------------------
每周日   做0级备份
每周一,四  做1级备份
每周二,三,五,六 做2级备份
------------------------------------------------
00 4 * * 0  /u01/oracle/app/rman_bak0.sh
00 4 * * 1,4  /u01/oracle/app/rman_bak1.sh
00 4 * * 2,3,5,6  /u01/oracle/app/rman_bak2.sh
------------------------------------------------

0级备份
----------------------------------------------------------------------
run {
      allocate channel ch1 type disk;
      backup incremental level 0 database
      format '/backup/rmanfiles/%d_dbfile_%I_%T_%s'
      include current controlfile
      plus archivelog format='/backup/rmanfiles/%d_arcfile_%I_%T_%s';
      delete noprompt obsolete;
      release channel ch1;
    }
----------------------------------------------------------------------

1级备份
----------------------------------------------------------------------
run {
      allocate channel ch1 type disk;
      backup incremental level 1 database
      format '/backup/rmanfiles/%d_dbfile_%I_%T_%s'
      include current controlfile
      plus archivelog format='/backup/rmanfiles/%d_arcfile_%I_%T_%s';
      delete noprompt obsolete;
      release channel ch1;
    }
----------------------------------------------------------------------

2级备份
----------------------------------------------------------------------
run {
      allocate channel ch1 type disk;
      backup incremental level 2 database
      format '/backup/rmanfiles/%d_dbfile_%I_%T_%s'
      include current controlfile
      plus archivelog format='/backup/rmanfiles/%d_arcfile_%I_%T_%s';
      delete noprompt obsolete;
      release channel ch1;
    }
----------------------------------------------------------------------


RAC模式下的RMAN备份
---------------------------------------------------------------------------------------------------
# 先登陆本地rman,再分配远程连接通道到rac节点db1,进行数据的零级备份
$ rman nocatalog target username/passwd
run {
      allocate channel d1 device type disk connect'username/passwd@db1';
      allocate channel d2 device type disk connect'username/passwd@db1';
      backup incremental level 0 database format '/backup/back/full_level0_%u';
      backup current controlfile format '/backup/back/control_bak_%t';
      release channel d1 ;
      release channel d2 ;
    }

# 先登陆本地rman,再分配远程连接通道,备份归档日志
$ rman nocatalog target username/passwd
run {
      allocate channel d3 type disk connect'username/passwd@db1'format '/backup/back/arc_rac1_%u';
      allocate channel d4 type disk connect'username/passwd@db2'format '/backup/back/arc_rac2_%u';
      sql 'alter system archive log current';
      backup filesperset 3 archivelog all delete all input;
      release channel d3;
      release channel d4;
    }

# 先登陆本地rman,再分配远程连接通道,备份归档日志
$ rman nocatalog target username/passwd
run {
      allocate channel d3 type disk connect'username/passwd@db1'format '/backup/back/arc_rac1_%u';
      allocate channel d4 type disk connect'username/passwd@db2'format '/backup/back/arc_rac2_%u';
      sql 'alter system archive log current';
      backup filesperset 3 archivelog all delete all input;
      release channel d3;
      release channel d4;
    }
--------------------------------------------------------------------------------------------------

 

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

上一篇: RMAN基础
请登录后发表评论 登录
全部评论

注册时间:2011-04-24

  • 博文量
    80
  • 访问量
    75419