RMAN備份恢復——備份集儲存位置改變

yangtingkun發表於2007-09-16

如果資料檔案或日誌檔案的位置發生了改變,那麼有多種方法可以解決這個問題。比如使用ALTER DATABASE RENAME DATAFILE的方法,或者SET NEWNAME

但是如果備份集的位置改變,Oracle在10g以前並沒有提供相應的解決方法。

這篇文章介紹9i如何透過OracleDBMS_BACKUP_RESTORE包來實現這個功能。


在進行備份之前,檢查備份表空間的資訊:

SQL> SELECT FILE_ID, TABLESPACE_NAME FROM DBA_DATA_FILES WHERE TABLESPACE_NAME = 'USERS';

FILE_ID TABLESPACE_NAME
---------- ------------------------------
9 USERS

下面對錶空間USERS進行備份:

$ rman target /

Recovery Manager: Release 9.2.0.4.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: MEMBER (DBID=1303377880)

RMAN> backup tablespace indx, info, users, tools;

Starting backup at 24-8 -07
using target database controlfile instead of recovery catalog
configuration for DISK channel 2 is ignored
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=20 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00018 name=/data/oradata/member/info.dbf
input datafile fno=00009 name=/data/oradata/member/users01.dbf
input datafile fno=00006 name=/data/oradata/member/indx01.dbf
input datafile fno=00008 name=/data/oradata/member/tools01.dbf
channel ORA_DISK_1: starting piece 1 at 24-8
-07
channel ORA_DISK_1: finished piece 1 at 24-8
-07
piece handle=/data/backup/member/5siq6isk_1_1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 24-8
-07

可以看到備份的輸出備份集在/data/backup/member目錄下,如果將備份透過作業系統轉移到/data/backup目錄下,則Oracle恢復的時候無法找到備份集,在9i及以前版本,Oracle也沒有提供相應的命令來重定位這個備份集。

在作業系統級的解決方案是,建立一個檔案連線ln,指向新的位置。如果要從Oracle方面解決這個問題,就只能使用DBMS_BACKUP_RESTORE包。

$ mv /data/backup/member/5siq6isk_1_1 /data/backup/
$ rman target /

Recovery Manager: Release 9.2.0.4.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: MEMBER (DBID=1303377880)

RMAN> sql 'alter tablespace users offline';

using target database controlfile instead of recovery catalog
sql statement: alter tablespace users offline

RMAN> restore tablespace users;

Starting restore at 24-8 -07

configuration for DISK channel 2 is ignored
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00009 to /data/oradata/member/users01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 08/24/2007 13:17:23
ORA-19505: failed to identify file "/data/backup/member/5siq6isk_1_1"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory

由於找不到相應的備份集,Rman直接報錯。

下面在SQLPLUS中使用DBMS_BACKUP_RESTORE進行RESTORE

$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on 星期五 8 24 13:22:33 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> DECLARE
2 V_DEVICE VARCHAR2(100);
3 V_FINISH BOOLEAN;
4 TYPE T_FILENAMETABLE IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
5 V_FILENAMETABLE T_FILENAMETABLE;
6 V_MAXPIECES NUMBER :=100;
7 BEGIN
8 V_FILENAMETABLE(1) := '/data/backup/5siq6isk_1_1';
9 V_DEVICE := SYS.DBMS_BACKUP_RESTORE.DEVICEALLOCATE();
10 SYS.DBMS_BACKUP_RESTORE.RESTORESETDATAFILE;
11 SYS.DBMS_BACKUP_RESTORE.RESTOREDATAFILETO(9, '/data/oradata/member/users01.dbf');
12
13 FOR I IN 1..V_MAXPIECES LOOP
14 SYS.DBMS_BACKUP_RESTORE.RESTOREBACKUPPIECE(V_FILENAMETABLE(I), V_FINISH);
15 IF V_FINISH THEN
16 SYS.DBMS_BACKUP_RESTORE.DEVICEDEALLOCATE;
17 RETURN;
18 END IF;
19 END LOOP;
20 SYS.DBMS_BACKUP_RESTORE.DEVICEDEALLOCATE;
21 END;
22 /

PL/SQL procedure successfully completed.

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ rman target /

Recovery Manager: Release 9.2.0.4.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: MEMBER (DBID=1303377880)

RMAN> recover tablespace users;

Starting recover at 24-8 -07
using target database controlfile instead of recovery catalog
configuration for DISK channel 2 is ignored
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=20 devtype=DISK

starting media recovery
media recovery complete

Finished recover at 24-8 -07

RMAN> sql 'alter tablespace users online';

sql statement: alter tablespace users online

至此,表空間已經順利的恢復。對於DBMS_BACKUP_RESTORE包的使用,這裡只是一個簡單的例子,不打算進行詳細描述,以後會有陸續的文章詳細描述這個包。

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

相關文章