ITPub博客

首页 > Linux操作系统 > Linux操作系统 > RMAN备份恢复——备份集存储位置改变

RMAN备份恢复——备份集存储位置改变

原创 Linux操作系统 作者:yangtingkun 时间:2007-09-16 00:00:00 0 删除 编辑

如果数据文件或日志文件的位置发生了改变,那么有多种方法可以解决这个问题。比如使用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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2007-12-29

  • 博文量
    1955
  • 访问量
    10355522