a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 123|回复: 0

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

[复制链接]
发表于 2012-8-4 14:06:19 | 显示全部楼层 |阅读模式
问题描述:: J* `, H5 |4 o4 f# V" P
Oracle自动备份脚本的实现。! @& c$ f+ S) H% v5 ?% a/ d
错误提示1:
9 @! [$ o: o! y  i( U! ?& YMessage file RMAN.msb not found
; {; B2 y: f. ]5 {9 RVerify that Oracle_HOME is set properly, k9 J: _2 ?/ u% Z. ^$ u
。。。。。。) e2 u9 }9 w/ w1 ~; V4 R* V
错误原因:; _9 A0 @  r- t9 `5 M5 A
自动执行的不能够识别相应的命令,需要在自动备份脚本中显式的声明Oracle的环境变量。8 K, `0 [' }7 k
错误提示2:; |- i. ~2 j9 g$ `
standard in must be a tty
* S! [2 v# s: F" u5 l。。。。。。
; X' Z* S+ Z% k0 k# I" e! D错误原因:
0 b' O/ o9 p8 ]3 q0 N% P4 }" Q0 C不能在cron使用su或者管道等操作,必须将su命令移动到相关的shell脚本中。0 G1 O( b$ Z+ H" Y4 \
错误提示3:, M+ D7 b6 l. d0 n5 l
Argument   Value     Description3 x8 C  \7 j& w) c( s5 i( D6 f
-----------------------------------------------------------------------------
  F* i: x5 Z) E3 X% Ftarget    quoted-string connect-string for target database% Z5 c5 v) ?8 v7 q) C) e9 a
catalog   quoted-string connect-string for recovery catalog
# F7 Q5 I5 W9 W9 Nnocatalog  none      if specified, then no recovery catalog. T1 f: D+ g- x1 Q
cmdfile   quoted-string name of input command file- o" U; f/ _% U& ^
log     quoted-string name of output message log file8 M: D  j, s6 O4 m
trace    quoted-string name of output debugging message log file- r- |8 U+ q5 `: @5 [
append    none      if specified, log is opened in append mode% E. V6 \1 u2 H( q( r6 T" n
debug    optional-args activate debugging/ w9 N' c' x8 F( V2 g0 x- M
msgno    none      show RMAN-nnnn prefix for all messages
* M7 y4 E! {8 Q8 l1 f8 L+ U! ^send     quoted-string send a command to the media manager
( i: R; Z7 @4 {4 Q, e+ F( v, ppipe     string     building block for pipe names, ]* `# _% E( W/ X$ W$ U2 P
timeout   integer    number of seconds to wait for pipe input
2 ~; Q4 y7 f6 S' L3 Zchecksyntax none      check the command file for syntax errors
. g* [; Q9 k; O8 _9 \. c3 U, Z- n-----------------------------------------------------------------------------4 M' x& ~( g, n  B% l$ b
Both single and double quotes (' or ") are accepted for a quoted-string.8 d9 S( b& K8 K- h/ Q. C
Quotes are not required unless the string contains embedded white-space.
( o) v* S  E0 k4 K) A3 F+ pRMAN-00571: ===========================================================
+ f0 Q3 {8 g7 TRMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============- b' y5 u- k4 \- M
RMAN-00571: ===========================================================
5 O, s; }4 j7 |RMAN-00556: could not open CMDFILE "backup_ar.rcv"
! N! X. i" u9 Z/ ^。。。。。。! Z# u/ }) [4 }! ]
错误原因:; P% L8 I% `5 c& c0 x
需要在cmdfile中指明绝对路径,不能因为shell脚本调用的cmdfile是在同一个目录下就可以直接使用文件名或者直接使用./
! Y4 a( e# ]! j& C- _9 N正确示例代码:
, ]4 z0 f1 _6 Z4 v  T' P( `4 i: k1、#cron文件: E& V7 X( m- f7 k& C( w/ h  i% j' X
0 12,18 * * * /home/Oracle/bak_sh/backup_ar.sh( L( k. g, }3 A* x) T+ R
#表示每天12,18点对数据库归档日至进行全备份. N, S) c2 p, f  ?+ m& Q: K7 o
2、入口shell文件,文件名:backup_ar.sh
" P3 g' N" }4 R( x$ N$ O2 c- rexport Oracle_HOME=/home/u01/app/Oracle/Oracle/product/10.2.0/db_1& V7 a: J2 Z# V3 K4 ]) z
export Oracle_SID=test. B  @$ |+ _- y' X% W2 j
export LANG=en_US.UTF-8
4 t9 ^8 C: W' z: u: V/home/u01/app/Oracle/Oracle/product/10.2.0/db_1/bin/rman cmdfile = backup_ar.rcv
; U' U; |6 `9 E5 Q/ d2 ^; |0 V3、rman备份脚本+ z, M/ p) P  r$ i/ r1 ?
connect target /) c' Z+ t& |5 w7 i, ^/ B
connect catalog rman/rman@rman
) T& ]8 ^3 Z' h% z) Crun{+ W: P. t: N$ t
allocate channel d1 device type disk;
- q4 P2 |6 n/ s/ t& Y5 E1 k& m9 ]sql 'alter system archive log current';: L% h) ]/ [$ d6 K; ]: S4 r
backup archivelog all delete input
$ ~6 x) |* n9 H0 U* V8 Y format '/opt/rmanback/full_%u_%p_%c.ac' filesperset = 3;
  m6 s4 d! i5 m9 k( R2 K% x. Jrelease channel d1;
9 o/ n+ }3 f3 y6 c% g  {, l}
2 D! P1 _6 n. L1 j3 b5 Q解决方法:
0 `9 }# j$ V/ ?6 A4 `1、两种办法1 ^! s8 }3 b4 m1 X2 H% _! a
一是用root的crontab,*/2 * * * * a.sh --》su - Oracle -c a.sh* {" J9 ]- `" m- T
一是在a.sh里加上Oracle的环境。( x6 \2 A+ b6 u+ ?: P
2、我们做的cron测试:
+ W& r( r5 K# K# _, x实例:
' h$ O* f2 I# O& g' T0 DVi /etc/cron.minly/new.sh" \2 H# ]. i8 c1 _- i5 h
内容:4 ^! Q. _- }( X/ [8 `$ }
Su – Oracle –c “/home/Oracle/mginfo.sh”
+ i) c* q8 \! PVi /home/Oracle/mginfo.sh
1 j% o1 E3 b0 W; T7 _0 d* n内容:9 ~; y& j$ F: U$ r0 _- C4 i
Exp mginfotech/mginfotech file=mginfotech.dmp log=mginfotech.log
& _$ w* }& v; O8 l' ]Vi /etc/crontab
2 w* i$ i8 ^& T) o/ J- }内容:' c9 k* s+ W1 F1 t
59 23 * * * root run-parts /etc/cron.minly1 S+ ^% W( b& N* W' o3 N$ E
每晚23:59分钟执行
4 ]( r6 i4 h5 A, R6 fcron中无法读取环境变量, e: ^/ G$ Q$ G  _5 Y  P
在shell中显示地export环境变量) x; b/ d) b( h" E" u  f6 U
export Oracle_HOME=/opt/ora9/product/9.2+ h& Q8 B8 X- ^( E# K3 H4 {! f0 L6 D
export Oracle_SID=Oracle
8 M7 w4 j3 b5 t7 Q. c4 i# fexport NLS_LANG=xxxxx4 o7 S* O0 ?. ~- s( U* n* a, p
然后再试
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-7 22:02 , Processed in 0.189421 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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