rman异机恢复步骤
- 备份现有主机上的数据库
- 在新主机上,将控制文件、数据文件和临时文件还原到新位置
- 在新主机上,重命名联机重做日志
- 使用 NID 更改db_name 和 dbid (根据需要)
原库DB_NAME:PRIM
目标DB_NAME:TEST
$ rman target /
RMAN> backup database format '/tmp/db_%U';
RMAN> backup archivelog all format '/tmp/archs_%U';
RMAN> backup current controlfile format '/tmp/control.bks';
RMAN> backup spfile format '/tmp/spfile.bks';
/*
如果是非归档模式
$ rman target /
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> backup database format '/tmp/db_%U';
RMAN> backup current controlfile format '/tmp/control.bks';
RMAN> backup spfile format '/tmp/spfile.bks';
*/
scp到目标主机
恢复参数文件
export ORACLE_SID = PRIM
RMAN> startup nomount force;
RMAN> restore spfile from '/tmp/spfile.bks';
RMAN> restore spfile to pfile '/tmp/initnewdb.ora' from '/tmp/spfile.bks';
修改配置参数
$ grep audit /tmp/initnewdb.ora
*.audit_file_dest='/<path>/admin/PRIM/adump'
$ mkdir -p /<path>/admin/PRIM/adump
SQL> shutdown immediate;
SQL> startup nomount;
SQL> show parameter control_files
SQL> show parameter dump
SQL> show parameter create
SQL> show parameter recovery
还原控制文件
RMAN> restore controlfile from '/tmp/control.bks';
RMAN> alter database mount;
RMAN> report schema;
RMAN> catalog start with '/<path for backuppiece location>/';
RMAN> restore database preview summary;
恢复
RMAN> run {
# set newname for all datafiles to be mapped to a new path
# OR use SET NEWNAME FOR DATABASE if you wish to have all files located in the same directory
# eg. SET NEWNAME FOR DATABASE to '+DATA/inovadg/datafile/%b'
set newname for datafile 1 to 'new file path and name';
...
set newname for tempfile 1 to 'new file path and name';
restore database;
switch datafile all;
switch tempfile all;
}
确认
RMAN> report schema;
如果从脱机备份中恢复
RMAN> recover database noredo;
在原库备份期间的归档
RMAN> backup archivelog all format '/tmp/rest_of_arc_%U.bks;
传到目标主机
scp ...
RMAN> catalog backuppiece '/tmp/rest_of_arc';
精准恢复
RMAN> run {# change the date and time to suit
SET UNTIL TIME "to_date('01 SEP 2011 12:04:00','DD MON YYYY hh24:mi:ss')";
recover database;
}
修改redo位置
SQL> select * from v$logfile;
SQL> alter database rename file '<old redo log path and name>' to '<new redo log path and name>';
开库
RMAN> alter database open resetlogs;
补全临时文件
SQL> select * from v$tempfile;
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE 'new tempfile path filename' REUSE;
重命名db_name
$ nid target=sys/<password> dbname=TEST
参考:
如何使用 RMAN 将数据库移动 / 恢复到新的主机和文件系统 (Doc ID 2942353.1)
How to Change the DBID, DBNAME Using NID Utility in version 10GgR2 onwards (Doc ID 863800.1)