使用windows自帶任務計划管理程序定時 調用Kettle作業


系統平台:windows系統,其他操作系統請參考其他資料。

 

Kettle自帶的定時任務調度不太穩定,而且必須打開Kettle,可以通過windows的任務計划程序調用Kettle的Kitchen.bat來實現定時作業。

網上找了一些Kitchen.bat的參數,也是一知半解,沒有深入研究。

kitchen.bat   后面可以是-也可以是/然后再加options

Options:
/rep        : Repository name
/user       : Repository username
/pass       : Repository password
/job        : The name of the job to launch
/dir        : The directory (dont forget the leading /)
/file       : The filename (Job XML) to launch
/level      : The logging level (Basic, Detailed, Debug, Rowlevel, Error, Nothing)
/logfile    : The logging file to write to
/listdir    : List the directories in the repository
/listjobs   : List the jobs in the specified directory
/listrep    : List the available repositories
/norep      : Do not log into the repository
/version    : show the version, revision and build date
/param      : Set a named parameter =. For example -param:FOO=bar
/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.

而options 后面可以是=也可以是:也可以是空格

kitchen.bat /file d:\   或者 -file=D:\ 或者/file:D:\等等都可以。。。

下面正式開始創建調用方案

1:創建啟動文件,用於被windows任務計划程序調用

  新建文本文件,重命名為   "每日9點執行.bat",文件右鍵編輯,以文本文件方式打開,然后復制下面內容進去,保存。

1 D:
2 cd D:\pdi-ce-6.0.0.0-353\data-integration
3 kitchen.bat -rep:XXX -dir:/ -job:"XXX" -user:XXX -pass:XXX -level:Basic -log:D:\kettlebat\log\每日9點執行%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.txt

 注:第一行D:到第三行的kitchen.bat為打開Kettle的Kitchen.bat,該文件一般在Kettle的根目錄,請根據實際保存路徑修改。

-rep:后的XXX修改為資源庫名稱,-job:后的XXX修改為要執行的作業名稱,-user:和-pass:后的XXX為資源庫的帳號密碼,

-level為日志級別,共有Basic, Detailed, Debug, Rowlevel, Error, Nothing六種級別,此處使用Basic,其它級別自行測試,

-log后為日志保存路徑,路徑中的%date和%time是在創建日志的時候給日志名添加上時間。

2:添加任務計划
右鍵計算機或者我的電腦,選擇管理,選擇任務計划程序。或者通過其他方式打開,總之打開任務計划程序就對了。

點擊右側創建基本任務,輸入任務名稱,點擊下一步設置觸發器,點擊下一步設置具體的觸發條件,這里可以設置成各種各樣的定時任務。

點擊下一步設置操作為啟動程序,然后選擇上面創建的  每日9點執行.bat,然后點擊完成即可。

上面為創建基本任務,設置比較簡單,功能比較弱,建議創建任務時直接點擊創建任務,指定更加可靠的任務,比如設置不管用戶是否登錄都要運行、設置任務失敗后的重啟次數、設置任務的超時時間等。

 

主要代碼來自於前輩翟大神,敬禮。

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM