XTTS利用XTTS迁移表空间

2023年 10月 19日 51.2k 0

XTTS--利用XTTS迁移表空间

  • XTTS迁移步骤
  • XTTS迁移方式
  • 迁移步骤
    • 环境说明
    • 数据库环境检查
    • 基本检查
    • 前期处理
    • 全量传输
    • 多次前滚
    • 正式停机割接
    • 收尾阶段
      • 数据校验
      • 收集统计信息

上篇文章https://www.modb.pro/db/1712677248980557824,讲了TTS的迁移方式,但是他有一个缺点,tablespace必须是静态的,如果是实时业务,那么表空间的增量数据,是没有办法同步过来的,唯一的办法就是停业务,静态状态下利用TTS进行迁移,停机窗口与数据量有关,一般都很长。那么对于实时业务的数据,如何才能快速迁移哪?答案就是XTTS,虽然只有一个表空间,但是它在初始化(不需要read only)后,仅需很短的停机窗口(需要read only),同步下增量,即可迁移成功,非常方便。所以他两适用的场景是不一样。
XTTS (Cross Platform Transportable Tablespaces) 跨平台迁移表空间,是Oracle推出的一个用来迁移单个表空间数据以及将一个完整的数据库从一个平台移动到另一个平台的迁移备份方法。在企业越来越大的数据量、相对停机时间要求日益减少的情况下,利用XTTS可以完成使用增量备份方式实现跨平台的数据迁移。是 Oracle 自10g推出的一个用来移动单个表空间数据以及创建一个完整的数据库从一个平台移动到另一个平台的迁移备份方法。它是 Oracle 8i 开始就引入的一种基于表空间传输的物理迁移方法,命名为 TTS,不过8i的表空间迁移仅支持相同平台、相同块大小之间的表空间传输,然而在那个年代还未像今天一样技术日新月异,TTS 的光芒一直被埋没在历史的尘埃里,从 Oracle 9i 开始,TTS 开始支持同平台中,不同块大小的表空间传输,这个时候很多数据库管理员就注意到了 TTS 在实际工作中的应用,不过由于每次移动表空间都需要停机、停业务,而9i的 TTS 只能在相同平台之间进行数据移动,相比 Oracle RMAN 本身的快捷方便,更多人更愿意选择使用 RMAN 进行数据备份、数据移动,基于这些原因,Oracle 10g 时代引入了跨平台的表空间传输方案 XTTS,标志着第一代 XTTS 的诞生。

XTTS迁移步骤

在 Oracle11gR2 以后,Oracle 推出了通过前滚数据文件,拷贝数据后再进行多次增量备份的 XTTS 来完成迁移过程,在这个过程中通过开启块跟踪特性,根据 SCN 号来执行一系列的增量备份,并且通过对块跟踪文件的扫描,来完成增量数据的增量备份应用,最后在通过一定的停机时间,在源库 read only 的状态下进行最后一次增量备份转换应用,使得整个迁移过程的停机时间同源库数据块的变化率成正比。这样大大的缩短了停机时间。

XTTS迁移方式

XTTS 是基于一组 rman-xttconvert_3.0 的脚本文件包来实现跨平台的数据迁移,主要包含 Perl script xttdriver 和 xttdriver Perl 脚本。Perl script xttdriver.pl 是备份、转换、应用的执行脚本,xtt.properties 是属性文件,其中包含XTTS配置的路径、参数。
采用 XTTS 迁移方式,具备跨平台字序转换和全量初始化加增量 merge 的功能,非常适用于异构 OS 跨平台迁移,成为数据库实施人员中公认的大数据量跨平台迁移的最佳选择。

传统的 TTS 传输表空间要求数据由源端到目标端传输的整个过程中,表空间必须置于 read only 模式,严重影响业务可用性。XTTS 方式可以在业务正常运行的情况下,进行物理全量初始化,增量 block 备份,数据高低字节序转码,增量 block 应用,保持目标端与源端数据的同步,整个过程不影响源端数据库使用。在最后的增量 block 应用完毕后,利用停机窗口进行数据库切换,显著地减少了停机时间。

rman-xttconvert_3.0 包参数说明如下表:

方式一:dbms_file_transfer DBMS_FILE_TRANSFER 包是 Oracle 提供的一个用于复制二进制数据库文件或在数据库之间传输二进制文件的程序包,在 XTTS 迁移中,利用不同的参数进行数据文件传输转换完成迁移。
方式二:RMANBackup RMAN Backup 方式是基于 RMAN 备份原理,通过使用 rman-xttconvert_3.0 包提供的参数,对数据库进行基于表空间的备份,将备份生产的备份集写到本地或者 NFS 盘上,然后在通过 rman-xttconvert_3.0 包中包含的不同平台之间数据文件格式转换的包对进行数据文件格式转换,最后通过记录的表空间 FILE_ID 号生产元数据的导入脚本,通过 db_link 执行完成。
方式三:手工 XTTS 迁移 手工脚本执行 XTTS 迁移是云和恩墨根据 Oracle 提供的 rman-xttconvert_3.0 包迁移步骤从原理入手结合 dbms_file_transfer 和 rman backup 方式集合实际工作需求,手工编写的一套专门用于大数据量跨平台的表空间传输迁移脚本,整套脚本从源库、中间库、目标库三个方面详细的通过手工脚本的方式,把需要进行的迁移工作根据任务以及子任务的方式固化,形成一套可执行的迁移技术方案。
本次采用方式二,rman backup落地的方式来行。

迁移步骤

环境说明

column1 源端 目标端
db类型 单实例 单实例
db version 10.2.0.4 11.2.0.4
db 存储 文件系统 ASM
OS版本及kernel版本 SunOS 5.10 Generic_147148-26 RHEL 6.8
db name orcl orcl
用户表空间 old_data_tbs old_data_tbs
业务用户 old_test old_test
字节序 Little Little
归档模式 归档模式 归档模式

源库环境准备

