# make direcory for backset file and scripts file,in my case /backup/db_bak
cd /backup/db_bak
mkdir scripts logs rman
# the following is contents of rman_backup_sh
vi /backup/db_bak/scripts/rman_backup_sh
#!/bin/bash # author: anbob.com # desc: rman backup database level 0 # contact: [email protected] export ORACLE_HOME=/oracle/product/11.2.0/db_1 export ORACLE_SID=pora40 RMAN_LOG_FILE=/backup/db_bak/logs/rman_database_backup.`date +%y%m%d%H%M`.out # ----------------------------------------------------------------- # Initialize the log file. # ----------------------------------------------------------------- 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_USER=oracle RMAN=$ORACLE_HOME/bin/rman BACKUP_TYPE="INCREMENTAL LEVEL 0" # --------------------------------------------------------------------------- # Print out the value of the variables set by this script. # --------------------------------------------------------------------------- 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 "BACKUP_TYPE: $BACKUP_TYPE">> $RMAN_LOG_FILE # --------------------------------------------------------------------------- echo >> $RMAN_LOG_FILE exec 1>> $RMAN_LOG_FILE 2>&1 $RMAN target / nocatalog <<-EOF RUN { ALLOCATE CHANNEL ch00 TYPE disk; ALLOCATE CHANNEL ch01 TYPE disk; BACKUP $BACKUP_TYPE SKIP INACCESSIBLE TAG hot_db_bk_level0 FORMAT ‘/backup/db_bak/rman/pora40_db_lv0_%T_%s_bak‘ DATABASE; RELEASE CHANNEL ch00; RELEASE CHANNEL ch01; ALLOCATE CHANNEL ch00 TYPE disk; ALLOCATE CHANNEL ch01 TYPE disk; BACKUP SKIP INACCESSIBLE FORMAT ‘/backup/db_bak/rman/pora40_arh_lv0_%T_%s_bak‘ ARCHIVELOG ALL DELETE INPUT; RELEASE CHANNEL ch00; RELEASE CHANNEL ch01; BACKUP CURRENT CONTROLFILE FORMAT ‘/backup/db_bak/rman/pora40_ctrl_%T_%s_bak‘; crosscheck backup; report obsolete; delete noprompt force obsolete; } EOF echo "****ATTN: Database backup is finished. The time is `date`.****"
[[email protected] scripts]$ ./rman_backup_sh
# add crontab job
[[email protected] rman]# ll -rth
-rw-r----- 1 oracle oinstall 626M Jun 26 13:19 pora40_db_lv0_20130626_13_bak
-rw-r----- 1 oracle oinstall 166K Jun 26 13:19 pora40_arh_lv0_20130626_16_bak
-rw-r----- 1 oracle oinstall 9.4M Jun 26 13:19 pora40_ctrl_20130626_18_bak
时间: 2024-11-09 17:24:42