本例子的目的:
1:熟悉RMAN进行备份和恢复
2:对于10g和9i在增量备份上的操作和功能的不同
(9i每次备份都会产生一个备份文件,
例如:在星期天做level为0的备份生成文件1,星期一做level为1的备份又为产生文件2,文件1和文件2是独立的
在做恢复的时候要同时利用文件1和文件2,恢复的时候时间花费较大。
而10g可以一直利用文件1进得累加,在做level为1的备份后不要再产生文件2了
所以10g在做恢复的时候只要利用文件1就可以完成了,恢复的时候时间花费较小
一:环境
1:
IP:192.168.1.14
操作系统:linux
数据库:10.2.0.1.0
rman属性:用户名/密码/专用表空间 rman/rman/ts_rman
用户rman拥有RECOVERY_CATALOG_OWNER,connect
命令运行机器192.168.1.14
CREATE TABLESPACE TS_RMAN
LOGGING
DATAFILE '/oracle/oradata/boss/TS_RMAN_001.dbf' SIZE 512M
REUSE DEFAULT STORAGE ( INITIAL 64K NEXT 64K MINEXTENTS 1 MAXEXTENTS 505
PCTINCREASE 0 );
create user RMAN identified by RMAN;
grant resource,connect,RECOVERY_CATALOG_OWNER to RMAN ;
grant create table to RMAN ;
alter user RMAN quota unlimited ON TS_RMAN;
alter user RMAN default tablespace TS_RMAN;
alter user RMAN temporary tablespace temp;
2:
目标数据库
IP:192.168.1.115
操作系统:linux
数据库:10.2.0.1.0
数据库的存储数据的一个用户:test
二: rman的操作流程(说明:以下所有rman 的相关命令都在192.168.1.14上运行,其它的操作都在192.168.1.115上运行)
1:注册目标数据库
2:进行一次level为0的备份
3:登录192.168.1.115的数据库用户test,建立表test_inc_levl_1
4:在192.168.1.14机子上对192.168.1.115做一个level为1的增量备份
5:在192.168.1.115的上删除数据文件ts_boss_001.dbf
6:登录192.168.1.115的用户test查表test_inc_levl_1
7:发现已经无法找到这个表了,因为是数据文件file 6已经找不到了,所以只好利用还原
8:验证恢复,登录192.168.1.115的用户test查表test_inc_levl_1
#########1:注册目标数据库(把192.168.1.115的数据库相关信息保存在192.168.1.14的rman用户的相应的表里)##################
[root@localhost 10g_script]# rman
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Jan 9 16:07:38 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN> connect target sys/boss@boss_115;
connected to target database: BOSS (DBID=1127560625)
RMAN> connect catalog rman/rman
connected to recovery catalog database
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
########################################2:进行一次level为0的备份####################################
RMAN> run
2> {
3> backup
4> incremental level 0
5> format '/oracle/rman_back/db_%d_%s_%p_%t'
6> database
7> tag='backup_inc0';
8> }
Starting backup at 09-JAN-07
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: starting incremental level 0 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00015 name=/oracle/oradata/boss/TS_RMAN_001.dbf
input datafile fno=00001 name=/oracle/oradata/boss/system01.dbf
input datafile fno=00003 name=/oracle/oradata/boss/sysaux01.dbf
input datafile fno=00002 name=/oracle/oradata/boss/undotbs01.dbf
input datafile fno=00005 name=/oracle/oradata/boss/example01.dbf
input datafile fno=00006 name=/oracle/oradata/boss/ts_boss_001.dbf
input datafile fno=00016 name=/oracle/oradata/boss/TS_update_001.dbf
input datafile fno=00017 name=/oracle/oradata/boss/TS_update1_001.dbf
input datafile fno=00004 name=/oracle/oradata/boss/users01.dbf
channel ORA_DISK_1: starting piece 1 at 09-JAN-07
channel ORA_DISK_1: finished piece 1 at 09-JAN-07
piece handle=/oracle/rman_back/db_BOSS_220_1_611424836 tag=BACKUP_INC0 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:36
Finished backup at 09-JAN-07
Starting Control File and SPFILE Autobackup at 09-JAN-07
piece handle=/oracle/flash_recovery_area/BOSS/autobackup/2007_01_09/o1_mf_s_611425055_2t6mx0q9_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 09-JAN-07
###3:登录192.168.1.115的一个用户boss,建立表test_inc_levl_1,等下做完备份后,删除,然后数据库做还原和恢复后看看这个表的相应记录##
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as boss
SQL> create table test_inc_levl_1 as select * from cust_user where rownum<=1000;
Table created
###############4:在192.168.1.14机子上对192.168.1.115做一个level为1的增量备份###########################################
RMAN> run
2> {
3> backup incremental level 1 for recover of copy with tag 'backup_inc0' database;
4> }
Starting backup at 09-JAN-07
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00015 name=/oracle/oradata/boss/TS_RMAN_001.dbf
input datafile fno=00001 name=/oracle/oradata/boss/system01.dbf
input datafile fno=00003 name=/oracle/oradata/boss/sysaux01.dbf
input datafile fno=00002 name=/oracle/oradata/boss/undotbs01.dbf
input datafile fno=00005 name=/oracle/oradata/boss/example01.dbf
input datafile fno=00006 name=/oracle/oradata/boss/ts_boss_001.dbf
input datafile fno=00016 name=/oracle/oradata/boss/TS_update_001.dbf
input datafile fno=00017 name=/oracle/oradata/boss/TS_update1_001.dbf
input datafile fno=00004 name=/oracle/oradata/boss/users01.dbf
channel ORA_DISK_1: starting piece 1 at 09-JAN-07
channel ORA_DISK_1: finished piece 1 at 09-JAN-07
piece handle=/oracle/flash_recovery_area/BOSS/backupset/2007_01_09/o1_mf_nnnd1_TAG20070109T163221_2t6nrq7t_.bkp tag=TAG20070109T163221 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 09-JAN-07
Starting Control File and SPFILE Autobackup at 09-JAN-07
piece handle=/oracle/flash_recovery_area/BOSS/autobackup/2007_01_09/o1_mf_s_611426018_2t6nv3rj_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 09-JAN-07
###########5:在192.168.1.115的上删除数据文件ts_boss_001.dbf##########
[root@localhost boss]# cd /oracle/oradata/boss
[root@localhost boss]# rm ts_boss_001.dbf#########################表test_inc_levl_1 在表空间ts_boss_001.dbf上面
rm: remove regular file `ts_boss_001.dbf'? y
###6:登录192.168.1.115的用户test查表test_inc_levl_1
SQL> select * from test_inc_levl_1 ;
select * from test_inc_levl_1
ORA-01116: error in opening database file 6
ORA-01110: data file 6: '/oracle/oradata/boss/ts_boss_001.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SQL>
######################7:发现已经无法找到这个表了,因为是数据文件file 6已经找不到了,所以只好利用还原来恢复来找回这个表了######
RMAN> run
2> {
3> sql 'alter tablespace ts_boss offline immediate';
4> restore datafile 6;
5> recover tablespace ts_boss;
6> sql 'alter tablespace ts_boss online';
7> }
sql statement: alter tablespace ts_boss offline immediate
Starting restore at 09-JAN-07
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00006 to /oracle/oradata/boss/ts_boss_001.dbf
channel ORA_DISK_1: reading from backup piece /oracle/rman_back/db_BOSS_220_1_611424836
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/rman_back/db_BOSS_220_1_611424836 tag=BACKUP_INC0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
Finished restore at 09-JAN-07
Starting recover at 09-JAN-07
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00006: /oracle/oradata/boss/ts_boss_001.dbf
channel ORA_DISK_1: reading from backup piece /oracle/flash_recovery_area/BOSS/backupset/2007_01_09/o1_mf_nnnd1_TAG20070109T163221_2t6nrq7t_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/flash_recovery_area/BOSS/backupset/2007_01_09/o1_mf_nnnd1_TAG20070109T163221_2t6nrq7t_.bkp tag=TAG20070109T163221
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 09-JAN-07
sql statement: alter tablespace ts_boss online
RMAN>
#########################8:验证恢复,登录192.168.1.115的用户test查表test_inc_levl_1
SQL> select count(*) from test_inc_levl_1 ;
COUNT(*)
----------
1000
SQL>
##########################说明已经成功的恢复了刚才删除的文件了,退出##################
v