[Email protected] # more hot_database_backup.sh
#!/bin/sh
# $Header: Hot_database_backup.sh,v 1.3 2010/08/04 17:56:02 $
#
#bcpyrght
#*********************************************************************
#* $VRTScprght: Copyright 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 was inconsistent because portions of the database is
# being modified and written to the disk while the backup is progressing.
# You must run your the database in ARCHIVELOG mode for hot backups. It is
# assumed that this script would be executed by user root. In order for RMAN
# To work properly we switch User (Su-) to the Oracle DBA account before
# execution. If This script runs under a user account the has Oracle DBA
# privilege, it'll be executed using the 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
# ---------------------------------------------------------------------------
# want to delete the output file so the 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 $ >> $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, below, with the Oracle SID of the target database.
# ---------------------------------------------------------------------------
oracle_sid=ora102#备份的数据库
Export Oracle_sid
# ---------------------------------------------------------------------------
# Replace ora102, below, with the Oracle DBA User ID (account).
# ---------------------------------------------------------------------------
oracle_user=ora102 backup used by system users
# ---------------------------------------------------------------------------
# Set the target connect string.
# Replace "Sys/manager", below, with the target connect string.
# ---------------------------------------------------------------------------
Target_connect_str=sys/manager# # # Sys/manager changed to/# #
# ---------------------------------------------------------------------------
# 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, the database is properly opened. If desired,
# This would is the place to verify.
# ---------------------------------------------------------------------------
echo >> $RMAN _log_file
# ---------------------------------------------------------------------------
# If This script was 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
# ---------------- --------------
# 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). The default for a user initiated
# Backup to incremental or incremental cumulative, uncomment
# One of the following and lines.
# backup_type= "INCREMENTAL level=1"
# backup_type= "INCREMENTAL level=1 Cumulative"
#
# Note that we use incremental level 0 to specify full backups.
# that's because, although they is identical on content, only
# The incremental level 0 backup can has 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 does 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 was part of the incremental
# strategy (this means it can have incremental backups of levels > 0
# applied to it).
#
# We don't need to explicitly request the control file to be included
# In this backup, as it was 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 is backed up,
# Hence the controlfile would also be included automatically).
#
# Typically, a level 0 backup would is done at least once a week.
#
# The scenario assumes:
# o You is backing your database up to both tape drives
# o want each backup set to include a maximum of 5 files
# o wish to include offline datafiles, and Read-only tablespaces,
# in the Backup
# o want the backup to continue if any files is inaccessible.
# O You is not using a Recovery Catalog
# o you is explicitly backing up the control file. Since are
# specifying Nocatalog, the Controlfile backup that occurs
# automatically as the result of backing the system file is
# not sufficient; It won't contain records for the backup that
# is currently in progress.
# O want to archive the current log, back up all the
# Archive logs using-channels, putting a maximum of logs
# In a backup set, and deleting them once the backup was complete.
#
# Note that the format string was constructed to guarantee uniqueness and
# to enhance NetBackup for Oracle backup and restore performance.
#
#
# NOTE when the 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 and words, when accessing a database
# through a listener, the environment variables set at the system level is not
# visible when RMAN is running. For more information on the environment
# variables, 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 { //Below is database backup
ALLOCATE CHANNEL ch00 TYPE ' Sbt_tape '; #为磁带备份分配通道
ALLOCATE CHANNEL ch01 TYPE ' Sbt_tape ';
BACKUP
$BACKUP _type
SKIP Inaccessible#跳过不可存取文件
TAG hot_db_bk_level0#设置备份标记, is just an identity name that can be restored later in the recovery by name
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 backups below
ALLOCATE CHANNEL ch00 TYPE ' Sbt_tape '; #分配通道
ALLOCATE CHANNEL ch01 TYPE ' Sbt_tape ';
#ALLOCATE CHANNEL ch00 TYPE ' sbt_tape ' connect= ' sys/[email protected] SEND ' Nb_ora_policy=yun-gtwdb-1-oralog ';
#ALLOCATE CHANNEL ch01 TYPE ' sbt_tape ' connect= ' sys/[email protected] SEND ' Nb_ora_policy=yun-gtwdb-2-oralog '; //Archive log backup for RAC
(Archivelog on non-shared storage)
BACKUP
Filesperset#最多包含20个文件
FORMAT ' al_%s_%p_%t '#备份名称格式
ARCHIVELOG all DELETE INPUT; #备份的是archive Log, delete all archived logs after backup
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" have been specified.
# to include the information of the current backup, the control file should
# is backed up as the last step of the RMAN section. This step would isn't 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; Release Channel
}
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 $ >> $RMAN _log_file
echo = = $LOGMSG on ' date ' = = >> $RMAN _log_file
echo >> $RMAN _log_file
NBU Backup Oracle fully prepared script annotations