首页 / 数据库 / MySQL / 异机RMAN数据不完全恢复
源库:Red Hat Enterprise Linux Server release 5.5 (Tikanga) 64bit + Oracle V11.2.0.4.0 + DG + RAC目标库:Red Hat Enterprise Linux Server release 5.8 (Catthage) 64bit + ORACLE V11.2.0.4.0
1、在目标库,安装好相同版本的Oracle数据库,创建同名实例orcl;
数据库实例默认安装路径为:/u01/app/oracle/oradata/orcl/…2、查询源库数据文件路径;
Select * from dba_data_files;如下图所示:数据文件路径为+DATA/standby/datafile/…3、拷贝源库rman备份文件:
查看源rman备份脚本,内容如下:run {allocate channel t1 type disk;sql "alter system archive log current";backup as compressed backupset database format="/mnt/rmanbackup/backup/db_%U";backup current controlfile format="/mnt/rmanbackup/backup/ctl_%U";crosscheck backupset;crosscheck archivelog all;delete expired backup;delete noprompt obsolete;delete archivelog all completed before "sysdate-60";delete archivelog until time "sysdate-60";deletebackupset completed before "sysdate-1";release channel t1;}在备份路径/mnt/rmanbackup/backup/下,找到备份文教拷贝。4、在目标库中创建相同的目录,并拷贝以上rman备份数据;
5、根据源数据库,数据存储路径制作rman恢复脚本
如下:Rman>run{ set newname for datafile 1 to "/u01/app/oracle/oradata/orcl/system.275.867195235";set newname for datafile 2 to "/u01/app/oracle/oradata/orcl/sysaux.281.867195261";set newname for datafile 3 to "/u01/app/oracle/oradata/orcl/undotbs1.283.867195263";set newname for datafile 4 to "/u01/app/oracle/oradata/orcl/users.280.867195255";set newname for datafile 5 to "/u01/app/oracle/oradata/orcl/undotbs2.290.867195331";…restore database;switch datafile all;}/2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27> 28> 29> 30> 31> 32> 33> 34> 35> 36> 37> 38> 39> 40> 41> 42> 43> 44> 45> 46> 47> 48> 49> 50> 51> 52> 53> 54> 55> 56> 57> 58> 59> 60> 61> 62> 63> 64> 65> executing command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAME…Starting restore at 12-JUN-16allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=134 device type=DISK RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of restore command at 06/12/2016 17:26:18RMAN-06026: some targets not found - aborting restoreRMAN-06023: no backup or copy of datafile 4 found to restoreRMAN-06023: no backup or copy of datafile 3 found to restoreRMAN-06023: no backup or copy of datafile 2 found to restoreRMAN-06023: no backup or copy of datafile 1 found to restore6、在目标库上恢复控制文件:
SQL>shutdown immediateSQL>startup nomountconnected to target database (not started)Oracle instance startedTotal System Global Area 1068937216 bytesFixed Size 2260088 bytesVariable Size 671089544 bytesDatabase Buffers 390070272 bytesRedo Buffers 5517312 bytes------cmdRman target /------Rman命令:RMAN>restore controlfile from "/mnt/rmanbackup/backup/ctl_5er51tei_1_1";Starting restore at 12-JUN-16allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=134 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:03output file name=/u01/app/oracle/oradata/orcl/control01.ctloutput file name=/u01/app/oracle/fast_recovery_area/orcl/control02.ctlFinished restore at 12-JUN-16… 7、在目标库上恢复数据文件,处理各种报错问题:
注意:数据文件恢复完成后重启数据库过程中会遇到很多问题,以下是事后整理内容,多有不完善之处!!!RMAN>alter database mount;database mountedreleased channel: ORA_DISK_1RMAN> run{set newname for datafile 1 to "/u01/app/oracle/oradata/orcl/system.275.867195235";set newname for datafile 2 to "/u01/app/oracle/oradata/orcl/sysaux.281.867195261";set newname for datafile 3 to "/u01/app/oracle/oradata/orcl/undotbs1.283.867195263";set newname for datafile 4 to "/u01/app/oracle/oradata/orcl/users.280.867195255";set newname for datafile 5 to "/u01/app/oracle/oradata/orcl/undotbs2.290.867195331";…restore database;switch datafile all;}/2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27> 28> 29> 30> 31> 32> 33> 34> 35> 36> 37> 38> 39> 40> 41> 42> 43> 44> 45> 46> 47> 48> 49> 50> 51> 52> 53> 54> 55> 56> 57> 58> 59> 60> 61> 62> 63> executing command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAME…Starting restore at 12-JUN-16Starting implicit crosscheck backup at 12-JUN-16RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of restore command at 06/12/2016 17:48:42RMAN-12010: automatic channel allocation initialization failedRMAN-06189: current DBID 1442122161 does not match target mounted database (1318669939) RMAN> shutdown immediate;database dismountedOracle instance shut downRMAN> startup nomount;connected to target database (not started)Oracle instance startedTotal System Global Area 1068937216 bytesFixed Size 2260088 bytesVariable Size 671089544 bytesDatabase Buffers 390070272 bytesRedo Buffers 5517312 bytes RMAN> set dbid=1318669939executing command: SET DBIDRMAN> alter database mount;database mountedRMAN> run{set newname for datafile 1 to "/u01/app/oracle/oradata/orcl/system.275.867195235";set newname for datafile 2 to "/u01/app/oracle/oradata/orcl/sysaux.281.867195261";set newname for datafile 3 to "/u01/app/oracle/oradata/orcl/undotbs1.283.867195263";set newname for datafile 4 to "/u01/app/oracle/oradata/orcl/users.280.867195255";…restore database;switch datafile all;}/2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27> 28> 29> 30> 31> 32> 33> 34> 35> 36> 37> 38> 39> 40> 41> 42> 43> 44> 45> 46> 47> 48> 49> 50> 51> 52> 53> 54> 55> 56> 57> 58> 59> 60> 61> 62> 63> executing command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAME…Starting restore at 12-JUN-16Starting implicit crosscheck backup at 12-JUN-16allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=134 device type=DISKCrosschecked 5 objectsFinished implicit crosscheck backup at 12-JUN-16 Starting implicit crosscheck copy at 12-JUN-16using channel ORA_DISK_1Finished implicit crosscheck copy at 12-JUN-16 searching for all files in the recovery areacataloging files...no files cataloged using channel ORA_DISK_1channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system.275.867195235channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux.281.867195261channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs1.283.867195263channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users.280.867195255channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/undotbs2.290.867195331…channel ORA_DISK_1: reading from backup piece /mnt/rmanbackup/backup/db_5cr51m5e_1_1… RMAN> alter database open resetlogs;RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of alter db command at 06/12/2016 22:42:40ORA-01194: file 1 needs more recovery to be consistentORA-01110: data file 1: "/u01/app/oracle/oradata/orcl/system.275.867195235"RMAN> exitRecovery Manager complete.[oracle@localhost ~]$ sqlplus /nologSQL*Plus: Release 11.2.0.4.0 Production on Sun Jun 12 22:48:23 2016Copyright (c) 1982, 2013, Oracle. All rights reserved.SQL> conn / as sysdba;Connected.SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;System altered.SQL> shutdown immediate;ORA-01109: database not openDatabase dismounted.ORACLE instance shut down.SQL> startup mount;ORACLE instance started.Total System Global Area 1068937216 bytesFixed Size 2260088 bytesVariable Size 671089544 bytesDatabase Buffers 390070272 bytesRedo Buffers 5517312 bytesDatabase mounted.SQL> alter database open resetlogs;alter database open resetlogs*ERROR at line 1:ORA-00349: failure obtaining block size for "+DATA/orcl/redo01.log"SQL> SELECT GROUP#,SEQUENCE#,BYTES,MEMBERS,STATUS FROM V$LOG; GROUP# SEQUENCE# BYTES MEMBERS STATUS---------- ---------- ---------- ---------- ---------------- 1 0 52428800 1 CLEARING 2 0 52428800 1 CLEARING 3 0 52428800 1 CLEARING_CURRENT 4 0 52428800 1 CLEARING 5 0 52428800 1 CLEARING_CURRENT 6 0 52428800 1 CLEARING6 rows selected.SQL> alter database drop logfile group 6;Database altered.SQL> alter database open resetlogs;alter database open resetlogs*ERROR at line 1:ORA-00392: log 3 of thread 1 is being cleared, operation not allowedORA-00312: online log 3 thread 1: "+DATA/orcl/redo03.log"SQL> alter database clear logfile group 1;alter database clear logfile group 1*ERROR at line 1:ORA-00349: failure obtaining block size for "+DATA/orcl/redo01.log"SQL> alter database rename file "+DATA/orcl/redo01.log" to "/u01/app/oracle/oradata/orcl/redo01.log" ;Database altered.SQL> alter database rename file "+DATA/orcl/redo02.log" to "/u01/app/oracle/oradata/orcl/redo02.log" ; Database altered.SQL> alter database rename file "+DATA/orcl/redo03.log" to "/u01/app/oracle/oradata/orcl/redo03.log" ;Database altered.SQL> alter database open resetlogs;alter database open resetlogs*ERROR at line 1:ORA-00392: log 3 of thread 1 is being cleared, operation not allowedORA-00312: online log 3 thread 1: "/u01/app/oracle/oradata/orcl/redo03.log"SQL> ALTER DATABASE CLEAR LOGFILE GROUP 2;Database altered.SQL> ALTER DATABASE CLEAR LOGFILE GROUP 3;Database altered.SQL> alter database rename file "+DATA/orcl/redo05.log" to "/u01/app/oracle/oradata/orcl/redo05.log";Database altered.SQL> alter database clear logfile group 5;Database altered.SQL> alter database rename file "+DATA/orcl/redo04.log" to "/u01/app/oracle/oradata/orcl/redo04.log";Database altered.SQL> alter database clear logfile group 4;Database altered.SQL> select group#,bytes,status from v$log; GROUP# BYTES STATUS---------- ---------- ---------------- 1 52428800 UNUSED 2 52428800 UNUSED 3 52428800 CURRENT 4 52428800 UNUSED 5 52428800 CURRENT…以上是自己最近两个星期做的一次数据库rman恢复,自己实践搭建Linux环境,安装Oracle,测试恢复数据。实践出真知啊!!!!更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址