oracle 10g RMAN管理

zhengbao_jun發表於2009-02-11

本例子的目的:
   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>
##########################說明已經成功的恢復了剛才刪除的檔案了,退出##################

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/235507/viewspace-548674/,如需轉載,請註明出處,否則將追究法律責任。

相關文章