前不久,因為開發人員把一張比較重要的表truncate了,於是找到我們,便做了一次異機恢複,恢複出這張表。
下面是事後我在vm上做的一次實驗,完全複製,當然也可以設定時間,scn,恢複到過去某個時間點。
1.語句準備
select 'set newname for datafile '||file_id||' to "/home/Oracle/oradata/s1/'||substr(file_name,25)||'";' from dba_data_files;
select 'set newname for tempfile '||file_id||' to "/home/oracle/oradata/s1/'||substr(file_name,25)||'";' from dba_temp_files;
select 'group '||a.group#||' (''/home/oracle/oradata/s1/'||substr(member,25)||''')size '||bytes||' reuse,'
from v$logfile a,v$log b
where a.GROUP#=b.GROUP#;
2.複製相關檔案到s2(備份目錄,日誌目錄,flash_recovery_area可用nfs將s1的目錄mount到s2,注意目錄許可權問題)
複製inits1.ora並添加(路徑一樣則可省略)
db_file_name_convert=('/home/oracle/oradata/s1','/home/oracle/oradata/s1')
log_file_name_convert=('/home/oracle/oradata/s1','/home/oracle/oradata/s1')
db_unique_name=s2
及相關對於的修改
複製tnsnames.ora,備份檔案,歸檔檔案,flash_recovery_area ,與dump相關的admin目錄
建立oradata/s1目錄
3.啟動s2到nomount狀態
startup nomount
如果採用nfs掛載應先在s2上執行
SQL>Alter system set events '10298 trace name context forever,level 32'
否則會報
ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
4.執行
rman target 'sys/fishcat@s1' auxiliary /
-----set newname 路徑一樣可省略
run{
set newname for datafile 7 to "/home/oracle/oradata/s1/test01.dbf";
set newname for datafile 6 to "/home/oracle/oradata/s1/vip01.dbf";
set newname for datafile 5 to "/home/oracle/oradata/s1/example01.dbf";
set newname for datafile 4 to "/home/oracle/oradata/s1/users01.dbf";
set newname for datafile 3 to "/home/oracle/oradata/s1/sysaux01.dbf";
set newname for datafile 2 to "/home/oracle/oradata/s1/undotbs01.dbf";
set newname for datafile 1 to "/home/oracle/oradata/s1/system01.dbf";
set newname for tempfile 1 to "/home/oracle/oradata/s1/temp01.dbf";
duplicate target database to s2 nofilenamecheck logfile
group 3 ('/home/oracle/oradata/s1/redo03.log')size 52428800 reuse,
group 2 ('/home/oracle/oradata/s1/redo02.log')size 52428800 reuse,
group 1 ('/home/oracle/oradata/s1/redo01.log')size 52428800 reuse;
}