热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Nocatalog下的RMAN增量备份shell脚本

nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd

之前整理了下catalog下全备的脚本,上次在生产库上弄了个nocatalog的脚本,结果没有在本本上保存,这次要用了,重新在整理了一下。

Linux 平台下 RMAN 全备 和 增量备份 shell 脚本

2011-02/32707.htm

在执行脚本之前,先修改几个参数值:

1. DB 参数:

修改控制文件的保存时间,从默认的7天改成14天

SQL> show parameter control

SQL> alter system set control_file_record_keep_time=14 scope=both;

2. RMAN 参数:

开启控制文件的自动备份,开启之后在数据库备份或者数据文件(比如添加数据文件)有修改的时候都会自动备份控制文件和spfile文件。

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

3. 备份策略根据自己的系统决

我这里是周日做0级备份。周四1级备份,其他2级备份。

4. 备份脚本如下:

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

##   rman_incremental_backup.sh               ##

##    created by Tianlesoftware                 ##

##        2011-1-25                         ##

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

#!/bin/ksh

export LANG=en_US

BACKUP_DATE=`date +%d`

RMAN_LOG_FILE=${0}.out

TODAY=`date`

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

echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE

Oracle_HOME=/u01/app/oracle/product/10.2.0/db_1

export ORACLE_HOME

RMAN=$ORACLE_HOME/bin/rman

export RMAN

ORACLE_SID=orcl

export ORACLE_SID

ORACLE_USER=oracle

export ORACLE_USER

 

echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE

echo "ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE

echo "ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE

echo "==========================================">>$RMAN_LOG_FILE

echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE

echo "                   ">>$RMAN_LOG_FILE

chmod 666 $RMAN_LOG_FILE

 

WEEK_DAILY=`date +%a`

case  "$WEEK_DAILY" in

       "Mon")

            BAK_LEVEL=2

            ;;

       "Tue")

            BAK_LEVEL=2

            ;;

       "Wed")

            BAK_LEVEL=2

            ;;

       "Thu")

            BAK_LEVEL=1

            ;;

       "Fri")

            BAK_LEVEL=2

            ;;

       "Sat")

            BAK_LEVEL=2

            ;;

       "Sun")

            BAK_LEVEL=0

            ;;

       "*")

            BAK_LEVEL=error

esac

 

export BAK_LEVEL=$BAK_LEVEL

echo "Today is : $WEEK_DAILY  incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE

 

RUN_STR="

BAK_LEVEL=$BAK_LEVEL

export BAK_LEVEL

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  incremental level= $BAK_LEVEL  skip inaccessible filesperset 5 Database format='/u01/backup/orcl_lev"$BAK_LEVEL"_%U_%T'  tag='orcl_lev"$BAK_LEVEL"' ;

sql 'alter system archive log current';

backup archivelog all tag='arc_bak' format='/u01/backup/arch_%U_%T' skip inaccessible  filesperset 5 not  backed up 1 times  delete input;

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

backup spfile tag='spfile' format='/u01/backup/ORCL_spfile_%U_%T';

release channel c2;

release channel c1;

}

allocate channel for maintenance device type disk;

report obsolete;

delete noprompt obsolete;

crosscheck backup;

delete noprompt expired backup;

list backup summary;

release channel;

EOF

"

 # Initiate the command string

 

if [ "$CUSER" = "root" ]

then

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

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

    RSTAT=$?

else

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

    /bin/sh -c "$RUN_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

/bin/mailx -s "RMAN Backup SID " www.test.com@www.test.com <$RMAN_LOG_FILE

exit $RSTAT

 

5. 备份脚本的log 日志:

 

connected to target database: DAVE (DBID=801102850)

using target database control file instead of recovery catalog

 

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12>

allocated channel: c1

channel c1: sid=158 devtype=DISK

 

allocated channel: c2

channel c2: sid=147 devtype=DISK

 

Starting backup at 01-FEB-12

