Oracle backup script

Source: Internet
Author: User

Oracle backup script


Oracle9i backup script:

Full backup (level 0 ):
Bash-3.00 $ more ora9i_rman_bak.sh | grep-v "#"


CUSER = 'id | cut-d "("-f2 | cut-d ")"-f1'


RMAN_LOG_FILE =$ {0}. out


If [-f "$ RMAN_LOG_FILE"]
Then
Rm-f "$ RMAN_LOG_FILE"
Fi


Echo> $ RMAN_LOG_FILE
Chmod 666 $ RMAN_LOG_FILE


Echo Script $0 >>$ RMAN_LOG_FILE
Echo === started on 'date' ==>> $ RMAN_LOG_FILE
Echo> $ RMAN_LOG_FILE


ORACLE_HOME =/orahome/oracle/product/9.2.0
Export ORACLE_HOME


ORACLE_SID = bims
Export ORACLE_SID


ORACLE_USER = oracle


TARGET_CONNECT_STR =/


RMAN = $ ORACLE_HOME/bin/rman


Echo> $ RMAN_LOG_FILE
Echo "RMAN: $ RMAN" >>$ RMAN_LOG_FILE
Echo "ORACLE_SID: $ ORACLE_SID" >>$ RMAN_LOG_FILE
Echo "ORACLE_USER: $ ORACLE_USER" >>$ RMAN_LOG_FILE
Echo "ORACLE_HOME: $ ORACLE_HOME" >>$ RMAN_LOG_FILE


Echo> $ RMAN_LOG_FILE
Echo "NB_ORA_FULL: $ NB_ORA_FULL" >>$ RMAN_LOG_FILE
Echo "NB_ORA_INCR: $ NB_ORA_INCR"> $ RMAN_LOG_FILE
Echo "NB_ORA_CINC: $ NB_ORA_CINC"> $ RMAN_LOG_FILE
Echo "NB_ORA_SERV: $ NB_ORA_SERV"> $ RMAN_LOG_FILE
Echo "NB_ORA_POLICY: $ NB_ORA_POLICY" >>$ RMAN_LOG_FILE


Echo> $ RMAN_LOG_FILE

If ["$ NB_ORA_FULL" = "1"]
Then
Echo "Full backup requested" >>$ RMAN_LOG_FILE
BACKUP_TYPE = "incremental level = 0"

Elif ["$ NB_ORA_INCR" = "1"]
Then
Echo "Differential incremental backup requested"> $ RMAN_LOG_FILE
BACKUP_TYPE = "incremental level = 1"

Elif ["$ NB_ORA_CINC" = "1"]
Then
Echo "Cumulative incremental backup requested"> $ RMAN_LOG_FILE
BACKUP_TYPE = "incremental level = 1 CUMULATIVE"

Elif ["$ BACKUP_TYPE" = ""]
Then
Echo "Default-Full backup requested"> $ RMAN_LOG_FILE
BACKUP_TYPE = "incremental level = 0"
Fi



Pai_str ="
ORACLE_HOME = $ ORACLE_HOME
Export ORACLE_HOME
ORACLE_SID = $ ORACLE_SID
Export ORACLE_SID
NLS_DATE_FORMAT = 'yyyy-mm-dd hh24: mi: ss'
Export NLS_DATE_FORMAT
$ RMAN target $ TARGET_CONNECT_STR nocatalog msglog $ RMAN_LOG_FILE append <EOF
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
RUN {
Allocate channel ch00 TYPE disk;
Allocate channel ch01 TYPE disk;
Allocate channel ch02 TYPE disk;
Allocate channel ch03 TYPE disk;
BACKUP
$ BACKUP_TYPE
SKIP INACCESSIBLE
TAG hot_db_bk_level0
FILESPERSET 5
FORMAT '/orahomebak/backup/database/bk _ % s _ % p _ % t'
DATABASE;
SQL 'alter system archive log current ';
Release channel ch00;
Release channel ch01;
Release channel ch02;
Release channel ch03;
Allocate channel ch00 TYPE disk;
Allocate channel ch01 TYPE disk;
BACKUP
Filesperset 20
FORMAT '/orahomebak/backup/arch/al _ % s _ % p _ % t'
Archivelog all delete input;
Release channel ch00;
Release channel ch01;
Allocate channel ch00 TYPE disk;
BACKUP
FORMAT '/orahomebak/backup/database/cntrl _ % s _ % p _ % t'
Current controlfile;
Release channel ch00;
}
EOF
"

If ["$ CUSER" = "root"]
Then
Su-$ ORACLE_USER-c "$ pai_str"> $ RMAN_LOG_FILE
RSTAT = $?
Else
/Usr/bin/sh-c "$ CMD_STR"> $ RMAN_LOG_FILE
RSTAT = $?
Fi