--源库开归档
alter system set db_recovery_file_dest='/export/home/oracle/arch' scope=spfile;
alter system set db_recovery_file_dest_size=20G;
alter system set log_archive_dest_1='location=use_db_recovery_file_dest';
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
--造数据
create tablespace old_data_tbs datafile size 1G;
create user old_test identified by "old_test" default tablespace old_data_tbs;
grant connect ,resource to old_test;
alter user old_test quota unlimited on old_data_tbs;
conn old_test/old_test
create table TB0101_08_09(id number,name varchar2(1000),other_col char(1000));
begin
for i in 1..1000 loop
insert into TB0101_08_09 values(i,lpad('a',995,'a')||i,'other col..');
end loop;
commit;
end;
/
create index idx_id_name_TB0101_08_09 on TB0101_08_09(id,name) online;
create index idx_name_id_TB0101_08_09 on TB0101_08_09(name,id) online;
exec dbms_stats.gather_table_stats(null,'TB0101_08_09',NO_INVALIDATE => FALSE);

数据库环境检查

基本检查

--查询COMPATIBLE
SQL> Show parameter COMPATIBLE;
-- 查询平台和字节序
col PLATFORM_NAME format a40
SELECT d.PLATFORM_ID,d.PLATFORM_NAME, tp.ENDIAN_FORMAT
FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;
-- 查询字符集
select * from nls_database_parameters t where t.parameter in ('NLS_CHARACTERSET','NLS_NCHAR_CHARACTERSET');

--识别待迁移表空间,排除系统表空间,避免冲突
select TABLESPACE_NAME,BLOCK_SIZE,CONTENTS,STATUS
from dba_tablespaces
where tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE');

select owner,tablespace_name,count(*)
from dba_segments
where tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE')
group by owner,tablespace_name order by tablespace_name;

-- 自包含检查
exec dbms_tts.transport_set_check('TS_LHR,TS_XXT,USERS',true);

-- 查看结果,结果为空,表示为自包含
col violations for a70
select * from transport_set_violations;
--要被传输的表空间必须是online的,且不能包含离线的数据文件
select file_name,online_status from dba_data_files t where t.online_status not in ('ONLINE','SYSTEM');
select tablespace_name,status from dba_tablespaces t where t.status 'ONLINE';

--检查是否存在不规范表空间对象
---sys和system用户,是否有对象在业务表空间里面
SQL> select table_name, owner, tablespace_name from dba_tables where tablespace_name not in('SYSTEM','SYSAUX') and owner in ('SYS','SYSTEM');

TABLE_NAME OWNER TABLESPACE_NAME
------------------------------ ------------------------------ ------------------
LOGINFAIL_INFO SYSTEM USERS
SQL> alter table system.LOGINFAIL_INFO move tablespace system;

Table altered.

SQL> select table_name, owner, tablespace_name from dba_tables where tablespace_name not in('SYSTEM','SYSAUX') and owner in ('SYS','SYSTEM');

no rows selected
SQL> select count(*) from system.LOGINFAIL_INFO;

COUNT(*)
----------
0

---迁移用户在系统表空间的对象
select 'Table' object_type,
t.owner,
t.tablespace_name,
t.table_name object_name
from dba_tables t
where tablespace_name in ('SYSTEM', 'SYSAUX')
and owner in ('HCC','ACARS2FOR9C','AOCDS','CCMS','HRSUPPORT','ERCREAD','ERC','TO_CHOLAP','FCMSOPER','FDS','FM','AOC_TEL','FOC','FOCFORUM','FOCCREW','FOCPX','HR','HR_COPY','JIWU_JP','COMPEHENSIVE','HRSYS','HUIQIAN','IPS','NNS','GGADMIN','OQAS','SKYWISE','SMP_MIS','SPC','SPRINGERP','TPF','VMUSER_READ','FMREAD','DBADM','MONITOR','DWREADONLY','FOCREAD','MGMT_VIE','VMUSER','YIXING','ZHONGHE')
union all
select 'Index' object_type,
i.owner,
i.tablespace_name,
i.index_name object_name
from dba_indexes i
where tablespace_name in ('SYSTEM', 'SYSAUX')
and owner in ('HCC','ACARS2FOR9C','AOCDS','CCMS','HRSUPPORT','ERCREAD','ERC','TO_CHOLAP','FCMSOPER','FDS','FM','AOC_TEL','FOC','FOCFORUM','FOCCREW','FOCPX','HR','HR_COPY','JIWU_JP','COMPEHENSIVE','HRSYS','HUIQIAN','IPS','NNS','GGADMIN','OQAS','SKYWISE','SMP_MIS','SPC','SPRINGERP','TPF','VMUSER_READ','FMREAD','DBADM','MONITOR','DWREADONLY','FOCREAD','MGMT_VIE','VMUSER','YIXING','ZHONGHE')
union all
select 'Lob' object_type,
i.owner,
i.tablespace_name,
i.segment_name object_name
from dba_lobs i
where tablespace_name in ('SYSTEM', 'SYSAUX')
and owner in ('HCC','ACARS2FOR9C','AOCDS','CCMS','HRSUPPORT','ERCREAD','ERC','TO_CHOLAP','FCMSOPER','FDS','FM','AOC_TEL','FOC','FOCFORUM','FOCCREW','FOCPX','HR','HR_COPY','JIWU_JP','COMPEHENSIVE','HRSYS','HUIQIAN','IPS','NNS','GGADMIN','OQAS','SKYWISE','SMP_MIS','SPC','SPRINGERP','TPF','VMUSER_READ','FMREAD','DBADM','MONITOR','DWREADONLY','FOCREAD','MGMT_VIE','VMUSER','YIXING','ZHONGHE');

OBJEC OWNER TABLESPACE_NAME OBJECT_NAME
----- ------------------------------ ------------------------------ ------------
Table FOCPX SYSTEM FLYER_ALLOW
Table FOCPX SYSTEM EMP_CLASS_FEE
Table FOCPX SYSTEM EMP_ALLOW
Table FOCPX SYSTEM DEFANSE_THING
Table FOCPX SYSTEM EFANSE_FLIGHT_DAY
Table FOCPX SYSTEM DAY_PLAN_FLY
Table FOCPX SYSTEM DAY_FLIGHT_VIP
Table FOCPX SYSTEM DAY_FLIGHT_2
......
Lob FOC SYSTEM SYS_LOB0000330768C00006$$
Lob FOC SYSTEM SYS_LOB0000330768C00005$$
Lob FOC SYSTEM SYS_LOB0000330773C00004$$

69 rows selected.