channel c1: starting incremental level 2 datafile backupset

channel c1: specifying datafile(s) in backupset

input datafile fno=00001 name=/u01/app/oracle/oradata/orcl/system.256.736598559

input datafile fno=00004 name=/u01/app/oracle/oradata/orcl/users.259.736598641

channel c1: starting piece 1 at 01-FEB-12

channel c2: starting incremental level 2 datafile backupset

channel c2: specifying datafile(s) in backupset

input datafile fno=00003 name=/u01/app/oracle/oradata/orcl/sysaux.257.736598563

input datafile fno=00002 name=/u01/app/oracle/oradata/orcl/undotbs1.258.736598599

channel c2: starting piece 1 at 01-FEB-12

channel c1: finished piece 1 at 01-FEB-12

piece handle=/u02/backup/orcl_lev2_0dn287g3_1_1_20120201 tag=ORCL_LEV2 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:36

channel c2: finished piece 1 at 01-FEB-12

piece handle=/u02/backup/orcl_lev2_0en287g3_1_1_20120201 tag=ORCL_LEV2 comment=NONE

channel c2: backup set complete, elapsed time: 00:00:36

Finished backup at 01-FEB-12

 

Starting Control File and SPFILE Autobackup at 01-FEB-12

piece handle=/u01/app/oracle/flash_recovery_area/DAVE/autobackup/2012_02_01/o1_mf_s_774118951_7lmfms6s_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 01-FEB-12

 

sql statement: alter system archive log current

 

Starting backup at 01-FEB-12

current log archived

channel c1: starting archive log backupset

channel c1: specifying archive log(s) in backup set

input archive log thread=1 sequence=9 recid=9 stamp=774118956

channel c1: starting piece 1 at 01-FEB-12

channel c2: starting archive log backupset

channel c2: specifying archive log(s) in backup set

input archive log thread=1 sequence=10 recid=10 stamp=774118956

channel c2: starting piece 1 at 01-FEB-12

channel c1: finished piece 1 at 01-FEB-12

piece handle=/u02/backup/arch_0hn287hc_1_1_20120201 tag=ARC_BAK comment=NONE

channel c1: backup set complete, elapsed time: 00:00:02

channel c1: deleting archive log(s)

archive log filename=/u01/archivelog/1_9_738254360.arch recid=9 stamp=774118956

channel c2: finished piece 1 at 01-FEB-12

piece handle=/u02/backup/arch_0gn287hc_1_1_20120201 tag=ARC_BAK comment=NONE

channel c2: backup set complete, elapsed time: 00:00:03

channel c2: deleting archive log(s)

archive log filename=/u01/archivelog/1_10_738254360.arch recid=10 stamp=774118956

Finished backup at 01-FEB-12

 

Starting backup at 01-FEB-12

channel c1: starting full datafile backupset

channel c1: specifying datafile(s) in backupset

including current control file in backupset

channel c1: starting piece 1 at 01-FEB-12

channel c1: finished piece 1 at 01-FEB-12

piece handle=/u02/backup/ctl_file_0in287hg_1_1_20120201 tag=BAK_CTLFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:02

Finished backup at 01-FEB-12

 

Starting backup at 01-FEB-12

channel c1: starting full datafile backupset

channel c1: specifying datafile(s) in backupset

including current SPFILE in backupset

channel c1: starting piece 1 at 01-FEB-12

channel c1: finished piece 1 at 01-FEB-12

piece handle=/u02/backup/ORCL_spfile_0jn287hi_1_1_20120201 tag=SPFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

Finished backup at 01-FEB-12

 

Starting Control File and SPFILE Autobackup at 01-FEB-12

piece handle=/u01/app/oracle/flash_recovery_area/DAVE/autobackup/2012_02_01/o1_mf_s_774118963_7lmfn45l_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 01-FEB-12

 

released channel: c2

 

released channel: c1

 

RMAN> RMAN>

