oracle 10g rman备份与恢复之三
1、rman实际上就是一个备份工具,协调这部件。
就是在target database、auxiliary database、disk/sbt tape、catalog database/controlfile
同时连接到上面3个库,达到备份到磁盘或者磁带,或者说从磁带或者磁带恢复。
----------------------------------------------------------------------
2、一个典型的增量备份方案
星期天晚上 -level 0 backup performed (full backup)
星期一晚上 -level 2 backup performed
星期二晚上 -level 2 backup performed
星期三晚上 -level 1 backup performed
星期四晚上 -level 2 backup performed
星期五晚上 -level 2 backup performed
星期六晚上 -level 2 backup performed
假设周二数据库需要恢复,就用到周日和周一的备份;
周四数据库需要恢复,就需要周日和周三的备份就行了。
当然恢复的时候rman会自动去找备份集。
-----------------------------------------------------------------------
自动备份:备份脚本+crontab
bakl0
bakl1
bakl2
执行脚本
rman target / msglog=bakl0.log cmdfile=bakl0
rman target / msglog=bakl1.log cmdfile=bak11
rman target / msglog=bakl2.log cmdfile=bakl2
------------------------------------------------------------------------
建立脚本
[oracle@redhat ora10g]$ cd script/
[oracle@redhat script]$ cat bakl0
run{
allocate channel cha1 type disk;
backup
incremental level 0
format "/oracle/ora10g/rmanback/inc0_%u_%T"
tag monday_inc0
database;
release channel cha1;
}
[oracle@redhat script]$ cp bakl0 bacl1
[oracle@redhat script]$ cp bakl0 bakl2
[oracle@redhat script]$ mv bacl1 bakl1
[oracle@redhat script]$ ls
bakl0 bakl1 bakl2
[oracle@redhat script]$ ls -l
total 12
-rw-r--r-- 1 oracle oinstall 160 Apr 21 02:29 bakl0
-rw-r--r-- 1 oracle oinstall 160 Apr 21 02:29 bakl1
-rw-r--r-- 1 oracle oinstall 160 Apr 21 02:30 bakl2
[oracle@redhat script]$ chmod 755 *
[oracle@redhat script]$ ll
total 12
-rwxr-xr-x 1 oracle oinstall 160 Apr 21 02:29 bakl0
-rwxr-xr-x 1 oracle oinstall 160 Apr 21 02:29 bakl1
-rwxr-xr-x 1 oracle oinstall 160 Apr 21 02:30 bakl2
[oracle@redhat script]$
[oracle@redhat script]$ vi bakl1
[oracle@redhat script]$ cat bakl1
run{
allocate channel cha1 type disk;
backup
incremental level 1
format "/oracle/ora10g/rmanback/inc0_%u_%T"
tag monday_inc1
database;
release channel cha1;
}
[oracle@redhat script]$ vi bakl2
[oracle@redhat script]$ cat bakl2
run{
allocate channel cha1 type disk;
backup
incremental level 2
format "/oracle/ora10g/rmanback/inc0_%u_%T"
tag monday_inc2
database;
release channel cha1;
}
[oracle@redhat script]$
---------------------------------------------------------------------
命令
rman target / msglog=/oracle/ora10g/rmanback/bakl0.log cmdfile=/oracle/rmanback/script/bakl0
rman target / msglog=/oracle/ora10g/rmanback/bakl1.log cmdfile=/oracle/rmanback/script/bakl1
rman target / msglog=/oracle/ora10g/rmanback/bakl2.log cmdfile=/oracle/rmanback/script/bakl2
我这里创建了catalog目录
执行备份
[oracle@redhat script]$ rman target / catalog rman/rman msglog=/oracle/ora10g/rmanback/backl0.log cmdfile=/oracle/ora10g/script/bakl0
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> [oracle@redhat script]$ ls
bakl0 bakl1 bakl2
[oracle@redhat ora10g]$ ls
admin bakl0 flash_recovery_area oradata oraInventory product rmanback rman_wolfbak.dbf script
[oracle@redhat ora10g]$ cd rmanback/
[oracle@redhat rmanback]$ ls
backl0.log full_20130420 inc0_1co7jn4l_20130421
[oracle@redhat rmanback]$ ll
total 1095796
-rw-r--r-- 1 oracle oinstall 1555 Apr 21 02:45 backl0.log
-rw-r----- 1 oracle oinstall 559783936 Apr 20 11:36 full_20130420
-rw-r----- 1 oracle oinstall 561201152 Apr 21 02:44 inc0_1co7jn4l_20130421
[oracle@redhat rmanback]$ cat backl0.log
Recovery Manager: Release 10.2.0.1.0 - Production on 星期日 4月 21 02:38:11 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: WOLF (DBID=3778783462)
connected to recovery catalog database
RMAN> run{
2> allocate channel cha1 type disk;
3> backup
4> incremental level 0
5> format "/oracle/ora10g/rmanback/inc0_%u_%T"
6> tag monday_inc0
7> database;
8> release channel cha1;
9> }
10>
11>
allocated channel: cha1
channel cha1: sid=135 devtype=DISK
Starting backup at 21-4月 -13
channel cha1: starting incremental level 0 datafile backupset
channel cha1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oracle/ora10g/oradata/wolf/system01.dbf
input datafile fno=00003 name=/oracle/ora10g/oradata/wolf/sysaux01.dbf
input datafile fno=00002 name=/oracle/ora10g/oradata/wolf/undotbs01.dbf
input datafile fno=00005 name=/oracle/ora10g/oradata/wolf/rmanwolf.dbf
input datafile fno=00004 name=/oracle/ora10g/oradata/wolf/users01.dbf
channel cha1: starting piece 1 at 21-4月 -13
channel cha1: finished piece 1 at 21-4月 -13
piece handle=/oracle/ora10g/rmanback/inc0_1co7jn4l_20130421 tag=MONDAY_INC0 comment=NONE
channel cha1: backup set complete, elapsed time: 00:06:45
Finished backup at 21-4月 -13
Starting Control File and SPFILE Autobackup at 21-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_21/o1_mf_s_813293099_8q72qj4l_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-4月 -13
released channel: cha1
Recovery Manager complete.
[oracle@redhat rmanback]$
上面的命令最好指定全路径,包括rman
[oracle@redhat rmanback]$ which rman
/oracle/ora10g/product/10.2.0/db_1/bin/rman
全路径
/oracle/ora10g/product/10.2.0/db_1/bin/rman target / catalog rman/rman msglog=/oracle/ora10g/rmanback/backl0.log cmdfile=/oracle/ora10g/script/bakl0
1及和2及备份命令如下
/oracle/ora10g/product/10.2.0/db_1/bin/rman target / catalog rman/rman msglog=/oracle/ora10g/rmanback/backl1.log cmdfile=/oracle/ora10g/script/bakl1
/oracle/ora10g/product/10.2.0/db_1/bin/rman target / catalog rman/rman msglog=/oracle/ora10g/rmanback/backl2.log cmdfile=/oracle/ora10g/script/bakl2
----------------------------------------------------------------------------------------------
计划任务crontab
root执行
cron文件语法:
分 小时 日 月 星期 命令
&nb