工作排程與守護行程

Koha 由若干背景工作支援。包括定期執行的工作 (工作排程) 或稱為 守護行程的持續執行的工作。

工作排程是安排自動伺服器裡的指令或腳本以完成指定工作的 Linux 指令。以工作排程方式執行的腳本通常是修改檔案或資料庫;然而,它們也可以執行其他不需修改伺服器資料的工作,像是送出電子郵件通知。

daemon 是 Linux 命令,系統啟動後就開始執行,並持續在背景執行若干功能。Koha 用到的資料庫 (MYSQL 或 MariaDB) 及網頁伺服器 (通常是 Apache),就是一種 daemon。

Koha 含有多個工作排程 (搜尋引擎索引、產生逾期通知、清除資料等) 及若干守護行程。本章將說明它們。

Crontab 範例

Koha crontab 在 misc/cronjobs/crontab.example

此範例包括 boilerplate 工作排程款目的樣本。

工作排程

工作排程應該在 misc/ 之下,若在 misc/ 之下找不到而且以標準方式安裝伺服器時則可能在 bin/

備份

每日備份

腳本路徑:misc/cronjobs/backup.sh

做:新增 Koha 資料庫逐日備份。

建議頻率:逐日

流通

預約佇列

腳本路徑:misc/cronjobs/holds/build_holds_queue.pl

做:更新預約順位報表

必須用到:預約順位報表

建議頻率:每 1-4 小時

說明:

  • 應定期執行腳本若您的圖書館系統允許讀者預約在架的館藏。此腳本決定負責滿足此預約的圖書館。

    由系統偏好 StaticHoldsQueueWeightRandomizeHoldsQueueWeight 共同控制其行為。

    不讓所有圖書館參與館藏滿足預約計畫,應列出*要*參加該計畫的圖書館,包括圖書館的條碼,並以逗點區隔(如:」MPL,CPL,SPL,BML」 等)。

    預設,預約順位將先列入提取圖書館。若無法滿足,則 build_holds_queue.pl 將取用 StaticHoldsQueueWeight 設定的圖書館。若停用 RandomizeHoldsQueueWeight (預設值為停用),則依 StaticHoldsQueueWeight 偏好設定的圖書館順序,逐一取用。

    例如,系統內有三個規模不一的圖書館(大型、中型與小型),希望由大型圖書館承擔較多的預約責任,StaticHoldsQueueWeight偏好應設為」LRG,MED,SML」。

    若期望各圖書館平均分擔預約的任務,應啟用RandomizeHoldsQueueWeight偏好,將隨機將預約分配給各圖書館。

    讓 StaticHoldsQueueWeight 空白是禁忌,將造成 build_holds_queue 腳本忽略 RandomizeHoldsQueueWeight,使該腳本要求不是隨機卻採用字順方式填入預約。

預約過期

腳本路徑:misc/cronjobs/holds/cancel_expired_holds.pl

做:預設,此工作排程僅自動執行使用者設定到期日的取消預約。若圖書館使用 ExpireReservesMaxPickUpDelayExpireReservesMaxPickUpDelayCharge 偏好則此腳本也取消在預約架太久的預約並將 (若圖書館要的) 向讀者收取未提取預約到館費用。

建議頻率:逐日

取消預約

腳本路徑:misc/cronjobs/holds/auto_unsuspend_holds.pl

做:若將 AutoResumeSuspendedHolds 偏好設為 『允許』 則此腳本檢查不需保留的預約並移除它們。此舉將讀者放回保留之前序列。

建議頻率:逐日

罰款

腳本路徑:misc/cronjobs/fines.pl

做: 計算和收取(或遞增)逾期罰款每館藏對讀者帳號。罰款計算使用寬限期已處理,罰款間隔, 罰款總數和其它參數從:ref:circulation and fines rules <circulation-and-fines-rules-label>.

必備:finesMode 系統偏好

建議頻率:每晚

說明 若 Koha 系統偏好 『finesMode』 已設為 『production』,則向讀者收取罰款。若設為 『test』,則計算罰款但不收取。

說明 假日不計入罰款。