allocated channel: ORA_MAINT_DISK_1

channel ORA_MAINT_DISK_1: sid=158 devtype=DISK

 

RMAN> RMAN>

RMAN retention policy will be applied to the command

RMAN retention policy is set to recovery window of 7 days

no obsolete backups found

 

RMAN> RMAN>

RMAN retention policy will be applied to the command

RMAN retention policy is set to recovery window of 7 days

no obsolete backups found

 

RMAN> RMAN>

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/orcl_lev2_06n2877c_1_1_20120201 recid=1 stamp=774118636

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/orcl_lev2_05n2877c_1_1_20120201 recid=2 stamp=774118636

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/DAVE/autobackup/2012_02_01/o1_mf_s_774118723_7lmfdojy_.bkp recid=3 stamp=774118725

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/arch_08n287ab_1_1_20120201 recid=4 stamp=774118732

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/arch_09n287ab_1_1_20120201 recid=5 stamp=774118732

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/ctl_file_0an287al_1_1_20120201 recid=6 stamp=774118742

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/ORCL_spfile_0bn287ao_1_1_20120201 recid=7 stamp=774118744

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/DAVE/autobackup/2012_02_01/o1_mf_s_774118745_7lmffb20_.bkp recid=8 stamp=774118746

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/orcl_lev2_0dn287g3_1_1_20120201 recid=9 stamp=774118915

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/orcl_lev2_0en287g3_1_1_20120201 recid=10 stamp=774118923

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/DAVE/autobackup/2012_02_01/o1_mf_s_774118951_7lmfms6s_.bkp recid=11 stamp=774118953

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/arch_0gn287hc_1_1_20120201 recid=12 stamp=774118957

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/arch_0hn287hc_1_1_20120201 recid=13 stamp=774118957

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/ctl_file_0in287hg_1_1_20120201 recid=14 stamp=774118961

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u02/backup/ORCL_spfile_0jn287hi_1_1_20120201 recid=15 stamp=774118962

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=/u01/app/oracle/flash_recovery_area/DAVE/autobackup/2012_02_01/o1_mf_s_774118963_7lmfn45l_.bkp recid=16 stamp=774118964

Crosschecked 16 objects

 

 

RMAN> RMAN>

 

RMAN> RMAN>

 

List of Backups

===============

Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag

------- -- -- - ----------- --------------- ------- ------- ---------- ---

1       B  2  A DISK        01-FEB-12       1       1       NO         ORCL_LEV2

2       B  2  A DISK        01-FEB-12       1       1       NO         ORCL_LEV2

3       B  F  A DISK        01-FEB-12       1       1       NO         TAG20120201T165843

4       B  A  A DISK        01-FEB-12       1       1       NO         ARC_BAK

5       B  A  A DISK        01-FEB-12       1       1       NO         ARC_BAK

6       B  F  A DISK        01-FEB-12       1       1       NO         BAK_CTLFILE

7       B  F  A DISK        01-FEB-12       1       1       NO         SPFILE

8       B  F  A DISK        01-FEB-12       1       1       NO         TAG20120201T165905

9       B  2  A DISK        01-FEB-12       1       1       NO         ORCL_LEV2

10      B  2  A DISK        01-FEB-12       1       1       NO         ORCL_LEV2

11      B  F  A DISK        01-FEB-12       1       1       NO         TAG20120201T170231

12      B  A  A DISK        01-FEB-12       1       1       NO         ARC_BAK

13      B  A  A DISK        01-FEB-12       1       1       NO         ARC_BAK

14      B  F  A DISK        01-FEB-12       1       1       NO         BAK_CTLFILE

15      B  F  A DISK        01-FEB-12       1       1       NO         SPFILE

16      B  F  A DISK        01-FEB-12       1       1       NO         TAG20120201T170243

 

RMAN> RMAN>

released channel: ORA_MAINT_DISK_1

 

RMAN> RMAN>

 

Recovery Manager complete.

 

Script rman_incremental_backup.sh

==== ended successfully on Wed Feb 1 17:02:50 EST 2012 ====

6. 将备份脚本添加到Crontab

[oracle@singledb u02]$ crontab -l

20 17 * * * /u02/rman_incremental_backup.sh 1>/u02/rman.log 2>&1 &

关于crontab 参考:

Linux Crontab 定时任务 命令详解

2007-09/7681.htm


推荐阅读
  • 主调|大侠_重温C++ ... [详细]
  • 云函数与数据库API实现增删查改的对比
    本文将深入探讨使用云函数和数据库API实现数据操作(增删查改)的不同方法,通过详细的代码示例帮助读者更好地理解和掌握这些技术。文章不仅提供代码实现,还解释了每种方法的特点和适用场景。 ... [详细]
  • 本文深入探讨了 PHP 实现计划任务的方法,包括其原理、具体实现方式以及在不同操作系统中的应用。通过详细示例和代码片段,帮助开发者理解和掌握如何高效地设置和管理定时任务。 ... [详细]
  • 本文详细介绍了在XAMPP环境中如何修改Apache和MySQL的默认端口号,并确保WordPress能够正常访问。同时,提供了针对Go语言社区和Golang开发者的相关建议。 ... [详细]
  • 本文详细介绍了一种通过MySQL弱口令漏洞在Windows操作系统上获取SYSTEM权限的方法。该方法涉及使用自定义UDF DLL文件来执行任意命令,从而实现对远程服务器的完全控制。 ... [详细]
  • 离线安装Grafana Cloudera Manager插件并监控CDH集群
    本文详细介绍如何离线安装Cloudera Manager (CM) 插件,并通过Grafana监控CDH集群的健康状况和资源使用情况。该插件利用CM提供的API接口进行数据获取和展示。 ... [详细]
  • 本文详细介绍了Java中实现异步调用的多种方式,包括线程创建、Future接口、CompletableFuture类以及Spring框架的@Async注解。通过代码示例和深入解析,帮助读者理解并掌握这些技术。 ... [详细]
  • 本文详细介绍了 Linux 系统中用户、组和文件权限的设置方法,包括基本权限(读、写、执行)、特殊权限(SUID、SGID、Sticky Bit)以及相关配置文件的使用。 ... [详细]
  • 本文详细探讨了Java命令行参数的概念、使用方法及在实际编程中的应用,包括如何通过命令行传递参数给Java程序,以及如何在Java程序中解析这些参数。 ... [详细]
  • Java项目分层架构设计与实践
    本文探讨了Java项目中应用分层的最佳实践,不仅介绍了常见的三层架构(Controller、Service、DAO),还深入分析了各层的职责划分及优化建议。通过合理的分层设计,可以提高代码的可维护性、扩展性和团队协作效率。 ... [详细]
  • 本文探讨了如何通过预处理器开关选择不同的类实现,并解决在特定情况下遇到的链接器错误。 ... [详细]
  • 我有一个SpringRestController,它处理API调用的版本1。继承在SpringRestControllerpackagerest.v1;RestCon ... [详细]
  • 本文详细介绍了如何在PHP中进行数组删除、清空等操作,并提供了在Visual Studio Code中创建PHP文件的步骤。 ... [详细]
  • 使用Powershell Studio快速构建GUI应用程序
    本文介绍了如何利用Powershell Studio创建功能强大的可视化界面。相较于传统的开发工具,Powershell Studio提供了更为简便和高效的开发体验,尤其适合需要快速构建图形用户界面(GUI)的场景。 ... [详细]
  • 深入解析动态代理模式:23种设计模式之三
    在设计模式中,动态代理模式是应用最为广泛的一种代理模式。它允许我们在运行时动态创建代理对象,并在调用方法时进行增强处理。本文将详细介绍动态代理的实现机制及其应用场景。 ... [详细]
author-avatar
淡漠少_341
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有