您好,欢迎访问一九零五行业门户网

RMAN多种备份脚本分享

分享的脚本在安装在linux的oracle 11g测试环境经过测试,如在自己环境使用请修改相应参数。使用source /home/oracle/.bash_profi
1.相关参数介绍:
命令行参数
描述
target
为目标数据库定义的一个连接字符串,当连接到一个目标数据库时,该连续是sysdba连接。该用户拥有启动和关闭数据库的权利,必须属于osdba组,必须建立一个口令文件允许sysdba连接。
catalog
连接到恢复目录。
nocatalog
不运用恢复目录。与catalog参数互斥
cmdfile
定义了输出命令文件名称的字符串。当运行rman时,可以运行命令文件或者交互式运行
log & msglog
定义了包含rman输出信息的文件的字符串,,log参数只能特别运用在命令行中。不能在rman中启动spooling,当应用日志文件时,输出的信息并不在屏幕上显示
trace
类似于log参数,将产生一个显示rman输入信息的文件。使用trace在屏幕上也显示。
append
特殊用法,如果消息日志文件存在则将消息追加到该文件中。经常与log联合使用
说明:分享的脚本在安装在linux的oracle 11g测试环境经过测试,如在自己环境使用请修改相应参数。使用source /home/oracle/.bash_profile语句可以确保在linux定时任务中执行成功,如果需要在win下使用,请酌情修改。
2.只备份归档文件,指定备份目录及备份文件格式指定的生成日志及备份文件的文件位置、格式。日志格式类似这样:rman-arch20130912-1634.log
[oracle@bys001 ~]$ cat archback.sh
#!/bin/sh
source /home/oracle/.bash_profile
/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman log /home/oracle/rman-arch`date +%y%m%d-%h%m`.log connect target /;
run{
backup archivelog all delete input
format '/backup/archlog/arch_%d_%t_%s';
}
exit
3.全库备份脚本,包括归档日志及控制文件、spfile参数文件[oracle@bys001 ~]$ cat fullback.sh
#!/bin/sh
source /home/oracle/.bash_profile
/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman log /home/oracle/backfull-`date +%y%m%d-%h%m`.log connect target /;
run {
backup full tag 'bys001-full' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
4.差异增量differential备份脚本--有0、1、2三级%%%这是默认的增量备份方式0级差异增量备份脚本 
[oracle@bys001 ~]$ cat back0.sh
#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level0
rman log /home/oracle/back0-`date +%y%m%d-%h%m`.log connect target /;
run {
backup incremental level=0 tag 'bys001-0' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
1级差异增量备份脚本[oracle@bys001 ~]$ cat back1.sh
#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level 1
##########
rman log /home/oracle/back1-`date +%y%m%d-%h%m`.log connect target /;
run {
backup incremental level=1 tag 'bys001-1' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
2级差异增量备份脚本[oracle@bys001 ~]$ cat back2sh
#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level 2
rman log /home/oracle/back2-`date +%y%m%d-%h%m`.log connect target /;
run {
backup incremental level=2 tag 'bys001-2' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
5.cumulative累积增量备份--有0、1、2三级0级累积增量备份脚本#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level 0 ---cumulative
rman log /home/oracle/back0-`date +%y%m%d-%h%m`.log connect target /;
run {
backup incremental level=0 cumulative tag 'bys001-0' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
备份脚本#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level 1 --cumulative
rman log /home/oracle/back1-`date +%y%m%d-%h%m`.log connect target /;
run {
backup incremental level=1 cumulative tag 'bys001-1' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
2级累积增量备份脚本 
这个脚本里使用了服务名来登陆rman。最好先在rman中使用connect target sys/sys@192.168.1.212:1521/bys001;确认登陆正常再写入脚本。
当然也可以使用 rman target sys/sys@bys001
#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level 2 ---cumulative
rman log /home/oracle/back2-`date +%y%m%d-%h%m`.log connect target sys/sys@192.168.1.212:1521/bys001;
run {
backup incremental level=2 cumulative tag 'bys001-2' database
format /backup/full/bys001full_%d_%t_%s
plus archivelog
format /backup/full/bys001arch_%d_%t_%s
delete all input;
}
exit
推荐阅读:
oracle基础教程之通过rman复制数据库
rman备份策略制定参考内容
rman备份学习笔记
oracle数据库备份加密 rman加密
其它类似信息

推荐信息