免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1278 | 回复: 0
打印 上一主题 下一主题

linux 下的 oracle 自动备份脚本 [复制链接]

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

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP