在单位用oracle备份到磁带的脚本(看不明白的地方交流)
# $Header: hot_database_backup.sh,v 1.2 2002/08/06 23:51:42 $
#
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2007 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 oracle dba account before
# execution. If this script runs under a user account that has Oracle dba
# 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.
# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate. If not, delete the following lines.
# ---------------------------------------------------------------------------
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/ora81, below, with the Oracle home path.
# ---------------------------------------------------------------------------
export ORACLE_HOME
# Replace ora81, below, with the Oracle SID of the target database.
# ---------------------------------------------------------------------------
export ORACLE_SID
# Replace ora81, below, with the Oracle DBA user id (account).
# ---------------------------------------------------------------------------
# Set the target connect string.
# Replace "sys/manager", below, with the target connect string.
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------
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 "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. If desired,
# this would be the place to verify that.
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# 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
# 'rcvcat <userid>/<passwd>@<tns alias>' 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 TNS ALIAS: When connecting to a database
# using a TNS alias, 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.
#
# ---------------------------------------------------------------------------
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 {
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
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
BACKUP
filesperset 20
FORMAT 'al_%s_%p_%t'
ARCHIVELOG ALL DELETE INPUT;
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.
#
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
exit $RSTAT
转载于:https://blog.51cto.com/jxwpx/193863
在单位用oracle备份到磁带的脚本(看不明白的地方交流)相关推荐
- Script:收集Oracle备份恢复信息
我们在诊断Oracle backup restore问题时总是希望能获得足够的诊断信息,一般来说RDA会是一个最好的诊断信息收集工具,但是有时候客户会很反感使用RDA(不信任感),这里我们提供一段专门 ...
- Oracle 如何删除控制文件中rman备份到磁带的备份集信息(RMAN-06091)
如何删除控制文件中rman备份到磁带的备份集信息 SQL> select name,block_size*file_size_blks/1024/1024 bytes from v$contro ...
- Oracle备份恢复(一)
Oracle备份恢复(一) 备份恢复的两个重要术语(**MTBF和MTTR**) 一.MTBF(Mean Time Between Failures)即平均故障间隔(时间/次) 二.MTTR(Mean ...
- ORACLE 备份恢复之RMAN详解
一.连接方式 (一).连接本地数据库 [oracle@oracle ~]$ rman target / (二).连接远程数据库 [oracle@oracle ~]$ rman target sys/o ...
- 12c双机rac oracle_深度干货 | 如何借助云原生搞定Oracle备份快速恢复?
作者:麟远 桓禹 Oracle备份面临的挑战 在传统企业里,经常会用Oracle数据库去承载业务重要核心数据,同时Oracle针对不同的恢复场景提供了灵活多样的恢复操作方法,灵活的设计给备份和恢复带来 ...
- dataguard如何实现切换_深度干货 | 如何借助云原生搞定Oracle备份快速恢复?
简介:DBS Oracle备份产品是阿里云自研的,结合阿里集团之前多年Oracle数据库的生产使用经验打造的云备份产品.它不仅提供了传统备份所提供的Oracle备份能力外,还实现了无入侵流式备份能力, ...
- Oracle备份解决方案
备份解决方案 使用以下方法可执行备份: Recovery Manager Oracle Secure Backup 用户管理的备份 Recovery Manager (RMAN) 是推荐使用的 Ora ...
- ORACLE备份策略(ORACLE BACKUP STRATEGY)
概要 1.了解什么是备份 2.了解备份的重要性 3.理解数据库的两种运行方式 4.理解不同的备份方式及其区别 5.了解正确的备份策略及其好处 一.了解备份的重要性 可以说,从计算机系统出世的那天 ...
- oracle bfile备份,整理的一些oracle备份笔记 (zt)
1.联机热备份的一般步骤: a.设置数据库为archivelog模式 startup mount; alter system set log_archive_dest_n='location=d:or ...
最新文章
- G - IP地址转换
- 千言万句,Nginx从入门到精通,看这一篇足矣
- 课后作业:字符串加密
- xgboost 多gpu支持 编译
- ios macos_设计师可以从iOS 14和macOS Big Sur中学到什么?
- php多个参数绑定,php – 如何绑定多个参数到MySQLi查询
- linux 返回非法指令,linux – ARM Cortex A7在内核模式下返回PMCCNTR = 0,在用户模式下返回非法指令(即使在PMUSERENR = 1之后)...
- Web前端笔记(10)Grid布局
- WebRequest 对象的使用
- Unity MRTK RadialView
- X5内核视频之问答汇总
- seo排名优化工具有哪些软件开发方案?
- BPSK_QPSK_16QAM _64QAM _MATLAB
- Python和R语言的区别
- Knowledge-based Systems期刊投稿经历
- tomcat7的下载和安装配置
- indesign怎么查找拼音_用Indesign CS 巧排拼音的方法
- 性能测试报告不会写?最标准的模板来了
- h5微信本地调试 vue_VUE开发微信H5页面总结
- 干货!软考中级网络工程师备考经验分享