MTK迁移Oracle单库
一. Mtk安装
1.1 安装jdk
要求jdk版本在1.7以上
安装完jdk后将需要的数据库jdbc驱动拷贝到$JAVA_HOME/jre/lib/ext 目录下面
https://www.enterprisedb.com/advanced-downloads的跳转连接下载对应Oracle版本的第三方JDBC驱动ojdbc8.jar。放置于服务器的JAVA_HOME/jre/lib/ext下。
https://www.enterprisedb.com/advanced-downloads的跳转链接下载对应PostgreSQL版本的JDBC驱动postgresql-42.2.2.jar。放置于服务器JAVA_HOME/jre/lib/ext下
将上图驱动包包括 Oracle及postgresql的JDBC驱动包拷贝到此目录下
其中oracle驱动包为压缩包需要解压出来tar -xzvf ojdbc-full.tar.gz
驱动包不能发错位置,否则数据迁移不成功
查看java安装路径:
[ceresdata@test135]$ whereis java
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz
[ceresdata@test135]$ ls -lrt /usr/bin/java
lrwxrwxrwx. 1 root root 22 Oct 29 10:23 /usr/bin/java -> /etc/alternatives/java
[ceresdata@test135]$ ls -lrt /etc/alternatives/java
lrwxrwxrwx. 1 root root 71 Oct 29 10:23 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/bin/java
ceresdata@test135]$ cd /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre
[ceresdata@test135 jre]$ ll
total 4
drwxr-xr-x. 2 root root 172 Oct 29 10:23 bin
drwxr-xr-x. 9 root root 4096 Oct 29 10:22 lib
[ceresdata@test135 jre]$ cd lib/
[ceresdata@test135 lib]$ cd ext/
将驱动放在此目录下
1.2获取安装包
http://sbp.enterprisedb.com/getfile.jsp?fileid=10872 下载地址
Linux版:edb-migrationtoolkit-51.0.1-1-linux-x64
https://www.enterprisedb.com/downloads/edb-migration-toolkit
也可以自己下载需要注册用户,下载链接会发到邮箱里面,Linux,Windows自选
使用xftp或者其他方法上传到安装postgresql数据库的服务器
chmod +x edb-migrationtoolkit-51.0.1-1-linux-x64.run
给安装包赋予可执行权限
./ edb-migrationtoolkit-51.0.1-1-linux-x64.run
执行安装
安装方式图形化安装或者命令行安装这里使用图像化安装:
这里是命令行安装
1.3安装MTK
[root@test128]
./edb-migrationtoolkit-51.0.0-1-linux-x64.run
Language Selection
Please select the installation language
[
1] English - English
[
2] Japanese -
日本語
[
3] Simplified Chinese -
简体中文
[
4] Traditional Chinese -
繁体中文
[
5] Korean -
한국어
Please choose an option [
1] :
----------------------------------------------------------------------------
Welcome to the EDB Postgres Migration Toolkit Setup Wizard.
----------------------------------------------------------------------------
Please read the following License Agreement. You must accept the terms
ofthis
agreement before continuing with the installation.
Press [Enter] to continue:
Limited Use Software License Agreement
Version
2.9
IMPORTANT - READ CAREFULLY
...............................................
Please specify the directory where Migration Toolkit will be installed.
Installation Directory [/opt/edb/mtk]:
----------------------------------------------------------------------------
Setup
isnow ready to begin installing Migration Toolkit
onyour computer.
Do you want to
continue? [Y/n]: Y
----------------------------------------------------------------------------
Please wait
whileSetup installs Migration Toolkit
onyour computer.
Installing EDB Postgres Migration Toolkit
0
% ______________
50% ______________
100%
#########################################
----------------------------------------------------------------------------
EnterpriseDB is the leading provider of value-added products and services for
the Postgres community.
Please visit our website at www.enterprisedb.com
二. MTK配置
2.1 修改MTK配置文件
Mtk配置文件路径,安装时候使用的是默认安装路径:/opt/edb/mtk/etc
进入此目录
vi toolkit.properties
SRC_DB_URL=jdbc:oracle:thin:@192.168.227.129:1521/orcl
SRC_DB_USER=C##TEST //数据库账号
SRC_DB_PASSWORD=123456 //数据库密码
TARGET_DB_URL=jdbc:postgresql://localhost:5432/postgres
TARGET_DB_USER=ceresdata //数据库账号
TARGET_DB_PASSWORD=123 //数据库密码
SRC_DB :源数据库库
TARGET_DB:目标数据库
配置完成:wq 保存退出
2.2 JDBC连接测试
这边因为中间出了很多问题,所以找了一个JDBC连接测试脚本,查看JDBC是否能够连接成功
此步骤不是必要步骤如果你操作顺利此步骤可以忽略不记
具体代码如下,图中标红部分为需要修改部分:
import java.sql.*;
public class test {
public static void main(String[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
/*String dbURL =
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.227.129)(PORT=1521)))"
+ "(CONNECT_DATA=(SERVICE_NAME=orcl.city.com)))";
*/
String dbURL = "jdbc:oracle:thin:@192.168.227.129:1521:orcl";
conn = DriverManager.getConnection(dbURL, "C##TEST", "123456");
System.out.println("连接成功");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
如图所示JDBC连接Oracle数据库成功;
三. 数据库数据导出
3.1数据迁移及准备
确认配置无误,及驱动包存放地方没有错误进入到MTK安装目录:
新建数据存放目录:
cd /opt/edb/mtk/bin/
mkdir Migration //数据存放目录需手动创建
在Oracle数据库中新建一张表(student),内容可以随意;
在/opt/edb/mtk/bin目录下执行此命令:
./runMTK.sh -targetdbtype postgres -sourcedbtype oracle -offlineMigration /opt/edb/mtk/bin/Migration/ C##TEST/
出现如下画面则代表成功:
[root@test128 bin]# ./runMTK.sh -targetdbtype postgres -sourcedbtype oracle -targetSchema public -offlineMigration /opt/edb/mtk/bin/Migration/ -singleDataFile -safeMode C##TEST
+++++++++++++++++++
gration/ -singleDataFile -safeMode C##TEST
Running EnterpriseDB Migration Toolkit (Build 51.0.1) ...
Source database connectivity info...
conn =jdbc:oracle:thin:@192.168.227.129:1521:orcl
user =C##TEST
password=******
Connecting with source Oracle database server...
Connected to Oracle, version 'Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options'
Importing redwood schema C##TEST...
Creating Tables...
Creating Table: COURSE
Creating Table: SCORE
Creating Table: STUDENT
Creating Table: TEACHER
Created 4 tables.
Loading table data in safe mode...
Loading Table: COURSE ...
[COURSE] Table Data Load Summary: Total Time(s): 0.006 Total Rows: 0
Loading Table: SCORE ...
[SCORE] Table Data Load Summary: Total Time(s): 0.002 Total Rows: 0
Loading Table: STUDENT ...
[STUDENT] Table Data Load Summary: Total Time(s): 0.006 Total Rows: 6
Loading Table: TEACHER ...
[TEACHER] Table Data Load Summary: Total Time(s): 0.002 Total Rows: 0
Data Load Summary: Total Time (sec): 0.016 Total Rows: 6 Total Size(MB): 0.0
Creating Constraint: PK_COURSE
Creating Constraint: PK_SCORE
Creating Constraint: PK_STUDENT
Creating Constraint: PK_TEACHER
Creating Constraint: FK_TNO
Creating Constraint: FK_CNO
Creating Constraint: FK_SNO
Schema C##TEST imported successfully.
Migration process completed successfully.
Migration logs have been saved to /home/ceresdata/.enterprisedb/migration-toolkit/logs
进入数据存放目录查看导出的数据
[ceresdata@test135 Migration]$ ll
total 20
-rw-rw-r-- 1 ceresdata ceresdata 635 Nov 5 10:51 mtk_public_constraint_ddl.sql
-rw-rw-r-- 1 ceresdata ceresdata 1620 Nov 5 10:51 mtk_public_data.sql
-rw-rw-r-- 1 ceresdata ceresdata 3287 Nov 5 10:51 mtk_public_ddl.sql
-rw-rw-r-- 1 ceresdata ceresdata 24 Nov 5 10:51 mtk_public_schema_ddl.sql
-rw-rw-r-- 1 ceresdata ceresdata 2654 Nov 5 10:51 mtk_public_table_ddl.sql
然后查看导出的Oracle数据验证一下
迁移数据:
cd /opt/edb/mtk/bin/Migration/
csql -h loclhost -p 5432 -d postgres -f mtk_public_ddl.sql
sql -h loclhost -p 5432 -d postgres -f mtk_public_data.sql
然后登录数据库验证一下
d 查看表
select * from 表名; //查看表的内容是否和oracle数据库一致