检查条件
- 源库的compatible初始参数至少是10.2.0以上,目标数据库的compatible参数必须等于或高于源库。
- 数据库版本目标库必须大于或等于源库
- 源库必须是archivelog模式
- 源数据库的默认rman通道设置不能指定compressed指令为configure device type disk 通道属性。
- 源库准备迁移的表空间必须都处于联机状态,不能包含离线文件。
- 所使用的操作系统账户必须是dba权属组
- 源端和目标端字符集一致
- 源库开启快追踪,加快备份速度
- 确定目标端无相同表空间名称
- 检查是否有用户对象在系统表空间(system,user,sysaux)
- 检查表空间内自包含
- 迁移对象检查
- 失效对象统计
1.源库目标库compatible参数查看
select * from v$parameter where name like '%compatible%';
2.数据库版本查看
select * from v$version ;
3.查看源库归档
archive log list;
4.查看rman compressed 通道属性
show all
5.源库准备迁移的表空间状态
select tablespace_name,status from dba_tablespaces;
6.所使用的操作系统账户必须是dba权属组
7.查看源端和目标端字符集
select * from nls_database_parameters;
8.源库开启快跟踪
select * from v$block_change_tracking;
alter database enable block change tracking using file '+DATA';
9.确定目标端无相同表空间名称
select tablespace_name from dba_tablespaces;
10.检查是否有用户对象在系统表空间(system,user,sysaux)
select tablespace_name,owner,COUNT(*) from dba_segments
where tablespace_name not in ('SYSTEM','SYSAUX','TEMP','UNDOTBS1','EXAMPLE') GROUP BY tablespace_name,owner;
11.检查表空间自包含
exec sys.dbms_tts.transport_set_check('tt1',TRUE,TRUE);
select * from transport_set_violations;
12.检查迁移对象
select owner,object_type,count(*) from dba_objects where object_name not like 'BIN%' and owner in ('XTTS') group by owner ,object_type order by 1,2 desc;.
13.失效对象统计
select owner,object_type,count(*) from dba_objects where STATUS <> 'VALID' and owner in 'XXTS'
GROUP BY OWNER,object_type ORDER BY 1,2 DESC;
实验环境
1.确认目标和源数据库的版本
2.下载xtts脚本
3.创建源数据库对象
mkdir /home/oracle/script
mkdir /home/oracle/inc_bk
mkdir /home/oracle/XTTSFILES
create or replace directory orcl_dbf as '/opt/oracle/oradata/ORCL' ;
grant read,write on directory orcl_dbf to public;
create or replace directory xttsfiles as '/home/oracle/XTTSFILES' ;
grant read,write on directory xttsfiles to public;
create tablespace xtts1 datafile '/opt/oracle/oradata/ORCL/xtts1.dbf' size 30m;
create tablespace xtts2 datafile '/opt/oracle/oradata/ORCL/xtts2.dbf' size 30m;
create user xtts identified by "xtts" default tablespace xtts1;
grant dba to xtts;
create table xtts.xtts1 as select * from dba_objects;
create index idx_obj on xtts1(object_id) tablespace xtts2;
4.目标端
mkdir /home/oracle/script
mkdir /home/oracle/inc_bk
mkdir /home/oracle/XTTS
mkdir /home/oracle/XTTSFILES
create or replace directory ty_dbf as '/opt/oracle/oradata/TY' ;
grant read,write on directory ty_dbf to public;
create or replace directory xttsfiles as '/home/oracle/XTTSFILES' ;
grant read,write on directory xttsfiles to public;
drop database link orcl;
create database link orcl connect to system identified by "Oracle123" using '192.168.5.150:1521/orcl';
create user xtts identified by "xtts" default tablespace xtts1;
grant dba to xtts;
5.解压xtts文件包
unzip -d /home/oracle/XTTS rman_xttconvert_VER4.3.zip
xtts脚本和对象
脚本/对象 | ||
---|---|---|
xttdriver.pl | perl脚本drive根据源和目标数据库的版本执行xtts操作 | |
xtts.properties | 设置源和目标数据库xtts属性 | |
xttcnvrtbkupdest.sql | 处理增量备份的转换 | |
xttdbopen.sql | 完成目标数据库从mount到open的过渡 | |
xttstartupnomount.sql | 在xtts操作期间,将目标数据库打开至nomount状态 | |
xttrep.tmpl | Pl/sql对象用于构造从源到目标端复制和转换的语句 |
6.配置xtts属性以及环境变量
1.4版本
export TMPDIR=/home/oracle/XTTS
------------------------------------------------
source database parameters:
tablespaces=xtts1,xtts2
platformid=2
srcdir=orcl_dbf
srclink=orcl
dfcopydir=/home/oracle/XTTSFILES
backupformat=/home/oracle/XTTSFILES
destination database parameters:
dstdir=ty_dbf
stageondest=/home/oracle/XTTSFILES
storageondest=/opt/oracle/oradata/TY
backupondest=/home/oracle/XTTSFILES
parallel=4
rollparallel=2
4.0-4.3版本
tablespaces=XTTS1,XTTS2,FIXF
platformid=13 #select PLATFORM_ID from V$DATABASE; 查询得出
src_scratch_location=/home/oracle/XTTSFILES
dest_datafile_location=+data/orcl/datafile
dest_scratch_location=/home/oracle/XTTSFILES
usermantransport=1
7.迁移存储在其他表空间的表和索引
alter table FIXF.sys_import_transportable_01 MOVE TABLESPACE fixf;
ALTER TABLE FIXF.sys_import_transportable_01 move tablespace fixf LOB (XML_CLOB) STORE AS (TABLESPACE fixf);
8.源端第一次全备
cd /home/oracle/XTTS
$ORACLE_HOME/perl/bin/perl xttdriver.pl --backup -d 3
9.cp 文件到目标端
scp /home/oracle/script/* oracle@192.168.5.133:/home/oracle/script/
scp /home/oracle/XTTSFILES/* oracle@192.168.5.133:/home/oracle/XTTSFILES/
10.目标端还原备份文件
$ORACLE_HOME/perl/bin/perl xttdriver.pl --restore
11.创建差异数据
select * from FIXF.sys_import_transportable_01;
UPDATE FIXF.sys_import_transportable_01 set abort_step=1;
select * from XTTS.test;
insert into XTTS.test (id,name)values(2,'bb');
commit;
12.第一次增量备份
$ORACLE_HOME/perl/bin/perl xttdriver.pl --backup
scp `cat incrbackups.txt` oracle@192.168.5.133:/home/oracle/XTTSFILES/
scp res.txt oracle@192.168.5.133:/home/oracle/script
13.第一次增量还原
$ORACLE_HOME/perl/bin/perl xttdriver.pl --restore
14.重新再次创建差异数据
select * from FIXF.sys_import_transportable_01;
UPDATE FIXF.sys_import_transportable_01 set access_method=1;
select * from XTTS.test;
insert into XTTS.test (id,name)values(3,'cc');
commit;
15.修改表空间为只读
alter tablespace FIXF read only;
alter tablespace XTTS1 read only;
alter tablespace XTTS2 read only;
16.第二次备份
$ORACLE_HOME/perl/bin/perl xttdriver.pl --backup
scp `cat incrbackups.txt` oracle@192.168.5.133:/home/oracle/XTTSFILES/
scp res.txt oracle@192.168.5.133:/home/oracle/script
17.表空间设置为 read only 后,如下的错误可以忽略
DECLARE*
ERROR at line 1:
ORA-20001: TABLESPACE(S) IS READONLY OR,
OFFLINE JUST CONVERT, COPY
ORA-06512: at line 284
TABLESPACE STRING :''''''''''
Prepare newscn for Tablespaces: ''''''''''
18.第二次还原
$ORACLE_HOME/perl/bin/perl xttdriver.pl --restore
19.导出用户和架构
su - oracle
mkdir expdp
vi exp.par
dumpfile=xttdump.dmp
directory=xttsfiles
statistics=NONE
transport_tablespaces=FIXF,XTTS1,XTTS2
transport_full_check=y
logfile=tts_export.log
cluster=n
expdp system/Oracle123 parfile=exp.par
20.scp 导出的文件到目标端
scp /home/oracle/XTTSFILES/xttsdump.dmp oracle@192.168.5.133:/home/oracle/XTTSFILES/
21.目标端执行导入
su - oracle
mkdir impdp
vi manual_imp.par
dumpfile= xttsdump.dmp
directory=xttsfiles
transport_datafiles='+data/orcl/datafile/fixf_2.dbf,+data/orcl/datafile/xtts1_9.dbf,+data/orcl/datafile/xtts2_10.dbf'
impdp system/Oracle123 parfile=manual_imp.par