表迁移表空间
-----move table
alter table FOCPX.FLYER_ALLOW move tablespace foc;
alter table FOCPX.EMP_CLASS_FEE move tablespace foc;
alter table FOCPX.EMP_ALLOW move tablespace foc;
.....
alter table FOC.AIRCREW_LEAVE0415 move tablespace foc;
alter table HRSYS.D_XT_QUERYRANGE move tablespace hr;
alter table HRSYS.T_XT_STATION move tablespace hr;
alter table ZHONGHE.ACMTYPE move tablespace ZHONGHE;
alter table ZHONGHE.ACMAWOKE move tablespace ZHONGHE;
alter table ZHONGHE.HR_HUMAN_FAMILY move tablespace ZHONGHE;
alter table system.LOGINFAIL_INFO move tablespace system;
--move index
alter index HRSYS.SYS_C00206944 rebuild tablespace HR parallel 4;
alter index HRSYS.SYS_C00206935 rebuild tablespace HR parallel 4;
alter index HRSYS.SYS_C00206934 rebuild tablespace HR parallel 4;
alter index HRSYS.SYS_C00206933 rebuild tablespace HR parallel 4;
alter index HRSYS.SYS_C00206932 rebuild tablespace HR parallel 4;
alter index HRSYS.SYS_C00206920 rebuild tablespace HR parallel 4;
alter index HRSYS.SYS_C00206911 rebuild tablespace HR parallel 4;
alter index "ACARS2FOR9C"."RawMsg_PK21111037114859" rebuild tablespace ACARS parallel 4;

alter index HRSYS.SYS_C00206944 noparallel;
alter index HRSYS.SYS_C00206935 noparallel;
alter index HRSYS.SYS_C00206934 noparallel;
alter index HRSYS.SYS_C00206933 noparallel;
alter index HRSYS.SYS_C00206932 noparallel;
alter index HRSYS.SYS_C00206920 noparallel;
alter index HRSYS.SYS_C00206911 noparallel;
alter index "FOC"."SYS_IL0000330768C00005$$" noparallel;
alter index "ACARS2FOR9C"."RawMsg_PK21111037114859" noparallel;

Blob索引确认表信息
select TABLE_NAME,TABLE_TYPE,INDEX_TYPE,INDEX_NAME,OWNER,VISIBILITY,STATUS from dba_indexes
where index_name in('SYS_IL0000330768C00005$$','SYS_IL0000330768C00006$$','SYS_IL0000330773C00004$$',
'SYS_IL0000328345C00005$$','SYS_IL0000328345C00006$$','SYS_IL0000328350C00004$$');
TABLE_NAME TABLE_TYPE INDEX_TYPE INDEX_NAME OWNER VISIBILIT STATUS
-------------------- --------------- ---------- ------------------------------ ---------- --------- --------
DEFANSE_OBSTRUC TABLE LOB SYS_IL0000328345C00005$$ FOCPX VISIBLE VALID
DEFANSE_OBSTRUC TABLE LOB SYS_IL0000328345C00006$$ FOCPX VISIBLE VALID
DEFANSE_FILE TABLE LOB SYS_IL0000328350C00004$$ FOCPX VISIBLE VALID
DEFANSE_FILE TABLE LOB SYS_IL0000330773C00004$$ FOC VISIBLE VALID
DEFANSE_OBSTRUC TABLE LOB SYS_IL0000330768C00005$$ FOC VISIBLE VALID
DEFANSE_OBSTRUC TABLE LOB SYS_IL0000330768C00006$$ FOC VISIBLE VALID

SQL> select OWNER,TABLE_NAME,COLUMN_NAME,INDEX_NAME from dba_lobs where index_name in('SYS_IL0000330768C00005$$','SYS_IL0000330768C00006$$','SYS_IL0000330773C00004$$',
'SYS_IL0000328345C00005$$','SYS_IL0000328345C00006$$','SYS_IL0000328350C00004$$')
SQL>
OWNER TABLE_NAME COLUMN_NAME INDEX_NAME
-------------------- ------------------------------ -------------------- ------------------------------
FOCPX DEFANSE_FILE FILEZ SYS_IL0000328350C00004$$
FOCPX DEFANSE_OBSTRUC REPORT SYS_IL0000328345C00006$$
FOCPX DEFANSE_OBSTRUC DEPOSITION SYS_IL0000328345C00005$$
FOC DEFANSE_FILE FILEZ SYS_IL0000330773C00004$$
FOC DEFANSE_OBSTRUC REPORT SYS_IL0000330768C00006$$
FOC DEFANSE_OBSTRUC DEPOSITION SYS_IL0000330768C00005$$

6 rows selected.

Blob索引迁移至其他表空间
alter table FOCPX.DEFANSE_FILE move tablespace foc lob(FILEZ) store as (tablespace foc);
alter table FOCPX.DEFANSE_OBSTRUC move tablespace foc lob(REPORT) store as (tablespace foc);
alter table FOCPX.DEFANSE_OBSTRUC move tablespace foc lob(DEPOSITION) store as (tablespace foc);
alter table FOC.DEFANSE_FILE move tablespace foc lob(FILEZ) store as (tablespace foc);
alter table FOC.DEFANSE_OBSTRUC move tablespace foc lob(REPORT) store as (tablespace foc);
alter table FOC.DEFANSE_OBSTRUC move tablespace foc lob(DEPOSITION) store as (tablespace foc);
临时表索引无需处理.

前期处理

  1. 源端清空回收站

SQL> show parameter recyclebin

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string on
SQL> select * from dba_recyclebin;

no rows selected

SQL> purge dba_recyclebin;

DBA Recyclebin purged.

  1. 源端开启tracking

SQL> alter database enable block change tracking using file '/export/home/oracle/trace.log';

Database altered.

SQL> col filename format a100
SQL> select status, filename from v$block_change_tracking;

STATUS FILENAME
---------- ----------------------------------------------------------------------------------------------------
ENABLED /export/home/oracle/trace.log

  1. 目标端创建dblink

复制源端TNS文件到目标端,并在目标端增加到源端的TNS解析。创建目标端到源端DB Link,用于迁移阶段通过network link方式导出源数据或进行迁移后对象比对。本次迁移过程中未使用network_link方式完成源数据导出,仅用该dblink完成minus对象比对。

$vi tnsnames.ora
添加如下内容:
source =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.11)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
SQL> create public database link to_old connect to system identified by oracle using 'source';

Database link created.

SQL> select * from dual@to_old;

D
-
X

  1. 上传xtts v3脚本,配置参数.
    目标端

