linux rman备份脚本,Linux下RMAN备份脚本

SKIP 选项

Excludes datafiles or archived redo logs from the backup set according to the criteria specified by the following keywords.

Note: You can also specify this option in the backupSpec clause.

OFFLINE

Specifies that offline datafiles should be excluded from the backup set.

READONLY

Specifies that read-only datafiles should be excluded from the backup set.

INACCESSIBLE

Specifies that datafiles or archived redo logs that cannot be read due to I/O errors should be excluded from the backup set.

A datafile is only considered inaccessible if it cannot be read. Some offline datafiles can still be read because they still exist on disk. Others have been deleted or moved and

so cannot be read, making them inaccessible.

FILESPERSET = integer

Specifies the maximum number of input files in each backup set. If you set FILESPERSET = n, then RMAN never includes more than n files in a backup set. The default for

FILESPERSET is the lesser of these two values: 64, number of input files divided by the number of channels. For example, if you back up 100 datafiles by using two channels, RMAN

sets FILESPERSET to 50.

RMAN always attempts to create enough backup sets so that all allocated channels have work to do. An exception to the rule occurs when there are more channels than files to back up. For example, if RMAN backs up two datafiles when three channels are allocated and FILESPERSET = 1, then one channel is necessarily idle.

示例:

平均文件数指:文件数/通道数。

allocate channel 提供备份并发度,若平均文件数

1、run {

allocate channel ch1 type disk;

allocate channel ch2 type disk;

backup datafile 3,4,5,6 filesperset 3;

release channel ch1;

release channel ch2;

}

平均数是 4(文件数)/2(channel数) = 2 ,小于filesperset 3,则生成2个备份集,每个备份集包含2个数据文件

2、run {

allocate channel ch1 type disk;

allocate channel ch2 type disk;

backup datafile 3,4,5,6 filesperset 1;

release channel ch1;

release channel ch2;

}

则生成4个备份集,每个包含一个数据文件

rman nocatalog target sys/Oracle msglog rmanLog.out append  --将命令执行的日志追加到rmanLog.out文件,如果没有append,则会覆盖已有的rmanLog.out文件。

备份脚本:

#########################################################################

##   t_database_backup.sh      ##

##   created by Tianlesoftware   ##

##        2010-7-16                 ##

#########################################################################

#!/bin/bash

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

# Determine the user which is executing this script.

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

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

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

# Put output in .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 {1} >> $RMAN_LOG_FILE

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

echo >> $RMAN_LOG_FILE

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

# Oracle home path.

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

ORACLE_HOME=/home/oracle/product/10.2.0/db_1

export ORACLE_HOME

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

# the Oracle SID of the target database.

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

ORACLE_SID=oralife

export ORACLE_SID

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

# The Oracle DBA user id (account).

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

ORACLE_USER=oracle

export ORACLE_USER

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

# Set the Oracle Recovery Manager name.

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

RMAN=$ORACLE_HOME/bin/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. If desired,

# this would be the place to verify that.

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

echo >> $RMAN_LOG_FILE

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

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

# Call Recovery Manager to initiate the backup.

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

CMD_STR="

ORACLE_HOME=$ORACLE_HOME

export ORACLE_HOME

ORACLE_SID=$ORACLE_SID

export ORACLE_SID

$RMAN nocatalog target sys/admin  msglog $RMAN_LOG_FILE append <

RUN {

allocate channel c1 type disk;

allocate channel c2 type disk;

BACKUP FORMAT '/home/oracle/backup/oralife_%U_%T' skip inaccessible filesperset 5  DATABASE TAG oralife_hot_db_bk;

sql 'alter system archive log current';

BACKUP FORMAT '/home/oracle/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;

backup current controlfile tag='bak_ctlfile' format='/home/oracle/backup/ctl_file_%U_%T';

backup spfile tag='spfile' format='/home/oracle/backup/oralife_spfile_%U_%T';

release channel c2;

release channel c1;

}

report obsolete;

delete noprompt obsolete;

crosscheck backup;

delete noprompt expired backup;

list backup summary;

#EOF

"

# Initiate the command string

if [ "$CUSER" = "root" ]

then

echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE

su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE

RSTAT=$?

else

echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE

/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 {1} >> $RMAN_LOG_FILE

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

echo >> $RMAN_LOG_FILE

#/bin/mailx -s "RMAN Backup SID " daimm@sf-express.com 

exit $RSTAT

邮件配置...

0b1331709591d260c1c78e86d0c51c18.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值