Koha 26.05 常用 CLI 命令与工具详解
Koha 26.05 两套命令行为工具体系全解:/usr/sbin 下 37 个 koha-* 实例管理命令(生命周期/shell/mysql/foreach/守护进程族/ES 与 Zebra 索引重建/备份恢复/模式升级/翻译/外围服务)逐个给用法参数与实测回显,/usr/share/koha/bin/cronjobs 56 项定时任务脚本(必须经 koha-shell 执行)详解 overdue_notices 与 cleanup_database,附 10 条注意事项与 8 条常见问题。全部回显实测照抄。
Koha 26.05 常用 CLI 命令与工具详解
目标:以实测环境为底,系统讲解 Koha 26.05 自带的两套命令行工具体系——
/usr/sbin下 37 个koha-*实例管理命令与/usr/share/koha/bin/cronjobs/下 56 项定时任务脚本——逐个给出用法、参数与真实回显,覆盖实例生命周期、实例环境进入、数据库直连、守护进程管理、检索索引重建、备份恢复、模式升级、翻译与外围服务开关等日常运维全部场景,并汇总实测踩坑与常见问题。
一、环境信息
本篇全部命令与回显实测自《Koha 26.05 Docker Compose 部署指南》搭建的部署栈,环境摘要:
| 项目 | 值 |
|---|---|
| 主机 | Linux master 7.0.0-38-generic #38-Ubuntu SMP x86_64 |
| Koha 版本 | 26.05(包 koha-core 26.05.04-1,界面 About 显示 Koha 26.05.04) |
| 实例名 | koha(实例系统用户 koha-koha) |
| 数据库 | MariaDB 11.4(实测服务端 11.4.13-MariaDB-ubu2404) |
| 检索引擎 | Elasticsearch 9.4.6(配置地址 es:9200) |
| 缓存 | memcached |
| 实例配置文件 | /etc/koha/sites/koha/koha-conf.xml(详见《Koha 26.05 配置参数详解》) |
Koha 的命令行工具体系分两套:
- 实例管理命令:安装时随
koha-core落在/usr/sbin/,共 37 个koha-*命令(另含koha-start-sip、koha-stop-sip、koha-start-zebra、koha-stop-zebra、koha-restart-zebra等指向主命令的 wrapper 脚本),以 root 身份按实例名管理各实例; - 定时任务脚本:业务周期性作业(逾期通知、罚款、数据清理等)位于
/usr/share/koha/bin/cronjobs/,共 56 项,为 Perl 脚本,须在实例环境内执行。
二、工具概览
实测 ls /usr/sbin/koha-* 得到的 37 个命令按职责分组如下:
| 分组 | 命令 | 职责 |
|---|---|---|
| 实例生命周期 | koha-create、koha-remove、koha-list、koha-enable、koha-disable、koha-create-dirs、koha-post-install-setup | 建实例、删实例、列实例、启用/停用站点 |
| 实例环境与数据库 | koha-shell、koha-mysql、koha-foreach | 进入实例环境、直连实例数据库、跨实例批量执行 |
| 口令管理 | koha-passwd、koha-reset-passwd | 查看实例 DB 密码、重置读者密码 |
| 守护进程管理 | koha-plack、koha-worker、koha-indexer、koha-zebra、koha-es-indexer | 应用/队列/索引进程的启停与状态 |
| 检索索引 | koha-elasticsearch、koha-rebuild-zebra | ES 与 Zebra 索引重建 |
| 备份恢复 | koha-dump、koha-restore、koha-run-backups、koha-dump-defaults | 实例数据导出、导入、批量备份 |
| 升级 | koha-upgrade-schema、koha-upgrade-to-3.4 | 数据库模式对齐、历史版本迁移 |
| 外围服务 | koha-sip、koha-z3950-responder、koha-sitemap、koha-enable-sip | SIP 自助借还、Z39.50/SRU、站点地图 |
| 邮件与翻译 | koha-email-enable、koha-email-disable、koha-translate | 实例邮件开关、界面语言包管理 |
cronjobs 目录 56 项全量清单见本篇第五节。
三、前置条件
- 已按《Koha 26.05 Docker Compose 部署指南》完成部署,实例已通过 web 安装器与 onboarding 初始化;
- 实例管理命令位于
/usr/sbin/,需以 root(或等价权限)执行; - cronjobs 脚本依赖实例环境变量(
KOHA_CONF、Perl 模块路径等),统一经koha-shell进入实例环境后执行(直接perl运行会报模块缺失,见 5.1 实测); - 想确认当前有哪些实例,先跑
koha-list。
四、实例管理命令详解
4.1 koha-list / koha-enable / koha-disable:实例清单与站点启停
koha-list 列出本机全部 Koha 实例,实测:
# koha-list
koha
它不识别额外选项,加 --all 会直接报错:
# koha-list --all
unrecognized option
koha-enable / koha-disable 按实例名启用/停用 Apache 站点,无参调用打印 usage:
# koha-enable
Enables Koha instances.
Usage: /usr/sbin/koha-enable instancename1 instancename2...
Missing instance name...
# koha-disable
Disables Koha instances.
Usage: /usr/sbin/koha-disable instancename1 instancename2...
Missing instance name...
日常用途:临时下线某个 OPAC/Staff 站点排障(koha-disable <实例>),修好后 koha-enable <实例> 恢复。
4.2 koha-create:创建实例
koha-create 是全系命令中参数最多的一个,负责生成实例目录、koha-conf.xml、数据库与 Apache vhost。无参调用回显(节选实测):
# koha-create
Creates new Koha instances.
Usage:
/usr/sbin/koha-create [DB usage mode] [options] instancename
DB usage mode:
--create-db Create a new database on localhost. (default).
--request-db Creates a instancename-db-request.txt file where
you adjust your DB settings and re-run with --populate-db.
--populate-db Finish the installation you started with --request-db after
you adjusted the instancename-db-request.txt file.
完整选项(实测 --help 输出整理):
| 选项 | 说明 |
|---|---|
--create-db / --request-db / --populate-db / --use-db | 四种数据库使用模式:本机建库(默认)/ 生成申请文件后回填 / 完成申请流程 / 复用已建好的库 |
--marcflavor marc21|unimarc | MARC 类型,默认 marc21 |
--zebralang lang | Zebra 索引主语言(cs/el/en/es/fr/nb/ru/uk) |
--elasticsearch-server s | 指定 Elasticsearch 服务器(默认 localhost:9200) |
--memcached-servers str / --memcached-prefix str | memcached 服务器列表与命名空间前缀 |
--enable-sru / --sru-port N | 启用 Z39.50/SRU 服务及端口(默认 7090) |
--defaultsql some.sql | 建库时额外装载的 SQL 文件 |
--configfile cfg_file | 读取默认值的替代配置文件 |
实践中若走 koha-docker 编排,实例由初始化阶段以 .env 喂参自动创建(见部署指南),手工补建其他实例时才直接敲 koha-create。
4.3 koha-remove:删除实例
无参调用即提示可选实例清单,实测:
# koha-remove
Please specify a Koha instance name. Your choices are:
koha
koha-remove <实例名> 会删除实例配置、数据目录与数据库,操作不可逆,执行前务必先用 koha-dump 备份(见 4.11)。
4.4 koha-shell:进入实例环境
koha-shell 是最核心的一个命令——它切到实例系统用户并注入 KOHA_CONF、Perl 模块路径等环境,是运行一切 Koha Perl 脚本(cronjobs、C4::Context 调试)的入口。usage 实测:
# koha-shell --help
koha-shell -- gives you a shell with your Koha environment set up
Usage: koha-shell [options] [instance name]
Options:
-c, --command COMMAND pass COMMAND to the invoked shell
-h, --help show this help and quit
-l, --login make the shell a login shell
-m, -p,
--preserve-environment do not reset environment variables
-s, --shell SHELL use SHELL instead of the one from your environment
-v, --verbose output the full command that will be executed
两种典型用法(均实测):
# koha-shell koha -c whoami
koha-koha
# koha-shell koha -c "perl -MC4::Context -e 'print C4::Context->preference(q{SearchEngine}), qq{\n}'"
Elasticsearch
不带 -c 则得到交互式 shell,适合连续执行多条脚本。
4.5 koha-mysql:直连实例数据库
koha-mysql <实例名> 用实例配置里的库名与凭据直接打开 MySQL 客户端,管道输入 SQL 即可脚本化查询(实测):
# echo "select version(),count(*) from borrowers;" | koha-mysql koha
version() count(*)
11.4.13-MariaDB-ubu2404 1
注意:koha-mysql 不识别 --help,参数会穿透到底层的 grep 并打印 grep 自己的 usage(实测回显为 Usage: grep [OPTION]... PATTERNS [FILE]...),查用法请直接 koha-mysql <实例名> 进入交互界面看提示。
4.6 koha-foreach:跨实例批量执行
koha-foreach 对本机每个实例各执行一次给定命令,多实例服务器批量运维用。实测行为与直觉不同:
# koha-foreach "echo hi from %INSTANCE%"
hi from %INSTANCE%
# koha-foreach --help
/bin/sh: 0: Illegal option --
koha: 2 status returned by "--help"
两个实测结论:一是它不做 %INSTANCE% 模板替换(原样输出),要在命令里拿到实例名需自行借助 shell 变量或改用 for i in $(koha-list); do ...; done;二是 --help 会因内部以 /bin/sh 执行而报 Illegal option --。
4.7 koha-passwd / koha-reset-passwd:口令管理
koha-passwd <实例1> ...:打印实例数据库密码(即koha-conf.xml中<pass>的值,见配置篇);koha-reset-passwd <实例名> <userid>:重置指定读者密码并打印生成的新密码,无参回显(实测):
# koha-reset-passwd
Resets the password for the specified user on the Koha instance.
Usage: /usr/sbin/koha-reset-passwd instancename userid
Note: The generated password will be printed.
Wrong parameters
提醒:实测本部署的读者密码策略要求至少一大写一小写一数字(q1w2e3r4 被拒、Q1w2e3r4 通过),重置后若登录仍失败先核对复杂度。
4.8 守护进程管理族:koha-plack / koha-worker / koha-indexer / koha-zebra / koha-es-indexer
五个命令结构一致:--start|--stop|--restart [--quiet|-q] 实例名... 加 --status。各自的差异点(实测 usage 整理):
| 命令 | 独有参数 | 说明 |
|---|---|---|
koha-plack | --reload、--enable/--disable、--development | --reload 让忙碌 worker 处理完当前请求再重启,改代码/配置后平滑生效的首选 |
koha-worker | --queue <名>、--all-queues | 队列现为 default、long_tasks 两种;usage 明确注明旧的 elastic_index 队列已被 koha-es-indexer 取代 |
koha-indexer | — | Zebra 索引守护进程 |
koha-zebra | `--verbose | -v` |
koha-es-indexer | --batch_size N(默认 10) | Elasticsearch 索引守护进程 |
koha-worker --help 关键片段实测:
Usage:
koha-worker [--start|--stop|--restart] [--queue queue_name|--all-queues] [--quiet|-q] instancename1 [instancename2...]
koha-worker --status instancename1 [instancename2...]
koha-worker -h|--help
--queue Specify the queue/worker to perform the action on - 'default' is
used if not specified (unless --all-queues is passed)
current queues are: default, long_tasks
重要实测发现:在本部署的拆分服务形态下,进程由各服务各自前台运行,这组命令的状态检查查不到传统 PID,--status 全部报 failed,属预期噪音而非故障:
# koha-plack --status koha
Plack not running for koha: failed!
# koha-worker --status koha
worker not running for koha (default): failed!
# koha-indexer --status koha
Indexer not running for koha: failed!
# koha-zebra --status koha
Zebra not running for koha: failed!
判断服务真实存活应以 HTTP 探测(8140/8142 端口)和任务是否实际执行为准;--restart 类操作在拆分形态下也应交由编排层对各服务下发。
4.9 koha-elasticsearch:ES 索引重建
无参回显(实测):
# koha-elasticsearch
Manage Elasticsearch-related tasks for Koha instances
Usage: /usr/sbin/koha-elasticsearch [actions] [options] instancename1 instancename2...
Actions:
--rebuild Trigger a rebuild process
Options:
--delete|-d Delete elasticsearch index before reindexing.
--reset|-r Reset elasticsearch mappings from file.
--authorities|-a Only run process for authorities.
--biblios|-b Only run process for biblios.
--rebuild -v 完整实测回显(空库场景):
# koha-elasticsearch --rebuild -v koha
[963] Checking state of biblios index
[963] Checking state of authorities index
[963] Indexing biblios
[963] Committing final records...
Use of uninitialized value in string eq at /usr/share/koha/bin/search_tools/rebuild_elasticsearch.pl line 368.
[963] Total 0 records indexed
[963] Indexing authorities
[963] Committing final records...
Use of uninitialized value in string eq at /usr/share/koha/bin/search_tools/rebuild_elasticsearch.pl line 368.
[963] Total 0 records indexed
Use of uninitialized value 是无记录场景下的无害告警(实测出现于 biblios/authorities 各一次)。重建后按实例配置记录的检索服务地址(es:9200)验证索引落地:
# curl -s 'http://es:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size dataset.size
yellow open koha_koha_authorities EZmegIlbS_ilbg_623Cvwg 5 1 0 0 1.2kb 1.2kb 1.2kb
yellow open koha_koha_biblios MuTtX0kMRv2dl0PxLqDPbg 5 1 0 0 1.2kb 1.2kb 1.2kb
索引命名规则为 koha_<实例名>_<biblios|authorities>;yellow 是单节点副本无法分配的常态。
4.10 koha-rebuild-zebra:Zebra 索引重建
选择 Zebra 检索引擎的实例用此命令,无参回显(实测):
# koha-rebuild-zebra
Rebuild the Zebra indexes for Koha instances. The default behaviour
is to do an incremental rebuild.
Usage: /usr/sbin/koha-rebuild-zebra [options] instancename1 instancename2...
Options:
--authorities|-a Only run process for authorities.
--biblios|-b Only run process for biblios.
--full|-f Does a reindex of the whole collection.
--force Run incremental indexing even if USE_INDEXER_DAEMON="yes"
--quiet|-q Sometimes be a bit quieter for scripts/cronjobs.
--verbose|-v Be verbose. Can be multiple.
--help|-h Print this help.
要点:默认增量重建;--full 全量重建(首次启用 Zebra 或索引损坏时用);--force 用于 indexer 守护进程开着但仍要手工跑增量的场景。
4.11 koha-dump / koha-restore / koha-run-backups:备份与恢复
koha-dump 单实例导出,usage 实测节选:
# koha-dump --help
koha-dump
This script dumps your Koha instance data for backup or migration.
Usage:
koha-dump [--quiet|-q] [--exclude-indexes] instancename1 [instancename2...]
--schema-only Dump only the database schema
--exclude-indexes Exclude Zebra indexes from the backup
--exclude-logs Exclude /var/log/koha/name from the backup
--uploaded_files Include uploaded files.
--uploaded_temp_files Include temporary uploaded files.
--without-db-name Do not include database name
实跑回显(实测):
# koha-dump koha
Dumping Koha site koha:
* DB to /var/spool/koha/koha/koha-2026-11-01.sql.gz
* configs, logs to /var/spool/koha/koha/koha-2026-11-01.tar.gz
Done.
产物落在 /var/spool/koha/<实例>/,实测目录清单:
# ls -l /var/spool/koha/koha/
total 324
-rw-r----- 1 root koha-koha 289452 Nov 1 15:58 koha-2026-11-01.sql.gz
-rw-r----- 1 root koha-koha 30525 Nov 1 15:58 koha-2026-11-01.tar.gz
即每次备份一对文件:*.sql.gz(数据库)+ *.tar.gz(配置与日志)。恢复用 koha-restore,无参回显即 usage(实测):
# koha-restore
Usage: /usr/sbin/koha-restore sqldump configdump
依次传入上面两个产物路径即可把备份灌回实例。批量场景用 koha-run-backups(本机所有实例轮一遍,自动清理过期备份),其 --help 只打印选项文档(实测):
# koha-run-backups --help
/usr/sbin/koha-run-backups - performs backups of the koha installations on the system
Options:
--output /path The directory that the resulting files will be placed into.
(default: /var/spool/koha)
--days 2 The number of days to keep backups around for
(default: 2)
--exclude-indexes Exclude Zebra indexes from the backups (default: false)
--exclude-logs Exclude /var/log/koha/name from the backup (default: false)
Note: backups produced using this tool can be restored using `koha-restore'.
实测无参直接执行时静默完成(正常备份本就不打印内容,产物见上),默认只保留 2 天,生产上建议显式 --days 7 以上并配 cron。
4.12 koha-upgrade-schema:数据库模式对齐
版本升级(apt 包更新)后必须跑一次,把数据库 schema 对齐到当前代码要求。实测回显:
# koha-upgrade-schema koha
Upgrading database schema for koha
No database change required
No database change required 表示 schema 已是最新。同样注意:该命令不识别 --help,参数会穿透到 grep 打印其 usage(同 4.5)。koha-upgrade-to-3.4 是历史版本(3.4 时代)迁移专用,现代部署用不到。
4.13 koha-translate:界面语言包管理
usage 实测:
# koha-translate --help
koha-translate
This script lets you manage your Koha templates translations.
Usage:
koha-translate --list|-l [--available|-a] [-d|--dev instance]
koha-translate --check|-c language_code] [-d|--dev instance]
koha-translate --install|-i language_code] [-d|--dev instance]
koha-translate --update|-u language_code] [-d|--dev instance]
koha-translate --remove|-r language_code] [-d|--dev instance]
-l | --list List the installed or available (combined with -a)
language translations
-a | --available Used in conjunction with -l to show all languages
-c | --check Check that the language .PO files are present
-i | --install Install the specified language translations
-u | --update Update the specified language translations
-r | --remove Remove the specified language translations
-d | --dev Limit actions to a specific dev instance
实测本环境 koha-translate --list 输出为空——部署时 KOHA_LANGS 未设、语言包未安装(初始化日志有 No locale installed WARN)。需要中文界面时装 koha-l10n 相关语言包后 koha-translate -i <语言代码>。
4.14 外围服务开关族:koha-sip / koha-z3950-responder / koha-sitemap / koha-email-*
koha-sip:SIP2 自助借还服务器管理,--start|--stop|--restart|--status|--enable|--disable(另有koha-start-sip/koha-stop-sip/koha-enable-sipwrapper,实测头部即koha-sip脚本本体);koha-z3950-responder:Z39.50/SRU 对外检索服务,--start|--stop|--restart|--enable|--disable,无参回显Error: you must provide at least one instance name;koha-sitemap:OPAC 站点地图生成,--enable|--disable|--generate;koha-email-enable/koha-email-disable:按实例开关邮件发送,usage 实测:
# koha-email-enable
Enables the email for Koha instances.
Usage: /usr/sbin/koha-email-enable instancename1 instancename2...
Missing instance name...
以上服务在本部署中默认未启用(编排侧按 profile 可选开启,见部署指南),命令留作实例级开关。koha-create-dirs、koha-post-install-setup、koha-dump-defaults 为安装/建实例过程的内部辅助命令,日常运维一般不直接调用。
五、定时任务脚本(cronjobs)详解
5.1 执行方式:必须经 koha-shell
/usr/share/koha/bin/cronjobs/ 实测共 56 项。这些 Perl 脚本不能在系统默认 Perl 环境直接跑——缺少实例 Perl 路径会立刻报模块缺失(实测):
# perl /usr/share/koha/bin/cronjobs/overdue_notices.pl --help
Can't locate Koha/Script.pm in @INC (you may need to install the Koha::Script module)
(@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.36.0 ... )
at /usr/share/koha/bin/cronjobs/overdue_notices.pl line 29.
BEGIN failed--compilation aborted at /usr/share/koha/bin/cronjobs/overdue_notices.pl line 29.
advance_notices.pl、cleanup_database.pl、process_message_queue.pl、fines.pl 直接执行同样报错。正确姿势是经 koha-shell 进入实例环境:
# koha-shell koha -c "perl /usr/share/koha/bin/cronjobs/overdue_notices.pl -n"
生产上通常给实例用户配 crontab(目录内附 crontab.example 模板),每条命令都包在 koha-shell <实例> -c "..." 里。
5.2 overdue_notices.pl:逾期通知
流通核心作业,扫描逾期借阅并按通知模板发信/生成文件。实测 --help(koha-shell 内)完整选项:
Usage:
overdue_notices.pl [ -n ][ --library <branchcode> ][ --library
<branchcode> ... ] [ --max <number of days> ][ --csv [<filename>] ][
--itemscontent <field list> ] [ --email <email_type> ... ]
Options:
--help Brief help message.
--man Full documentation.
--verbose | -v Verbose mode. Can be repeated for increased output.
--nomail | -n No email will be sent.
--max <days> Maximum days overdue to deal with.
--library <branchcode> Only deal with overdues from this library.
(repeatable : several libraries can be given)
--csv <filename> Populate CSV file.
--html <directory> Output html to a file in the given directory.
--text <directory> Output plain text to a file in the given directory.
--itemscontent <list of fields> Item information in templates.
--borcat <categorycode> Category code that must be included.
--borcatout <categorycode> Category code that must be excluded.
--triggered | -t Only include triggered overdues.
常用组合:-n 干跑不发信(上线前验证触发逻辑)、--library CTR 限定分馆、--max 30 限定逾期天数上限。通知内容本身由后台「Notice & Slips」模板控制,脚本只负责触发。
5.3 cleanup_database.pl:数据库清理
定期清理会话、消息队列、过期记录,防库表膨胀。实测 --help(koha-shell 内):
Usage: /usr/share/koha/bin/cronjobs/cleanup_database.pl
-h --help prints this help message, and exits, ignoring all
other options
--confirm Confirmation flag, the script will be running in dry-run mode is not set.
--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.
-v --verbose will cause the script to give you a bit more information
about the run.
--zebraqueue DAYS purge completed zebraqueue entries older than DAYS days.
Defaults to 30 days if no days specified.
-m --mail DAYS purge items from the mail queue that are older than DAYS days.
Defaults to 30 days if no days specified.
--merged purged completed entries from need_merge_authorities.
--messages DAYS purge entries from messages table older than DAYS days.
Defaults to 365 days if no days specified.
--import DAYS purge records from import tables older than DAYS days.
Defaults to 60 days if no days specified.
--z3950 purge records from import tables that are the result
of Z39.50 searches
--fees DAYS purge entries accountlines older than DAYS days, where
amountoutstanding is 0 or NULL.
In the case of --fees, DAYS must be greater than
or equal to 1.
关键纪律:不带 --confirm 时是 dry-run 模式(只报告不删除),确认无误后再加 --confirm 实删。--sessions 会把在线用户踢下线,安排低峰执行。
5.4 其他常用脚本与全量清单
56 项按业务域择要(用途均为脚本名与官方文档语义,全量以目录实测为准):
| 脚本 | 用途 |
|---|---|
advance_notices.pl | 到期提前提醒 |
fines.pl / staticfines.pl / writeoff_debts.pl / debar_patrons_with_fines.pl | 罚款计算、固定罚款、坏账核销、欠费停借 |
longoverdue.pl | 长期逾期处理(可联动注销读者/标记丢失) |
automatic_renewals.pl / automatic_checkin.pl / cart_to_shelf.pl | 自动续借、自动还书、书车归架 |
process_message_queue.pl | 消化消息队列(通知发送的实际出口) |
batch_anonymise.pl / anonymize_last_borrowers.pl / delete_patrons.pl / delete_items.pl / delete_records_via_leader.pl | 隐私匿名化与批量删除 |
membership_expiry.pl / update_patrons_category.pl / restrict_patrons_with_failed_notices.pl | 读者到期、批量改类别、通知失败限制 |
merge_authorities.pl / serialsUpdate.pl / harvest_oai.pl / edi_cron.pl / marc_ordering_process.pl | 规范记录合并、期刊到刊、OAI 收割、EDI、MARC 到馆处理 |
hold_recall_trigger.pl(holds 目录)/ recalls/ | 预借与回调用触发 |
runreport.pl / share_usage_with_koha_community.pl / plugins_nightly.pl / sitemap.pl | 定时报表、使用统计上报、插件夜间任务、站点地图 |
backup.sh / printoverdues.sh | 备份与逾期单打印辅助 |
目录全量 56 项实测清单:CONFIGURE.gmail、advance_notices.pl、anonymize_last_borrowers.pl、archive_purchase_suggestions.pl、automatic_checkin.pl、automatic_item_modification_by_age.pl、automatic_renewals.pl、backup.sh、batch_anonymise.pl、build_browser_and_cloud.pl、cart_to_shelf.pl、check-url-quick.pl、cleanup_database.pl、cloud-kw.pl、cloud-sample.conf、create_koc_db.pl、crontab.example、debar_patrons_with_fines.pl、delete_items.pl、delete_patrons.pl、delete_records_via_leader.pl、edi_cron.pl、erm_run_harvester.pl、fines.pl、gather_print_notices.pl、harvest_oai.pl、holds、import_webservice_batch.pl、longoverdue.pl、marc_ordering_process.pl、membership_expiry.pl、merge_authorities.pl、notice_unprocessed_suggestions.pl、overdue_notices.pl、patron_emailer.pl、plugins_nightly.pl、printoverdues.sh、process_message_queue.pl、purge_suggestions.pl、recalls、reconcile_balances.pl、remove_temporary_edifiles.pl、restrict_patrons_with_failed_notices.pl、rss、runreport.pl、serialsUpdate.pl、sftp_file.pl、share_usage_with_koha_community.pl、sitemap.pl、social_data、staticfines.pl、stockrotation.pl、thirdparty、update_patrons_category.pl、update_totalissues.pl、writeoff_debts.pl。
六、注意事项
- root 与实例用户分层:
koha-*管理命令以 root 执行;业务脚本以实例用户(实测koha-koha)在koha-shell内执行,权限与配置读取方式完全不同。 - cronjobs 必须经 koha-shell:直接
perl运行一律Can't locate Koha/Script.pm(实测),配 crontab 时每条都包koha-shell <实例> -c。 - 拆分服务形态下
--status不可信:koha-plack/worker/indexer/zebra --status全报 failed 是预期噪音(见 4.8),存活判断以 HTTP 探测和任务实际执行为准;启停操作交由编排层对各服务下发。 koha-mysql与koha-upgrade-schema不识别--help:参数穿透到底层 grep,打印的是 grep 的 usage(实测),别误以为命令坏了。koha-foreach不做%INSTANCE%替换且--help报错(实测,见 4.6):需要实例名时改用for i in $(koha-list)循环。koha-run-backups默认只保留 2 天:生产显式加大--days,并确认--output落在有备份策略的位置。- 备份产物成对使用:
koha-restore需同时传*.sql.gz与*.tar.gz两个文件(见 4.11)。 - 升级后固定动作:包升级完成后立刻
koha-upgrade-schema <实例>对齐 schema,再按配置篇重启应用侧进程。 - 密码复杂度:读者密码需至少一大写一小写一数字(实测),
koha-reset-passwd生成的随机密码若含特殊字符登录失败,先查复杂度规则。 - ES 重建告警可忽略:空库
--rebuild时的Use of uninitialized value(rebuild_elasticsearch.pl line 368)为无害告警,索引正常创建(实测_cat/indices可见)。
七、常见问题
Q1:跑 cronjobs 脚本报 Can't locate Koha/Script.pm in @INC?
没在实例环境里执行。改用 koha-shell <实例> -c "perl /usr/share/koha/bin/cronjobs/xxx.pl ..."(实测直接 perl 必报此错)。
Q2:koha-plack --status koha 报 failed,但网页明明正常?
拆分服务部署形态下状态脚本查不到传统 PID,属预期噪音(实测四个 daemon 命令全 failed)。以 HTTP 200 和日志为准。
Q3:koha-mysql --help 为什么打印 grep 用法?
该命令未实现 --help,参数穿透(实测)。直接 koha-mysql <实例> 进入交互客户端即可。
Q4:koha-translate --list 什么都没输出?
语言包未安装(本部署 KOHA_LANGS 为空,实测初始化日志 No locale installed)。安装对应 l10n 包后用 -i <语言代码> 安装。
Q5:koha-elasticsearch --rebuild 出现 Use of uninitialized value?
无记录/空索引场景的已知无害告警(实测 line 368),以 _cat/indices 出现 koha_<实例>_biblios/authorities 为成功标志。
Q6:koha-reset-passwd 生成的密码登录不进去?
密码策略要求大小写+数字(实测 q1w2e3r4 被拒)。重新生成或后台改密时选合规密码。
Q7:cleanup_database.pl 跑了但数据没删?
不带 --confirm 时脚本处于 dry-run 模式(官方 usage 明示),确认后补 --confirm 重跑。
Q8:想备份整个实例给迁移用,用哪个命令?
单实例 koha-dump <实例>(实测产物 /var/spool/koha/<实例>/<日期>.sql.gz + .tar.gz),目标机 koha-restore sqldump configdump 灌回;多实例定时化用 koha-run-backups --days N。
八、参考链接
- Koha 官方 CLI 文档:https://wiki.koha-community.org/wiki/Koha_Command_Line_Tools
- Koha 定时任务文档:https://wiki.koha-community.org/wiki/Cronjobs
- koha-docker 编排仓库:https://github.com/koha-community/koha-docker
- Koha 主仓库:https://github.com/Koha-community/Koha
- 站内系列:《Koha 介绍与选型指南》《Koha 26.05 Docker Compose 部署指南》《Koha 26.05 配置参数详解》