參數 - -h|–help

  • 取得協助資訊

  • -l|–log

    • log the output to a file (optional if the -o parameter is given)

  • -o|–out

    • ouput directory for logs (defaults to env or /tmp if the directory does not exist)

  • -v|–verbose

    • verbose mode

  • -m|–maxdays

    • how many days back of overdues to process

    • this can improve performance by simply the number of records that need to be processed. It can be safe to limit the overdues processed to those under X days overdues given that circulation policy often caps fines at a maximum after a number of days.

固定罰款

腳本路徑:misc/cronjobs/staticfines.pl

做: 針對目前未付的讀者對任何/所有逾期收取單獨一定的罰款.費用由讀者類型每指令行定義或將使用流通規則針對讀者未付的最長逾期館藏(只針對第一個罰款期間)。一旦收費,罰款是定額: 沒有新罰款會再加入直到現有罰款已完全付清。

建議頻率:每晚

說明 若 Koha 系統偏好 『finesMode』 已設為 『production』,則向讀者收取罰款。若設為 『test』,則計算罰款但不收取。

說明 假日不計入罰款。

逾期太久

腳本路徑:misc/cronjobs/longoverdue.pl

做:允許更改不同程度的遺失館藏,並向讀者收取館藏記錄內的重置價格。

建議頻率:每晚

說明

館員可以經由 DefaultLongOverdueLostValueDefaultLongOverdueChargeValue 偏好控制逾期太久的工作排程。

追蹤借出總數

腳本路徑:misc/cronjobs/update_totalissues.pl

做:以最新的借出現況更新資料庫內 biblioitems.totalissues 欄位的內容。

建議頻率:每晚

警示

需考量資料庫伺服器與 Koha 伺服器的時間不同步的狀況,並使用 –since 參數取代 –interval 參數做為新增性更新的依據。

說明

可以使用此工作排程。也可使用 UpdateTotalIssuesOnCirc 系統偏好。

產生讀者檔供離線流通之用

腳本路徑:misc/cronjobs/create_koc_db.pl

做:從 Koha 離線流通 工具產生 borrowers.db 檔案

建議頻率:每週

自動續借

腳本路徑:misc/cronjobs/automatic_renewals.pl

做:若在 流通與罰款規則 裡允許自動續借,將自動續借。

建議頻率:每晚

重要

To run this properly, you must use the –confirm parameter, otherwise it will only run in test mode

參數 - -h|–help

  • 取得協助資訊

  • –send-notices

    • sends the AUTO_RENEWALS notice to patrons if the automatic renewal has been done

  • -v|–verbose

    • verbose mode

  • -c|–confirm

    • without this parameter no changes will be made, the script will run in test mode

    • without this parameter, the script will default to verbose mode as well

讀者

批次刪除讀者

腳本路徑:misc/cronjobs/delete_patrons.pl

做:依照未曾借出日期、到期日、上網日期、屬性、或所屬圖書館,批次刪除讀者紀錄。

說明

應採用 ISO 格式的日期,如 2013-07-19,可以用指令產生 date -d 『-3 month』 「+%Y-%m-%d」。

重要

此選項是選擇讀者記錄去刪除 累積的。比方說,供應同為 –expired_before 以及 –library 指定特定讀者記錄必須吻合 同時 選擇刪除為條件。

參數

  • –not_borrowed_since 刪除到此日未曾借過書過的讀者

  • –expired_before 刪除帳號失效日早過此日的讀者

  • –last_seen 刪除那些在此日期後沒有使用的讀者。系統偏好 TrackLastPatronActivity 必須啟用以使用此選項。

  • –category_code 刪除此類讀者類型的讀者

  • –library 刪除此圖書館的讀者

  • -c|–confirm 此旗標心須提供以便程式能實際刪除讀者記錄。如果未提供,程式將呈報它將刪除的讀者記錄

  • -v|–verbose Verbose 模式.

匿名讀者資料

腳本路徑:misc/cronjobs/batch_anonymise.pl

做:用於匿名讀者資料。此腳本將從流通記錄裡移除讀者號,一方面保護讀者的隱私同時又保持原有的流通記錄。

Update patron categories

Script path: misc/cronjobs/update_patrons_category.pl

