Oracle-Rman 增量备份计划任务

Oracle-Rman 增量备份计划任务

Rman其实就是一个工具,通过这一个工具,协调上面的几大部件。

Rman可以通过生产的数据库备份自己的硬盘上面,磁带上面,备份的信息会放到控制文件里面或者数据库里面。

Oracle-Rman 增量备份计划任务

Oracle-Rman 增量备份计划任务

要实现上面的典型的增量备份方案 可以做成执行计划   因为只有0,1,2三种级别备份所以只需要三个脚本。

[[email protected] script]$ pwd

/rmanbackup/script

在该目录下面创建三个文件,即备份的脚本,分别为0,1,2级的脚本。

[[email protected] script]$ vi bakl0

[[email protected] script]$ vi bakl1

[[email protected] script]$ vi bakl2

里面写上

run {

allocate channel c1 type disk;

backup

incremental level 0

format "/rmanbackup/beifeng/inc0_%u_%T"

tag monday_inc0

database;

release channel c1;

}

里面通过修改数字来表示增量为多少的备份。

 

 

rman target /  msglog=/rmanbackup/ramlog/bakl0.log cmdfile=/rmanbackup/script/bakl0

[[email protected] script]$ rman target /  msglog=/rmanbackup/ramlog/bakl0.log cmdfile=/rmanbackup/script/bakl0

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> [[email protected] script]$

看到可以使用rman脚本进行备份。

备份产生的文件可以看到已经产生了

[[email protected] beifeng]$ pwd

/rmanbackup/beifeng

[[email protected] beifeng]$ ls

inc0_03sln8as_20171209  inc0_04sln8eh_20171209

 

再去看看日志文件里面内容

[[email protected] ramlog]$ vi bakl0.log

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Dec 9 19:19:55 2017

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORADB (DBID=2714287021)

 

RMAN> run {

2> allocate channel c1 type disk;

3> backup

4> incremental level 0

5> format "/rmanbackup/beifeng/inc0_%u_%T"

6> tag monday_inc0

7> database;

8> release channel c1;

9> }

10>

using target database control file instead of recovery catalog

allocated channel: c1

channel c1: SID=35 device type=DISK

 

Starting backup at 09-DEC-17

channel c1: starting incremental level 0 datafile backup set

channel c1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/oradb/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/oradb/sysaux01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/oradb/undotbs01.dbf

channel c1: starting piece 1 at 09-DEC-17

channel c1: finished piece 1 at 09-DEC-17

piece handle=/rmanbackup/beifeng/inc0_03sln8as_20171209 tag=MONDAY_INC0 comment=NONE

channel c1: backup set complete, elapsed time: 00:01:56

channel c1: starting incremental level 0 datafile backup set

channel c1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel c1: starting piece 1 at 09-DEC-17

channel c1: finished piece 1 at 09-DEC-17

piece handle=/rmanbackup/beifeng/inc0_04sln8eh_20171209 tag=MONDAY_INC0 comment=NONE

channel c1: backup set complete, elapsed time: 00:00:03

"bakl0.log" 44L, 1628C       

 

在使用上面方式备份的时候最好使用全路径,不要使用相对路径。Rman也最好使用全路径。

 

 

[[email protected] ramlog]$ which rman

/u01/app/oracle/product/11.2.0/db_1/bin/rman

这样写最好

/u01/app/oracle/product/11.2.0/db_1/bin/rman target /  msglog=/rmanbackup/ramlog/bakl0.log cmdfile=/rmanbackup/script/bakl0

   

 

上面都是手动备份,如果要自动实现备份就要使用crontab了。


Oracle-Rman 增量备份计划任务

每天晚上23:45分执行脚本。

 

/etc/crontab中加入下面的两句,第一句就是注释了。以#号开始,后面写一个自己能知道这是什么任务的备注;

# reboot OS
30 8 * * * root /sbin/reboot

第一段应该定义的是:分钟,表示每个小时的第几分钟来执行。范围是从0-59
第二段应该定义的是:小时,表示从第几个小时来执行,范围是从0-23
第三段应该定义的是:日期,表示从每个月的第几天执行,范围从1-31
第四段应该定义的是:月,表示每年的第几个月来执行,范围从1-12
第五段应该定义的是:周,表示每周的第几天执行,范围从0-6,其中 0表示星期日。
每六段应该定义的是:用户名,也就是执行程序要通过哪个用户来执行,这个一般可以省略;
第七段应该定义的是:执行的命令和参数

 

# For details see man 4 crontabs

 

# Example of job definition:

# .---------------- minute (0 - 59)

# |  .------------- hour (0 - 23)

# |  |  .---------- day of month (1 - 31)

# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...

# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# |  |  |  |  |

# *  *  *  *  * user-name command to be executed

 

 

[[email protected] ramlog]# crontab -e -u oracle

在里面加上上面那些语句,代表会以Oracle用户执行rman target /..............................

注意修改完用户的执行计划之后使用下面语句重启一下服务。

[[email protected] ramlog]# service crond restart

Stopping crond:                                            [  OK  ]

Starting crond: