a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 141|回复: 0

[考试辅导] Oracle数据库自动备份的实现经过

[复制链接]
发表于 2012-8-4 14:06:19 | 显示全部楼层 |阅读模式
问题描述:6 x$ |5 R1 A. A( P; ^" V# y& E1 b
Oracle自动备份脚本的实现。) O1 G( |  V5 U) \# s9 g1 E# j6 C
错误提示1:6 f5 d8 a6 y# }: a8 m  z
Message file RMAN.msb not found6 `: L* k" w0 K% S! K$ x8 _
Verify that Oracle_HOME is set properly
5 P6 Z  u( S+ i7 F. n6 b5 z。。。。。。2 C, E/ u2 a1 Q8 K% H
错误原因:
, F* J8 f6 G3 E2 c自动执行的不能够识别相应的命令,需要在自动备份脚本中显式的声明Oracle的环境变量。2 ~: C# Q/ v$ _* [& y) y0 I- A+ L8 m* L& S
错误提示2:/ d4 |1 r" |# C6 C* A
standard in must be a tty
, D' B7 ^; w$ l$ J。。。。。。' ]; z0 m' X# R9 a1 ]
错误原因:. l; n  `6 M# {" a* ]' l* n3 }
不能在cron使用su或者管道等操作,必须将su命令移动到相关的shell脚本中。
* z" K1 D: ~) W% D2 G7 |错误提示3:
. C4 |( G5 _/ O+ GArgument   Value     Description6 }% q+ s  z3 u5 h
-----------------------------------------------------------------------------
; ?6 X9 m* i4 h+ q8 v8 jtarget    quoted-string connect-string for target database9 O9 {/ v! Q: b% S! `6 {/ }) `
catalog   quoted-string connect-string for recovery catalog6 d( w$ D* q2 W+ }9 w5 @& Z
nocatalog  none      if specified, then no recovery catalog
& w9 k' o; F5 G  X6 ncmdfile   quoted-string name of input command file# U, T/ a  L2 g* ^9 E' e
log     quoted-string name of output message log file9 _$ Q, `6 ^% K- y, T( s6 V
trace    quoted-string name of output debugging message log file
0 T$ S" W  D! S. j. K3 Kappend    none      if specified, log is opened in append mode
0 \: D/ \6 y1 l/ i0 }debug    optional-args activate debugging; g6 Y+ D  R8 F  K
msgno    none      show RMAN-nnnn prefix for all messages3 f) }5 u# ]/ G( l
send     quoted-string send a command to the media manager
, ^7 z* h1 A# \+ B5 [pipe     string     building block for pipe names
- ~% J& {7 `* F3 \* k" V: S: w/ htimeout   integer    number of seconds to wait for pipe input
2 _' a- |* Y2 r$ K4 Pchecksyntax none      check the command file for syntax errors) Z5 s. k: M7 {0 N& C
-----------------------------------------------------------------------------
: {1 \  V0 g! A- n, j2 A% C" @2 ^Both single and double quotes (' or ") are accepted for a quoted-string.
9 v9 T8 e: P! O- c; [Quotes are not required unless the string contains embedded white-space.
; O8 T' @0 p) X) ]# JRMAN-00571: ===========================================================9 v) D, W; |2 Y) k( H
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============3 N$ Z' O6 h  P
RMAN-00571: ===========================================================
$ t+ ^7 }" V/ iRMAN-00556: could not open CMDFILE "backup_ar.rcv"
2 D5 Q$ a1 n% x3 i: C8 K- O7 k。。。。。。2 @# j) w& r! W- Z- _4 R6 V0 w: f
错误原因:
4 v/ ^# H+ J3 g; z' V+ a7 V需要在cmdfile中指明绝对路径,不能因为shell脚本调用的cmdfile是在同一个目录下就可以直接使用文件名或者直接使用./
# {' O  p6 V$ x. ]0 Y正确示例代码:7 d5 G, D( @' }
1、#cron文件; X# e4 w- f# ~/ ^& d: s9 d
0 12,18 * * * /home/Oracle/bak_sh/backup_ar.sh/ t0 p' c  V6 g2 Y3 V: ~- ?
#表示每天12,18点对数据库归档日至进行全备份) l! x1 J$ Q/ a% f& m
2、入口shell文件,文件名:backup_ar.sh# f0 e) ~0 S" e4 K/ H% \! c
export Oracle_HOME=/home/u01/app/Oracle/Oracle/product/10.2.0/db_1
+ |( q4 f3 [) S! ]export Oracle_SID=test
  e! Z% U* N% a% Oexport LANG=en_US.UTF-8
* j2 R; n6 m7 z7 O& o. S$ |" L/home/u01/app/Oracle/Oracle/product/10.2.0/db_1/bin/rman cmdfile = backup_ar.rcv0 k' g& {1 b9 a7 g
3、rman备份脚本
; {4 C) q* N& X5 a, B5 }% ~connect target /
1 W% }" l2 l  |1 _/ o9 L# Z2 _connect catalog rman/rman@rman
/ f8 ?8 e; m6 O/ T7 P0 R. ^7 mrun{
; H% P/ w; [( ^2 P" p2 e! qallocate channel d1 device type disk;
2 g) Z9 W  Z0 m* B: Q7 G8 L, `/ S! [sql 'alter system archive log current';% n) n8 o4 r2 @2 E
backup archivelog all delete input0 \+ V1 l* T/ V9 u
 format '/opt/rmanback/full_%u_%p_%c.ac' filesperset = 3;# P# K5 t) e/ E7 w6 Y9 M( `
release channel d1;
0 N6 k- g+ i$ W}# P( v, z" v4 V, t- L0 u) S) }
解决方法:7 r( Q8 L8 O) x2 E: D
1、两种办法# H3 T0 p5 Y$ T( Z) U  o1 {4 ?0 Q5 L# `
一是用root的crontab,*/2 * * * * a.sh --》su - Oracle -c a.sh
( ^7 r6 u9 P! c- d( }! q一是在a.sh里加上Oracle的环境。! y# g. h& F4 y1 i1 W
2、我们做的cron测试:
: B% ^* o% s/ @2 T1 R9 B8 S实例:
5 Y- o8 f6 u8 lVi /etc/cron.minly/new.sh
7 P( Q2 |8 k+ S9 O5 t内容:) x- T/ E. [7 {8 u! @" @2 I
Su – Oracle –c “/home/Oracle/mginfo.sh”' n3 \9 ^. d/ }
Vi /home/Oracle/mginfo.sh1 T3 ?" D" }8 f) Y+ I7 C" N: U! o
内容:) I4 p3 ?) V; L! K
Exp mginfotech/mginfotech file=mginfotech.dmp log=mginfotech.log" c* d4 a1 n8 _
Vi /etc/crontab
6 j3 x6 y7 [  i& D  R$ Z6 X内容:5 F1 ~" h' V8 ^, E, x: o# L
59 23 * * * root run-parts /etc/cron.minly
  m( C. ^; q3 i+ o6 q每晚23:59分钟执行$ `5 R( M! ?% l& M
cron中无法读取环境变量
+ Q& n: t/ b8 D在shell中显示地export环境变量
; K8 U) ]8 X( g3 `* Zexport Oracle_HOME=/opt/ora9/product/9.2# Z2 O7 @5 x4 `
export Oracle_SID=Oracle/ ]+ S" w9 R! E1 Z1 U% p* U2 f
export NLS_LANG=xxxxx6 X: b1 r! ]$ x6 _2 Z" q
然后再试
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-9-28 06:38 , Processed in 0.219693 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表