Oracle全备增量备份脚本,RMAN备份Oracle数据库脚本(包括全备与增量)

[oracle@11rac1 ~]$ cat hot_rman_backup.sh

#!/bin/sh

# $Header: hot_database_backup.sh,v 1.3 2010/08/04 17:56:02 $

#

# ---------------------------------------------------------------------------

# this script directory.

# ---------------------------------------------------------------------------

SHELL_HOME=/home/oracle

# ---------------------------------------------------------------------------

# Determine the timeexecuting this script.

# ---------------------------------------------------------------------------

RMAN_DATA=`date'+%Y%m%d%H'`

# ---------------------------------------------------------------------------

# test log directiry .  If not, run the following lines.

# ---------------------------------------------------------------------------

if [ ! -d "$SHELL_HOME/log"]

then

mkdir -p $SHELL_HOME/log

fi

# ---------------------------------------------------------------------------

# Put outputin.out. Changeasdesired.

# Note: outputdirectory requires write permission.

# ---------------------------------------------------------------------------

RMAN_LOG_FILE=${SHELL_HOME}/log/hot_rman_backup_${RMAN_DATA}.out

# ---------------------------------------------------------------------------

# You may want todeletetheoutputfile so that backup information does

# notaccumulate.  Ifnot,deletethe following lines.

# ---------------------------------------------------------------------------

if [ -f "$RMAN_LOG_FILE"]

then

rm -f "$RMAN_LOG_FILE"

fi

# ---------------------------------------------------------------------------

# rman image outputdirectory.

# ---------------------------------------------------------------------------

RMAN_IMAGE_DIR=/home/oracle/rman

echo "rman image output directory:${RMAN_IMAGE_DIR}">>$RMAN_LOG_FILE

# ---------------------------------------------------------------------------

# Log the start ofthis script.

# ---------------------------------------------------------------------------

echo Script $0 >> $RMAN_LOG_FILE

echo ==== started on`date` ==== >> $RMAN_LOG_FILE

echo >> $RMAN_LOG_FILE

# ---------------------------------------------------------------------------

# Replace/db/oracle/product/ora102, below,withthe Oracle home path.

# ---------------------------------------------------------------------------

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export ORACLE_HOME

# ---------------------------------------------------------------------------

# Replaceora102, below,withthe Oracle SIDofthe targetdatabase.

# ---------------------------------------------------------------------------

ORACLE_SID=power1

export ORACLE_SID

# ---------------------------------------------------------------------------

# Setthe targetconnectstring.

# Replace"sys/manager", below,withthe targetconnectstring.

# ---------------------------------------------------------------------------

TARGET_CONNECT_STR=sys/manager

# ---------------------------------------------------------------------------

# Setthe Oracle Recovery Managername.

# ---------------------------------------------------------------------------

RMAN=$ORACLE_HOME/bin/rman

# ---------------------------------------------------------------------------

# Print outthe valueofthe variablessetbythis 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

# ---------------------------------------------------------------------------

# Print outthe valueofthe variablessetbybphdb.

# ---------------------------------------------------------------------------

echo  >> $RMAN_LOG_FILE

# ---------------------------------------------------------------------------

# NOTE: This script assumes that the databaseisproperly opened. If desired,

# this would be the place toverify that.

# ---------------------------------------------------------------------------

echo >> $RMAN_LOG_FILE

# ---------------------------------------------------------------------------

# If this script isexecutedfroma NetBackup schedule, NetBackup

# sets an NB_ORA environment variable based onthe schedule type.

# The NB_ORA variable isthenusedtodynamicallysetBACKUP_TYPE

# Forexample,when:

#     schedule type isBACKUP_TYPEis

#     ----------------                --------------

# Automatic FullINCREMENTALLEVEL=0

# Automatic Differential Incremental INCREMENTAL LEVEL=1

# Automatic Cumulative Incremental   INCREMENTAL LEVEL=1 CUMULATIVE

#

# Foruserinitiated backups, BACKUP_TYPE defaultstoincremental

# level0 (full).Tochange thedefaultforauserinitiated

# backup toincrementalorincremental cumulative, uncomment

# one ofthe following two lines.

# BACKUP_TYPE="INCREMENTAL LEVEL=1"

# BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"

#

# Note that we use incremental level0tospecifyfullbackups.

# That isbecause, although they are identicalincontent,only

# the incremental level0 backup can have incremental backupsof

# level> 0 appliedtoit.

# ---------------------------------------------------------------------------

INCR_DATA=`date'+%A'`

if [ "$INCR_DATA"="Sunday"]

then

echo "Full backup requested">> $RMAN_LOG_FILE

BACKUP_TYPE="INCREMENTAL LEVEL=0"

else

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

echo "BACKUP_TYPE">> $RMAN_LOG_FILE

