Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5205361
  • 博文数量: 1004
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13042
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1004)

文章存档

2020年(1)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Oracle

2012-06-02 11:47:42

环境:
OS:Red Hat Linux As 5
DB:10.2.0.4
 
-------------------------------Linux----------------------------------
1.备份数据文件,归档日志文件,控制文件
run{
allocate channel dup type disk;
backup format '/u02/rman_bak/20120602/df_t%t_s%s_p%p' database;
backup current controlfile format '/u02/rman_bak/20120602/control_flie_t%t_s%s_p%p';
sql 'alter system archive log current';
backup format '/u02/rman_bak/20120602/archive_log_t%t_s%s_p%p' archivelog all delete input;
release channel dup;
}
 
2.我们在备份了归档日志后作了删除后,将备份集的归档日志解压到某个目录.
run
{
  set archivelog destination to '/u02/archive_log';
  restore archivelog all;
}
3.制定备份参数文件和控制文件
run{
  allocate channel c1 device type disk;
  allocate channel c2 device type disk;
  allocate channel c3 device type disk;
  allocate channel c4 device type disk;
  backup database format '/u02/rman_bak/full_%u_%T.bak';
  backup spfile format '/u02/rman_bak/spfile_%u_%T.bak';
  backup current controlfile format '/u02/rman_bak/ctl_%u_%T.bak';
  sql 'alter system archive log current';
  backup archivelog all delete input format '/u02/rman_bak/arc_%u_%T.bak';
  release channel c1;
  release channel c2;
  release channel c3;
  release channel c4;
}
这里单独制定备份了控制文件和参数文件,其实不用单独制定系统也会备份参数文件和控制文件.  这里delete input的作用是删除备份的归档日志,若没有这个语句的话,下次备份会重复备份上次备份过的归档日志.
 
4.零级备份
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup incremental level 0 database format '/u02/rman_backup/0_level_backup_%u_%T';
release channel c1;
release channel c2;
}
5.差异一级备份(备份上最近一次0级或1级备份所变化的数据块)
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup incremental level 1 database format '/u02/rman_backup/1_level_backup_%u_%T';
release channel c1;
release channel c2;
}
 
 
6.root用户下备份
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=oracl
export ORACLE_USER=oracle
#start or stop script
user=sys
user_pwd=sys
l_rman_path='/u01/rman_backup'
l_date=`date +%Y%m%d`
l_year=`echo ${l_date}|cut -c1-4`
l_month=`echo ${l_date}|cut -c1-6`
su - "$ORACLE_USER"< rman< connect target ${user}/${user_pwd}
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup spfile format '/rmanbak/mybak/spfile_%u_%t_%T.bak';
backup current controlfile format '/rmanbak/mybak/ctl_%u_%t_%T.bak';
release channel c1;
release channel c2;
}
EOF
EOO
 
7.oracle用户下备份
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=oracl
#start or stop script
user=sys
user_pwd=sys
l_rman_path='/u01/rman_backup'
l_date=`date +%Y%m%d`
l_year=`echo ${l_date}|cut -c1-4`
l_month=`echo ${l_date}|cut -c1-6`
rman< connect target ${user}/${user_pwd}
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup spfile format '/rmanbak/mybak/spfile_%u_%t_%T.bak';
backup current controlfile format '/rmanbak/mybak/ctl_%u_%t_%T.bak';
release channel c1;
release channel c2;
}
EOF

备份数据库、控制文件、参数文件、归档日志(备份后不删除)
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=slnngk
#start or stop script
user=sys
user_pwd=sys
l_rman_path='/u01/rman'
l_date=`date +%Y%m%d`
cur_date=`date +%Y%m%d%H%M`
l_year=`echo ${l_date}|cut -c1-4`
l_month=`echo ${l_date}|cut -c1-6`
rman< connect target ${user}/${user_pwd}
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup spfile format '${l_rman_path}/spfile_%u_%t_%T_${cur_date}.bak';
backup current controlfile format '${l_rman_path}/ctl_%u_%t_%T_${cur_date}.bak';
sql 'alter system archive log current';
backup archivelog all format '/u01/rman/archivelog_%u_%t_%T_${cur_date}';
release channel c1;
release channel c2;
}
EOF

备份归档日志后进行删除的话,需要加上delete input选择项:
backup archivelog all delete input format '/u01/rman/archivelog_%u_%t_%T';


8.AIX(root用户下)
ctl_bak.sh内容如下
#!/bin/ksh
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=oracl
export ORACLE_USER=oracle
l_date=`date +%Y%m%d%H%M`
l_day=`echo ${l_date}|cut -c1-8`
su - "$ORACLE_USER"< rman target / nocatalog cmdfile '/rbak/script/ctl_bak.sql' log '/rbak/script/ctl_bak_${l_day}.log'
EOO
ctl_bak.sql内容如下
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup spfile format '/rbak/rmanbak/spfile_%u_%n_%T.bak';
backup current controlfile format '/rbak/rmanbak/ctl_%u_%n_%T.bak';
release channel c1;
release channel c2;
}
 
9.duration使用(hh:mi)
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup duration 00:30 minimize load database;
release channel c1;
release channel c2;
}

-- minimize time快一些
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup duration 00:30 minimize time database;
release channel c1;
release channel c2;
}



---------------------------------Windows--------------------------------
备份脚本rman_bakup.sql
run{
allocate channel c1 type disk;
backup database format 'F:\rman_backup\full_%U_%T.bak';
release channel c1;
}
exit
 
生成批处理文件rman_backup.bat
rman target sys/sys nocatalog CMDFILE 'F:\rman_script\rman_bakup.sql' LOG 'F:\rman_script\rman_backup_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log'
 
 
通配符号说明
%c 备份片的拷贝数
%d 数据库名称
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,YYYYMMDD为日期,QQ是一个1-256的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)
阅读(1540) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~