RMAN 备份常用脚本

1. 建立 RMAN 用户(create_rmanuser.sql)
create user rmanuser identified by 1234 default tablespace users temporary tablespace temp;
grant connect,resource,recovery_catalog_owner to rmanuser;
exit;

2. 建立恢复目录(create_catalog.rcv)
connect catalog rmanuser/1234@cata
create catalog tablespace users;
connect target sys/1234@testdb
register database;

3. 建立恢复目录 shell 脚本(create_catalog.sh)
#!/bin/bash

cd $HOME
. .bash_profile

export ORACLE_SID=cata
export NLS_LANG="american_america.WE8ISO8859P1"

cd $HOME/dbbat/recover
sqlplus sys/1234 as sysdba @create_rmanuser.sql

rman cmdfile=create_catalog.rcv msglog=$HOME/dblog/create_catalog.log

cd $HOME
. .bash_profile

4. RMAN 导出(exprman.sql)
userid=rmanuser/1234
buffer=32768
owner=rmanuser
file=/home/oracle/dbbak/rman.dmp
rows=Y
compress=Y


5. RMAN 导出 shell 脚本(exprman.sh)
#!/bin/bash

cd $HOME
. .bash_profile

export ORACLE_SID=cata
export NLS_LANG="american_america.WE8ISO8859P1"

cd $HOME/dbbat/backup
exp parfile = exprman.sql

cd $HOME
. .bash_profile

6. 整库备份(backup_full.rcv)
connect target sys/1234@testdb
connect catalog rmanuser/1234@cata

run{
    allocate channel c1 type disk;
    allocate channel c2 type disk;
    allocate channel c3 type disk;
    backup full tag 'dbfull' format '/u02/oradata/flash_recovery_area/full%u_%s_%p' database include current controlfile;
    sql 'alter system archive log current';
    backup filesperset 3 format '/u02/oradata/flash_recovery_area/arch%u_%s_%p' archivelog all delete all input;
    release channel c1;
    release channel c2;
    release channel c3;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

7. 整库备份 shell 脚本(backup_full.sh)
#!/bin/bash

cd $HOME
. .bash_profile

cd $HOME/dbbat/backup
rman cmdfile=backup_full.rcv msglog=$HOME/dblog/backup_full.log

/home/oracle/dbbat/backup/exprman.sh

8. 0 级备份(backup_0.rcv)
connect target sys/1234@testdb
connect catalog rmanuser/1234@cata

run{
    allocate channel c1 type disk;
    allocate channel c2 type disk;
    allocate channel c3 type disk;
    backup incremental level 0 cumulative tag 'db0' format '/u02/oradata/flash_recovery_area/db0%u_%s_%p' database skip readonly;
    sql 'alter system archive log current';
    backup filesperset 3 format '/u02/oradata/flash_recovery_area/arch%u_%s_%p' archivelog all delete all input;
    release channel c1;
    release channel c2;
    release channel c3;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

9. 0 级备份 shell 脚本(backup_0.sh)
#!/bin/bash

cd $HOME
. .bash_profile

cd $HOME/dbbat/backup
rman cmdfile=backup_0.rcv msglog=$HOME/dblog/backup_0.log

/home/oracle/dbbat/backup/exprman.sh

10. 1 级备份(backup_1.rcv)
connect target sys/1234@testdb
connect catalog rmanuser/1234@cata

run{
    allocate channel c1 type disk;
    allocate channel c2 type disk;
    allocate channel c3 type disk;
    backup incremental level 1 cumulative tag 'db1' format '/u02/oradata/flash_recovery_area/db1%u_%s_%p' database skip readonly;
    sql 'alter system archive log current';
    backup filesperset 3 format '/u02/oradata/flash_recovery_area/arch%u_%s_%p' archivelog all delete all input;
    release channel c1;
    release channel c2;
    release channel c3;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

11. 1 级备份 shell 脚本(backup_1.sh)
#!/bin/bash

cd $HOME
. .bash_profile

cd $HOME/dbbat/backup
rman cmdfile=backup_1.rcv msglog=$HOME/dblog/backup_1.log

/home/oracle/dbbat/backup/exprman.sh

12. 2 级备份(backup_2.rcv)
connect target sys/1234@testdb
connect catalog rmanuser/1234@cata

run{
    allocate channel c1 type disk;
    allocate channel c2 type disk;
    allocate channel c3 type disk;
    backup incremental level 2 cumulative tag 'db2' format '/u02/oradata/flash_recovery_area/db2%u_%s_%p' database skip readonly;
    sql 'alter system archive log current';
    backup filesperset 3 format '/u02/oradata/flash_recovery_area/arch%u_%s_%p' archivelog all delete all input;
    release channel c1;
    release channel c2;
    release channel c3;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

13. 2 级备份 shell 脚本(backup_2.sh)
#!/bin/bash

cd $HOME
. .bash_profile

cd $HOME/dbbat/backup
rman cmdfile=backup_2.rcv msglog=$HOME/dblog/backup_2.log

/home/oracle/dbbat/backup/exprman.sh 

14. Creating Recovery Catalog

1. Create tablespace

create tablespace cata datafile '/u01/oradata/shady/catalog_01.dbf' size 1024M

segment space management auto extent management local uniform;

2. Create catalog owner

create user cata identifed by cata default tablespace cata quota unlimited on cata;

3. Grant privileges

grant connect,resource to cata;

grant recovery_catalog_owner to cata;

4. Create catalog

C:/>rman catalog cata/cata@pitts

RMAN>create catalog tablespace cata;

5. Connect to target database

C:/>rman target sys/oracle@mahee 

RMAN>connect catalog cata/cata@pitts;

或者:

C:/>rman

RMAN>connect target sys/oracle@mahee

RMAN>connect catalog cata/cata@pitts

RMAN>quit

或者:

C:/>rman target sys/oracle@mahee catalog cata/cata@pitts

RMAN>

6. Register target database

RMAN>register database;

RMAN>list incarnation;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值