Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

0

积分

1

好友

3

主题
1#
发表于 2013-11-11 23:35:48 | 查看: 4453| 回复: 17
本帖最后由 与晶之恋 于 2013-11-12 22:09 编辑

想使用脚本自动恢复控制文件.但是rman怎么都使用不了shell中的参数,请问下哪里有问题了?

10g的rman确实不具备传递参数的功能.还有没有其他办法去使用变量?
http://blog.ronnyegner-consulting.de/2010/08/02/rman-and-variables/

oracle: 10.2.0.5.0
环境:hpux 11.31


两个脚本如下
oracle@nms[/rman/shell]$vi ctlbak.sh
#! /bin/sh
connect target /
run{
restore controlfile from '/rman/&1';
}

oracle@nms[/rman/shell]$vi ctl.sh
export ORACLE_SID=nmdb
$ORACLE_HOME/bin/rman <<EOF
@/rman/shell/ctlbak.sh "cf_c-2883472017-20131111-05"
EOF



文件路径是对的
oracle@nms[/rman]$ll
total 278032
-rw-r----- 1 oracle dba  14352384 2013-11-10 23:18 cf_c-2883472017-20131110-02
-rw-r----- 1 oracle dba  14352384 2013-11-11 00:40 cf_c-2883472017-20131111-03
-rw-r----- 1 oracle dba  14352384 2013-11-11 00:41 cf_c-2883472017-20131111-04
-rw-r----- 1 oracle dba  14647296 2013-11-11 11:56 cf_c-2883472017-20131111-05
2#
发表于 2013-11-11 23:47:13
具体运行了报什么错 总要说一下吧?

回复 只看该作者 道具 举报

3#
发表于 2013-11-11 23:48:19
给一个例子

Example 2-128 Specifying Substitution Variables

Suppose that you want to create a Linux shell script that backs up the database. You want to use shell variables so that you can pass arguments to the RMAN backup script at run time. Substitution variables solve this problem. First, you create a command file named whole_db.cmd with the following contents:

cat > /tmp/whole_db.cmd <<EOF
# name: whole_db.cmd
CONNECT TARGET /
BACKUP TAG &1 COPIES &2 DATABASE FORMAT '/disk2/db_%U';
EXIT;
EOF
Next, you write the following Linux shell script, which sets csh shell variables tagname and copies. The shell script starts RMAN, connects to target database prod1, and runs whole_db.cmd. The USING clause passes the values in the variables tagname and copies to the RMAN command file at execution time.

#!/bin/csh
# name: runbackup.sh
# usage: use the tag name and number of copies as arguments
set tagname = $argv[1]
set copies = $argv[2]
rman @'/tmp/whole_db.cmd' USING $tagname $copies LOG /tmp/runbackup.out
# note that the preceding line is equivalent to:
# rman @'/tmp/whole_db.cmd' $tagname $copies LOG /tmp/runbackup.out
Finally, you execute the shell script runbackup.sh from a Linux shell as follows to create two backups of the database with the tag Q106:

回复 只看该作者 道具 举报

4#
发表于 2013-11-11 23:54:38
Maclean Liu(刘相兵 发表于 2013-11-11 23:47
具体运行了报什么错 总要说一下吧?

sorry 报错信息如下,

oracle@nms[/rman/shell]$./ctl.sh

Recovery Manager: Release 10.2.0.5.0 - Production on Mon Nov 11 16:51:56 2013

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

RMAN>
RMAN> #! /bin/sh
2> connect target *
connected to target database: nmdb (not mounted)

RMAN> run{
2> restore controlfile from '/rman/&1';
3> }
Starting restore at 11-NOV-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1091 devtype=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 11/11/2013 16:51:57
RMAN-06172: no autobackup found or specified handle is not a valid copy or piece

RMAN> **end-of-file**

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "double-quoted-string": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"
RMAN-01007: at line 0 column 2 file: standard input

RMAN>

Recovery Manager complete.
oracle@nms[/rman/shell]$

回复 只看该作者 道具 举报

5#
发表于 2013-11-11 23:58:03
去掉双引号试试 "cf_c-2883472017-20131111-05", 或者这个并非有效的 控制文件备份

回复 只看该作者 道具 举报

6#
发表于 2013-11-12 00:05:14
Maclean Liu(刘相兵 发表于 2013-11-11 23:58
去掉双引号试试 "cf_c-2883472017-20131111-05", 或者这个并非有效的 控制文件备份 ...

试过,去掉后的报错,
oracle@nms[/rman/shell]$./ctl.sh

Recovery Manager: Release 10.2.0.5.0 - Production on Mon Nov 11 17:00:06 2013

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

RMAN>
RMAN> #! /bin/sh
2> connect target *
connected to target database: nmdb (not mounted)

RMAN> run{
2> restore controlfile from '/rman/&1';
3> }
Starting restore at 11-NOV-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1094 devtype=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 11/11/2013 17:00:07
RMAN-06172: no autobackup found or specified handle is not a valid copy or piece

RMAN> **end-of-file**

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"
RMAN-01008: the bad identifier was: cf_c
RMAN-01007: at line 0 column 2 file: standard input

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01006: error signalled during parse
RMAN-02001: unrecognized punctuation symbol "-"

RMAN>

Recovery Manager complete.
oracle@nms[/rman/shell]$

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
控制文件备份是有效的
oracle@nms[/rman/shell]$rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Mon Nov 11 17:02:45 2013

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: nmdb (not mounted)

RMAN> restore controlfile from '/rman/cf_c-2883472017-20131111-05';

Starting restore at 11-NOV-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1094 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/oracle/oradata/nmdb/ctl/control01.ctl
output filename=/oracle/oradata/nmdb/ctl/control02.ctl
output filename=/oracle/oradata/nmdb/ctl/control03.ctl
Finished restore at 11-NOV-13

回复 只看该作者 道具 举报

7#
发表于 2013-11-12 00:08:35
1、cat ctl.sh

2、 对于autobackup 如果没特殊要求 , 其实可以不指定文件名,当然有前提

3、 毫无疑问是低级错误, 目前没有 时间帮你测

回复 只看该作者 道具 举报

8#
发表于 2013-11-12 00:14:19
1.
oracle@nms[/rman/shell]$cat ctl.sh
export ORACLE_SID=nmdb
$ORACLE_HOME/bin/rman <<EOF
@/rman/shell/ctlbak.sh cf_c-2883472017-20131111-05
EOF

自动恢复不是自动备份.需要恢复一个最新的备份文件.这不是完整的脚本,挑出这段有问题来专门测试的.

我对了你之前文章的格式来的,看报错就是参数传不进去不然就是传进去因为符号之类的原因表达错误了.但是找不出来为啥.http://www.askmaclean.com/archives/%E4%BD%BF%E7%94%A8oracle-rman%E8%84%9A%E6%9C%AC.html

回复 只看该作者 道具 举报

9#
发表于 2013-11-12 14:59:22
test on:Vbox linux 32bit oracle 11.2.0.3
变量需要加单引号

  1. [oracle@localhost ~]$ cat ctlbak.rman
  2. connect target /
  3. run{
  4. restore controlfile from '/oracle/product/dbs/&1';
  5. }
  6. [oracle@localhost ~]$ cat ctl.sh
  7. export ORACLE_SID=nmdb
  8. $ORACLE_HOME/bin/rman <<EOF
  9. @ctlbak.rman 'c-4173336992-20131112-00'
  10. EOF


  11. [oracle@localhost ~]$ ./ctl.sh

  12. Recovery Manager: Release 11.2.0.3.0 - Production on Tue Nov 12 14:54:24 2013

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

  14. RMAN>

  15. RMAN> connect target *
  16. connected to target database: NMDB (not mounted)

  17. RMAN> run{
  18. 2> restore controlfile from '/oracle/product/dbs/c-4173336992-20131112-00';
  19. 3> }
  20. Starting restore at 12-NOV-13
  21. using target database control file instead of recovery catalog
  22. allocated channel: ORA_DISK_1
  23. channel ORA_DISK_1: SID=20 device type=DISK

  24. channel ORA_DISK_1: restoring control file
  25. channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
  26. output file name=/oracle/oradata/nmdb/control01.ctl
  27. Finished restore at 12-NOV-13

  28. RMAN> **end-of-file**

  29. RMAN>

  30. Recovery Manager complete.
复制代码

回复 只看该作者 道具 举报

10#
发表于 2013-11-12 18:03:49
kevinlin.ora 发表于 2013-11-12 14:59
test on:Vbox linux 32bit oracle 11.2.0.3
变量需要加单引号

谢谢,难打版本不一样么?我之前就试过单引号的.一样传递不进去.

回复 只看该作者 道具 举报

11#
发表于 2013-11-12 18:06:19
kevinlin.ora 发表于 2013-11-12 14:59
test on:Vbox linux 32bit oracle 11.2.0.3
变量需要加单引号

真心感谢你还专程搭了实例才测试.
oracle@nms[/rman/shell]$cat ctl.sh
export ORACLE_SID=nmdb
$ORACLE_HOME/bin/rman <<EOF
@/rman/shell/ctlbak.sh 'cf_c-2883472017-20131111-05'
EOF

oracle@nms[/rman/shell]$cat ctlbak.sh
#! /bin/sh
connect target /
run{
restore controlfile from '/rman/&1';
}

  1. Recovery Manager: Release 10.2.0.5.0 - Production on Tue Nov 12 11:03:01 2013

  2. Copyright (c) 1982, 2007, Oracle.  All rights reserved.

  3. RMAN>
  4. RMAN> #! /bin/sh
  5. 2> connect target *
  6. connected to target database: nmdb (not mounted)

  7. RMAN> run{
  8. 2> restore controlfile from '/rman/&1';
  9. 3> }
  10. Starting restore at 12-NOV-13
  11. using target database control file instead of recovery catalog
  12. allocated channel: ORA_DISK_1
  13. channel ORA_DISK_1: sid=1094 devtype=DISK

  14. RMAN-00571: ===========================================================
  15. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  16. RMAN-00571: ===========================================================
  17. RMAN-03002: failure of restore command at 11/12/2013 11:03:01
  18. RMAN-06172: no autobackup found or specified handle is not a valid copy or piece

  19. RMAN> **end-of-file**

  20. RMAN-00571: ===========================================================
  21. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  22. RMAN-00571: ===========================================================
  23. RMAN-00558: error encountered while parsing input commands
  24. RMAN-01009: syntax error: found "single-quoted-string": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"
  25. RMAN-01007: at line 0 column 2 file: standard input

  26. RMAN>

  27. Recovery Manager complete.
复制代码

回复 只看该作者 道具 举报

12#
发表于 2013-11-12 21:57:47
11.2
[oracle@mlab2 ~]$ cat ctl.sh
#!/bin/bash
export ORACLE_SID=G11R204
export ORACLE_HOME=/s01/oracle/app/oracle/product/11.2.0.4/dbhome_1
$ORACLE_HOME/bin/rman  cmdfile='/home/oracle/ctlbak.cmd' 'maclean'

[oracle@mlab2 ~]$ cat ctlbak.cmd

connect target /
run{
restore controlfile from  '/s01/fast_recovery_area/G11R204/backupset/2013_11_12/&1.bkp';
}


[oracle@mlab2 ~]$ ./ctl.sh

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 12 08:50:30 2013

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

RMAN>
RMAN> connect target *
2> run{
3> restore controlfile from  '/s01/fast_recovery_area/G11R204/backupset/2013_11_12/macleanbkp';
4> }
5>
6>
connected to target database: G11R204 (DBID=2438469611)

Starting restore at 12-NOV-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 device type=DISK

回复 只看该作者 道具 举报

13#
发表于 2013-11-12 21:59:12
结论 : 10.2 当路径中存在SHELL输入变量时可能存在问题

workaround:使用 restore controlfile from autobackup;

回复 只看该作者 道具 举报

14#
发表于 2013-11-12 22:08:44
Maclean Liu(刘相兵 发表于 2013-11-11 23:47
具体运行了报什么错 总要说一下吧?

额,10g的rman确实没有传递参数的功能,还有其他的办法么?是在是需要制定控制文件的文件名去恢复最新的控制文件
http://blog.ronnyegner-consulting.de/2010/08/02/rman-and-variables/

回复 只看该作者 道具 举报

15#
发表于 2013-11-12 22:12:41
为什么不能用restore controlfile from autobackup;?

回复 只看该作者 道具 举报

16#
发表于 2013-11-12 22:18:04
Maclean Liu(刘相兵 发表于 2013-11-12 22:12
为什么不能用restore controlfile from autobackup;?

备份文件是从异地复制过来了,restore controlfile from autobackup;可以识别到和恢复么?

回复 只看该作者 道具 举报

17#
发表于 2013-11-12 22:19:53
当然可以

回复 只看该作者 道具 举报

18#
发表于 2013-11-12 22:40:53
Maclean Liu(刘相兵 发表于 2013-11-12 22:19
当然可以

谢谢 尝试了可以.问题解决了.

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-5-17 16:55 , Processed in 0.054282 second(s), 20 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569