-bash-3.2$ mkdir xtts
-bash-3.2$ ls -ltr
-rw-r--r-- 1 root root 34672 Oct 18 11:33 rman_xttconvert_v3.zip
bash-3.2# chown oracle:oinstall rman_xttconvert_v3.zip
bash-3.2# chmod 775 rman_xttconvert_v3.zip
bash-3.2# su - oracle
Oracle Corporation SunOS 5.10 Generic Patch January 2005
-bash-3.2$ cd xtts/
-bash-3.2$ ls -ltr
total 69
-rwxrwxr-x 1 oracle oinstall 34672 Oct 18 11:33 rman_xttconvert_v3.zip
-bash-3.2$ unzip rman_xttconvert_v3.zip
Archive: rman_xttconvert_v3.zip
inflating: xtt.properties
inflating: xttcnvrtbkupdest.sql
inflating: xttdbopen.sql
inflating: xttdriver.pl
inflating: xttprep.tmpl
extracting: xttstartupnomount.sql
-bash-3.2$ ls -ltr
total 75
-rw-r--r-- 1 oracle oinstall 1390 May 24 2017 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall 52 May 24 2017 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall 11710 May 24 2017 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall 71 May 24 2017 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 7969 Jun 5 2017 xtt.properties
-rw-r--r-- 1 oracle oinstall 142020 Sep 20 2018 xttdriver.pl
-rwxrwxr-x 1 oracle oinstall 34672 Oct 18 11:33 rman_xttconvert_v3.zip

根据脚本注释,里面会有清楚的说明,区分是source还是destinaion的参数即可。

--去掉#注释和空行
sed -i 's/^#.*$//g' xtt.properties
sed -i '/^$/d' xtt.properties
--最终配置文件如下:
-bash-3.2$ cat xtt.properties
tablespaces=OLD_DATA_TBS
platformid=20
dfcopydir=/export/home/oracle/xtts/backup
backupformat=/export/home/oracle/xtts/backup
stageondest=/home/oracle/xtts/backup
storageondest=+DATADG/orcl/datafile
backupondest=/home/oracle/xtts/backup
asm_home=/u01/app/grid/11.2.0/grid
asm_sid=+ASM
parallel=3
rollparallel=2

以上均为rman的参数。
DFT专用参数:
srcdir=SDIR1,SDIR2
dstdir=DDIR1,DDIR2
getfileparallel=8

整个目录传输到目标端:

