1、拷贝源库的一份 RMAN 全备到目标库。
查询源库的 RMAN 备份
RMAN> list backup of database;
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
55 Full 1.60G DISK 00:00:02 16-DEC-15
BP Key: 55 Status: AVAILABLE Compressed: NO Tag: TAG20151216T031039
Piece Name: /oradata/bk/rman_20qou75f_1_1
List of Datafiles in backup set 55
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 20904683 16-DEC-15 /oradata/oradata/site/site/system01.dbf
2 Full 20904683 16-DEC-15 /oradata/oradata/site/site/sysaux01.dbf
3 Full 20904683 16-DEC-15 /oradata/oradata/site/site/undotbs01.dbf
4 Full 20904683 16-DEC-15 /oradata/oradata/site/site/users01.dbf
5 Full 20904683 16-DEC-15 /oradata/oradata/site/site/ts_site_data01.dbf
6 Full 20904683 16-DEC-15 /oradata/oradata/site/site/ts_site_index01.dbf
拷贝源库的一份 RMAN 全备到目标库。
[oracle@DB1 bk]$ scp rman_1vqou75e_1_1 rman_20qou75f_1_1 rman_21qou75m_1_1
[email protected]:/oradata/bk
[email protected]'s password:
rman_1vqou75e_1_1 100% 147MB 146.6MB/s 00:01
rman_20qou75f_1_1 100% 1641MB 109.4MB/s 00:15
rman_21qou75m_1_1 100% 8704 8.5KB/s 00:00
查看控制文件备份。
需要注意的是,在11G,数据库全备的时候,
RMAN
不会备份控制文件,除非在备份语句后面加上
INCLUDE CURRENT CONTROLFILE
。
例如:BACKUP DATABASE INCLUDE CURRENT CONTROLFILE;
也可以单独备份控制文件。
例如:BACKUP CURRENT CONTROLFILE;
在11G的 RMAN 中,有 CONTROLFILE AUTOBACK 这参数,设置这个参数后,每当数据库执行 RMAN 备份的时候,RMAN 会自动备份控制文件和参数文件到指定目录下。
可以视图中查询指定备份是否包含控制文件,下面视图中的
CON
TROLFILE_INCLUDED
表明备份是否包含控制文件
SQL> SELECT S.RECID backset_id,
S.START_TIME,
ROUND(P.BYTES / 1024 / 1024 / 1024,2) GB,
S.BACKUP_TYPE,
INCREMENTAL_LEVEL,
P.STATUS,
ROUND(P.ELAPSED_SECONDS) ELAPSED_SECONDS,
P.HANDLE AS "MEDIA_HANDLE",
CON
TROLFILE_INCLUDED
FROM V$BACKUP_PIECE P, V$BACKUP_SET S
WHERE P.SET_STAMP = S.SET_STAMP
AND P.SET_COUNT = S.SET_COUNT
ORDER BY P.COMPLETION_TIME;
BACKSET_ID START_TIME GB B INCREMENTAL_LEVEL S ELAPSED_SECONDS MEDIA_HANDLE CONTROLFILE_INCLUDED
---------- ------------------- ---------- - ----------------- - --------------- ---------------------------------------------------------------------- -------------------------
1737 2016-01-16 05:10:49 5.6 L A 171 naqrg5qp_1_1 NO
1738 2016-01-16 05:13:45 .03 D A 130 c-1864798816-20160116-01 YES
1739 2016-01-17 04:44:49 24.59 I 1 A 1195 ncqriom1_1_1 NO
1740 2016-01-17 05:04:45 .03 D A 128 c-1864798816-20160117-00 YES
1741 2016-01-17 05:07:08 5.64 L A 161 neqripvs_1_1 NO
1742 2016-01-17 05:09:54 5.53 L A 171 nfqriq52_1_1 NO
1743 2016-01-17 05:12:51 .03 D A 119 c-1864798816-20160117-01 YES
1744 2016-01-18 04:16:33 29.92 I 1 A 1578 nhqrlbd1_1_1 NO
1745 2016-01-18 04:42:59 .03 D A 120 c-1864798816-20160118-00 YES
1746 2016-01-18 04:45:13 5.33 L A 159 njqrld2p_1_1 NO
1747 2016-01-18 04:47:59 5.19 L A 169 nkqrld7v_1_1 NO
--查询控制文件备份
RMAN> LIST BACKUP OF CONTROLFILE;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5 Full 17.17M DISK 00:00:00 03-DEC-15
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20151203T233014
Piece Name: /oradata/bk/c-4224792395-20151203-00
Control File Included: Ckp SCN: 2165935 Ckp time: 03-DEC-15
由于源库开启了 CONTROLFILE AUTO BACKUP,将全备份时生成的控制文件也拷贝到备库。
[oracle@DB1 bk]$ scp c-4224792395-20151216-00
[email protected]:/oradata/bk
[email protected]'s password:
c-4224792395-20151216-00 100% 17MB 17.4MB/s 00:00
2、在目标库上进行 RMAN 恢复。
目标库上面已经安装了 ORACLE 软件。
设置 ORACLE_SID
[oracle@DB2 ~]$ export ORACLE_SID=site
登录 RMAN ,启动到 NOMOUNT
% rman NOCATALOG
RMAN> CONNECT TARGET /
--DBID的值可以登录主库的 RMAN 查看到,也可以在 RMAN 的 CONTROLFILE AUTO BACKUP 生成的文件名中看到
SET DBID 4224792395;
STARTUP NOMOUNT
恢复参数文件
RUN
{
ALLOCATE CHANNEL c1 DEVICE TYPE disk;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata/bk/%F';
RESTORE SPFILE
TO PFILE '/u01/app/oracle/product/12.1.0/db_1/dbs/initsite.ora'
FROM AUTOBACKUP;
SHUTDOWN ABORT;
}
编辑生成的参数文件,修改对应的控制文件目录、audit_file_dest、db_recovery_file_dest 等目录,保证指定的目录存在
oracle@DB2 dbs]$ vim initsite.ora
注释掉 local_listener 参数,否则启动会报错
#*.local_listener='LISTENER_SITE'
用新还原的参数文件启动数据库
STARTUP FORCE NOMOUNT PFILE='/u01/app/oracle/product/12.1.0/db_1/dbs/initsite.ora';
执行控制文件恢复
rman target /
SET DBID 4224792395;
RUN
{
ALLOCATE CHANNEL c1 DEVICE TYPE disk;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata/bk/%F';
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
}
登记传输过来的
备份到 RMAN
CATALOG START WITH '/oradata/bk/';
检查数据备份,删除过期的备份
RMAN> crosscheck backup;
RMAN> delete noprompt expired backup;
查看归档日志备份的 SCN,决定介质
恢复的时间点
RMAN> list backup of archivelog all;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
54 146.61M DISK 00:00:00 16-DEC-15
BP Key: 54 Status: AVAILABLE Compressed: NO Tag: TAG20151216T031038
Piece Name: /oradata/bk/rman_1vqou75e_1_1
List of Archived Logs in backup set 54
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 206 20633382 15-DEC-15 20716789 16-DEC-15
1 207 20716789 16-DEC-15 20895202 16-DEC-15
1 208 20895202 16-DEC-15 20904669 16-DEC-15
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
56 8.00K DISK 00:00:00 16-DEC-15
BP Key: 56 Status: AVAILABLE Compressed: NO Tag: TAG20151216T031046
Piece Name: /oradata/bk/rman_21qou75m_1_1
List of Archived Logs in backup set 56
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 209 20904669 16-DEC-15 20904701 16-DEC-15
执行 RESTORE 命令,恢复数据文件
RMAN> RESTORE DATABASE;
执行介质恢复
SQL> RECOVER DATABASE using backup controlfile UNTIL CHANGE 20716789;
Media recovery complete.
3、打开数据库
[oracle@DB2 site]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Wed Dec 16 11:50:22 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00392: log 5 of thread 1 is being cleared, operation not allowed
ORA-00312: online log 5 thread 1: '/u01/app/oracle/oradata/site/redo05.log'
出现报错,清空报错的日志文件
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 5;
Database altered.
打开数据库
SQL> alter database open resetlogs;
Database altered.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-1873417/,如需转载,请注明出处,否则将追究法律责任。