Does: Updates the patron category of patrons matching the given criteria to another specified patron category. This can be used to convert child patrons from a child patron category to an adult patron category when they reach the upper age limit defined in the patron category.

This script replaces the j2a.pl script.

建議頻率:每晚

DESCRIPTION

This script is designed to update patrons from one category to another using the criteria specified using command line arguments.

參數

  • –too_old Update, if patron is over the upper age limit of their current category.

  • –too_young Update, if patron is below the minimum age limit of their patron category.

  • –fo=X|–fineover=X Update, if the total fine amount on the patron account is over X.

  • –fu=X|–fineunder=X Update, if the total fine amount on the patron account is below X.

  • –rb=date|regbefore=date Update, if the registration date of the patron is before the given date.

  • –ra=date|regafter=date Update, if the registration date of the patron is after the given date.

  • -d –field name=value Update, if the given condition is met. <name> has to be replaced by a column name of the borrowers table. The condition is met, if the the content of the field equals <value>.

  • –where <conditions> Update, if the SQL <where> clause is met.

  • -v|–verbose Verbose mode: Without this flag only fatal errors are reported.

  • -c|–confirm Commits the changes to the database. No changes will be made unless this argument is added to the command.

  • -b|–branch <branchcode> Update, if the home branch of the patron matches the <branchcode> given.

  • -f|–form <categorycode> Update, if the patron currently has this patron category.

  • -t|–to <categorycode> Update the patrons matching the criteria to this patron category.

USAGE EXAMPLES

「update_patrons_category.pl」

「update_patrons_category.pl」 -b=<branchcode> -f=<categorycode> -t=<categorycode> -c」 (Processes a single branch, and updates the patron categories from category to category)

「update_patrons_category.pl」 -f=<categorycode> -t=<categorycode> -v」 (Processes all branches, shows all messages, and reports the patrons who would be affected. Takes no action on the database)

通知

信件佇列

腳本路徑:misc/cronjobs/process_message_queue.pl

做:處理訊息佇列納入發送給讀者的借出、還入與預約歸檔電子郵件與簡訊以及送給讀者的電子郵件。必須將 EnhancedMessagingPreferences 偏好設為開啟

建議頻率:1-4小時

重要

到期館藏與到期提前通知由 advance_notices cron 控制。

提前通知

腳本路徑:misc/cronjobs/advance_notices.pl

做:應讀者的要求提供 「到期提前」 通知與 「到期館藏」 通知給需要的讀者。需將 EnhancedMessagingPreferences 偏好設為開啟

建議頻率:每晚

說明

此腳本不會真的送出通知。祗把通知置於 訊息佇列 供以後使用

逾期通知

腳本路徑:Script path: misc/cronjobs/overdue_notices.pl

做:準備讀者逾期的訊息 (經電子郵件或列印)

建議頻率:每晚

說明

此腳本不會真的送出通知。它把通知列入 訊息佇列 內供列印之用

參見

此 misc/cronjobs/advance_notices.pl 程式允許您送出訊息給逾期的讀者,或警示他們即將逾期。

Talking Tech

設定此第三方產品的詳情參見 Talking Tech

送出通知檔

腳本路徑:misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl

做:產生 Spec C 的通知檔案供 Talking Tech i-tiva 電話通知系統。

必備於:TalkingTechItivaPhoneNotification

建議頻率:每晚

收到通知檔案

腳本路徑:misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl

做:腳本處理收到來自Talking Tech i-tiva 電話通知系統的結果檔案。

必備於:TalkingTechItivaPhoneNotification

建議頻率:每晚

通知讀者證有效日期

腳本路徑:misc/cronjobs/membership_expiry.pl

做:把借書證到期的警示通知置於 訊息佇列 工作排程。

必備:MembershipExpiryDaysNotice

頻率:每天

處理中/圖書車

腳本路徑:misc/cronjobs/cart_to_shelf.pl

做:以 CART 位置做為館藏永久位置而更新所有館藏。

Required by: NewItemsDefaultLocation, and UpdateItemLocationOnCheckin system preferences

建議頻率:每小時

目錄

批次匯入網頁服務

腳本路徑:misc/cronjobs/import_webservice_batch.pl

做:處理批次匯入 『網頁服務』 屬性佇列的工作排程。也可經由 UI 處理批次。

說明

此腳本適用於 OCLC Connexion

Connexion Import Daemon

腳本路徑:misc/bin/connexion_import_daemon.pl

做:daemon 聽取 OCLC Connexion 的請求並回應 OCLC Gateway 規格。讀取 MARC XML 的請求並從組態檔匯入參數轉交給 svc/import_bib

說明

此腳本適用於 OCLC Connexion

批次刪除館藏

腳本路徑:misc/cronjobs/delete_items.pl

做:產生一項工作排程針對館藏資料庫並刪除在指令行符合條件的館藏。

參數

  • –verbose發送由收集的 C <-where> 參數以及受 Standard Out 影響的館藏所生成的 「WHERE」 子句。

  • –where C<-where> 選項可以多次調用。以下參數必須是有效的SQL語法,該語法是語法查詢館藏表 C<WHERE> 的一部分。這些由 C<AND> 加入。

  • –commit 無館藏會被刪除, 除非 C<–commit> 旗標出現

範例

下列是此程式的範例:

delete_items.pl –where 「items.withdrawn ! 0」 –where 「items.withdrawn_on < $(date –date=」13 month ago」 –rfc-3339=date)」 –commit

delete_items.pl –where 「itemlost >= 『1』」 –where 「itemlost <=』4』」 –where 「itemlost_on < 『2014-04-28』」 –commit

快速檢查 URL

腳本路徑:misc/cronjobs/check-url-quick.pl

做: 檢查書目記錄中的網址;掃瞄所有書目記錄從856段分欄u發現的網址並且顯示

說明

此腳本用以重置 check-url.pl

參數

  • –host=http://default.tld 使用不含URL,即不以 『http:』 開頭的服務器主機。例如,若 –host=http://www.mylib.com,則當856$u包含 『img/image.jpg』 時,檢查的URL為:http://www.mylib.com/image.jpg

  • –tags 段保留分欄u裡的網址。如果未提供,856段已檢查,許多段可以被指定,舉例:

    check-url-quick.pl –tags 310 410 856

  • –verbose|v 兩者輸出成功以及失敗的網址

  • –html 輸出格式為HTML。結果可以轉成檔案,可以透過 http 取得.從這個方式,有可能直接連結至書目記錄的編輯模式。使用此參數 –host-intranet 是必需的.

  • –host-intranet=http://koha-pro.tld 網路伺服器連結至Koha館員介面中書目記錄的編輯頁面。

  • –timeout=10 抓網址的時限。預設10秒。

  • –maxconn=1000 同時連結 HTTP 的數目. 預設是200個連結。

檢查 URL

腳本路徑:misc/cronjobs/check-url.pl

做:檢查 856$u 欄位裡的 URL。腳本的輸出是 CSV 或 HTML 格式。HTML 版本直接連結至 MARC 書目記錄編輯器。

建議頻率:每月

詳情見:http://wiki.koha-community.org/wiki/Check-url_enhancements

經由紀錄標示刪除紀錄

腳本路徑:misc/cronjobs/delete_records_via_leader.pl

做:刪除紀錄標示第 5 碼的內容為 『d』 的 MARC 紀錄

參數

  • -c|–confirm 若沒有此參數,程式將無法執行

  • -v|–verbose Verbose 模式

  • -t|–test 測試模式,不會刪除記錄。測試模式不能決定記錄/館藏被刪除,它只能讓您知道程式將刪除那些記錄或館藏。

  • -i|–delete-items 在刪除記錄前試著刪除。 記錄連同館藏無法刪除。

更新權威記錄

腳本路徑:misc/cronjobs/merge_authorities.pl

做:依照權威記錄的變動更新對應的書目資料

說明

此腳本的名稱是誤導。此腳本並未合併權威記錄反而合併與其連結的書目記錄。執行腳本時編輯權威記錄將適用於使用權威記錄的書目記錄。

必備於: AuthorityMergeLimit 系統偏好

建議頻率:每晚

更新期刊

腳本路徑:misc/cronjobs/serialsUpdate.pl

做:檢查訂閱中的期刊是否有 「遲到」 的刊期,若有,此腳本設定它為遲到,並把下一期列為期待簽收。

