Oracle   发布时间:2022-05-17  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了NBU备份oracle全备脚本注释大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

root@gzwgnbu1 # more hot_database_BACkup.sh

#!/bin/sh

# $header: hot_database_BACkup.sh,v 1.3 2010/08/04 17:56:02 $

#

#bcpyrght

#*********************************************************************

#* $VRTScprght: copyright 2014 Symantec Corporation,All Rights Reserved $ *

#*********************************************************************

#ecpyrght

#

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

# hot_database_BACkup.sh

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

# This script uses Recovery Manager to take a hot (inconsistent) database

# BACkup. A hot BACkup is inconsistent because portions of the database are

# being modifIEd and written to the disk while the BACkup is progressing.

# You must run your database in ARCHIVELOG mode to make hot BACkups. it is

# assumed that this script will be executed by user root. In order for RMAN

# to work properly we switch user (su -) to the @R_673_3393@ account before

# execution. If this script runs under a user account that has @R_673_3393@

# privilege,it will be executed using this user's account.

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


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

# Determine the user which is execuTing this script.

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

CUSER=`ID |cut -d"(" -f2 | cut -d ")" -f1`

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

# Put output in <this file name>.out. Change as desired.

# Note: output directory requires write permission.

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


RMAN_LOG_file=${0}.out


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

# You may want to delete the output file so that BACkup information does

# not accumulate. If not,delete the following lines.

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


if [ -f "$RMAN_LOG_file" ]

then

rm -f "$RMAN_LOG_file"

fi


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

# Initialize the log file.

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

echo >> $RMAN_LOG_file

chmod 666 $RMAN_LOG_file

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

# Log the start of this script.

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

echo Script $0 >> $RMAN_LOG_file

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

echo >> $RMAN_LOG_file

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

# replace /db/Oracle/product/ora102,below,with the Oracle home path.

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


OracLE_HOME=/db/Oracle/product/ora102 #Oracle目录

export OracLE_HOME


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

# replace ora102,with the Oracle SID of the target database.

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


oracle_sid=ora102 #备份的数据库

export oracle_sid


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

# replace ora102,with the @R_673_3393@ user ID (account).

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


OracLE_USER=ora102 备份使用的系统用户


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

# Set the target connect String.

# replace "sys/manager",with the target connect String.

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


TARGET_CONNECT_STR=sys/manager ### sys/manager 改为 / ###

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

# Set the Oracle Recovery Manager name.

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


RMAN=$OracLE_HOME/bin/RMAN #NBU中RMAN命令的位置


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

# 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


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

# Print out the value of the variables set by bphdb.

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


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


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

# NOTE: This script assumes that the database is properly opened. @R_801_9792@esired,

# this would be the place to verify that.

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


echo >> $RMAN_LOG_file

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

# If this script is executed from a NetBACkup schedule,NetBACkup

# sets an NB_ORA environment variable based on the schedule type.

# The NB_ORA variable is then used to dynamically set BACKUP_TYPE

# For example,when:

# schedule type is BACKUP_TYPE is

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

# automatic Full INCREMENTAL LEVEL=0

# automatic Differential Incremental INCREMENTAL LEVEL=1

# automatic Cumulative Incremental INCREMENTAL LEVEL=1 CUMulATIVE

#

# For user initiated BACkups,BACKUP_TYPE defaults to incremental

# level 0 (full). To change the default for a user initiated

# BACkup to incremental or incremental cumulative,uncomment

# one of the following two lines.

# BACKUP_TYPE="INCREMENTAL LEVEL=1"

# BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMulATIVE"

#

# Note that we use incremental level 0 to specify full BACkups.

# That is because,although they are IDentical in content,only

# the incremental level 0 BACkup can have incremental BACkups of

# level > 0 applIEd to it.

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

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



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

# Call Recovery Manager to initiate the BACkup. This example does not use a

# Recovery Catalog. If you choose to use one,replace the option 'nocatalog'

# from the RMAN command line below with the

# 'catalog <userID>/<passwd>@<net service name>' statement.

#

# Note: Any environment variables needed at run time by RMAN

# must be set and exported within the switch user (su) command.

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

# BACks up the whole database. This BACkup is part of the incremental

# strategy (this means it can have incremental BACkups of levels > 0

# applIEd to it).

#

# We do not need to explicitly request the control file to be included

# in this BACkup,as it is automatically included each time file 1 of

# the system tablespace is BACked up (the inference: as it is a whole

