RMAN 备份集在异机异路径下恢复过程

RMAN 备份集在异机异路径下恢复过程

原数据库环境
机器名:yfzx
数据库名:HRP270
归档模式打开
路径: I:ORACLEPRODUCT10.2.0db_1

新数据库环境:
机器名:zhengsh
只安装了数据库ORACLE 10.2G软件,在D盘,没有建数据库,该机器没有I盘


RMAN 备份集在异机异路径下恢复过程

原数据库环境
机器名:yfzx
数据库名:HRP270
归档模式打开
路径: I:ORACLEPRODUCT10.2.0db_1

新数据库环境:
机器名:zhengsh
只安装了数据库ORACLE 10.2G软件,在D盘,没有建数据库,该机器没有I盘

1.通过网络拷贝RMAN备份文件到zhengsh机器下E:ora_bak,包括数据备份、控制文件备份、SPFILE文件备份

2.建立数据库服务
C:Documents and Settingszhengsh>oradim -NEW -SID HRP270 -INTPWD bsoft -pfile
"E:ora_bakpfilehrp270.ora"

结果: 成功!

注意
用此方法建的ORACLE服务只是个壳,windows服务启动不代表ORACLE的实例启动,需要在安装完ORACLE后在注册表中设置
加在HKEY_LOCAL_MACHINEORACLEHOME下加上
ORA_SID_AUTOSTART=TURE
ORA_SID_SHUTDOWN=TURE
ORA_SID_SHUTDOWNTYPE=i

3.配置监听与网络连接

结果:
监听配置成功
网络连接配置失败

4.在CMD中设置环境变量
Set oracle_sid=hrp270
手工建立相应子目录

5.通过登录RMAN获取原数库DBID=79382924
在RMAN中设置DBID
set DBID=79382924

6.恢复控制文件
在sqlplus中启动到NOMOUNT状态
Sql>Startup nomount
Sql>exit
进入RMAN
C:>rman target sys/bsoft
执行命令
run{
set controlfile autobackup format for device type disk to 'E:ora_bak %d_%s_%p.bak';
restore controlfile from autobackup;
}
结果: 失败!

改用以下方式来替代

declare
devtype varchar2(256);
done boolean;
begin
devtype:=dbms_backup_restore.deviceallocate(NULL);
dbms_backup_restore.restoresetdatafile;
dbms_backup_restore.restorecontrolfileto('D:oracleproduct10.2.0oradatahrp270control01.ctl');
dbms_backup_restore.restorebackuppiece('E:ora_bakC-79382924-20070330-00',DONE=>done);
end;

结果: 成功!

然后拷贝二个一样的文件(control01,control02)到同一目录下

7.修改数据文件路径在RMAN中到新机器安装路径,然后RESTORE DATABASE
Rman sys/bsoft
Startup mount
Run{
Set newname for datafile 1 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSTEM01.DBF';
Set newname for datafile 2 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270UNDOTBS01.DBF';
Set newname for datafile 3 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSAUX01.DBF';
Set newname for datafile 4 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270USERS01.DBF';
Set newname for datafile 5 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270EXAMPLE01.DBF';
Set newname for datafile 6 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270HIS01';
Set newname for datafile 7 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270TEST01';
Set newname for datafile 8 to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270STREAMS_TBS.DBF';
}

Rman>restore databased;
结果: 还是提示找不到恢复文件位置,恢复失败


8采用DBMS_BACKUP_RESTORE包进行恢复数据库
以下恢复数据文件
Startup nomount
DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');
sys.dbms_backup_restore.restoreSetDatafile;
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>01,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSTEM01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>02,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270UNDOTBS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>03,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSAUX01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>04,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270USERS01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>05,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270EXAMPLE01.DBF');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>06,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270HIS01');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>07,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270TEST01');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>08,toname=>'D:ORACLEPRODUCT10.2.0ORADATAHRP270STREAMS_TBS.DBF');
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'E:ora_bakHRP270_18_1.BAK', params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
/
结果: 恢复成功!