建議頻率:每晚

自動更新館藏

腳本路徑:misc/cronjobs/automatic_item_modification_by_age.pl

做:根據在 依年齡自動修改館藏 工具的規則更新館藏

使用到的是:依年齡自動修改館藏

建議頻率:每晚

OPAC

RSS Feeds

腳本路徑:misc/cronjobs/rss/rss.pl

做:給任何 SQL 詢問使用的 RSS XML 文件 (不是供搜尋結果 RSS feed 使用)。詳情

建議頻率:每小時

權威瀏覽器

腳本路徑:misc/cronjobs/build_browser_and_cloud.pl

做:在 OPAC 產生權威瀏覽的內容

必備於:OpacBrowser 系統偏好

重要

此偏好與工作排程應祗適用於法語系統。

主題/著者雲

腳本路徑:misc/cronjobs/cloud-kw.pl

做:從 Koha Zebra 索引產生 HTML 鍵詞雲。misc/cronjobs/cloud-sample.conf 有若干此腳本運算元的範例。

頻率:這是您可每月執行一次的腳本類型,其內容並不常變動。

系統管理

服務量

腳本路徑:misc/cronjobs/services_throttle.pl

做:重設 xISBN 服務量

建議頻率:每晚

清理資料庫

腳本路徑:misc/cronjobs/cleanup_database.pl

做:截切 sessions 表單、清理 zebra 序列款目、作為記錄與待處理 MARC 檔案。

請參考 http://schema.koha-community.org/ Koha 資料庫綱要

參數 - –del-exp-selfreg

  • –del-unv-selfreg DAYS

    • Delete all unverified self registrations in borrower_modifications older than DAYS.

  • –deleted-catalog DAYS

    • Purge bibliographic records deleted more than DAYS days ago from tables deletedbiblio, deletedbiblio_metadata, deletedbiblioitems and deleteditems.

  • –deleted-patrons DAYS

    • Purge patrons deleted more than DAYS days ago from the deletedborrowers table.

  • –fees DAYS

    • Purge entries in the accountlines table older than DAYS days, where the amountoutstanding is 0 or NULL.

    • In the case of –fees, DAYS must be greater than or equal to 1.

  • -h|–help

    • Get help message

  • –import DAYS

    • Purge entries from import tables older than DAYS days.

    • This includes import_batches, import_biblios, import_items, import_record_matches and import_records.

    • In import_batches, the batches that are the result of Z39.50 searches are removed with the –z3950 parameter.

    • Defaults to 60 days if no days specified.

  • --list-invites

    日數

    • Purge (unaccepted) list share invites from the virtualshelfshares table older than DAYS days

    • Defaults to 14 days if no days specified.

  • –logs DAYS

    • Purge entries from the action_logs table older than DAYS days.

    • Defaults to 180 days if no days specified.

  • -m|–mail DAYS

    • Purge entries from the message_queue table that are older than DAYS days.

    • Defaults to 30 days if no days specified.

  • –merged

    • Purge completed entries from the need_merge_authorities table.

  • –oauth-tokens

    • Delete expired OAuth2 tokens

  • –old-issues DAYS

    • Purge checkouts returned more than DAYS days ago from the old_issues table.

  • –old-reserves DAYS

    • Purge holds more than DAYS old from the old_reserves table.

  • –restrictions DAYS

    • Purge patrons restrictions from the borrower_debarments table expired since more than DAYS days.

    • Defaults to 30 days if no days specified.

  • –all-restrictions

    • Purge all expired patrons restrictions from the borrower_debarments table.

  • –searchhistory DAYS

    • Purge entries from the search_history table older than DAYS days.

    • Defaults to 30 days if no days specified

  • –sessions

    • Purge the sessions table.

    • If you use this while users are logged into Koha, they will have to reconnect.

  • –sessdays DAYS

    • Purge only sessions older than DAYS days.

  • –statistics DAYS

    • Purge entries from the statistics tables that are more than DAYS days old.

  • –temp-uploads

    • Delete temporary uploads from the uploaded_files table older than the number of days specified in the UploadPurgeTemporaryFilesDays system preference.

  • –temp-uploads-days DAYS

  • –transfers DAYS

    • Purge transfers completed more than DAYS days ago from the branchtransfers table.

  • –unique-holidays DAYS

    • Delete all unique holidays from the special_holidays table older than DAYS

  • –uploads-missing FLAG

    • Delete upload records for missing files when FLAG is true, count them otherwise

  • -v|–verbose

    • verbose mode

  • –zebraqueue DAYS

    • Purge completed zebraqueue entries older than DAYS days.

    • Defaults to 30 days if no days specified.

  • –z3950

    • Purge records from import tables that are the result of Z39.50 searches.

    • To purge all other import information, see the –import parameter above.