-bash-3.2$ scp -r /export/home/oracle/xtts/* 10.1.11.12:/home/oracle/

全量传输

  1. xtts执行-p参数,进行copy备份

-bash-3.2$ cd /export/home/oracle/xtts
-bash-3.2$ export TMPDIR=/export/home/oracle/xtts
-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -p
Can't locate Getopt/Long.pm in @INC (@INC contains: /build/001/perl/bin/Solaris/Opt/lib/5.8.3/i86pc-solaris-thread-multi /build/001/perl/bin/Solaris/Opt/lib/5.8.3 /build/001/perl/bin/Solaris/Opt/lib/site_perl/5.8.3/i86pc-solaris-thread-multi /build/001/perl/bin/Solaris/Opt/lib/site_perl/5.8.3 /build/001/perl/bin/Solaris/Opt/lib/site_perl .) at xttdriver.pl line 138.
BEGIN failed--compilation aborted at xttdriver.pl line 138.

10g的perl会报错,参考:https://www.cnblogs.com/jyzhao/p/9966762.html
perl xttdriver.pl fails: Can’t locate Getopt/Long.pm in @INC (文档 ID 1912400.1)

--临时设置PERL5LIB环境变量,再次使用Oracle自带的perl执行xttdriver.pl不再报之前的错误
-bash-3.2$ export PERL5LIB=$ORACLE_HOME/perl/lib
-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -p

-bash-3.2$ export PERL5LIB=$ORACLE_HOME/perl/lib
-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -p
============================================================
trace file is /export/home/oracle/xtts/prepare_Oct19_Thu_14_58_21_623//Oct19_Thu_14_58_21_623_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Starting prepare phase
--------------------------------------------------------------------

Prepare source for Tablespaces:
'OLD_DATA_TBS' /home/oracle/xtts/backup
xttpreparesrc.sql for 'OLD_DATA_TBS' started at Thu Oct 19 14:58:21 2023
xttpreparesrc.sql for ended at Thu Oct 19 14:58:21 2023
Prepare source for Tablespaces:
'''' /home/oracle/xtts/backup
xttpreparesrc.sql for '''' started at Thu Oct 19 14:58:30 2023
xttpreparesrc.sql for ended at Thu Oct 19 14:58:30 2023

--------------------------------------------------------------------
Done with prepare phase
--------------------------------------------------------------------

--------------------------------------------------------------------
Find list of datafiles in system
--------------------------------------------------------------------

--------------------------------------------------------------------
Done finding list of datafiles in system
--------------------------------------------------------------------

结果解释:
该操作执行过程包括以下内容:
1、此过程会将相关的表空间文件执行一次镜像拷贝过程,可以认为是全备,可以在rman中执行“list copy;”查看。此处会把数据文件拷贝一份到/export/home/oracle/xtts/backup/目录。需要注意目录/export/home/oracle/xtts/backup/的空间。

RMAN> list copy;

List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
3 5 A 19-OCT-23 521643 19-OCT-23 /export/home/oracle/xtts/backup/OLD_DATA_TBS_5.tf

List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
1 1 27 A 02-OCT-19 /export/home/oracle/arch/ORCL/archivelog/2023_10_19/o1_mf_1_27_lm18l5jy_.arc

2、会在/export/home/oracle/xtts 目录下产生几个文件,xttplan.txt、rmanconvert.cmd和xttnewdatafiles.txt:

-bash-3.2$ ls -ltr
total 649
-rw-r--r-- 1 oracle oinstall 1390 May 24 2017 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall 52 May 24 2017 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall 11710 May 24 2017 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall 71 May 24 2017 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 7969 Jun 5 2017 xtt.propertiesbak
-rw-r--r-- 1 oracle oinstall 142020 Sep 20 2018 xttdriver.pl
-rwxrwxr-x 1 oracle oinstall 34672 Oct 18 11:33 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall 311 Oct 19 14:57 xtt.properties
-rw-r--r-- 1 oracle oinstall 25 Oct 19 14:58 xttplan.txt
-rw-r--r-- 1 oracle oinstall 214 Oct 19 14:58 rmanconvert.cmd
drwxr-xr-x 2 oracle oinstall 3 Oct 19 14:58 backup
-rw-r--r-- 1 oracle oinstall 58 Oct 19 14:58 xttnewdatafiles.txt
drwxr-xr-x 2 oracle oinstall 11 Oct 19 14:58 prepare_Oct19_Thu_14_58_21_623

其中xttplan.txt文件中的内容如下:

-bash-3.2$ cat xttplan.txt
OLD_DATA_TBS::::516935
5

该文件中的数值代表数据库的 SCN。如果后面再次运行脚本进行增量操作时,该值会发现改变。
rmanconvert.cmd的内容:

-bash-3.2$ cat rmanconvert.cmd
host 'echo ts::OLD_DATA_TBS';
convert from platform 'Solaris Operating System (x86-64)'
datafile
'/home/oracle/xtts/backup/OLD_DATA_TBS_5.tf'
format '+DATADG/orcl/datafile/%N_%f.dbf'
parallelism 3;

上述脚本是 perl 脚本产生的 rman convert 脚本,需要将该脚本传递到目标端主机。注意,上述脚本文件格式需要注意,同时并行度是默认的,可以进行调整。
2. 将源端的数据文件副本和rmanconvert.cmd、xttplan.txt传到目标端

-bash-3.2$ scp xttplan.txt 10.1.11.12:/home/oracle/xtts
-bash-3.2$ scp rmanconvert.cmd 10.1.11.12:/home/oracle/xtts
-bash-3.2$ scp backup/OLD_DATA_TBS_5.tf 10.1.11.12:/home/oracle/xtts/backup

  1. 在目标端对数据文件拷贝进行字节序的转换

[oracle@11gasm xtts]$ export TMPDIR=/home/oracle/xtts
[oracle@11gasm xtts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -c
============================================================
trace file is /home/oracle/xtts/convert_Oct19_Thu_15_11_03_361//Oct19_Thu_15_11_03_361_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Performing convert
--------------------------------------------------------------------

--------------------------------------------------------------------
Converted datafiles listed in: /home/oracle/xtts/xttnewdatafiles.txt
--------------------------------------------------------------------

转换后的数据文件拷贝会出现在 xtt.properties 文件中定义的参数 storageondest下,即最终的数据文件目录。

[oracle@11gasm xtts]$ cat xttnewdatafiles.txt
::OLD_DATA_TBS
5,+DATADG/orcl/datafile/old_data_tbs_5.dbf
--数据文件已拷贝
ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE OCT 19 12:00:00 Y SYSAUX.261.1023146139
DATAFILE UNPROT COARSE OCT 19 12:00:00 Y SYSTEM.260.1023146137
DATAFILE UNPROT COARSE OCT 19 12:00:00 Y UNDOTBS1.262.1023146139
DATAFILE UNPROT COARSE OCT 19 12:00:00 Y USERS.264.1023146143
DATAFILE UNPROT COARSE OCT 19 12:00:00 Y ZHUO.266.1024792071
DATAFILE UNPROT COARSE OCT 19 15:00:00 Y OLD_DATA_TBS.267.1150643465
N old_data_tbs_5.dbf => +DATADG/ORCL/DATAFILE/OLD_DATA_TBS.267.1150643465

多次前滚

在此阶段,在源端做增量数据,从源数据库创建增量备份(内部其实是仍然使用rman增量备份),将其传输到目标端,在目标端转换为目标系统Endian格式,然后应用于转换后的目标数据文件副本,将其前滚。此阶段可以多次重复运行。每次连续的增量备份都应该比以前的增量备份花费更少的时间,并且将使目标数据文件副本与源数据库更加一致。这样对于目标库上的数据文件拷贝,通过一次次应用增量数据就可以逐渐追上源库的生产数据。
这个阶段中的步骤可以运行多次,以使目标中的datafiles更接近源文件的时间/ SCN。在此阶段,源数据库完全可访问。
模仿源端有业务:

SQL> delete from TB0101_08_09 where rownum commit;

Commit complete.

  1. 源端做增量备份

-bash-3.2$ export TMPDIR=/export/home/oracle/xtts
-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -i
============================================================
trace file is /export/home/oracle/xtts/incremental_Oct19_Thu_15_35_36_25//Oct19_Thu_15_35_36_25_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

============================================================
No new datafiles added
=============================================================
Prepare newscn for Tablespaces: 'OLD_DATA_TBS'
Prepare newscn for Tablespaces: ''''

--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------

--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------

-bash-3.2$ ls -ltr
total 653
-rw-r--r-- 1 oracle oinstall 1390 May 24 2017 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall 52 May 24 2017 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall 11710 May 24 2017 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall 71 May 24 2017 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 7969 Jun 5 2017 xtt.propertiesbak
-rw-r--r-- 1 oracle oinstall 142020 Sep 20 2018 xttdriver.pl
-rwxrwxr-x 1 oracle oinstall 34672 Oct 18 11:33 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall 311 Oct 19 14:57 xtt.properties
-rw-r--r-- 1 oracle oinstall 25 Oct 19 14:58 xttplan.txt
-rw-r--r-- 1 oracle oinstall 214 Oct 19 14:58 rmanconvert.cmd
-rw-r--r-- 1 oracle oinstall 58 Oct 19 14:58 xttnewdatafiles.txt
drwxr-xr-x 2 oracle oinstall 11 Oct 19 14:58 prepare_Oct19_Thu_14_58_21_623
-rw-r--r-- 1 oracle oinstall 27 Oct 19 15:35 xttplan.txt.new
drwxr-xr-x 2 oracle oinstall 4 Oct 19 15:35 backup
-rw-r--r-- 1 oracle oinstall 33 Oct 19 15:35 tsbkupmap.txt
-rw-r--r-- 1 oracle oinstall 45 Oct 19 15:35 incrbackups.txt
drwxr-xr-x 2 oracle oinstall 15 Oct 19 15:35 incremental_Oct19_Thu_15_35_36_25
-bash-3.2$ cat xttplan.txt
OLD_DATA_TBS::::516935
5
-bash-3.2$ cat tsbkupmap.txt
OLD_DATA_TBS::5:::1=0829asm9_1_1
-bash-3.2$ cat incrbackups.txt
/export/home/oracle/xtts/backup/0829asm9_1_1
-bash-3.2$ cat xttplan.txt.new
OLD_DATA_TBS::::521643
5

  1. 将源端的增量数据传到目标端
    3个txt文件和增量备份文件:

-bash-3.2$ scp xttplan.txt 10.1.11.12:/home/oracle/xtts
-bash-3.2$ scp incrbackups.txt 10.1.11.12:/home/oracle/xtts
-bash-3.2$ scp tsbkupmap.txt 10.1.11.12:/home/oracle/xtts
-bash-3.2$ scp backup/0829asm9_1_1 10.1.11.12:/home/oracle/xtts/backup

  1. 目标端进行增量转换和数据写入同步

[oracle@11gasm xtts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -r
============================================================
trace file is /home/oracle/xtts/rollforward_Oct19_Thu_15_54_36_68//Oct19_Thu_15_54_36_68_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Start rollforward
--------------------------------------------------------------------

Can't locate strict.pm in @INC (@INC contains: /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0 /u01/app/grid/11.2.0/grid/lib /u01/app/grid/11.2.0/grid/lib/asmcmd /u01/app/grid/11.2.0/grid/rdbms/lib/asmcmd /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl .) at /u01/app/grid/11.2.0/grid/bin/asmcmdcore line 143.
BEGIN failed--compilation aborted at /u01/app/grid/11.2.0/grid/bin/asmcmdcore line 143.

--------------------------------------------------------------------
End of rollforward phase
--------------------------------------------------------------------

“Can’t locate strict.pm in @INC”错误是可以忽略的,这是由于Perl pragma在asmcmdcore中使用“严格模式”的结果

  1. 源端确定下一个增量备份的FROM_SCN
    该步骤会计算下一个FROM_SCN,将其记录在xttplan.txt文件中,然后在创建下一个增量备份时使用该SCN。
    该步骤会将-i时生成的xttplan.txt.new改名为xttplan.txt,并将原来的xttplan.txt备份。
    建议在目标端每次做完recover动作后,源端就执行一次该命令,以免遗忘。

-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -s
============================================================
trace file is /export/home/oracle/xtts/determinescn_Oct19_Thu_15_57_53_625//Oct19_Thu_15_57_53_625_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

Prepare newscn for Tablespaces: 'OLD_DATA_TBS'
Prepare newscn for Tablespaces: ''''
New /export/home/oracle/xtts/xttplan.txt with FROM SCN's generated
-bash-3.2$ ls -ltr
total 659
-rw-r--r-- 1 oracle oinstall 1390 May 24 2017 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall 52 May 24 2017 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall 11710 May 24 2017 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall 71 May 24 2017 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 7969 Jun 5 2017 xtt.propertiesbak
-rw-r--r-- 1 oracle oinstall 142020 Sep 20 2018 xttdriver.pl
-rwxrwxr-x 1 oracle oinstall 34672 Oct 18 11:33 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall 311 Oct 19 14:57 xtt.properties
-rw-r--r-- 1 oracle oinstall 214 Oct 19 14:58 rmanconvert.cmd
-rw-r--r-- 1 oracle oinstall 58 Oct 19 14:58 xttnewdatafiles.txt
drwxr-xr-x 2 oracle oinstall 11 Oct 19 14:58 prepare_Oct19_Thu_14_58_21_623
drwxr-xr-x 2 oracle oinstall 4 Oct 19 15:35 backup
-rw-r--r-- 1 oracle oinstall 33 Oct 19 15:35 tsbkupmap.txt
-rw-r--r-- 1 oracle oinstall 45 Oct 19 15:35 incrbackups.txt
drwxr-xr-x 2 oracle oinstall 15 Oct 19 15:35 incremental_Oct19_Thu_15_35_36_25
-rw-r--r-- 1 oracle oinstall 27 Oct 19 15:57 xttplan.txt
drwxr-xr-x 2 oracle oinstall 13 Oct 19 15:57 determinescn_Oct19_Thu_15_57_53_625
-bash-3.2$ cat xttplan.txt
OLD_DATA_TBS::::521643
5

在割接前,可以重复以上4步,是目标端和源端不断还原。
1.每次增量时都必须复制xttplan.txt、tsbkupmap.txt和incrbackups.txt,因为它们的内容在每次增量时都是不同的。
2.不修改、不复制文件incrbackups.txt.new。
3.该过程每次执行都会重启目标数据库。
4.如果重新开始,那么需要删除/home/oracle/scripts/FAILED
5.XTTDEBUG=1为打开debug模式,进行调试。Debug 模式可以打印更多的屏幕输出,并且开启 RMAN 的 debug 模式。要启用 debug 模式,或者以 -d 参数运行 xttdriver.pl 或者在运行 xttdriver.pl 前设置环境变量 XTTDEBUG=1。这个参数接受3种级别,-d[1/2/3]级别3会显示最多的信息。

下面使用-d 参数,研究下内部流程:

-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -i -d
============================================================
trace file is /export/home/oracle/xtts/incremental_Oct19_Thu_16_02_35_338//Oct19_Thu_16_02_35_338_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: backupondest
Values: /home/oracle/xtts/backup
Key: platformid
Values: 20
Key: backupformat
Values: /export/home/oracle/xtts/backup
Key: parallel
Values: 3
Key: storageondest
Values: +DATADG/orcl/datafile
Key: dfcopydir
Values: /export/home/oracle/xtts/backup
Key: asm_sid
Values: +ASM
Key: rollparallel
Values: 2
Key: stageondest
Values: /home/oracle/xtts/backup
Key: tablespaces
Values: OLD_DATA_TBS
Key: asm_home
Values: /u01/app/grid/11.2.0/grid

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID : orcl
ORACLE_HOME : /export/home/oracle/opt/product/10.2.0/

--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------

============================================================
No new datafiles added
=============================================================
TABLESPACE STRING :'OLD_DATA_TBS'
Prepare newscn for Tablespaces: 'OLD_DATA_TBS'
OLD_DATA_TBS::::522596
5
TABLESPACE STRING :''''
Prepare newscn for Tablespaces: ''''

--------------------------------------------------------------------
Starting incremental backup
--------------------------------------------------------------------

/export/home/oracle/xtts/incremental_Oct19_Thu_16_02_35_338//rmanincr.cmd

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Oct 19 16:02:36 2023

Copyright (c) 1982, 2007, Oracle. All rights reserved.

RMAN-06005: connected to target database: ORCL (DBID=1548383716)

RMAN> set nocfau;
2> host 'echo ts::OLD_DATA_TBS';
3> backup incremental from scn 521643
4> tag tts_incr_update tablespace 'OLD_DATA_TBS' format
5> '/export/home/oracle/xtts/backup/%U';
6>
RMAN-03023: executing command: SET NOCFAU
RMAN-06009: using target database control file instead of recovery catalog

ts::OLD_DATA_TBS
RMAN-06134: host command complete

RMAN-03090: Starting backup at 19-OCT-23
RMAN-08030: allocated channel: ORA_DISK_1
RMAN-08500: channel ORA_DISK_1: sid=526 devtype=DISK
RMAN-08008: channel ORA_DISK_1: starting full datafile backupset
RMAN-08010: channel ORA_DISK_1: specifying datafile(s) in backupset
RMAN-08522: input datafile fno=00005 name=/export/home/oracle/opt/oradata/ORCL/datafile/o1_mf_old_data_llynz3w6_.dbf
RMAN-08038: channel ORA_DISK_1: starting piece 1 at 19-OCT-23
RMAN-08044: channel ORA_DISK_1: finished piece 1 at 19-OCT-23
RMAN-08530: piece handle=/export/home/oracle/xtts/backup/0929au8s_1_1 tag=TTS_INCR_UPDATE comment=NONE
RMAN-08540: channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
RMAN-03091: Finished backup at 19-OCT-23

Recovery Manager complete.

--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------
-bash-3.2$ cat xttplan.txt.new
OLD_DATA_TBS::::522596
5
-bash-3.2$ cat tsbkupmap.txt
OLD_DATA_TBS::5:::1=0929au8s_1_1
-bash-3.2$ cat incrbackups.txt
/export/home/oracle/xtts/backup/0929au8s_1_1 --指定具体数据文件增量备份文件

增量备份其实就是调用rman backup ncremental from scn xxx,scn号就是xttplan.txt里面记录的scn,备份的起点。

```shell
[oracle@11gasm xtts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -r -d
============================================================
trace file is /home/oracle/xtts/rollforward_Oct19_Thu_16_10_15_465//Oct19_Thu_16_10_15_465_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: backupondest
Values: /home/oracle/xtts/backup
Key: platformid
Values: 20
Key: backupformat
Values: /export/home/oracle/xtts/backup
Key: parallel
Values: 3
Key: storageondest
Values: +DATADG/orcl/datafile
Key: dfcopydir
Values: /export/home/oracle/xtts/backup
Key: asm_sid
Values: +ASM
Key: rollparallel
Values: 2
Key: stageondest
Values: /home/oracle/xtts/backup
Key: tablespaces
Values: OLD_DATA_TBS
Key: asm_home
Values: /u01/app/grid/11.2.0/grid

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest
ARGUMENT backupondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID : orcl
ORACLE_HOME : /u01/app/oracle/product/11.2.0/dbhome_1

--------------------------------------------------------------------
Start rollforward
--------------------------------------------------------------------

ORACLE instance started.

Total System Global Area 622149632 bytes
Fixed Size 2255792 bytes
Variable Size 180356176 bytes
Database Buffers 432013312 bytes
Redo Buffers 7524352 bytes
rdfno 5

BEFORE ROLLPLAN

datafile number : 5

datafile name : +DATADG/orcl/datafile/old_data_tbs_5.dbf

AFTER ROLLPLAN

CONVERTED BACKUP PIECE/home/oracle/xtts/backup/xib_0929au8s_1_1_5

PL/SQL procedure successfully completed.
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece

PL/SQL procedure successfully completed.
asmcmd rm /home/oracle/xtts/backup/xib_0929au8s_1_1_5 /u01/app/grid/11.2.0/grid .. +ASM

Can't locate strict.pm in @INC (@INC contains: /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0 /u01/app/grid/11.2.0/grid/lib /u01/app/grid/11.2.0/grid/lib/asmcmd /u01/app/grid/11.2.0/grid/rdbms/lib/asmcmd /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /u01/app/grid/11.2.0/grid/perl/lib/site_perl/5.10.0 /u01/app/grid/11.2.0/grid/perl/lib/site_perl .) at /u01/app/grid/11.2.0/grid/bin/asmcmdcore line 143.
BEGIN failed--compilation aborted at /u01/app/grid/11.2.0/grid/bin/asmcmdcore line 143.
ASMCMD:

--------------------------------------------------------------------
End of rollforward phase
--------------------------------------------------------------------

[oracle@11gasm xtts]$

asmcmd rm /home/oracle/xtts/backup/xib_0929au8s_1_1_5 /u01/app/grid/11.2.0/grid … +ASM
确实删除旧文件的时候,报错,不影响。
先covert,在apply,在restore。

-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -s -d
============================================================
trace file is /export/home/oracle/xtts/determinescn_Oct19_Thu_16_13_49_970//Oct19_Thu_16_13_49_970_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------

Key: backupondest
Values: /home/oracle/xtts/backup
Key: platformid
Values: 20
Key: backupformat
Values: /export/home/oracle/xtts/backup
Key: parallel
Values: 3
Key: storageondest
Values: +DATADG/orcl/datafile
Key: dfcopydir
Values: /export/home/oracle/xtts/backup
Key: asm_sid
Values: +ASM
Key: rollparallel
Values: 2
Key: stageondest
Values: /home/oracle/xtts/backup
Key: tablespaces
Values: OLD_DATA_TBS
Key: asm_home
Values: /u01/app/grid/11.2.0/grid

--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------

--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------

ARGUMENT tablespaces
ARGUMENT platformid
ARGUMENT backupformat
ARGUMENT stageondest

--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

ORACLE_SID : orcl
ORACLE_HOME : /export/home/oracle/opt/product/10.2.0/
TABLESPACE STRING :'OLD_DATA_TBS'
Prepare newscn for Tablespaces: 'OLD_DATA_TBS'

TABLESPACE STRING :''''
Prepare newscn for Tablespaces: ''''

New /export/home/oracle/xtts/xttplan.txt with FROM SCN's generated

其实就是拿上次恢复完成后的xttplan.txt.new中的scn覆盖现在的xttplan.txt,成为新的备份起点。

正式停机割接

  1. 清空回收站

SQL> purge dba_recyclebin;

DBA Recyclebin purged.

  1. 源端表空间read only

set lines 500
set pages 1000
select 'ALTER TABLESPACE ' || tablespace_name || ' READ ONLY;'
from dba_tablespaces
where tablespace_name not in ('SYSTEM','SYSAUX')
and contents = 'PERMANENT';

select TABLESPACE_NAME,status,CONTENTS from dba_tablespaces

SQL> select 'ALTER TABLESPACE ' || tablespace_name || ' READ ONLY;'
2 from dba_tablespaces
3 where tablespace_name not in ('SYSTEM','SYSAUX')
4 and contents = 'PERMANENT';

'ALTERTABLESPACE'||TABLESPACE_NAME||'READONLY;'
----------------------------------------------------------
ALTER TABLESPACE USERS READ ONLY;
ALTER TABLESPACE OLD_DATA_TBS READ ONLY;
SQL> ALTER TABLESPACE OLD_DATA_TBS READ ONLY;

Tablespace altered.

  1. 最后一次增量
    重复上面多次回滚步骤,唯一不用做生成下次scn,因为已经是最后一次增量备份恢复了。
    源端增量备份:

-bash-3.2$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -i

传输3个txt+增量备份文件。
目标端增量应用:

[oracle@11gasm xtts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -r

  1. 创建所有的业务用户
    直接利用之前创建的dblink,在目标端创建用户即可。

SQL> set serveroutput ON echo on
SQL> DECLARE
2 v_sql VARCHAR2 (2000);
3 BEGIN
4 FOR c_username IN (SELECT name, password
5 FROM sys.user$@to_old
6 WHERE name NOT IN ('ANONYMOUS',
7 'APEX_030200',
8 'APEX_PUBLIC_USER',
9 'APPQOSSYS',
10 'CTXSYS',
11 'DBSNMP',
12 'DIP',
13 'EXFSYS',
14 'FLOWS_FILES',
15 'MDDATA',
16 'MDSYS',
17 'MGMT_VIEW',
18 'OLAPSYS',
19 'ORACLE_OCM',
20 'ORDDATA',
21 'ORDPLUGINS',
22 'ORDSYS',
23 'OUTLN',
24 'OWBSYS',
25 'OWBSYS_AUDIT',
26 'SI_INFORMTN_SCHEMA',
27 'SPATIAL_CSW_ADMIN_USR',
28 'SPATIAL_WFS_ADMIN_USR',
29 'SYS',
30 'SYSMAN',
31 'SYSTEM',
32 'WMSYS',
33 'XDB',
34 'XS$NULL','DMSYS','TSMSYS')
35 AND TYPE# = 1)
36 LOOP
37 v_sql :=
38 'create user '
39 || c_username.name
40 || ' identified by values '||chr(39)
41 || c_username.password||chr(39)
42 || ';';
43 DBMS_OUTPUT.put_line (v_sql);
44 END LOOP;
45 END;
46 /
create user OLD_TEST identified by values '87F029CDFF3E3ABA';

PL/SQL procedure successfully completed.
SQL> create user OLD_TEST identified by values '87F029CDFF3E3ABA';

User created.

  1. 目标端生成元数据导出命令

[oracle@11gasm xtts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -e

生成文件:Done generating plugin file /home/oracle/xtts/xttplugin.txt
内容如下:

[oracle@11gasm xtts]$ cat xttplugin.txt
impdp directory= logfile=
network_link= transport_full_check=no
transport_tablespaces=OLD_DATA_TBS
transport_datafiles='+DATADG/orcl/datafile/old_data_tbs_5.dbf'

他主要生成transport_datafiles 参数比较方便,剩下的参数需要自己根据实际情况修改。
6. 导入表空间元数据

[oracle@11gasm xtts]$ impdp '/ as sysdba' directory=DATA_PUMP_DIR logfile=test.log network_link=to_old transport_full_check=no transport_tablespaces=OLD_DATA_TBS transport_datafiles='
+DATADG/orcl/datafile/old_data_tbs_5.dbf' exclude=TABLE_STATISTICS,INDEX_STATISTICS

Import: Release 11.2.0.4.0 - Production on Thu Oct 19 17:50:47 2023

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01": "/******** AS SYSDBA" directory=DATA_PUMP_DIR logfile=test.log network_link=to_old transport_full_check=no transport_tablespaces=OLD_DATA_TBS transport_datafiles=+DATADG/orcl/datafile/old_data_tbs_5.dbf exclude=TABLE_STATISTICS,INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Thu Oct 19 17:50:57 2023 elapsed 0 00:00:09

  1. 目标端表空间read write

set lines 500
set pages 1000
select 'ALTER TABLESPACE ' || tablespace_name || ' READ WRITE;'
from dba_tablespaces
where tablespace_name not in ('SYSTEM','SYSAUX')
and contents = 'PERMANENT';
select TABLESPACE_NAME,status,CONTENTS from dba_tablespaces;

SQL> ALTER TABLESPACE OLD_DATA_TBS READ WRITE;

Tablespace altered.

收尾阶段

  1. 导入其他元数据,如存储过程、视图等

[oracle@11gasm xtts]$ nohup impdp "'/ as sysdba'" network_link=to_old SCHEMAS='OLD_TEST' content=metadata_only TABLE_EXISTS_ACTION=SKIP exclude=table,index parallel=16 metrics=y direct
ory=DATA_PUMP_DIR &


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SYS"."SYS_IMPORT_SCHEMA_01": "/******** AS SYSDBA" network_link=to_old SCHEMAS=OLD_TEST content=metadata_only TABLE_EXISTS_ACTION=SKIP exclude=table,index parallel=16 metrics=y directory=DATA_PUMP_DIR
Startup took 0 seconds
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"OLD_TEST" already exists
Completed 1 USER objects in 0 seconds
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Completed 1 SYSTEM_GRANT objects in 0 seconds
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Completed 2 ROLE_GRANT objects in 0 seconds
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Completed 1 DEFAULT_ROLE objects in 0 seconds
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Completed 1 TABLESPACE_QUOTA objects in 0 seconds
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Completed 1 PROCACT_SCHEMA objects in 1 seconds
Job "SYS"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at Thu Oct 19 17:54:51 2023 elapsed 0 00:00:02

  1. 将用户默认表空间还原

SQL> select 'alter user '||username||' default tablespace '||default_tablespace||';' from dba_users where username in ('OLD_TEST') order by created;

'ALTERUSER'||USERNAME||'DEFAULTTABLESPACE'||DEFAULT_TABLESPACE||';'
--------------------------------------------------------------------------------------------
alter user OLD_TEST default tablespace OLD_DATA_TBS;

数据校验

checkobject.sql

收集统计信息

EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;
EXEC DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论