分享

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

 小雪初晴i 2022-12-13 发布于河北

我们在前面介绍的实战篇章中,基本都是在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会为我们打印出来相关的参数介绍信息

  1. Options:
  2. /rep : 资源库名称
  3. /user : 资源库用户名
  4. /trustuser : 资源库用户名
  5. /pass : 资源库密码
  6. /trans : 要启动的转换名称
  7. /dir : 目录(不要忘了前缀 /)
  8. /file : 要启动的文件名(转换所在的 XML 文件)
  9. /level : 日志等级 (Basic,Detailed,Debug,Rowlevel,Error,Minimal,Nothing)
  10. /logfile : 要写入的日志文件
  11. /listdir : 列出资源库里的目录
  12. /listtrans : 列出指定目录下的转换
  13. /listrep : 列出可用资源库
  14. /exprep : 将资源库里的所有对象导出到 XML 文件中
  15. /norep : 不要将日志写到资源库中
  16. /safemode : 安全模式下运行: 有额外的检查
  17. /version : 显示版本,校订和构建日期
  18. /param : Set a named parameter <NAME>=<VALUE>. For example -param:FOO=bar
  19. /listparam : List information concerning the defined named parameters in the specified transformation.
  20. /metrics : Gather metrics during execution
  21. /maxloglines : The maximum number of log lines that are kept internally by Kettle. Set to 0 to keep all rows (default)
  22. /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来查看输入参数,参数如下:

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

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

  13. Example: Carte 127.0.0.1 8080
  14. Example: Carte 192.168.1.221 8081

  15. Example: Carte /foo/bar/carte-config.xml
  16. Example: Carte http://www./carte-config.xml
  17. Example: Carte 127.0.0.1 8080 -s -u cluster -p cluster

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

加密工具(Encr)

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

定义:

  1. encr <-kettle|-carte> <password>
  2. Options:
  3. -kettle: generate an obfuscated password to include in Kettle XML files
  4. -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"

 

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多