1,源与目标数据库的概况
编号 数据库类型 数据库名称 数据库版本 数据库IP地址 操作系统平台
1 oracleRAC devdb 11.2.0.3 192.168.40.191 redhat 6.5
2 oracleRAC orcl 12.2.0.1 192.168.40.180 redhat 6.5
2,创建源端数据库的测试表空间及测试用户并创建测试表和插入数据
--//数据文件放在了本地(只是测试用)
drop tablespace TBS_XTTS including contents and datafiles;
create tablespace tbs_xtts datafile '/home/oracle/tbs_xtts01.dbf' size 10m;
create user user_xtts identified by system account unlock default tablespace tbs_xtts;
grant resource,connect to user_xtts;
conn user_xtts/system
create table t_test(a int);
insert into t_test values(1);
commit;
SQL> create tablespace tbs_xtts datafile '/home/oracle/tbs_xtts01.dbf' size 10m;
Tablespace created.
SQL> create user user_xtts identified by system account unlock default tablespace tbs_xtts;
User created.
SQL> grant resource,connect to user_xtts;
Grant succeeded.
SQL>
SQL>
SQL> conn user_xtts/system
Connected.
SQL> create table t_test(a int);
Table created.
SQL> insert into t_test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL>
set linesize 300
col name for a50
select file#,name from v$datafile;
FILE# NAME
---------- --------------------------------------------------
1 +DATA/devdb/datafile/system.256.940551845
2 +DATA/devdb/datafile/sysaux.257.940551847
3 +DATA/devdb/datafile/undotbs1.258.940551847
4 +DATA/devdb/datafile/users.259.940551847
5 +DATA/devdb/datafile/undotbs2.264.940552089
6 +DATA/devdb/datafile/tset.297.1040701645
7 /home/oracle/tbs_xtts01.dbf
3,在源端数据库对data file 7进行data file copy
--源端执行
rman target /
backup as copy datafile 7 tag 'datafile 7 copy note' format '/home/oracle/tbs_xtts01.copy';
--//表空间个文件
rman target /
backup as copy datafile 7,8 tag 'datafile 7,8 copy note' format '/home/oracle/tbs_xtts01_%U';
或者
backup as copy tablespace tbs_xtts format '/home/oracle/xxx_%U';
[oracle@rac1]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on ? 58 17:35:54 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DEVDB (DBID=845281939)
RMAN> backup as copy datafile 7 tag 'datafile 7 copy note' format '/home/oracle/tbs_xtts01.copy';
Starting backup at 2020/05/18 17:36:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=162 instance=devdb1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/home/oracle/tbs_xtts01.dbf
output file name=/home/oracle/tbs_xtts01.copy tag=DATAFILE 7 COPY NOTE RECID=26 STAMP=1040751380
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2020/05/18 17:36:21
RMAN>
[oracle@rac1]$ ls -ltr tbs_xtts*
-rw-r----- 1 oracle asmadmin 10493952 May 18 17:36 tbs_xtts01.copy
-rw-r----- 1 oracle asmadmin 10493952 May 18 17:45 tbs_xtts01.dbf
[oracle@rac1]$
4,传输源端数据库测试表空间DATA FILE COPY到目标端数据库对应目录
[oracle@rac1]$ scp /home/oracle/tbs_xtts01.copy [email protected]:/home/oracle
[email protected]'s password:
tbs_xtts01.copy 100% 10MB 10.0MB/s 00:00
[oracle@rac1]$
5,在目标端数据库对自源端数据库传输过来的测试表空间DATA FILE COPY进行字节序转换
---目标端
[oracle@node1 ~]$ pwd
/home/oracle
[oracle@node1 ~]$ ls -ltr tbs*
-rw-r-----. 1 oracle oinstall 10493952 May 15 23:41 tbs_xtts01.copy
[oracle@node1 ~]$
查看PDB的配置
[oracle@node1 admin]$ cat tnsnames.ora
ORCL=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.180)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.localdomain)
)
)
QXY1=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.180)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = qxy111pdb.localdomain)
)
)
--//监听状态
[oracle@node1 admin]$ lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 16-MAY-2020 00:14:41
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 15-MAY-2020 09:06:16
Uptime 0 days 15 hr. 8 min. 26 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/12.1.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/node1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.40.183)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=node1.localdomain)(PORT=5500))(Security=(my_wallet_directory=/gridhome/app/oracle/product/12.2.0.1/db_1/admin/orcl/xdb_wallet))(Presentation=HTTP)(Session=RAW))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.40.180)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_MGMT" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_OCR" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "962e987502a6b068e053b428a8c05c98.localdomain" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "966960d9daccacf1e053b428a8c0cae8.localdomain" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "QXY111XDB.localdomain" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "SYS$C##GGADMIN.OGG$Q_EX1.0.ORCL.LOCALDOMAIN" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "SYS$C##GGADMIN.OGG$Q_EX2.0.ORCL.LOCALDOMAIN" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "SYS$C##GGADMIN.OGG$Q_EX3.0.ORCL.LOCALDOMAIN" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "SYS$C##GGADMIN.OGG$Q_EX4.0.ORCL.LOCALDOMAIN" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "orcl.localdomain" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "pdb02.localdomain" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
Service "qxy111pdb.localdomain" has 1 instance(s).
Instance "QXY1111", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@node1 admin]$
--//pdb的状态
[oracle@node1 admin]$ o
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 16 00:15:10 2020
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 QXY111PDB READ WRITE NO <====需要导入的PDB
4 PDB02 READ WRITE YES
SQL>
--//创建用户
登陆到QXY111PDB创建
create user user_xtts identified by tiger account;
grant resource,connect to user_xtts;
grant SYSBACKUP to user_xtts;
grant sysdba to user_xtts identified by tiger;
--//使用pdb登陆rman
[oracle@node1 ~]$ rman target user_xtts/tiger@QXY1
Recovery Manager: Release 12.2.0.1.0 - Production on Fri May 15 23:48:13 2020
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL:QXY111PDB (DBID=3045978822)
RMAN>
RMAN>
RMAN> convert datafile '/home/oracle/tbs_xtts01.copy' format '/home/oracle/tbs_xtts01.dbf' from platform 'Linux x86 64-bit';
Starting conversion at target at 15-MAY-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=25 instance=QXY1111 device type=DISK
channel ORA_DISK_1: starting datafile conversion
input file name=/home/oracle/tbs_xtts01.copy
converted datafile=/home/oracle/tbs_xtts01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Finished conversion at target at 15-MAY-20
RMAN> exit
Recovery Manager complete.
[oracle@node1 ~]$
6,在源端数据库查询测试表空间data file copy的SCN
set linesize 300
col name for a50
select recid,name,file#,incremental_level,checkpoint_time,checkpoint_change# from v$datafile_copy where file#=7;
SQL> set linesize 300
SQL> col name for a50
SQL> select recid,name,file#,incremental_level,checkpoint_time,checkpoint_change# from v$datafile_copy where file#=7;
RECID NAME FILE# INCREMENTAL_LEVEL CHECKPOINT_TIME CHECKPOINT_CHANGE#
---------- -------------------------------------------------- ---------- ----------------- ------------------- ------------------
7 /home/oracle/tbs_xtts01.copy 7 2020/05/18 17:36:20 35072924
SQL>
7,在源端数据库对测试表空间进行数据库事务变化
conn user_xtts/tiger
insert into t_test values(2);
commit;
SQL>
SQL> conn user_xtts/tiger
Connected.
SQL>
SQL> insert into t_test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL>
--//设置表空间read only
SQL> alter tablespace tbs_xtts read only;
Tablespace altered.
8,在源端数据库基于 上述的DATA FILE COPY的SCN进行增量RMAN备份
backup incremental from scn 35072924 datafile 7 format '/home/oracle/incr_datafile7_first_bak_35072924_%u_%d.bak' tag='datafile7_first_incr_bak';
[oracle@rac1]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on ? 58 17:46:00 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DEVDB (DBID=845281939)
RMAN> backup incremental from scn 35072924 datafile 7 format '/home/oracle/incr_datafile7_first_bak_35072924_%u_%d.bak' tag='datafile7_first_incr_bak';
Starting backup at 2020/05/18 17:46:03
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=162 instance=devdb1 device type=DISK
backup will be obsolete on date 2020/05/25 17:46:03
archived logs will not be kept or backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/home/oracle/tbs_xtts01.dbf
channel ORA_DISK_1: starting piece 1 at 2020/05/18 17:46:03
channel ORA_DISK_1: finished piece 1 at 2020/05/18 17:46:04
piece handle=/home/oracle/incr_datafile7_first_bak_35072924_8nv0h7ar_DEVDB.bak tag=DATAFILE7_FIRST_INCR_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
using channel ORA_DISK_1
backup will be obsolete on date 2020/05/25 17:46:05
archived logs will not be kept or backed up
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 2020/05/18 17:46:06
channel ORA_DISK_1: finished piece 1 at 2020/05/18 17:46:07
piece handle=/home/oracle/incr_datafile7_first_bak_35072924_8ov0h7at_DEVDB.bak tag=DATAFILE7_FIRST_INCR_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020/05/18 17:46:07
RMAN>
9,传输源端上述的增量RMAN备份到目标端数据库对应目录
[oracle@rac1]$ scp /home/oracle/incr_datafile7_first_bak_35072924_8nv0h7ar_DEVDB.bak [email protected]:/home/oracle
[email protected]'s password:
incr_datafile7_first_bak_35072924_8nv0h7ar_DEVDB.bak 100% 56KB 56.0KB/s 00:00
[oracle@rac1]$
10,在目标端数据库对自源端数据库传输过来的增量RMAN备份集进行字节序转换
[oracle@node1 ~]$ ls -l /home/oracle/incr_datafile*
-rw-r-----. 1 oracle oinstall 57344 May 15 23:52 /home/oracle/incr_datafile7_first_bak_35072924_8nv0h7ar_DEVDB.bak
[oracle@node1 ~]$
--//登陆QXY111PDB
sqlplus user_xtts/tiger@QXY1
SQL> DECLARE
2 handle varchar2(512);
3 comment varchar2(80);
4 media varchar2(80);
5 concur boolean;
6 recid number;
7 stamp number;
8 pltfrmfr number;
9 devtype VARCHAR2(512);
10 BEGIN
11 BEGIN
12 sys.dbms_backup_restore.restoreCancel(TRUE);
13 devtype := sys.dbms_backup_restore.deviceAllocate;
14 sys.dbms_backup_restore.backupBackupPiece(bpname => '/home/oracle/incr_datafile7_first_bak_35072924_8nv0h7ar_DEVDB.bak',fname => '/home/oracle/first_incr_bak.bak',handle => handle,media=> media,comment=> comment, concur=> concur,recid=> recid,stamp => stamp, check_logical => FALSE,copyno=> 1, deffmt=> 0, copy_recid=> 0,copy_stamp => 0,npieces=> 1,dest=> 0,pltfrmfr=>13);
15 END;
16 END;
17 /
PL/SQL procedure successfully completed.
SQL>
[oracle@node1 ~]$ pwd
/home/oracle
[oracle@node1 ~]$ ls -ltr first_incr_bak.bak
-rw-r-----. 1 oracle asmadmin 57344 May 15 23:53 first_incr_bak.bak
[oracle@node1 ~]$
11,在目标端数据库对上述的DATA FILE COPY以及初次的增量RMAN备份集进行前滚应用
sqlplus user_xtts/tiger@QXY1
set serveroutput on;
DECLARE
outhandle varchar2(512) ;
outtag varchar2(30) ;
done boolean ;
failover boolean ;
devtype VARCHAR2(512);
BEGIN
DBMS_OUTPUT.put_line('Entering RollForward');
-- Now the rolling forward.
devtype := sys.dbms_backup_restore.deviceAllocate;
sys.dbms_backup_restore.applySetDatafile(
check_logical => FALSE, cleanup => FALSE) ;
DBMS_OUTPUT.put_line('After applySetDataFile');
sys.dbms_backup_restore.applyDatafileTo(
dfnumber => 7,
toname => '/home/oracle/tbs_xtts01.dbf',
fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,
recid => 0, stamp => 0);
DBMS_OUTPUT.put_line('Done: applyDataFileTo');
DBMS_OUTPUT.put_line('Done: applyDataFileTo');
-- Restore Set Piece
sys.dbms_backup_restore.restoreSetPiece(
handle => '/home/oracle/first_incr_bak.bak',
tag => null, fromdisk => true, recid => 0, stamp => 0) ;
DBMS_OUTPUT.put_line('Done: RestoreSetPiece');
-- Restore Backup Piece
sys.dbms_backup_restore.restoreBackupPiece(
done => done, params => null, outhandle => outhandle,
outtag => outtag, failover => failover);
DBMS_OUTPUT.put_line('Done: RestoreBackupPiece');
sys.dbms_backup_restore.restoreCancel(TRUE);
sys.dbms_backup_restore.deviceDeallocate;
END;
/
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece
PL/SQL procedure successfully completed.
SQL>
12,在源端数据库导出测试表空间的元数据
sqlplus '/as sysdba'
col directory_name for a50
col directory_path for a50
set linesize 300
select directory_name,directory_path from dba_directories;
DIRECTORY_NAME DIRECTORY_PATH
-------------------------------------------------- --------------------------------------------------
XTTSFILES /home/oracle/xttsfiles
DATADUMP /ogg/datadump
XMLDIR /u01/app/oracle/product/11.2.0/db_1/rdbms/xml
DPDATA1 /tmp/datadump
DATA_PUMP_DIR /u01/app/oracle/product/11.2.0/db_1/rdbms/log/
ORACLE_OCM_CONFIG_DIR /u01/app/oracle/product/11.2.0/db_1/ccr/state
6 rows selected.
SQL>
[oracle@rac1]$ expdp "'/ as sysdba'" dumpfile=expdp_tbs_xtts.dmp directory=XTTSFILES transport_tablespaces=tbs_xtts logfile=expdp_tbs_xtts.log
Export: Release 11.2.0.3.0 - Production on ? 58 06:38:38 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
"SYS"."SYS_EXPORT_TRANSPORTABLE_01": "/******** AS SYSDBA" dumpfile=expdp_tbs_xtts.dmp directory=XTTSFILES transport_tablespaces=tbs_xtts logfile=expdp_tbs_xtts.log
TRANSPORTABLE_EXPORT/PLUGTS_BLK
TRANSPORTABLE_EXPORT/TABLE
TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
YS"."SYS_EXPORT_TRANSPORTABLE_01"
******************************************************************************
SYS.SYS_EXPORT_TRANSPORTABLE_01 ?:
/home/oracle/xttsfiles/expdp_tbs_xtts.dmp
******************************************************************************
TBS_XTTS
/home/oracle/tbs_xtts01.dbf
"SYS"."SYS_EXPORT_TRANSPORTABLE_01" 06:39:33
[oracle@rac1]$
13,传输源端导出的测试表空间元数据到目标端数据库对应目录
create directory XTTSFILES as '/home/oracle/xttsfiles';
sqlplus user_xtts/tiger@QXY1
col directory_name for a50
col directory_path for a50
set linesize 300
select directory_name,directory_path from dba_directories;
SQL> col directory_name for a50
SQL> col directory_path for a50
SQL> set linesize 300
SQL> select directory_name,directory_path from dba_directories;
DIRECTORY_NAME DIRECTORY_PATH
-------------------------------------------------- --------------------------------------------------
DBMS_OPTIM_LOGDIR /gridhome/app/oracle/product/12.2.0.1/db_1/cfgtoollogs
DBMS_OPTIM_ADMINDIR /gridhome/app/oracle/product/12.2.0.1/db_1/rdbms/admin
XTTSFILES /home/oracle/xttsfiles
---源端
scp /home/oracle/xttsfiles/expdp_tbs_xtts.dmp [email protected]:/home/oracle/xttsfiles/
[oracle@rac1]$ cd xttsfiles/
[oracle@rac1]$ ls
expdp_tbs_xtts.dmp expdp_tbs_xtts.log
[oracle@rac1]$ scp /home/oracle/xttsfiles/expdp_tbs_xtts.dmp [email protected]:/home/oracle/xttsfiles/
[email protected]'s password:
expdp_tbs_xtts.dmp 100% 88KB 88.0KB/s 00:00
[oracle@rac1]$
14,在目标端数据库导入测试表空间
impdp user_xtts/tiger@QXY1 directory=XTTSFILES transport_datafiles='/home/oracle/tbs_xtts01.dbf' dumpfile=expdp_tbs_xtts.dmp logfile=impdp_tbs_xtts.log
[oracle@node1 ~]$ impdp user_xtts/tiger@QXY1 directory=XTTSFILES transport_datafiles='/home/oracle/tbs_xtts01.dbf' dumpfile=expdp_tbs_xtts.dmp logfile=impdp_tbs_xtts.log
Import: Release 12.2.0.1.0 - Production on Fri May 15 23:59:36 2020
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "USER_XTTS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "USER_XTTS"."SYS_IMPORT_TRANSPORTABLE_01": user_xtts/********@QXY1 directory=XTTSFILES transport_datafiles=/home/oracle/tbs_xtts01.dbf dumpfile=expdp_tbs_xtts.dmp logfile=impdp_tbs_xtts.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "USER_XTTS"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Sat May 16 00:00:47 2020 elapsed 0 00:00:43
[oracle@node1 ~]$
15、测试验证数据
[oracle@node1 ~]$ sqlplus user_xtts/tiger@QXY1
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 16 00:01:10 2020
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Last Successful login time: Fri May 15 2020 23:59:36 +08:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> select TABLESPACE_NAME from dba_tablespaces;
TABLESPACE_NAME
--------------------------------------------------------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
UNDO_2
USERS
TBS_XTTS
7 rows selected.
SQL> select * from t_test;
A
----------
2
1
SQL>
16、设置源端和目标端的表空间为read write;