usharkp 发表于 2011-12-23 03:15

linux 下的 oracle 自动备份脚本

<DIV>这个脚本比较简单:</DIV>
<DIV>周天对数据库进行全备,周一到周六进行归档日志备份。</DIV>
<DIV>$ cat backup.sh <BR>#!/bin/bash<BR>#oracle backup script<BR>btime=`date +%A`<BR>export ORACLE_SID=snzo<BR>export ORACLE_HOME=/u01/oracle/product/10g/db<BR>if [ $btime = "Sunday" ] ; then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /u01/oracle/product/10g/db/bin/rman target / cmdfile=/home/oracle/datafile.sql log=/home/oracle`date +%Y-%m-%d`_dbf.log<BR>else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /u01/oracle/product/10g/db/bin/rman target / cmdfile=/home/oracle/archive.sql log=/home/oracle/`date +%Y-%m-%d`_arc.log<BR>fi</DIV>
<DIV>备份数据库的数据库脚本:<BR>$ cat datafile.sql <BR>run<BR>{<BR>allocate channel ch1 type disk;<BR>allocate channel ch2 type disk;<BR>backup database format '/u01/oracle/backup/%U_%T.dbf';</DIV>
<DIV>backup archivelog all delete input format '/u01/oracle/backup/%U_%T.arc';<BR>release channel ch1;<BR>release channel ch2;<BR>}<BR>exit</DIV>
<DIV>备份归档日志的脚本:<BR>$ cat archive.sql <BR>run<BR>{<BR>allocate channel ch1 type disk;<BR>backup archivelog all delete input format '/u01/oracle/backup/%U_%T.arc';<BR>release channel ch1;<BR>}<BR>exit</DIV>
<DIV>设置crontab:</DIV>
<DIV>$ crontab -l<BR>SHELL=/bin/bash<BR>PATH=/sbin:/bin:/usr/sbin:/usr/bin:/u01/orace/product/10g/db/bin<BR>HOME=/home/oracle<BR>*/5&nbsp; *&nbsp; *&nbsp; *&nbsp; *&nbsp; /home/oracle/backup.sh</DIV>
<DIV>此处为测试,没5分钟进行一次备份。</DIV>
<DIV>最后查看备份结果:</DIV>
<DIV>$ cat 2011-10-19_arc.log </DIV>
<DIV>Recovery Manager: Release 10.2.0.4.0 - Production on Wed Oct 19 16:55:01 2011</DIV>
<DIV>Copyright (c) 1982, 2007, Oracle.&nbsp; All rights reserved.</DIV>
<DIV>connected to target database: SNZO (DBID=2088621957)</DIV>
<DIV>RMAN&gt; run<BR>2&gt; {<BR>3&gt; allocate channel ch1 type disk;<BR>4&gt; backup archivelog all format '/u01/oracle/backup/%U_%T.arc';<BR>5&gt; release channel ch1;<BR>6&gt; }<BR>7&gt; exit<BR>using target database control file instead of recovery catalog<BR>allocated channel: ch1<BR>channel ch1: sid=10 devtype=DISK</DIV>
<DIV>Starting backup at 19-OCT-11<BR>current log archived<BR>channel ch1: starting archive log backupset<BR>channel ch1: specifying archive log(s) in backup set<BR>input archive log thread=1 sequence=102 recid=14 stamp=764953366<BR>input archive log thread=1 sequence=103 recid=15 stamp=764953435<BR>input archive log thread=1 sequence=104 recid=16 stamp=764956491<BR>input archive log thread=1 sequence=105 recid=17 stamp=764958304<BR>input archive log thread=1 sequence=106 recid=18 stamp=764958604<BR>input archive log thread=1 sequence=107 recid=19 stamp=764958903<BR>input archive log thread=1 sequence=108 recid=20 stamp=764959203<BR>input archive log thread=1 sequence=109 recid=21 stamp=764959503<BR>input archive log thread=1 sequence=110 recid=22 stamp=764959803<BR>input archive log thread=1 sequence=111 recid=23 stamp=764960103<BR>channel ch1: starting piece 1 at 19-OCT-11<BR>channel ch1: finished piece 1 at 19-OCT-11<BR>piece handle=/u01/oracle/backup/1rmpgnb7_1_1_20111019.arc tag=TAG20111019T165503 comment=NONE<BR>channel ch1: backup set complete, elapsed time: 00:00:02<BR>Finished backup at 19-OCT-11</DIV>
<DIV>Starting Control File and SPFILE Autobackup at 19-OCT-11<BR>piece handle=/u01/oracle/backup/c-2088621957-20111019-0d comment=NONE<BR>Finished Control File and SPFILE Autobackup at 19-OCT-11</DIV>
<DIV>released channel: ch1</DIV>
<DIV>Recovery Manager complete.<BR></DIV>
页: [1]
查看完整版本: linux 下的 oracle 自动备份脚本