共享使用統計

路徑腳本:misc/cronjobs/share_usage_with_koha_community.pl

做:如果通過 UsageStats 功能分享訊息,則訊息將發送到 Hea website

頻率:每月

採訪

清除舊的建議

腳本路徑:misc/cronjobs/purge_suggestions.pl

做:從建議管理區塊移除舊的 (由您定義) 建議。

說明

系統偏好 PurgeSuggestionsOlderThan 設定在腳本使用的日數

將建議以電郵送入程序

腳本路徑:misc/cronjobs/notice_unprocessed_suggestions.pl

做:將待處理的採訪建議告知基金擁有者

EDI 訊息處理

腳本路徑:misc/cronjobs/edi_cron.pl

做:送出與接收 EDI 訊息

頻率:每 15 分鐘

移除暫存 EDI 檔案

腳本路徑:misc/cronjobs/remove_temporary_edifiles.pl

做:移除 5 天前的暫存 EDI 檔案

報表

執行報表

腳本路徑:misc/cronjobs/runreport.pl

做:執行已經儲存的報表

參數

  • -v|–verbose Verbose 輸出

  • –format=s 選擇格式。選擇文字, html, csv或tsv

  • -e|–email 無論使用或不使用電子郵件 (implied by –to 或 –from)

  • -a|–attachment 附加報告檔案。無法使用html格式

  • –username 使用者名稱透過 SMTP 伺服器認證

  • –password 密碼透過 SMTP 伺服器認證

  • –method 身份驗證的類型。就是登錄, DIGEST-MD5, 等

  • –to=s 電子郵件地址送報告至

  • –from=s 電子郵件地址送報告來自

  • –subject=s 電子郵件的主旨

  • –store-results 儲存報告結果

  • –csv-header 在csv的第一列加入欄位名稱

參數

  • reportID 報表 ID 的 save_sql.id 編號,可以指定多個ID

社會資料

取得社會資料報表

腳本路徑:misc/cronjobs/social_data/get_report_social_data.pl

做:從 Babelthèque 下載資料加入 OPAC 紀錄

建議頻率:每晚

更新社會資料

腳本路徑:misc/cronjobs/social_data/update_social_data.pl

做:以 Babelthèque 資料更新 OPAC 紀錄

守護行程

守護行程會持續運作以幫忙輔助 Koha 操作的工作。 您的數據庫和Web服務器將作為守護形成運作。較新版本的Koha啟動兩個不同的守護形程:

  • zebra - 此為索引伺服器

  • koha-indexer - 此守護行程使用新的和修改的數據(書目和權威)更新索引伺服器

這些守護行程由腳本 /etc/init.d/koha-common 啟動。

Zebra indexer daemon

腳本路徑:/usr/sbin/koha-indexer(從 /etc/init.d/koha-common 調用)

koha-indexer 腳本以守護行程模式調用 rebuild_zebra.pl。此模式下,腳本將連續運作並每30秒檢查數據庫中是否有新數據或修改過的數據。 然後將新記錄或修改後的記錄發送到Zebra 進行索引,這只需一秒鐘左右。與 cron job approach 相比,此方法的優點是搜尋系統對更改的反應快很多。

不適用的腳本

不應在未修改前執行這些:

腳本路徑:misc/cronjobs/update_items.pl

腳本路徑:misc/cronjobs/smsoverdues.pl

腳本路徑:misc/cronjobs/notifyMailsOp.pl

腳本路徑:misc/cronjobs/reservefix.pl

腳本路徑:misc/cronjobs/zebraqueue_start.pl