签到成功

知道了

CNDBA社区CNDBA社区

datax源端最小化权限创建Oracle用户

2021-10-14 10:14 1302 0 原创 oracle DATAX
作者: hbhe0316

前言:在使用datax抄写数据的时候,需要将源端的用户权限最小化,比如,只需要抄写T1表,那么我只将T1表的SELECT权限授权给dataxuser用户

http://www.cndba.cn/hbhe0316/article/4928
http://www.cndba.cn/hbhe0316/article/4928

1.在源端创建用户并授权

http://www.cndba.cn/hbhe0316/article/4928

SQL> show pdbs;
SQL> alter session set container=hbhe;
SQL> select count(*) from hbhe.T1

  COUNT(*)
----------
     100

SQL> create user dataxuser identified by wwwwww;
SQL> grant connect, resource to dataxuser;
SQL> grant select on HBHE.T1 to datauser;
SQL> alter user dataxuser identified by passw0rd;

2.编写oracle to oracle的json文件

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "oraclereader", 
                    "parameter": {
                        "connection": [
                            {
                                "jdbcUrl": ["jdbc:oracle:thin:@IP:PORT/dbname"], 
                                "querySql": ["select * FROM schema.table where 1=1"],
                            }
                        ], 
                        "password": "password", 
                        "username": "username"
                    }
                }, 
                "writer": {
                    "name": "oraclewriter", 
                    "parameter": {
                        "column": ["*"], 
            "batchWriteCount": "10000",
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:oracle:thin:@IP:Port/dbname", 
                                "table": ["schema.table"]
                            }
                        ], 
                        "password":"password", 
                        "preSql": ["truncate table schema.table"], 
                        "username":"username"
                    }
                }
            }
        ], 
        "setting": {
            "speed": {
                "channel": "36",
            }
        }
    }
}

3.这里有个乌龙,将preSql写成postSql,导致执行datax后,日志显示已经抄写完成,但是目标端的数据一直是空的。
在datax官网找到答案:
https://github.com/alibaba/DataX/blob/master/postgresqlwriter/doc/postgresqlwriter.md

postSql
描述:写入数据到目的表后,会执行这里的标准语句。(原理同 preSql )
必选:否
默认值:无http://www.cndba.cn/hbhe0316/article/4928

preSql
描述:写入数据到目的表前,会先执行这里的标准语句。如果 Sql 中有你需要操作到的表名称,请使用 @table 表示,这样在实际执行 Sql 语句时,会对变量按照实际表名称进行替换。比如你的任务是要写入到目的端的100个同构分表(表名称为:datax_00,datax01, … datax_98,datax_99),并且你希望导入数据前,先对表中数据进行删除操作,那么你可以这样配置:”preSql”:[“delete from @table”],效果是:在执行到每个表写入数据前,会先执行对应的 delete from 对应表名称
必选:否
默认值:无http://www.cndba.cn/hbhe0316/article/4928http://www.cndba.cn/hbhe0316/article/4928

4.编写脚本http://www.cndba.cn/hbhe0316/article/4928

#!/bin/sh
python /datax/bin/datax.py /datax/job/t1.json >> /datax/datax_shot.log 2>&1

5.将datax加入crontab -e中,每隔两小时一次http://www.cndba.cn/hbhe0316/article/4928http://www.cndba.cn/hbhe0316/article/4928http://www.cndba.cn/hbhe0316/article/4928

[dataxuser@test01 ~]$ crontab -l
* */2 * * * /datax/bin/fullSync.sh

版权声明:本文为博主原创文章,未经博主允许不得转载。

DATAX

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:1038530次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