Kettle实战100篇 第23篇 命令行介绍使用

2019/08/18 Kettle实战 浏览

我们在前面介绍的实战篇章中,基本都是在Spoon的图形化界面中点击运行按钮时来运行我们的作业或者转换的,但是Kettle也为我们提供了基于命令行的调用方式,基于命令行的方式可以方便我们通过Shell脚本或者Windows的Bat脚本来对作业&转换进行调用,这方便我们配置作业&转换的任务调度

我们可以在类似Unix平台上使用crontab服务来调用我们的Kettle作业&转换,在Windows平台也可以编写bat脚本添加任务计划进行有规律的调用,这对ETL的自动化处理是非常方便的.

本章就详细的介绍Kettle为我们提供的命令行工具

命令行工具介绍

在我们下载的Kettle目录下,我们可以看到存在几个bat或者sh文件,主要包含:

  • Pan:执行转换的命令行工具
  • Kitchen:执行作业的命令行工具
  • Encr:加密工具
  • import: 备份和还原资源库命令工具
  • Spoon:Kettle的Spoon图形化启动命令
  • runSample:执行Kettle为我们提供的转换示例
  • Carte:Kettle提供的基于Jetty的简单作业服务器,主要用于Kettle集群,不同于Kitchen命令的是,该服务是后台一直运行的

转换执行工具(Pan)

在Windows平台执行Pan.bat文件,如果是在类似Unix环境下需要执行pan.sh文件

关于Pan工具我们如果不知道输入参数的话,可以直接运行,此时Kettle会为我们打印出来相关的参数介绍信息

Options:
/rep            : 资源库名称
/user           : 资源库用户名
/trustuser      : 资源库用户名
/pass           : 资源库密码
/trans          : 要启动的转换名称
/dir            : 目录(不要忘了前缀 /)
/file           : 要启动的文件名(转换所在的 XML 文件)
/level          : 日志等级 (Basic,Detailed,Debug,Rowlevel,Error,Minimal,Nothing)
/logfile        : 要写入的日志文件
/listdir        : 列出资源库里的目录
/listtrans      : 列出指定目录下的转换
/listrep        : 列出可用资源库
/exprep         : 将资源库里的所有对象导出到 XML 文件中
/norep          : 不要将日志写到资源库中
/safemode       : 安全模式下运行: 有额外的检查
/version        : 显示版本,校订和构建日期
/param          : Set a named parameter <NAME>=<VALUE>. For example -param:FOO=bar
/listparam      : List information concerning the defined named parameters in the specified transformation.
/metrics        : Gather metrics during execution
/maxloglines    : The maximum number of log lines that are kept internally by Kettle. Set to 0 to keep all rows (default)
/maxlogtimeout  : The maximum age (in minutes) of a log line while being kept internally by Kettle. Set to 0 to keep all rows indefinitely (default)

如果我们的转换是另存为XML文件存在在本地磁盘上的,我们可以通过pan这样来调用(Windows平台)

Pan.bat -file=test.ktr -logfile=test.log -level=RowLevel

作业执行工具(Kitchen)

作业执行工具和转换差不多,可以直接运行Kitchen.bat来查看输入参数,参数如下:

Options:
  /rep            : 资源库名称
  /user           : 资源库用户名
  /trustuser      : 资源库用户名
  /pass           : 资源库密码
  /job            : 资源库中的作业名称
  /dir            : 资源库中的作业目录
  /file           : 本地作业XML文件路径
  /level          : 日志级别(Basic,Detailed,Debug,Rowlevel,Error,Minimal,Nothing)
  /logfile        : 日志文件
  /listdir        : 列出当前资源库中的所有目录
  /listjobs       : 列出指定目录下的所有子夜
  /listrep        : 列出可用的资源库
  /norep          : 不要将日志写到资源库中
  /version        : 显示版本号
  /param          : Set a named parameter <NAME>=<VALUE>. For example -param:FILE=customers.csv
  /listparam      : List information concerning the defined parameters in the specified job.
  /export         : Exports all linked resources of the specified job. The argument is the name of a ZIP file.
  /custom         : Set a custom plugin specific option as a String value in the job using <NAME>=<Value>, for example: -custom:COLOR=Red
  /maxloglines    : The maximum number of log lines that are kept internally by Kettle. Set to 0 to keep all rows (default)
  /maxlogtimeout  : The maximum age (in minutes) of a log line while being kept internally by Kettle. Set to 0 to keep all rows indefinitely (default)

如果我们的作业文件是存在磁盘则可以这样调用(Windows平台)

Kitchen.bat -file=F:\公共技术\kettle\任务调度系统同步ES日志作业.kjb -logfile=F:\公共技术\kettle\mySqlToES.log -level=Rowlevel

作业服务器(Carte)

Usage: Carte <Interface address> <Port> [-h] [-p <arg>] [-s] [-u <arg>]
or
Usage: Carte <Configuration File>
Starts or stops the carte server.
     -h,--help               This help text
     -p,--password <arg>     The administrator password.  Required only if
                             stopping the Carte server.
     -s,--stop               Stop the running carte server.  This is only
                             allowed when using the hostname/port form of the
                             command.
     -u,--userName <arg>     The administrator user name.  Required only if
                             stopping the Carte server.

Example: Carte 127.0.0.1 8080
Example: Carte 192.168.1.221 8081

Example: Carte /foo/bar/carte-config.xml
Example: Carte http://www.example.com/carte-config.xml
Example: Carte 127.0.0.1 8080 -s -u cluster -p cluster

通过命令行调用帮助可以查看,Carte -h

加密工具(Encr)

加密工具,我们在生产服务器部署时可以用到此工具,针对数据库密码等敏感信息进行加密处理

定义:

  encr <-kettle|-carte> <password>
  Options:
    -kettle: generate an obfuscated password to include in Kettle XML files
    -carte : generate an obfuscated password to include in the carte password file 'pwd/kettle.pwd'

主要分为kettle和carte两种不同类型的密码处理

kettle是我们在XML文件中使用的

carte主要用于作用于作业服务器中

使用方法

Encr.bat -kettle 123456

最终生成字符串Encrypted 2be98afc86aa7f2e4cb79ff228dc6fa8c

导入备份工具(import)

导入脚本是一个命令行实用程序,可将内容从单个.kjb或.ktr文件或完整存储库导出XML文件中提取到企业或数据库存储库中

您还必须声明一个规则文件,该文件定义要导入的数据集成内容的某些参数,们提供了一个名为import-rules.xml的示例文件,该文件包含在标准数据集成客户端工具分发中。它包含所有潜在规则,以及描述每个规则的作用的注释。您可以修改import-rules.xml文件或将其内容复制到另一个文件,然后将规则文件声明为命令行参数。

下表定义了导入脚本的命令行选项,这些选项是使用特定于操作系统类型的语法声明的:

  • Linux

    使用短划线( - )后跟选项名称,然后是等号(=)和值(如果适用)声明选项。例如:-option = value

  • Windows

    使用正斜杠(/)后跟选项名称,然后使用冒号(:)和值(如果适用)声明选项。例如:/ option:value

注意:对于不需要输入值(替换,系数和版本)的选项,选项后面的破折号或斜线(取决于您的操作系统)相当于选择“是”;否则,该选项被忽略。

选项 说明
rep 要导入的企业或数据库存储库的名称。
user 企业或数据库访问用户名
pass 密码
dir 存储库中要将内容复制到的目录。
limitdir 可选的。要包含的逗号分隔源目录列表(不包括未显式声明的那些目录)。
file 要从中导入的存储库导出文件的路径
rules 如上所述,规则文件的路径
comment 将为导入的转换和作业的新修订设置的注释。
replace 替换存储库中的现有转换和作业。 (默认为:No)
coe 发生错误时继续运行,忽略错误(默认:No)
version 显示导入脚本与之接口的PDI实例的版本,修订版和构建日期。 (默认为:No)
  • Linux
Import.sh -rep= Archive71 -user=admin -pass=password -coe -replace -dir=/home/admin -file= /Downloads/imagitasDemoEnclosure.ktr -rules=/Downloads/import-rules.xml -comment="New version upload from UAT"
  • Windows
Import.bat /rep:Archive71 /user:admin /pass:password /coe /replace /dir:\home\admin /file:C:\Downloads\imagitasDemoEnclosure.ktr /rules:C:\Downloads\import-rules.xml /comment:"New version upload from UAT"

站内搜索

    TorchV Bot开放试用中......

    最新内容,关注“八一菜刀”公众号

    Table of Contents