RMAN 备份常用脚本

1988阅读 0评论2009-01-06 liyf0371
分类:Oracle

 OS:RHEL 3;RMAN 备份信息保存在恢复目录中,恢复目录建立在所要备份数据库(testdb)以外的另一个数据库(cata)上。

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

上一篇:Linux常用命令
下一篇:RMAN实验总结