1. 程式人生 > >異機環境不完全恢復

異機環境不完全恢復

1.已備份的介質
        [[email protected] bak_dir]# tree .
        ├── 2016_12_28                                           --控制檔案 spfile檔案
        │   └── o1_mf_s_931822213_d67pn609_.bkp                 
        ├── 2016_12_29                                           --rman備份之後產生的歸檔日誌
        │   ├── o1_mf_1_2841_d68fh9bc_.arc                      
        │   ├── o1_mf_1_2842_d68o9nf9_.arc
        │   └── o1_mf_1_2843_d68o9o0j_.arc              
        ├── clinics_archbak_ORCL_20161228_474                    --被rman備份的歸檔日誌
        ├── clinics_archbak_ORCL_20161228_475
        ├── clinics_archbak_ORCL_20161228_479
        ├── clinics_fullbak_ORCL_20161228_476_1                  --被rman備份的庫
        ├── clinics_fullbak_ORCL_20161228_477_1
        └── clinics_fullbak_ORCL_20161228_478_1
        [
[email protected]
bak_dir]# 注: 1.當前環境只安裝了oracle軟體,並未安裝任何資料庫 2.當前目錄需同源機備份目錄相同 否則rman通過控制檔案無法找到備份集 2.恢復 2.1 從自動備份中回覆spfile [[email protected] clinics]# su - oracle [[email protected] ~]$ rman target / nocatalog Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 11:48:30 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup nomount force; startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora' starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global Area 158662656 bytes Fixed Size 2211448 bytes Variable Size 88080776 bytes Database Buffers 62914560 bytes Redo Buffers 5455872 bytes RMAN> restore spfile from '/home/oracle/bak_dir/2016_12_28/o1_mf_s_931822213_d67pn609_.bkp'; Starting restore at 29-DEC-16 using channel ORA_DISK_1 channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/bak_dir/2016_12_28/o1_mf_s_931822213_d67pn609_.bkp channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 29-DEC-16 RMAN> #檢視當前恢復出來的spfile [
[email protected]
dbs]$ pwd /u01/app/oracle/product/11.2.0/dbhome_1/dbs [[email protected] dbs]$ ls -l 總用量 12 -rw-r--r--. 1 oracle oinstall 2851 5月 15 2009 init.ora -rw-r-----. 1 oracle oinstall 2560 12月 29 11:57 spfileorcl.ora [[email protected]
dbs]$ more spfileorcl.ora orcl.__java_pool_size=268435456 orcl.__large_pool_size=268435456 orcl.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment orcl.__pga_aggregate_target=12348030976 orcl.__sga_target=18253611008 orcl.__shared_io_pool_size=0 orcl.__shared_pool_size=4563402752 orcl.__streams_pool_size=536870912 *.audit_file_dest='/opt/oracle/admin/orcl/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/opt/oracle/oradata/orcl/control01.ctl','/opC *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/opt/oracle/flash_recovery_area' *.db_recovery_file_dest_size=10737418240 *.diagnostic_dest='/opt/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.memory_target=30484201472 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' [[email protected] dbs]$ 根據實際情況修改spfile中引數的目錄。 [[email protected] dbs]$ more spfileorcl.ora orcl.__java_pool_size=26843545 orcl.__large_pool_size=26843545 orcl.__oracle_base='/u01/app/oracle' #ORACLE_BASE set from environment orcl.__pga_aggregate_target=1234803097 orcl.__sga_target=1825361100 orcl.__shared_io_pool_size=0 orcl.__shared_pool_size=456340275 orcl.__streams_pool_size=53687091 *.audit_file_dest='/u01/app/oracle/admin/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/oradata/orcl/control01.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/u01/fast_recovery_area' *.db_recovery_file_dest_size=107374182 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' [[email protected] dbs]$ 2.2 從自動備份中恢復controfile #利用恢復的spfile將資料庫啟動到nomount狀態 SQL> startup nomount pfile="/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora" ORACLE instance started. Total System Global Area 217157632 bytes Fixed Size 2211928 bytes Variable Size 159387560 bytes Database Buffers 50331648 bytes Redo Buffers 5226496 bytes SQL> #從備份中恢復controfile [[email protected] ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 16:34:04 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (not mounted) RMAN> RESTORE CONTROLFILE FROM '/home/oracle/bak_dir/2016_12_28/o1_mf_s_931822213_d67pn609_.bkp'; Starting restore at 29-DEC-16 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=20 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/u01/oradata/orcl/control01.ctl Finished restore at 29-DEC-16 RMAN> 2.3 恢復資料 將資料庫切換到mount狀態 SQL> alter database mount; Database altered. SQL> 確定原始檔目錄 SQL> select name from v$controlfile 2 union 3 select name from v$datafile 4 union 5 select member from v$logfile 6 union 7 select name from v$tempfile; NAME -------------------------------------------------------------------------------- /opt/oracle/112/network/admin/clinics_data01.dbf /opt/oracle/oradata/orcl/example01.dbf /opt/oracle/oradata/orcl/redo01.log /opt/oracle/oradata/orcl/redo02.log /opt/oracle/oradata/orcl/redo03.log /opt/oracle/oradata/orcl/sysaux01.dbf /opt/oracle/oradata/orcl/system01.dbf /opt/oracle/oradata/orcl/undotbs01.dbf /opt/oracle/oradata/orcl/users01.dbf /u01/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/temp01.dbf /opt/oracle/112/network/admin/clinics_temp01.dbf SQL> #更改redo日誌目錄 SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/orcl/redo01.log' TO '/u01/oradata/orcl/redo01.log'; SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/orcl/redo02.log' TO '/u01/oradata/orcl/redo02.log'; SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/orcl/redo03.log' TO '/u01/oradata/orcl/redo03.log'; SQL> #更改tmp檔案目錄 tmp檔案目錄更改需要在資料庫open狀態下進行,恢復後在處理 #恢復資料檔案 RMAN> run { 2> set newname for datafile '/opt/oracle/112/network/admin/clinics_data01.dbf' to '/u01/oradata/orcl/clinics01.dbf'; 3> set newname for datafile '/opt/oracle/oradata/orcl/example01.dbf' to '/u01/oradata/orcl/example01.dbf'; 4> set newname for datafile '/opt/oracle/oradata/orcl/sysaux01.dbf' to '/u01/oradata/orcl/sysaux01.dbf'; 5> set newname for datafile '/opt/oracle/oradata/orcl/system01.dbf' to '/u01/oradata/orcl/system01.dbf'; 6> set newname for datafile '/opt/oracle/oradata/orcl/undotbs01.dbf' to '/u01/oradata/orcl/undotbs01.dbf'; 7> set newname for datafile '/opt/oracle/oradata/orcl/users01.dbf' to '/u01/oradata/orcl/users01.dbf'; 8> restore database; 9> switch datafile all; 10> } executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting restore at 29-DEC-16 Starting implicit crosscheck backup at 29-DEC-16 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=20 device type=DISK Crosschecked 17 objects Finished implicit crosscheck backup at 29-DEC-16 Starting implicit crosscheck copy at 29-DEC-16 using channel ORA_DISK_1 Finished implicit crosscheck copy at 29-DEC-16 searching for all files in the recovery area cataloging files... no files cataloged using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /u01/oradata/orcl/system01.dbf channel ORA_DISK_1: restoring datafile 00004 to /u01/oradata/orcl/users01.dbf channel ORA_DISK_1: restoring datafile 00006 to /u01/oradata/orcl/clinics01.dbf channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_476_1 channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_476_1 tag=TAG20161228T233003 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:35 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00002 to /u01/oradata/orcl/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00003 to /u01/oradata/orcl/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00005 to /u01/oradata/orcl/example01.dbf channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_477_1 channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/clinics_fullbak_ORCL_20161228_477_1 tag=TAG20161228T233003 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:25 Finished restore at 29-DEC-16 datafile 1 switched to datafile copy input datafile copy RECID=8 STAMP=931879279 file name=/u01/oradata/orcl/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=9 STAMP=931879279 file name=/u01/oradata/orcl/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=10 STAMP=931879279 file name=/u01/oradata/orcl/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=11 STAMP=931879280 file name=/u01/oradata/orcl/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=12 STAMP=931879280 file name=/u01/oradata/orcl/example01.dbf datafile 6 switched to datafile copy input datafile copy RECID=13 STAMP=931879280 file name=/u01/oradata/orcl/clinics01.dbf RMAN> #查看回復結果 SQL> conn /as sysdba Connected. SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /u01/oradata/orcl/system01.dbf /u01/oradata/orcl/sysaux01.dbf /u01/oradata/orcl/undotbs01.dbf /u01/oradata/orcl/users01.dbf /u01/oradata/orcl/example01.dbf /u01/oradata/orcl/clinics01.dbf SQL> 2.4 執行不完全恢復 #將備份之後產生的歸檔日誌登記到控制檔案中 [[email protected] dbs]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 15:29:47 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1435659836, not open) RMAN> catalog archivelog '/home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc'; using target database control file instead of recovery catalog cataloged archived log archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc RECID=803 STAMP=931879849 RMAN> catalog archivelog '/home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc'; cataloged archived log archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc RECID=804 STAMP=931879869 RMAN> catalog archivelog '/home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc'; cataloged archived log archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc RECID=805 STAMP=931879897 RMAN> #檢視登記後的歸檔日誌 SQL> select thread#,sequence#,name,next_change# from v$archived_log; THREAD# SEQUENCE# NAME NEXT_CHANGE# ---------- ---------- ------------------------------------------------------------ ------------ 1 2840 39240733 1 2841 /home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc 39270727 1 2842 /home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc 39282742 1 2843 /home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc 39284949 SQL> #根據歸檔日誌檢視v$archived_log.SEQUENCE#,在RMAN命令列下執行恢復 RMAN> run{ 2> set until sequence 2844 thread 1; 3> recover database; 4> } executing command: SET until clause Starting recover at 29-DEC-16 using channel ORA_DISK_1 starting media recovery archived log for thread 1 with sequence 2841 is already on disk as file /home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc archived log for thread 1 with sequence 2842 is already on disk as file /home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc archived log for thread 1 with sequence 2843 is already on disk as file /home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc channel ORA_DISK_1: starting archived log restore to default destination channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=2840 channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/clinics_archbak_ORCL_20161228_479 channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/clinics_archbak_ORCL_20161228_479 tag=TAG20161228T233012 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 archived log file name=/u01/fast_recovery_area/ORCL/archivelog/2016_12_29/o1_mf_1_2840_d69m35bo_.arc thread=1 sequence=2840 channel default: deleting archived log(s) archived log file name=/u01/fast_recovery_area/ORCL/archivelog/2016_12_29/o1_mf_1_2840_d69m35bo_.arc RECID=806 STAMP=931884133 archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2841_d68fh9bc_.arc thread=1 sequence=2841 archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2842_d68o9nf9_.arc thread=1 sequence=2842 archived log file name=/home/oracle/bak_dir/2016_12_29/o1_mf_1_2843_d68o9o0j_.arc thread=1 sequence=2843 media recovery complete, elapsed time: 00:00:10 Finished recover at 29-DEC-16 RMAN> 2.5 以resetlogs方式開啟資料庫 [[email protected] ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 29 17:04:31 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1435659836, not open) RMAN> sql'alter database open resetlogs'; using target database control file instead of recovery catalog sql statement: alter database open resetlogs RMAN> 3.恢復庫的後續處理 3.1檢視各個檔案目錄 SQL> select name from v$controlfile 2 union 3 select name from v$datafile 4 union 5 select member from v$logfile 6 union 7 select name from v$tempfile; NAME ------------------------------------------------------------ /opt/oracle/112/network/admin/clinics_temp01.dbf /opt/oracle/oradata/orcl/temp01.dbf /u01/oradata/orcl/clinics01.dbf /u01/oradata/orcl/control01.ctl /u01/oradata/orcl/example01.dbf /u01/oradata/orcl/redo01.log /u01/oradata/orcl/redo02.log /u01/oradata/orcl/redo03.log /u01/oradata/orcl/sysaux01.dbf /u01/oradata/orcl/system01.dbf /u01/oradata/orcl/undotbs01.dbf NAME ------------------------------------------------------------ /u01/oradata/orcl/users01.dbf SQL> select ts#,bytes/1024/1024,name from v$tempfile; TS# BYTES/1024/1024 NAME ---------- --------------- ------------------------------------------------------------ 3 0 /opt/oracle/oradata/orcl/temp01.dbf 7 0 /opt/oracle/112/network/admin/clinics_temp01.dbf SQL> select ts#,name from v$tablespace where ts# in (3,7); TS# NAME ---------- ------------------------------------------------------------ 3 TEMP 7 CLINICS_TEMP SQL> 新增新臨時檔案 SQL> alter tablespace temp add tempfile '/u01/oradata/orcl/temp01.dbf' size 50M; SQL> alter tablespace CLINICS_TEMP add tempfile '/u01/oradata/orcl/clinics_temp01.dbf' size 50M; 刪除歷史臨時檔案 SQL> alter database tempfile '/opt/oracle/oradata/orcl/temp01.dbf' drop; SQL> alter database tempfile '/opt/oracle/112/network/admin/clinics_temp01.dbf' drop; 3.2建立spfile SQL> create spfile from memory; File created. SQL> OK鳥!