echo ${BACKUP_TYPE} >> $RMAN_LOG_FILE

# ---------------------------------------------------------------------------

# Call Recovery Manager toinitiate the backup. This example doesnotuse a

# Recovery Catalog. If you choose touse one,replacetheoption'nocatalog'

# fromthe rman command line belowwiththe

# 'catalog /@'statement.

#

# Note: Anyenvironment variables neededatruntimebyRMAN

#       must be setandexported within the switchuser(su) command.

# ---------------------------------------------------------------------------

#  Backs up the whole database.  This backupispartofthe incremental

#  strategy (this means it can have incremental backups oflevels > 0

#  applied toit).

#

#  We do notneedtoexplicitly request the control filetobe included

#  inthis backup,asitisautomatically included eachtimefile 1of

#  the system tablespace isbacked up (the inference:asitisa whole

#  databasebackup, file 1ofthe system tablespace will be backed up,

#  hence the controlfile will also be included automatically).

#

#  Typically, a level0 backup would be doneatleast once a week.

#

#  The scenario assumes:

#     o you are backing your databaseuptotwo tape drives

#     o you want each backup settoinclude a maximumof5 files

#     o you wish toinclude offline datafiles,andread-onlytablespaces,

#       inthe backup

#     o you want the backup tocontinueifanyfiles are inaccessible.

#     o you are notusing a Recovery Catalog

#     o you are explicitly backing up the control file.  Since you are

#       specifying nocatalog, the controlfile backup that occurs

#       automatically asthe resultofbacking up the system fileis

#       notsufficient; it willnotcontain recordsforthe backup that

#       iscurrentlyinprogress.

#     o you want toarchive thecurrentlog, back upallthe

#       archive logs using two channels, putting a maximum of20 logs

#       ina backupset,anddeleting them once the backupiscomplete.

#

#  Note that the format string isconstructedtoguarantee uniquenessand

#  toenhance NetBackupforOracle backupandrestore performance.

#

#

#  NOTE WHENUSING NET SERVICENAME:Whenconnectingtoadatabase

#  using a net service name, you must use a send commandora parms operandto

#  specify environment variables.  Inother words,whenaccessing adatabase

#  through a listener, the environment variables setatthe systemlevelarenot

#  visible whenRMANisrunning.Formore informationonthe environment

#  variables, please refer tothe NetBackupforOracle Admin. Guide.

#

# ---------------------------------------------------------------------------

ORACLE_HOME=$ORACLE_HOME

export ORACLE_HOME

ORACLE_SID=$ORACLE_SID

export ORACLE_SID

$RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append <

RUN {

ALLOCATE CHANNEL ch00 TYPE DISK;

ALLOCATE CHANNEL ch01 TYPE DISK;

# crosscheck archivelog

CROSSCHECK ARCHIVELOG ALL;

# crosscheck backup image

CROSSCHECK BACKUP;

#DELETEOBSOLETE BACKUP IMAGE

DELETENOPROMPT OBSOLETE;

#DELETEEXPIRED BACKUP IMAGE

DELETENOPROMPT EXPIRED BACKUP;

BACKUP

$BACKUP_TYPE

SKIP INACCESSIBLE

TAG hot_db_bk_level0

FILESPERSET 2

# recommended format

FORMAT '${RMAN_IMAGE_DIR}/bk_%s_%p_%t'

DATABASE;

sql 'alter system archive log current';

RELEASE CHANNEL ch00;

RELEASE CHANNEL ch01;

# backup allarchive logs

ALLOCATE CHANNEL ch00 TYPE DISK;

ALLOCATE CHANNEL ch01 TYPE DISK;

BACKUP

filesperset 20

FORMAT '${RMAN_IMAGE_DIR}/al_%s_%p_%t'

ARCHIVELOG ALLDELETEINPUT;

RELEASE CHANNEL ch00;

RELEASE CHANNEL ch01;

#

# Note: During the process ofbacking up thedatabase, RMAN also backs up the

# control file.  This version ofthe control file doesnotcontain the

# information about the currentbackup because"nocatalog"has been specified.

# Toinclude the information about thecurrentbackup, the control file should

# be backed up asthelaststepofthe RMANsection.  This step wouldnotbe

# necessary if we were using a recovery catalog orauto control file backups.

#

ALLOCATE CHANNEL ch00 TYPE DISK;

BACKUP

# recommended format

FORMAT '${RMAN_IMAGE_DIR}/cntrl_%s_%p_%t'

CURRENTCONTROLFILE;

RELEASE CHANNEL ch00;

}

exit

EOF

# ---------------------------------------------------------------------------

# Print datetologfile

# ---------------------------------------------------------------------------

echo Script $0 >> $RMAN_LOG_FILE

echo ==== endon`date` ==== >> $RMAN_LOG_FILE

echo >> $RMAN_LOG_FILE

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值