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 <<EOF
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 <<EOF
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 <<EOF
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 <<EOF
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 <<EOF
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 <<EOF
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
1级累积增量备份脚本
#!/bin/sh
source /home/oracle/.bash_profile
#########rman-back level 1 --cumulative
rman log /home/oracle/back1-`date +%Y%m%d-%H%M`.log <<EOF
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 <<EOF
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