Oracle 12C 基于 RMAN 备份集 进行跨平台(different Endian)数据传输 操作示例
1 背景说明
在之前的博客我们演示了异构平台的TTS操作,如下:
Oracle 11g 单实例 TTS(异构平台传输表空间) 操作示例
https://www.cndba.cn/dave/article/4392Oracle TTS异构平台传输表空间 [单实例(11.2.0.4) —> RAC(18.4) PDB迁移] 操作示例
https://www.cndba.cn/dave/article/4394Oracle TTS异构平台传输表空间[RAC(18.4) PDB —> 单实例(19.10) 迁移] 操作示例
https://www.cndba.cn/dave/article/4396
基于RMAN 备份的方式与之前的TTS 步骤差不多,都是先将表空间设置为只读,然后转换Endian格式,再将数据在目标库恢复,在切换表空间为读写模式。
在Oracle 12c 中引入该功能,也是有其主要的背景。因为使用 RMAN 备份集进行跨平台的数据库传输,可利用块压缩,而降低备份集大小,从而提高备份性能,并降低备份集通过网络传输的时间。 这也是使用RMAN 的最主要原因。 如果数据量不大,那么传统的TTS即可满足需要,但当数据库很大,比如几十T,那么临时转存需要的空间和网络传输占用的时间就会多很多。
在 backup 命令中,要指定参数 TO PLATFORM /FOR TRANSPORT 来进行endian format的转换,同时还需要使用 DATAPUMP 参数来明确对应表空间的数据文件。
1) 当使用TO PLATFORM时,将在源数据库上执行字节序格式转换。
因此,您只能在指定平台上还原此跨平台备份。 如果省略TO PLATFORM,则可以在任何受支持的平台上还原此跨平台备份。TO PLATFORM子句指定的目标平台必须是跨平台传输的受支持平台。 V$TRANSPORTABLE_PLATFORM视图包含受支持平台的列表.
2) 当使用FOR TRANSPORT时,可以将创建的备份集传输到任何目标数据库。
如果目标数据库使用字节序格式与源数据库不同,则在目标数据库上执行所需的字节序格式转换(这适用于表空间级别的传输)。仅当源和目标使用相同的字节序格式时,才可以传输整个数据库。 这种方法的好处是将转换操作的处理开销转移到了目标数据库中.
2 源端环境说明
我们这里演示Linux 19.10 到Linux 19.10 的操作。 跨平台操作类似。
[dave@www.cndba.cn_1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 17 15:45:55 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 DAVE READ WRITE NO
4 USTC READ WRITE NO
SQL> select name,dbid from v$database;
NAME DBID
--------------------------- ----------
CNDBA 299079762
SQL> col file_name for a50
SQL> set lines 120
SQL> col tablespace_name for a20
SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- --------------------
7 /u01/app/oracle/oradata/CNDBA/users01.dbf USERS
4 /u01/app/oracle/oradata/CNDBA/undotbs01.dbf UNDOTBS1
1 /u01/app/oracle/oradata/CNDBA/system01.dbf SYSTEM
3 /u01/app/oracle/oradata/CNDBA/sysaux01.dbf SYSAUX
SQL>
我们这里使用DAVE的PDB 进行操作。
[dave@www.cndba.cn_1 ~]$ sqlplus dave/dave@dave
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 17 15:50:15 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Fri Feb 05 2021 23:57:46 +08:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
SQL> show con_name
CON_NAME
------------------------------
DAVE
SQL> col file_name for a50
SQL> set lines 120
SQL> col tablespace_name for a20
SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- --------------------
9 /u01/app/oracle/oradata/CNDBA/dave/system01.dbf SYSTEM
10 /u01/app/oracle/oradata/CNDBA/dave/sysaux01.dbf SYSAUX
11 /u01/app/oracle/oradata/CNDBA/dave/undotbs01.dbf UNDOTBS1
12 /u01/app/oracle/oradata/CNDBA/dave/users01.dbf USERS
20 /u01/app/oracle/oradata/CNDBA/dave/dave_12.dbf CNDBA
21 /u01/app/oracle/oradata/CNDBA/dave/dave_11.dbf CNDBA
6 rows selected.
SQL>
SQL> create tablespace anqing datafile '/u01/app/oracle/oradata/CNDBA/dave/huaining01.dbf' size 20M,'/u01/app/oracle/oradata/CNDBA/dave/huaining02.dbf' size 20M;
Tablespace created.
SQL> create user ustc identified by ustc;
User created.
SQL> grant connect,resource,dba to ustc;
Grant succeeded.
SQL> alter user ustc default tablespace anqing;
User altered.
SQL>
SQL> create table ustc.hefei as select * from dba_objects;
Table created.
SQL> select count(1) from ustc.hefei;
COUNT(1)
----------
72677
SQL> conn ustc/ustc@dave
Connected.
SQL> select count(1) from hefei;
COUNT(1)
----------
72677
我们这里用anqing 这个表空间进行测试。
3 查看平台 endian format (byte ordering)和字符集
SQL> set pages 200
SQL> COLUMN PLATFORM_NAME FORMAT A40
SQL> SELECT * FROM V$TRANSPORTABLE_PLATFORM;
PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ---------------------------------------- ----------------------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
10 Linux IA (32-bit) Little
6 AIX-Based Systems (64-bit) Big
3 HP-UX (64-bit) Big
5 HP Tru64 UNIX Little
4 HP-UX IA (64-bit) Big
11 Linux IA (64-bit) Little
15 HP Open VMS Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
13 Linux x86 64-bit Little
16 Apple Mac OS Big
12 Microsoft Windows x86 64-bit Little
17 Solaris Operating System (x86) Little
18 IBM Power Based Linux Big
19 HP IA Open VMS Little
20 Solaris Operating System (x86-64) Little
21 Apple Mac OS (x86-64) Little
20 rows selected.
--也可以直接查询当前平台:
SQL> SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;
PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- ----------------------------
Linux x86 64-bit Little
SQL> select userenv('LANGUAGE') FROM DUAL;
USERENV('LANGUAGE')
--------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
Linux 和Windows 都是Little,Unix 都是Big。
4 检查表空间自包含
在执行传输之前必须确保这一步通过,否则无法正常进行传输表空间。
SQL> execute sys.dbms_tts.transport_set_check('ANQING', true);
PL/SQL procedure successfully completed.
SQL> select * from sys.transport_set_violations;
no rows selected
5 将ANQING表空间设置为只读
在执行RMAN 备份之前,必须先将表空间设置为只读模式:
SQL> alter tablespace anqing read only;
Tablespace altered.
6 RMAN 备份ANQING 表空间
与传统的TTS不同,使用rman 备份不需要单独导出元数据,rman 备份时会自动生成元数据的dump文件(默认是在$ORACLE_HOME/dbs 目录下),导出完成后移动到DATAPUMP FORMAT指定的路径。 所以采用RMAN 传输数据的备份会生成2个备份集,一个是数据文件的,一个是dump 文件的。
[dave@www.cndba.cn_1 ~]$ rman target '"dave/dave@dave as sysbackup"'
Recovery Manager: Release 19.0.0.0.0 - Production on Wed Feb 17 16:25:39 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA:DAVE (DBID=3516530670)
RMAN> BACKUP TO PLATFORM 'Linux x86 64-bit'
FORMAT '/tmp/xplat_backups/trans_ts.bck'
DATAPUMP FORMAT '/tmp/xplat_backups/trans_ts_dmp.bck'
TABLESPACE ANQING;
Starting backup at 2021:02:1716:48:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
Running TRANSPORT_SET_CHECK on specified tablespaces
TRANSPORT_SET_CHECK completed successfully
Performing export of metadata for specified tablespaces...
EXPDP> Starting "SYSBACKUP"."TRANSPORT_EXP_CNDBA_leqb":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Master table "SYSBACKUP"."TRANSPORT_EXP_CNDBA_leqb" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYSBACKUP.TRANSPORT_EXP_CNDBA_leqb is:
EXPDP> /u01/app/oracle/product/19.3.0/dbhome_1/dbs/backup_tts_CNDBA_10710.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace ANQING:
EXPDP> /u01/app/oracle/oradata/CNDBA/dave/huaining01.dbf
EXPDP> /u01/app/oracle/oradata/CNDBA/dave/huaining02.dbf
EXPDP> Job "SYSBACKUP"."TRANSPORT_EXP_CNDBA_leqb" successfully completed at Wed Feb 17 16:49:01 2021 elapsed 0 00:00:35
Export completed
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00022 name=/u01/app/oracle/oradata/CNDBA/dave/huaining01.dbf
input datafile file number=00023 name=/u01/app/oracle/oradata/CNDBA/dave/huaining02.dbf
channel ORA_DISK_1: starting piece 1 at 2021:02:1716:49:03
channel ORA_DISK_1: finished piece 1 at 2021:02:1716:49:04
piece handle=/tmp/xplat_backups/trans_ts.bck tag=TAG20210217T164820 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting full datafile backup set
input Data Pump dump file=/u01/app/oracle/product/19.3.0/dbhome_1/dbs/backup_tts_CNDBA_10710.dmp
channel ORA_DISK_1: starting piece 1 at 2021:02:1716:49:04
channel ORA_DISK_1: finished piece 1 at 2021:02:1716:49:05
piece handle=/tmp/xplat_backups/trans_ts_dmp.bck tag=TAG20210217T164820 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2021:02:1716:49:05
RMAN>
7 移动备份集到目标库
将 Backup 命令和数据泵导出的文件移动到目的主机。可以使用 sftp,ftp 和 scp 等系统工具进行移动/复制。
在目标库创建存放目录,并将源库的备份集传输过来。
目标库:
[dave@www.cndba.cn_2 ~]$ mkdir /tmp/xplat_backups/
源库:
[dave@www.cndba.cn_1 dbs]$ cd /tmp/xplat_backups/
[dave@www.cndba.cn_1 xplat_backups]$ ls
trans_ts.bck trans_ts_dmp.bck
[dave@www.cndba.cn_1 xplat_backups]$ scp * 192.168.74.203:`pwd`
oracle@192.168.74.203's password:
trans_ts.bck 100% 13MB 46.8MB/s 00:00
trans_ts_dmp.bck 100% 224KB 15.2MB/s 00:00
[dave@www.cndba.cn_1 xplat_backups]$
这里trans_ts.bck是数据文件的备份,trans_ts_dmp.bck是dump 元数据的备份。
8 目标端RMAN恢复表空间
从源数据库传输过来的备份集中,使用 restore 命令恢复数据文件。使用数据泵文件导入包含表空间的源数据,并将这个表空间插入到目的数据库。
我们这里已经将备份集和数据泵文件复制到了目录/tmp/xplat_backups。
这里有两种情况:
1)如果目的数据库的参数 db_create_file_dest 已经设置,执行下面命令:
RMAN> RESTORE
FOREIGN TABLESPACE TEST1 to NEW
FROM BACKUPSET '/u01/app/oracle/oradata/test/trans_ts.bck'
DUMP FILE FROM BACKUPSET '/u01/app/oracle/oradata/test/trans_ts_dmp.bck';
注意:使用"to NEW"还原数据文件到参数 db_create_file_dest 指定的目录中。
如果正在使用多备份集,则显示如下:
RMAN> RESTORE
ALL FOREIGN DATAFILES TO NEW
FROM BACKUPSET '/mnt/staging_clt_target/tts/all_3tbs_uhrdm8f5_1_1.bck'
BACKUPSET '/mnt/staging_clt_target/tts/all_3tbs_uirdm8f6_1_1.bck'
DUMP FILE FROM BACKUPSET '/mnt/staging_clt_target/tts/all_3tbs_uhrdm8f5_1_1.bck' ;
如果为每个备份集使用多个备份片,则需要指定每个备份集里面备份片的名字:
RMAN> RESTORE
ALL FOREIGN DATAFILES TO NEW
FROM BACKUPSET '/mnt/staging_clt_target/tts/RTODP-a0r8utgu_1_1','/mnt/staging_clt_target/tts/RTODP-a0r8utgu_2_1',
BACKUPSET '/mnt/staging_clt_target/tts/RTODP-a1r8utgu_1_1','/mnt/staging_clt_target/tts/RTODP-a1r8utgu_2_1'
DUMP FILE FROM BACKUPSET '/mnt/staging_clt_target/tts/RTODP_metadata_1.bck';
2)如果目的数据库的参数 db_create_file_dest 没有设置,需要指定数据文件的存放路径:
RMAN> RESTORE
FOREIGN TABLESPACE TEST1 format '/u01/app/oracle/oradata/%U'
FROM BACKUPSET '/u01/app/oracle/oradata/dest/trans_ts.bck'
DUMP FILE FROM BACKUPSET '/u01/app/oracle/oradata/dest/trmp.bck';
因为默认情况下db_create_file_dest 参数都没有设置,所以我们这里制定路径导入。
[dave@www.cndba.cn_2 xplat_backups]$ sqlplus dave/dave@dave
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 17 18:14:37 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Wed Feb 17 2021 16:33:17 +08:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
SQL> show con_name
CON_NAME
------------------------------
DAVE
SQL> show parameter db_create_file_dest
NAME TYPE
------------------------------------ ---------------------------------
VALUE
------------------------------
db_create_file_dest string
SQL>
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/CNDBA/dave/system01.dbf
/u01/app/oracle/oradata/CNDBA/dave/sysaux01.dbf
/u01/app/oracle/oradata/CNDBA/dave/undotbs01.dbf
/u01/app/oracle/oradata/CNDBA/dave/users01.dbf
/u01/app/oracle/oradata/CNDBA/dave/dave_12.dbf
/u01/app/oracle/oradata/CNDBA/dave/dave_11.dbf
6 rows selected.
在导入之前还需要创建表空间对应的用户,否则导入会因如下错误失败:
Performing import of metadata...
IMPDP> Master table "SYSBACKUP"."TSPITR_IMP_CNDBA_DdAs" successfully loaded/unloaded
IMPDP> Starting "SYSBACKUP"."TSPITR_IMP_CNDBA_DdAs":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> ORA-39123: Data Pump transportable tablespace job aborted
ORA-29342: user USTC does not exist in the database
[dave@www.cndba.cn_2 xplat_backups]$ sqlplus dave/dave@dave
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 17 18:14:37 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Wed Feb 17 2021 16:33:17 +08:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
SQL> show con_name
CON_NAME
------------------------------
DAVE
SQL> s
SQL> create user ustc identified by ustc;
User created.
SQL> grant connect,resource,dba to ustc;
Grant succeeded.
执行导入:
RESTORE
FOREIGN TABLESPACE ANQING format '/u01/app/oracle/oradata/CNDBA/dave/%N_%f'
FROM BACKUPSET '/tmp/xplat_backups/trans_ts.bck'
DUMP FILE FROM BACKUPSET '/tmp/xplat_backups/trans_ts_dmp.bck';
这里format 我们使用的是%N_%f, 具体格式说明可以参考我之前的博客:
Oracle RMAN format 中占位符 格式化 输出 说明
https://www.cndba.cn/dave/article/4403
[dave@www.cndba.cn_2 admin]$ rman target '"dave/dave@dave as sysbackup"'
Recovery Manager: Release 19.0.0.0.0 - Production on Wed Feb 17 18:30:15 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA:DAVE (DBID=3516530670)
RMAN> RESTORE
FOREIGN TABLESPACE ANQING format '/u01/app/oracle/oradata/CNDBA/dave/%N_%f'
FROM BACKUPSET '/tmp/xplat_backups/trans_ts.bck'
DUMP FILE FROM BACKUPSET '/tmp/xplat_backups/trans_ts_dmp.bck';
Starting restore at 2021:02:1718:30:28
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=250 device type=DISK
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 all files in foreign tablespace ANQING
channel ORA_DISK_1: reading from backup piece /tmp/xplat_backups/trans_ts.bck
channel ORA_DISK_1: restoring foreign file 22 to /u01/app/oracle/oradata/CNDBA/dave/ANQING_22
channel ORA_DISK_1: restoring foreign file 23 to /u01/app/oracle/oradata/CNDBA/dave/ANQING_23
channel ORA_DISK_1: foreign piece handle=/tmp/xplat_backups/trans_ts.bck
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
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 Data Pump dump file to /u01/app/oracle/product/19.3.0/dbhome_1/dbs/backup_tts_CNDBA_77413.dmp
channel ORA_DISK_1: reading from backup piece /tmp/xplat_backups/trans_ts_dmp.bck
channel ORA_DISK_1: foreign piece handle=/tmp/xplat_backups/trans_ts_dmp.bck
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Performing import of metadata...
IMPDP> Master table "SYSBACKUP"."TSPITR_IMP_CNDBA_FuAg" successfully loaded/unloaded
IMPDP> Starting "SYSBACKUP"."TSPITR_IMP_CNDBA_FuAg":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYSBACKUP"."TSPITR_IMP_CNDBA_FuAg" successfully completed at Wed Feb 17 18:30:36 2021 elapsed 0 00:00:03
Import completed
Finished restore at 2021:02:1718:30:37
RMAN>
9 将目标端表空间设置为读写并验证数据
SQL> show con_name
CON_NAME
------------------------------
DAVE
SQL> col tablespace_name for a25
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------- ---------------------------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
CNDBA ONLINE
ANQING READ ONLY
7 rows selected.
SQL>
SQL> alter tablespace anqing read write;
Tablespace altered.
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------- ---------------------------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
CNDBA ONLINE
ANQING ONLINE
7 rows selected.
SQL>
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/CNDBA/dave/system01.dbf
/u01/app/oracle/oradata/CNDBA/dave/sysaux01.dbf
/u01/app/oracle/oradata/CNDBA/dave/undotbs01.dbf
/u01/app/oracle/oradata/CNDBA/dave/users01.dbf
/u01/app/oracle/oradata/CNDBA/dave/dave_12.dbf
/u01/app/oracle/oradata/CNDBA/dave/dave_11.dbf
/u01/app/oracle/oradata/CNDBA/dave/ANQING_23
/u01/app/oracle/oradata/CNDBA/dave/ANQING_22
8 rows selected.
SQL> select count(1) from dave.dave;
COUNT(1)
----------
173925
SQL>
SQL> select count(1) from ustc.hefei;
COUNT(1)
----------
72677
至此,采用RMAN备份集进行跨平台数据传输示例结束,当然在生产环境操作时,前期的准备工作还是要做充分。
版权声明:本文为博主原创文章,未经博主允许不得转载。