Oracle backup script (RMAN/EXP)

Source: Internet
Author: User

Environment:
 
OEL + Oracle 11.2.0.1
 
ORACLE_SID = orcl2
 
Create the following directory:
 
[Root @ DBA2/] $ mkdir/backup
[Root @ DBA2/] $ mkdir/backup/0
[Root @ DBA2/] $ mkdir/backup/1
[Root @ DBA2/] $ mkdir/backup/2
[Root @ DBA2/] $ mkdir/backup/3
[Root @ DBA2/] $ mkdir/backup/4
[Root @ DBA2/] $ mkdir/backup/5
[Root @ DBA2/] $ mkdir/backup/6

Change owner:
 
[Root @ DBA2 ~] # Chown-R oracle: dba/backup/

The script content is as follows:
 
######################################## #################

### Backup. sh ###

######################################## #################

# Set Environment Variables

Export ORACLE_BASE =/opt/oracle
Export ORACLE_HOME = $ ORACLE_BASE/product/OraHome
Export ORACLE_SID = orcl2
Export ORACLE_OWNER = oracle
Export ORACLE_TERM = vt100
Export PATH = $ PATH: $ ORACLE_HOME/bin: $ HOME/bin
Export PATH = $ ORACLE_HOME/bin: $ ORACLE_HOME/Apache/bin: $ PATH
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib:/usr/local/lib
Export CLASSPATH = $ ORACLE_HOME/JRE: $ ORACLE_HOME/jlib: $ ORACLE_HOME/rdbms/jlib
Export CLASSPATH = $ CLASSPATH: $ ORACLE_HOME/network/jlib
Export PATH = $ PATH:/usr/sbin
Export PATH = $ PATH:/usr/bin
NLS_LANG = AMERICAN_AMERICA.WE8MSWIN1252
Export NLS_LANG

 

NOW = 'date + % W'
Rq = 'date + % Y % m % d % H % M % s'
RMAN = $ ORACLE_HOME/bin/rman
TARGET_CONNECT_STR =/
RMAN_LOG_FILE =/backup/$ NOW/$ ORACLE_SID.backup_all_out.log
CUSER = 'id | cut-d "("-f2 | cut-d ")"-f1'
FILE_NAME =/backup/$ NOW/$ ORACLE_SID. $ rq



If ["$ NOW" = "0"]
Then
BACKUP_TYPE = "incremental level 0"
Else
BACKUP_TYPE = "incremental level 1"
Fi

# Logical backup
Exp system/oracle direct = Y full = y file = $ FILE_NAME.logic log =/backup/$ NOW/orcl2_logic_backup.log

Cat/backup/$ NOW/orcl2_logic_backup.log> $ RMAN_LOG_FILE
Rm/backup/$ NOW/orcl2_logic_backup.log


# Physical backup
Pai_str ="
ORACLE_HOME = $ ORACLE_HOME
Export ORACLE_HOME
ORACLE_SID = $ ORACLE_SID
Export ORACLE_SID
Rq = $ rq
Export rq
$ RMAN target $ TARGET_CONNECT_STR msglog $ RMAN_LOG_FILE append <EOF
Run {
Allocate channel c1 type disk;
Allocate channel c2 type disk;
Backup as compressed backupset $ BACKUP_TYPE format '$ FILE_NAME.DATAFILE _ % s _ % t. bak' database;
SQL 'alter SYSTEM ARCHIVE LOG current ';
Backup as compressed backupset format' $ FILE_NAME.ARCHIVELOG _ % s _ % t. bak'
Archivelog from time 'sysdate-3 'until time 'sysdate' delete all input;
Release channel c1;
Release channel c2;
Delete noprompt expired backup;
Delete noprompt obsolete;
}
EOF
"
If ["$ CUSER" = "root"]
Then
Su-$ ORACLE_USER-c "$ pai_str"> $ RMAN_LOG_FILE
RSTAT = $?
Else
/Usr/bin/ksh-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

Related Article

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.