If ["$ RSTAT" = "0"]
Then
LOGMSG = "ended successfully"
Else
LOGMSG = "ended in error"
Fi

Echo> $ RMAN_LOG_FILE
Echo Script $0 >>$ RMAN_LOG_FILE
Echo ===$ LOGMSG on 'date' ====>> $ RMAN_LOG_FILE
Echo> $ RMAN_LOG_FILE

Exit $ RSTAT





Differential incremental backup (level 1 ):

Bash-3.00 $ more ora9i_rman_bak.sh | grep-v "#"


CUSER = 'id | cut-d "("-f2 | cut-d ")"-f1'


RMAN_LOG_FILE =$ {0}. out


If [-f "$ RMAN_LOG_FILE"]
Then
Rm-f "$ RMAN_LOG_FILE"
Fi


Echo> $ RMAN_LOG_FILE
Chmod 666 $ RMAN_LOG_FILE


Echo Script $0 >>$ RMAN_LOG_FILE
Echo === started on 'date' ==>> $ RMAN_LOG_FILE
Echo> $ RMAN_LOG_FILE


ORACLE_HOME =/orahome/oracle/product/9.2.0
Export ORACLE_HOME


ORACLE_SID = bims
Export ORACLE_SID


ORACLE_USER = oracle


TARGET_CONNECT_STR =/


RMAN = $ ORACLE_HOME/bin/rman


Echo> $ RMAN_LOG_FILE
Echo "RMAN: $ RMAN" >>$ RMAN_LOG_FILE
Echo "ORACLE_SID: $ ORACLE_SID" >>$ RMAN_LOG_FILE
Echo "ORACLE_USER: $ ORACLE_USER" >>$ RMAN_LOG_FILE
Echo "ORACLE_HOME: $ ORACLE_HOME" >>$ RMAN_LOG_FILE


Echo> $ RMAN_LOG_FILE
Echo "NB_ORA_FULL: $ NB_ORA_FULL" >>$ RMAN_LOG_FILE
Echo "NB_ORA_INCR: $ NB_ORA_INCR"> $ RMAN_LOG_FILE
Echo "NB_ORA_CINC: $ NB_ORA_CINC"> $ RMAN_LOG_FILE
Echo "NB_ORA_SERV: $ NB_ORA_SERV"> $ RMAN_LOG_FILE
Echo "NB_ORA_POLICY: $ NB_ORA_POLICY" >>$ RMAN_LOG_FILE


Echo> $ RMAN_LOG_FILE
Echo "Differential incremental backup requested"> $ RMAN_LOG_FILE



Pai_str ="
ORACLE_HOME = $ ORACLE_HOME
Export ORACLE_HOME
ORACLE_SID = $ ORACLE_SID
Export ORACLE_SID
NLS_DATE_FORMAT = 'yyyy-mm-dd hh24: mi: ss'
Export NLS_DATE_FORMAT
$ RMAN target $ TARGET_CONNECT_STR nocatalog msglog $ RMAN_LOG_FILE append <EOF
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
RUN {
Allocate channel ch00 TYPE disk;
Allocate channel ch01 TYPE disk;
Allocate channel ch02 TYPE disk;
Allocate channel ch03 TYPE disk;
BACKUP
Incremental level 1
SKIP INACCESSIBLE
TAG hot_db_bk_level1
FILESPERSET 5
FORMAT '/orahomebak/backup/database/bk _ % s _ % p _ % t'
DATABASE;
SQL 'alter system archive log current ';
Release channel ch00;
Release channel ch01;
Release channel ch02;
Release channel ch03;
Allocate channel ch00 TYPE disk;
Allocate channel ch01 TYPE disk;
BACKUP
Filesperset 20
FORMAT '/orahomebak/backup/arch/al _ % s _ % p _ % t'
Archivelog all delete input;
Release channel ch00;
Release channel ch01;
Allocate channel ch00 TYPE disk;
BACKUP
FORMAT '/orahomebak/backup/database/cntrl _ % s _ % p _ % t'
Current controlfile;
Release channel ch00;
}
EOF
"

If ["$ CUSER" = "root"]
Then
Su-$ ORACLE_USER-c "$ pai_str"> $ RMAN_LOG_FILE
RSTAT = $?
Else
/Usr/bin/sh-c "$ CMD_STR"> $ RMAN_LOG_FILE
RSTAT = $?
Fi


If ["$ RSTAT" = "0"]
Then
LOGMSG = "ended successfully"
Else
LOGMSG = "ended in error"
Fi

Echo> $ RMAN_LOG_FILE
Echo Script $0 >>$ RMAN_LOG_FILE
Echo ===$ LOGMSG on 'date' ====>> $ RMAN_LOG_FILE
Echo> $ RMAN_LOG_FILE

Exit $ RSTAT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.