-
Notifications
You must be signed in to change notification settings - Fork 0
自动调用datax来全量同步oracle到mysql的数据
License
zhangzaki/auto_run_datax
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
此脚本用于自动生成运行datax所需要的jobconf,并且根据生成的jobconf来批量的执行任务 使用方法: ***************************************************** ** 前置条件 ***************************************************** 1.需要在目标端创建好表结构,表结构要与源端一致 2.oracle的schema_name与目标端的database名称可以不一致 ***************************************************** ** 安装oracle client ***************************************************** 1.unzip package,oracle client下载链接参考:https://www.oracle.com/cn/database/technologies/instant-client/downloads.html unzip instantclient-sqlplus-linux.x64-11.2.0.4.0.zip unzip instantclient-basic-linux.x64-11.2.0.4.0.zip unzip instantclient-jdbc-linux.x64-11.2.0.4.0.zip unzip instantclient-odbc-linux.x64-11.2.0.4.0.zip unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip 2.configuration env export ORACLE_HOME=/mysqldata/edbtools/migration/instantclient_11_2 export LD_LIBRARY_PATH=$ORACLE_HOME export PATH=$PATH:$ORACLE_HOME ***************************************************** ** 配置运行环境,运行环境为python的运行环境,此运行环境可用于centeos 7 或者redhat 7,在6版本中需要自行创建 ***************************************************** 1.unzip package tar zxf datax.tar.gz cd datax tar zxf pvenv.tar.gz sh setenv.sh 2.测试使用 source pvenv/bin/activate (pvenv) [greatdb@cluster-node1 datax]$ pip list DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Package Version --------------- --------- certifi 2019.9.11 chardet 3.0.4 cx-Oracle 7.2.3 future 0.18.2 futures 3.3.0 idna 2.8 itchat 1.3.10 mysql-connector 2.2.9 pip 19.3.1 pypng 0.0.20 PyQRCode 1.2.1 requests 2.22.0 setuptools 42.0.1 urllib3 1.25.7 wheel 0.33.6 WARNING: You are using pip version 19.3.1; however, version 20.1.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. ***************************************************** ** 配置使用 ***************************************************** 1.生成配置文件之前在目标库创建表: create database sync_log; use sync_log; drop table if exists sync_log; create table sync_log( table_name varchar(50), schema_name varchar(50), job_name varchar(300), syning int, sync_complete int, complete_status int, source_count bigint, target_count bigint,parimary key (table_name,job_name) ); 列解释: complete_status : 0 是成功 1是失败 2是未知 syning : 0是未同步 1是同步中 sync_complete 1是完成 0是未完成 source_count 源端的行数 target_count 目标端的行数 2.生成配置文件,把配置文件信息插入到sync_log表中,脚本需要放在datax目录的第一级目录下 cd datax source pvenv/bin/activate sed -i "s#owner='SCOTT'#owner='ZJTEST'#" general_datax_jobconfig_file_sqlsub_v1.1.py python general_datax_jobconfig_file_sqlsub_v1.1.py --suser=scott --spwd='tiger' --sip=192.168.56.31 \ --sid=orcl --tuser=root --tpwd=passwd --tip=192.168.56.32 --tport=3306 --tdb=zjtest deactivate 执行完毕之后在目标端查看配置文件生成信息: select * from sync_log.sync_log; 3.同步数据方法 cd datax source pvenv/bin/activate python run_job_full.py --suser=scott --spwd='tiger' --sip=192.168.56.31 \ --sid=orcl --tuser=root --tpwd=passwd --tip=192.168.56.32 \ --tport=3306 --tdb=zjtest --threadnum=5 --limitnum=50 --only_validate_data=0 注意事项:不能同时运行两个run_job_full.py脚本,可以等一个脚本运行结束之后重新修改并发量运行 4.结果检查 select * from sync_log.sync_log where schema_name='ZJTEST' and source_count!=target_count; ***************************************************** ** 同步过程问题处理参考 ***************************************************** 当一直是:syning为1,sync_complete为0,complete_status为2的时候,并且datax任务没有运行,这时候需要手动干预 update sync_log.sync_log set syning=0 where table_name='' and schema_name=''; 例如: update sync_log.sync_log set syning=0 where table_name='TEST_PRIMARY_KEY_NOBLOB' and schema_name='SCOTT'; update sync_log.sync_log set syning=0 where table_name='TEST_UNIQUE_KEY' and schema_name='SCOTT'; update sync_log.sync_log set syning=0 where table_name='EMPLOYEE' and schema_name='SCOTT'; update sync_log.sync_log set syning=0 where table_name='SALGRADE' and schema_name='SCOTT';
About
自动调用datax来全量同步oracle到mysql的数据
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published