1. 程式人生 > >RMAN 備份常用指令碼 && RAC RMAN

RMAN 備份常用指令碼 && RAC RMAN

 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/[email protected]
create catalog tablespace users;
connect target sys/[email protected]
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/[email protected]
connect catalog rmanuser/[email protected]

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

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

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

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

refer:

rac  rman: