RMAN脚本中使用替换变量--windows 下rman全备脚本

0    138    1

Tags:

👉 本文共约7816个字,系统预计阅读时间或需30分钟。

前言部分

导读

各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,\~O(∩_∩)O\~:

① windows 下rman全备脚本的写法(重点)

② 11g rman中run块中采用变量(亮点)

实验环境介绍

目标库:11.2.0.1 windows XP

本文简介

Oracle 11g出了一个新特性,在RMAN脚本中使用替换变量,这是一个非常有用的特点,找到这么一篇文章:

Creating Dynamic Command Files
Problem
You want to create dynamic command files that can be used for multiple jobs by passing substitution variables.
Solution
You can create dynamic shell scripts by using substitution variables in the RMAN command
files inside the shell scripts. You can specify values for use in substitution variables through
the new using clause when calling an RMAN command file. You use the \&integer syntax (&1,
&2, and so on) to indicate to which variable your substitution values should be assigned, just
as in SQL*Plus.
Let’s review an example that shows how to create a dynamic backup shell script.
1. Create the RMAN command file that uses two substitution variables:
#backup.cmd
connect target sys/\<sys_password>@prod1
run {
backup database
tag &1
format &2
}
exit;
The command file shown here will back up the database using two substitution variables (&1 and &2), one for the backup tag and the other for the string value in the
format specification.
2. Create the shell script to run the backup command file you created in step 1:
#!/bin/tcsh
# script name: nightly_backup.sh
set tag=$argv(1)
set format=$argv[2]
rman @backup.cmd using $tag $format
3. Now that you have created a dynamic shell script, you can specify the arguments for
the tag and format variables on the command line, thus being able to modify them for
different jobs. Here’s an example:
$ nightly_backup.sh longterm_backup back0420
The example shows how to execute the shell script nightly_backup.sh with two dynamic
parameters, longterm_backup (tag) and back0420 (format string).

How It Works
The ability to use substitution variables in RMAN scripts is new in Oracle Database 11g. The
use of substitution variables in RMAN scripts is similar to the way you specify substitution
variables in operating system and SQL*Plus scripts. Specifying substitution variables lets you
use the same command file by modifying it appropriately for different backup tasks, thus
making the command file dynamic.

相关知识点扫盲

都是很基础的内容,没啥说的,直接贴我的脚本:

我的windows环境下rman全备脚本

Windows 下RMAN备份脚本,比较简单。

1、创建文件 call_full_backup.sql ,内容如下

run{

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'e:\rman_backup\ctlfileautoback%d_%F.bak';

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;

allocate channel c1 type disk;

allocate channel c2 type disk;

backup as compressed backupset skip inaccessible filesperset 5 full database format 'e:\rman_backup\datafilefull%d%I%U_%T.bak' Database tag='bk_dffull&1' ;

sql 'alter system archive log current';

backup archivelog all format 'e:\rmanbackup\arch%d%I%e%U%T.bak' tag='bkarc&1' skip inaccessible not backed up 1 times delete all input;

backup current controlfile format 'e:\rmanbackup\ctlfile%d%I%U_%T.bak' tag='bkctlfile&1' ;

backup spfile format='e:\rmanbackup\spfile%d%I%U_%T.bak' tag='bkspfile&1';

release channel c1;

release channel c2;

report obsolete;

crosscheck copy;

crosscheck archivelog all;

delete noprompt obsolete;

crosscheck backup;

delete noprompt expired backup;

}

2、新建bat文件full_backup.bat,内容如下:

SET ORACLE_SID=ORA11G

SET ORACLE_HOME=F:\app\oracle\product

SET PATH=%ORACLE_HOME%\BIN

set MYDATE=%DATE:\~0,4%%DATE:\~5,2%%DATE:\~8,2%

SET NLS_DATE_FORMAT=YYYY-MM-DD HH24:mi:ss

rman target / cmdfile='f:\rman_backup\call_full_backup.sql' log='e:\rman_backup\log\rman_fullbackup%MYDATE%.log' using %MYDATE%

3、把上述创建的两个文件存放在相对应的路径,然后在系统新建计划任务执行full_backup.bat文件即可。

4、windows下创建定时任务

XP下在:

RMAN脚本中使用替换变量--windows 下rman全备脚本

RMAN脚本中使用替换变量--windows 下rman全备脚本

下边设置时间即可,需要启用如下服务方可,不然可能报错:

选用任务计划,添加任务计划,下一步,选择程序,下一步,执行任务的周期,下一步,下一步,输入密码,下一步,完成。问题就出在这里,它弹出一个对话框“已创建新任务,但可能不能运行,因为无法设置账户信息,指定的错误是:0x80041315:任务计划程序服务没有运行”

我的电脑->右键->属性->管理->服务和应用程序->服务->Task Scheduler->启用该服务然后应该就可以添加任务计划了吧!

RMAN脚本中使用替换变量--windows 下rman全备脚本

实验部分

按照上边的脚本部署好之后,等到约定的时间点就可以运行了,运行结果如下:

恢复管理器: Release 11.2.0.1.0 - Production on 星期三 5月 27 12:43:05 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

连接到目标数据库: ORA11G (DBID=4275029574)

RMAN> run{

2> CONFIGURE CONTROLFILE AUTOBACKUP ON;

3> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'e:\rman_backup\ctlfileautoback%d_%F.bak';

4> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;

5> allocate channel c1 type disk;

6> allocate channel c2 type disk;

7> backup as compressed backupset skip inaccessible filesperset 5 full database format 'e:\rman_backup\datafilefull%d%I%U_%T.bak' Database tag='bk_df_full_20150527' ;

8> sql 'alter system archive log current';

9> backup archivelog all format 'e:\rmanbackup\arch%d%I%e%U%T.bak' tag='bk_arc_20150527' skip inaccessible not backed up 1 times delete all input;

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!
RMAN脚本中使用替换变量--windows 下rman全备脚本后续精彩内容已被小麦苗无情隐藏,请输入验证码解锁本站所有文章!
验证码:
请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“DB宝”或者“www_xmmup_com”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复

嘿,我是小麦,需要帮助随时找我哦。
  • 18509239930
  • 个人微信

  • DB宝
  • 个人邮箱
  • 点击加入QQ群
  • 个人微店

  • 回到顶部