# database BACkup,file 1 of the system tablespace will be BACked up,

# hence the CONTROLFILE will also be included automatically).

#

# Typically,a level 0 BACkup would be done at least once a week.

#

# The scenario assumes:

# o you are BACking your database up to two tape drives

# o you want each BACkup set to include a maximum of 5 files

# o you wish to include offline DATAFILEs,and read-only tablespaces,

# in the BACkup

# o you want the BACkup to conTinue if any files are inaccessible.

# o you are not using a Recovery Catalog

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

# specifying nocatalog,the CONTROLFILE BACkup that occurs

# automatically as the result of BACking up the system file is

# not sufficIEnt; it will not contain records for the BACkup that

# is currently in progress.

# o you want to archive the current log,BACk up all the

# archive logs using two chAnnels,putTing a maximum of 20 logs

# in a BACkup set,and deleting them once the BACkup is complete.

#

# Note that the format String is constructed to guarantee uniqueness and

# to enhance NetBACkup for Oracle BACkup and restore perfoRMANce.

#

#

# NOTE WHEN USING NET serviCE name: When connecTing to a database

# using a net service name,you must use a send command or a parms operand to

# specify environment variables. In other words,when accessing a database

# through a Listener,the environment variables set at the system level are not

# visible when RMAN is running. For more information on the environment

# variables,please refer to the NetBACkup for Oracle admin. GuIDe.

#

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


CMD_STR="

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 << EOF

RUN { //以下为database备份

ALLOCATE CHAnnEL ch00 TYPE 'SBT_TAPE'; #为磁带备份分配通道

ALLOCATE CHAnnEL ch01 TYPE 'SBT_TAPE';

BACKUP

$BACKUP_TYPE

SKIP INACCESSIBLE #跳过不可存取文件

TAG hot_db_bk_level0 #设置备份标记,仅仅是一个标识名称,在以后恢复中可以根据名称来恢复

fileSPERSET 5 #最多包含五个文件

# recommended format

FORMAT 'bk_%s_%p_%t' #定义备份的名称

DATABASE; #标识定义的是整个数据库

sql 'alter system archive log current';

RELEASE CHAnnEL ch00; #释放通道

RELEASE CHAnnEL ch01;

# BACkup all archive logs //以下为archive log备份

ALLOCATE CHAnnEL ch00 TYPE 'SBT_TAPE'; #分配通道

ALLOCATE CHAnnEL ch01 TYPE 'SBT_TAPE';


#ALLOCATE CHAnnEL ch00 TYPE 'SBT_TAPE' connect='sys/sysadmin@gtwdb01 SEND 'NB_ORA_POliCY=yun-gtwdb-1-oralog';

#ALLOCATE CHAnnEL ch01 TYPE 'SBT_TAPE' connect='sys/sysadmin@gtwdb02 SEND 'NB_ORA_POliCY=yun-gtwdb-2-oralog'; //针对RAC的archive log备份

//(archivelog在非共享存储上)


BACKUP

filesperset 20 #最多包含20个文件

FORMAT 'al_%s_%p_%t' #备份名称格式

ARCHIVELOG ALL deletE input; #备份的是archive log,备份之后删除所有归档日志

RELEASE CHAnnEL ch00; #释放通道

RELEASE CHAnnEL ch01;

#

# Note: During the process of BACking up the database,RMAN also BACks up the

# control file. This version of the control file does not contain the

# information about the current BACkup because "nocatalog" has been specifIEd.

# To include the information about the current BACkup,the control file should

# be BACked up as the last step of the RMAN section. This step would not be

# necessary if we were using a recovery catalog or auto control file BACkups.

#

ALLOCATE CHAnnEL ch00 TYPE 'SBT_TAPE'; #分配通道

BACKUP

# recommended format

FORMAT 'cntrl_%s_%p_%t' #备份名称格式

CURRENT CONTROLFILE; #备份控制文件

RELEASE CHAnnEL ch00; 释放通道

}

EOF

"

# Initiate the command String

if [ "$CUSER" = "root" ]

then

su - $OracLE_USER -c "$CMD_STR" >> $RMAN_LOG_file

RSTAT=$?

else

/usr/bin/sh -c "$CMD_STR" >> $RMAN_LOG_file

RSTAT=$?

fi

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

# Log the completion of this script.

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

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

大佬总结

以上是大佬教程为你收集整理的NBU备份oracle全备脚本注释全部内容,希望文章能够帮你解决NBU备份oracle全备脚本注释所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: