重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1584|回复: 0
打印 上一主题 下一主题

[备份恢复] 12C Linux备份恢复到Win10(异机恢复)

[复制链接]
跳转到指定楼层
楼主
发表于 2020-7-30 15:00:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 windjack 于 2020-8-25 09:24 编辑

12C Linux备份恢复到Win10   --实现异构OS恢复 ORACLE数据库
环境:
源库 linux 7.8  oracle 12.1.0.2
目标库 win10  oracle 12.1.0.2
------------------------------------------------------------------------------------------------------------------------------------------------

1.源库执行整库备份

RMAN> backup database format '/home/oracle/db_full%U.bak' plus archivelog format '/home/oracle/arch_%U.bak';
Starting backup at 30-JUL-20
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=1 STAMP=1047123002
input archived log thread=1 sequence=2 RECID=2 STAMP=1047123011
channel ORA_DISK_1: starting piece 1 at 30-JUL-20
channel ORA_DISK_1: finished piece 1 at 30-JUL-20
piece handle=/home/oracle/arch_03v6jl23_1_1.bak tag=TAG20200730T113011 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-JUL-20

Starting backup at 30-JUL-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/example01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/undotbs1.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/tbs_idx01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/sztech/SZTECH/datafile/users01.dbf
channel ORA_DISK_1: starting piece 1 at 30-JUL-20
channel ORA_DISK_1: finished piece 1 at 30-JUL-20
piece handle=/home/oracle/db_full04v6jl24_1_1.bak tag=TAG20200730T113012 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 30-JUL-20
channel ORA_DISK_1: finished piece 1 at 30-JUL-20
piece handle=/home/oracle/db_full05v6jl2k_1_1.bak tag=TAG20200730T113012 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-JUL-20

Starting backup at 30-JUL-20
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=3 STAMP=1047123030
channel ORA_DISK_1: starting piece 1 at 30-JUL-20
channel ORA_DISK_1: finished piece 1 at 30-JUL-20
piece handle=/home/oracle/arch_06v6jl2m_1_1.bak tag=TAG20200730T113030 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-JUL-20

2、备份最新的控制文件并改备份文件名字(方便识别)
RMAN> backup current controlfile to destination '/home/oracle/';
Starting backup at 30-JUL-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 30-JUL-20
channel ORA_DISK_1: finished piece 1 at 30-JUL-20
piece handle=/home/oracle/SZTECH/backupset/2020_07_30/o1_mf_ncnnf_TAG20200730T113117_hl4hr6l2_.bkp tag=TAG20200730T113117 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-JUL-20
[oracle@dbserver ~]$ cd /home/oracle/SZTECH/backupset/2020_07_30/
[oracle@dbserver 2020_07_30]$ ll
total 10176
-rw-r----- 1 oracle asmadmin 10420224 Jul 30 11:31 o1_mf_ncnnf_TAG20200730T113117_hl4hr6l2_.bkp
[oracle@dbserver 2020_07_30]$ mv o1_mf_ncnnf_TAG20200730T113117_hl4hr6l2_.bkp  /home/oracle/control.bak

3.传输相关备份文件、参数文件、口令文件(可选)到win10
sftp> lcd d:\back\
sftp> cd /home/oracle
sftp> get db*
Downloading db_full04v6jl24_1_1.bak from /home/oracle/db_full04v6jl24_1_1.bak
  100% 1403280KB  63785KB/s 00:00:22     
/home/oracle/db_full04v6jl24_1_1.bak: 1436958720 bytes transferred in 22 seconds (63785 KB/s)
Downloading db_full05v6jl2k_1_1.bak from /home/oracle/db_full05v6jl2k_1_1.bak
  100% 10208KB  10208KB/s 00:00:00     
/home/oracle/db_full05v6jl2k_1_1.bak: 10452992 bytes transferred in 0 seconds (10208 KB/s)
sftp> get ar
arch_03v6jl23_1_1.bak arch_06v6jl2m_1_1.bak
sftp> get arch_0*
Downloading arch_03v6jl23_1_1.bak from /home/oracle/arch_03v6jl23_1_1.bak
  100% 12404KB  12404KB/s 00:00:00     
/home/oracle/arch_03v6jl23_1_1.bak: 12702208 bytes transferred in 0 seconds (12404 KB/s)
Downloading arch_06v6jl2m_1_1.bak from /home/oracle/arch_06v6jl2m_1_1.bak
  100% 3KB      3KB/s 00:00:00     
/home/oracle/arch_06v6jl2m_1_1.bak: 3072 bytes transferred in 0 seconds (3072 bytes/s)
sftp> get control.bak
Downloading control.bak from /home/oracle/control.bak
  100% 10176KB  10176KB/s 00:00:00     
/home/oracle/control.bak: 10420224 bytes transferred in 0 seconds (10176 KB/s)
sftp> get initsztech.ora
Downloading initsztech.ora from /home/oracle/initsztech.ora
  100% 727 bytes    727 bytes/s 00:00:00     
/home/oracle/initsztech.ora: 727 bytes transferred in 0 seconds (727 bytes/s)

4. WIN10中创建新的 oracle sid
C:\Users\lg>oradim -new -sid sztech

5.WIN10中修改参数文件pfile

修改参数文件d:\back\initsztech.ora如下:
*.audit_file_dest='C:\app\oracle\admin\sztech\adump'
*.audit_trail='db'
*.compatible='12.1.0.2.0'
*.control_files='C:\app\oracle\oradata\sztech\control01.ctl','C:\app\oracle\oradata\sztech\control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='C:\app\oracle\oradata\sztech'
*.db_domain=''
*.db_name='sztech'
*.db_recovery_file_dest='C:\app\oracle\fast_recovery_area'
*.db_recovery_file_dest_size=4560m
*.diagnostic_dest='C:\app\oracle\'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=sztechXDB)'
*.max_shared_servers=200
*.open_cursors=300
*.pga_aggregate_target=256m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=768m
*.shared_server_sessions=500
*.shared_servers=10
*.undo_tablespace='UNDOTBS1'

6.创建上面参数文件标注的相关文件目录


7.创建SPFILE并启动到nomount

C:\Users\lg>sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on 星期四 7月 30 14:07:27 2020
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
已连接到空闲例程。

SQL> startup nomount pfile='d:\back\initsztech.ora';
ORACLE 例程已经启动。

Total System Global Area  805306368 bytes
Fixed Size                  3050800 bytes
Variable Size             373293776 bytes
Database Buffers          423624704 bytes
Redo Buffers                5337088 bytes


SQL> create spfile from pfile='d:\back\initsztech.ora';
文件已创建。


SQL> startup force nomount;
ORACLE 例程已经启动。

Total System Global Area  805306368 bytes
Fixed Size                  3050800 bytes
Variable Size             373293776 bytes
Database Buffers          423624704 bytes
Redo Buffers                5337088 bytes
SQL>


8.登录RMAN执行相关恢复操作

C:\WINDOWS\system32>set nls_lang=american_america.zhs16gbk

C:\WINDOWS\system32>rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Thu Jul 30 14:09:41 2020
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
connected to target database: SZTECH (not mounted)

RMAN> restore controlfile from 'd:\back\control.bak';
Starting restore at 30-JUL-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=241 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=C:\APP\ORACLE\ORADATA\SZTECH\CONTROL01.CTL
output file name=C:\APP\ORACLE\ORADATA\SZTECH\CONTROL02.CTL
Finished restore at 30-JUL-20

RMAN> alter database mount;
Statement processed
released channel: ORA_DISK_1

-注册复制到windows中的备份到控制文件中
RMAN> catalog start with 'd:\back\';

Starting implicit crosscheck backup at 30-JUL-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=241 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 30-JUL-20

Starting implicit crosscheck copy at 30-JUL-20
using channel ORA_DISK_1
Finished implicit crosscheck copy at 30-JUL-20

searching for all files in the recovery area
cataloging files...
no files cataloged

searching for all files that match the pattern d:\back\

List of Files Unknown to the Database
=====================================
File Name: D:\BACK\ARCH_03V6JL23_1_1.BAK
File Name: D:\BACK\ARCH_06V6JL2M_1_1.BAK
File Name: D:\BACK\CONTROL.BAK
File Name: D:\BACK\DB_FULL04V6JL24_1_1.BAK
File Name: D:\BACK\DB_FULL05V6JL2K_1_1.BAK
File Name: D:\BACK\INITSZTECH.ORA

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: D:\BACK\ARCH_03V6JL23_1_1.BAK
File Name: D:\BACK\ARCH_06V6JL2M_1_1.BAK
File Name: D:\BACK\CONTROL.BAK
File Name: D:\BACK\DB_FULL04V6JL24_1_1.BAK
File Name: D:\BACK\DB_FULL05V6JL2K_1_1.BAK

List of Files Which Were Not Cataloged
=======================================
File Name: D:\BACK\INITSZTECH.ORA
  RMAN-07517: Reason: The file header is corrupted

--删除原来linux文件路径的备份
RMAN> delete expired backup;
using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
3       3       1   1   EXPIRED     DISK        /home/oracle/arch_03v6jl23_1_1.bak
4       4       1   1   EXPIRED     DISK        /home/oracle/db_full04v6jl24_1_1.bak
5       5       1   1   EXPIRED     DISK        /home/oracle/db_full05v6jl2k_1_1.bak
6       6       1   1   EXPIRED     DISK        /home/oracle/arch_06v6jl2m_1_1.bak

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/home/oracle/arch_03v6jl23_1_1.bak RECID=3 STAMP=1047123011
deleted backup piece
backup piece handle=/home/oracle/db_full04v6jl24_1_1.bak RECID=4 STAMP=1047123012
deleted backup piece
backup piece handle=/home/oracle/db_full05v6jl2k_1_1.bak RECID=5 STAMP=1047123029
deleted backup piece
backup piece handle=/home/oracle/arch_06v6jl2m_1_1.bak RECID=6 STAMP=1047123030
Deleted 4 EXPIRED objects  
  


RMAN> list backup;
List of Backup Sets
===================
BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
3       12.11M     DISK        00:00:00     30-JUL-20
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20200730T113011
        Piece Name: D:\BACK\ARCH_03V6JL23_1_1.BAK

  List of Archived Logs in backup set 3
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    1       3212502    30-JUL-20 3221025    30-JUL-20
  1    2       3221025    30-JUL-20 3221054    30-JUL-20

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    1.34G      DISK        00:00:08     30-JUL-20
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: TAG20200730T113012
        Piece Name: D:\BACK\DB_FULL04V6JL24_1_1.BAK
  List of Datafiles in backup set 4
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 3221063    30-JUL-20 /u01/app/oracle/oradata/sztech/SZTECH/datafile/system01.dbf
  2       Full 3221063    30-JUL-20 /u01/app/oracle/oradata/sztech/SZTECH/datafile/tbs_idx01.dbf
  3       Full 3221063    30-JUL-20 /u01/app/oracle/oradata/sztech/SZTECH/datafile/sysaux01.dbf
  4       Full 3221063    30-JUL-20 /u01/app/oracle/oradata/sztech/SZTECH/datafile/undotbs1.dbf
  5       Full 3221063    30-JUL-20 /u01/app/oracle/oradata/sztech/SZTECH/datafile/example01.dbf
  6       Full 3221063    30-JUL-20 /u01/app/oracle/oradata/sztech/SZTECH/datafile/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5       Full    9.95M      DISK        00:00:01     30-JUL-20
        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: TAG20200730T113012
        Piece Name: D:\BACK\DB_FULL05V6JL2K_1_1.BAK
  SPFILE Included: Modification time: 30-JUL-20
  SPFILE db_unique_name: SZTECH
  Control File Included: Ckp SCN: 3221068      Ckp time: 30-JUL-20

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
6       2.50K      DISK        00:00:00     30-JUL-20
        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20200730T113030
        Piece Name: D:\BACK\ARCH_06V6JL2M_1_1.BAK

  List of Archived Logs in backup set 6
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    3       3221054    30-JUL-20 3221073    30-JUL-20

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    9.92M      DISK        00:00:01     30-JUL-20
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20200730T113117
        Piece Name: D:\BACK\CONTROL.BAK
  Control File Included: Ckp SCN: 3221120      Ckp time: 30-JUL-20

--选择合适的scn,并指定新文件路径,进行不完整恢复。
RMAN> run {
set until scn 3221063;
set newname for datafile 1 to 'C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\SYSTEM01.DBF';
set newname for datafile 2 to 'C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\TBS_IDX01.DBF';
set newname for datafile 3 to 'C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\SYSAUX01.DBF';
set newname for datafile 4 to 'C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\UNDTOTBS1.DBF';
set newname for datafile 5 to 'C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\EXAMPLE01.DBF';
set newname for datafile 6 to 'C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\USERS01.DBF';
restore database;
switch datafile all;
recover database;
}

executing command: SET until clause

Starting restore at 30-JUL-20
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 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\SYSTEM01.DBF
channel ORA_DISK_1: restoring datafile 00002 to C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\TBS_IDX01.DBF
channel ORA_DISK_1: restoring datafile 00003 to C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\SYSAUX01.DBF
channel ORA_DISK_1: restoring datafile 00004 to C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\UNDTOTBS1.DBF'
channel ORA_DISK_1: restoring datafile 00005 to C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\EXAMPLE01.DBF'
channel ORA_DISK_1: restoring datafile 00006 to C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\USERS01.DBF'
channel ORA_DISK_1: reading from backup piece D:\BACK\DB_FULL04V6JL24_1_1.BAK
channel ORA_DISK_1: piece handle=D:\BACK\DB_FULL04V6JL24_1_1.BAK tag=TAG20200730T113012
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 30-JUL-20

Starting recover at 30-JUL-20
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 30-JUL-20

--以resetlogs打开数据库

RMAN> alter database open resetlogs;

Statement processed

9.执行相关脚本:
重新编译对象:
SQL> @?/rdbms/admin/utlrp.sql;


10.执行相关验证
SQL> select file#,name from v$datafile

     FILE# NAME
---------- ------------------------------------------------------------------------------------------
         1 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\SYSTEM01.DBF
         2 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\TBS_IDX01.DBF
         3 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\SYSAUX01.DBF
         4 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\UNDTOTBS1.DBF
         5 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\EXAMPLE01.DBF
         6 C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\USERS01.DBF


--logfile 采用OMF

SQL> select member from v$logfile

MEMBER
----------------------------------------------------------------------------------------------------
C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\ONLINELOG\O1_MF_3_HL4SHQ33_.LOG
C:\APP\ORACLE\FAST_RECOVERY_AREA\SZTECH\ONLINELOG\O1_MF_3_HL4SHQ8L_.LOG
C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\ONLINELOG\O1_MF_2_HL4SHPO0_.LOG
C:\APP\ORACLE\FAST_RECOVERY_AREA\SZTECH\ONLINELOG\O1_MF_2_HL4SHPVB_.LOG
C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\ONLINELOG\O1_MF_1_HL4SHP7W_.LOG
C:\APP\ORACLE\FAST_RECOVERY_AREA\SZTECH\ONLINELOG\O1_MF_1_HL4SHPFN_.LOG

--tempfile采用OMF
SQL> select name from v$tempfile;

NAME
------------------------------------------------------------------------------------------
C:\APP\ORACLE\ORADATA\SZTECH\SZTECH\DATAFILE\O1_MF_TEMP_HL4SHQWD_.TMP


SQL> show parameter control_files

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
control_files                        string                 C:\APP\ORACLE\ORADATA\SZTECH\C
                                                            ONTROL01.CTL, C:\APP\ORACLE\OR
                                                            ADATA\SZTECH\CONTROL02.CTL
                                                            
                                                            
--至此,完成恢复,建议做一次全备。                                                        
--附加说明:
  从linux到windows通过RMAN duplicate 也是可以的,但可能会遇到一些问题需要处理,复制脚本如下:
run{
allocate auxiliary channel c1 device type disk;
set newname for datafile 1 to "d:\backup\system01.dbf";
set newname for datafile 3 to "d:\backup\sysaux01.dbf";
set newname for datafile 4 to "d:\backup\undotbs01.dbf";
set newname for datafile 5 to "d:\backup\example01.dbf";
set newname for datafile 6 to "d:\backup\users01.dbf";
set newname for tempfile 1 to "d:\backup\temp01.dbf";
duplicate target database to "test"  backup location 'd:\backup\' nofilenamecheck
LOGFILE
'd:\backup\redo01.log' SIZE 50M,
'd:\backup\redo02.log' SIZE 50M,
'd:\backup\redo03.log' SIZE 50M;

}











--THE END





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-30 06:24 , Processed in 0.099606 second(s), 21 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表