以下恢复归档日志
SQL> DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'t1');
sys.dbms_backup_restore.restoreSetArchivedLog(destination=>' D:oracleproduct10.2.0flash_recovery_areaHRP270ARCHIVELOG');
sys.dbms_backup_restore.restoreArchivedLog(thread=>1,sequence=>6);
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'E:ora_bakHRP270_17_1.BAK',params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
/
结果: 无法打开归档日志,恢复失败!,估计sequence值需要正确设置,但怎么找还不知道。
下面就用无归档日志来恢复数据库

9.修改数据文件在控制文件中路径
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270SYSTEM01.DBF' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSTEM01.DBF';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270UNDOTBS01.DBF' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270UNDOTBS01.DBF';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270SYSAUX01.DBF' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSAUX01.DBF';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270USERS01.DBF' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270USERS01.DBF';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270EXAMPLE01.DBF' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270EXAMPLE01.DBF';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270HIS01' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270HIS01';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270TEST01' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270TEST01';
Alter database rename file 'I:ORACLEPRODUCT10.2.0ORADATAHRP270STREAMS_TBS.DBF' to 'D:ORACLEPRODUCT10.2.0ORADATAHRP270STREAMS_TBS.DBF';

10.重新指定REDO Log路径
删除以前的REDO LOG,由于GROUP 2是当前日志组,所以先删除GROUP 1 与GROUP 3,然后重建日志文件,再切换日志,再删除GROUP 2;
SQL>ALTER DATABASE DROP LOGFILE GROUP 1;
SQL>ALTER DATABASE DROP LOGFILE GROUP 2;

SQL> ALTER DATABASE ADD LOGFILE ('D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO01.LOG') SIZE 30M;

EM
SQL> ALTER DATABASE ADD LOGFILE ('D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO01
.LOG') SIZE 30M;

数据库已更改。
SQL> ALTER DATABASE ADD LOGFILE ('D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO03
.LOG') SIZE 30M;

数据库已更改。

SQL> ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE
*
第 1 行出现错误:
ORA-01109: 数据库未打开
SQL> RECOVER DATABASE UNTIL CANCEL;
ORA-00283: 恢复会话因错误而取消
ORA-01610: 使用 BACKUP CONTROLFILE 选项的恢复必须已完成

结果: 失败!
改用以下11步骤来做

11.用重建控制文件的方法来重建数据库(一定要使用导出文件的后一部分来建)
CREATE CONTROLFILE REUSE DATABASE "HRP270" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 'D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO01.LOG' SIZE 50M,
GROUP 2 'D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO02.LOG' SIZE 50M,
GROUP 3 'D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO03.LOG' SIZE 50M,
GROUP 4 'D:ORACLEPRODUCT10.2.0ORADATAHRP270REDO4.LOG' SIZE 200M
-- STANDBY LOGFILE
DATAFILE
'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSTEM01.DBF',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270UNDOTBS01.DBF',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270SYSAUX01.DBF',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270USERS01.DBF',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270EXAMPLE01.DBF',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270HIS01',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270TEST01',
'D:ORACLEPRODUCT10.2.0ORADATAHRP270STREAMS_TBS.DBF'
CHARACTER SET ZHS16GBK
;

结果: 成功!

12.恢复及打开数据库
SQL> recover database using backup controlfile until cancel;
SQL> alter database open resetlogs;
结果: 成功!
到此为止已可以完全打开数据库!


13.创建web访问em服务
设置环境变量 set ORACLE_HOSTNAME=zhengsh (为机器名)
重建密码文件
orapwd file=D:oracleproduct10.2.0db_1databasePWDhrp270.ora password=bsoft entries=10

建立临时表空间,因为建完数据库后临时表空间为0,需要重新增加表空间
SQL> alter tablespace temp add tempfile 'D:oracleproduct10.2.0oradatahrp270
temp1.dbf' size 100m;

删除原资料库
emca -deconfig all db -repos drop

建立资料库
emca -config dbcontrol db -repos create

结果: 成功!
到目前为止可以使用EM,全部工作成功完成

你可能感兴趣的:(职场,rman,休闲,异机异路径,恢复过程)