i-doit 38 常用 CLI 命令与运维实操

i-doit open 38 console.php 全命令实测:-n 铁律与两套凭据、租户启停、search-index/logbook:archive/contracts-outdated 等 cron 命令、system:tenant-export 整库导出、mysqldump 备份恢复演练、update --check-versions 升级前核查、uninstall 卸载,附 system-checkforupdates 崩溃等 5 个排障实录。

i-doitCLI命令运维MariaDBPHPCMDB2026/11/03

i-doit 38 常用 CLI 命令与运维实操

i-doit open 38 自带一个基于 Symfony Console 的命令行工具:应用根目录的 console.php(php console.php --version 实测输出 i-doit console utility 38)。它覆盖了安装/卸载、租户管理、搜索索引、日志归档、合同处理、系统设置、备份导出与升级等日常运维动作,是无人值守脚本与 cron 的唯一入口。本文按"通用规则 → 命令总表 → 高频命令逐条实测 → 备份恢复 → 升级与卸载 → 排障实录"组织,所有输出均为真实服务器(Ubuntu 22.04 + Apache 2.4.52 + MariaDB 10.6.23 + PHP 8.3.36,i-doit open 38,Web 监听 8137)逐行照抄。部署过程见《Ubuntu 22.04 安装 i-doit 38 指南》,配置项含义见《i-doit 38 配置参数详解》。

通用规则:三条铁律

  1. 无人值守必须加 -n。console.php 的多数命令继承 AbstractConfigurableCommand,只要处于交互模式,就会把命令行传入的选项逐项重新提问;在管道/cron 等非终端环境里提示读到空值,轻则参数失效、重则写出错误的配置哈希(见排障实录)。-n(--no-interaction)后命令行参数才生效。
  2. 分清两套凭据。install/tenant-create/tenant-remove 用 数据库管理员账号(-u root -p <DB密码>);其余业务命令用 i-doit 应用管理员(-u admin -p <登录密码>)+ -i <tenantId>。给错凭据的典型现象是 Authorisation: failed 并整体 Undo。
  3. 凭据可外置为 ini。凡支持 -u/-p/-i 的命令都支持 -c <file.ini>,节名固定 [commandOptions](详见配置篇第六节),cron 场景推荐用它替代明文命令行。

命令总表(实测 php console.php list)

i-doit console utility 38

Available commands:
  addon-license-check                 This command checks if a specific add-on is licensed.
  admin-center-password-reset         With this command you can reset the Admin-Center password
  auth-cleanup                        Cleanup all auth paths
  clear-credentials                   It removes both attributes username and password from the users "login" category
  contracts-outdated                  Updates status of outdated contracts
  extend-contracts                    Automatically extend the runtime of not-cancelled contracts
  import-hinventory                   Imports files formatted in the hInventory XML syntax
  import-syslog                       Imports data from a Syslog server textfile to the i-doit Logbook
  import-xml                          Imports files formatted in the i-doit XML syntax
  install                             Install the i-doit application
  migrate-uploaded-files              Migrates uploaded files in i-doit <v1.13 to v.1.14>
  notifications-list                  Lists all notification types and notifications for later usage
  notifications-send                  Sends out e-mails for notifications defined in the notification add-on
  search                              Triggers a search and gives the results as formatted text table
  search-index                        Deletes current search index and create it
  send-welcome-mail                   This command sends welcome e-mail with all required information ...
  strip-description-html              With this command you can strip html tags in description field ...
  sync-dynamic-groups                 Synchronize dynamic group members
  system-autoincrement                Changes the initial autoincrement value for all i-doit database tables ...
  system-categorycleanup              Purges optionally category entries that are in the state unfinished, archived or deleted
  system-checkforupdates              Checks for i-doit core updates
  system-convert-non-innodb-tables    Converts all tables which are not in INNODB to INNODB ...
  system-convert-non-utf8-tables      Changes all non-UTF8-tables to UTF8 ...
  system-location-fix                 Performs the location fix from the systemtools GUI
  system-objectcleanup                Purges optionally objects that are in the state unfinished, archived or deleted
  system-objectrelations              Regenerates all object relation names
  system-refresh-table-configuration  Refreshes all available list configurations (object types and categories)
  system-set-settings                 Set system settings
  tenant-disable                      Disables the tenant with specific id
  tenant-enable                       Enables the tenant with specific id
  tenant-list                         Shows list of available tenants
  tenant-remove                       Remove the i-doit Tenant
  tenant-set-settings                 This command enables you to set tenant related settings by providing a settings list based on json
  uninstall                           Uninstall the i-doit application
  update                              Update the i-doit application
 idoit
  idoit:feature-manager               [idoit:fm] With this command it will be possible to activate a set of features in i-doit.
  idoit:set-env-var                   With this command it will be possible to set environmental variables for i-doit.
  idoit:set-update-capability         Dis- and enable the i-doit update capability
 logbook
  logbook:archive                     [logbook-archive] Archive Logbook entries that precede a certain interval (settings are defined in the GUI)
 system
  system:tenant-export                Export your tenant data inluding uploaded files in a ZIP package.
  system:tenant-import                Import your tenant data inluding uploaded files from a ZIP package generated from the system:tenant-export command.

open 版能力边界(实测):清单中没有 ldap-sync、report-export、import-csv 等命令(KB 示例里出现的那些属 Pro/插件);notifications-* 与 sync-dynamic-groups 虽在清单中,但 open 运行即抛 Class not found(见排障实录)。

高频命令逐条实测

租户管理:tenant-list / tenant-disable / tenant-enable

root@idoit-server:/var/www/html/i-doit# php console.php tenant-list
Available tenants:
+----+-----------+------------------+------------+----------+
| ID | Title     | (host:port)      | database   | [status] |
+----+-----------+------------------+------------+----------+
| 1  | quzuo-lab | (localhost:3306) | idoit_data | active   |
+----+-----------+------------------+------------+----------+

停用/启用租户(维护窗口用,停用后该租户用户无法登录)。注意 -i 是租户 ID,且必须带应用管理员凭据,否则 Authorisation: failed → Disable Tenant: Undo:

root@idoit-server:/var/www/html/i-doit# php console.php tenant-disable -n -u admin -p q1w2e3r4 -i 1
 ------------------------------- --------
  Message                         Result
 ------------------------------- --------
  Disable Tenant                  OK
  Disable Tenant 1: deactivated   OK
 ------------------------------- --------
root@idoit-server:/var/www/html/i-doit# php console.php tenant-enable -n -u admin -p q1w2e3r4 -i 1
 ---------------------------- --------
  Message                      Result
 ---------------------------- --------
  Disable Tenant               OK
  Enable Tenant 1: activated   OK
 ---------------------------- --------

(tenant-enable 汇总表首行仍印 Disable Tenant OK,是命令复用父类的显示瑕疵,不影响结果——实测状态确实回到 active。)

search-index 删除并重建全文索引,--dry-run 先评估规模(实测节选,租户库初始种子数据下):

root@idoit-server:/var/www/html/i-doit# php console.php search-index --dry-run -u admin -p q1w2e3r4 -i 1
Start Indexing!

Finished reading 26 rows
Start mapping 26 rows to 70 documents for "General" (C__CATG__GLOBAL)
32 of 70 documents were skipped!
...
Finished indexing!

0 rows got read!
154 documents got mapped!
88 documents got skipped while mapping, because of empty data!
0 documents got inserting!
0 documents of inserted documents got skipped because they were duplicated!

search 直接在终端查索引(结果表为空说明索引未建或无命中):

root@idoit-server:/var/www/html/i-doit# php console.php search --searchString server -u admin -p q1w2e3r4 -i 1
+----+-----+-------------+-------+
| ID | Key | Found Match | Score |
+----+-----+-------------+-------+
Search process took 0.0049s.

会话清理:auth-cleanup

清理过期的 auth path(登录会话残留),日常巡检用:

root@idoit-server:/var/www/html/i-doit# php console.php auth-cleanup -u admin -p q1w2e3r4 -i 1
Auth paths cleanup initialized (2026-11-03 04:51:28)
Cleanup done.

合同维护:contracts-outdated / extend-contracts

按"合同到期日"批量更新状态、按"通知期"自动顺延,适合每日 cron:

root@idoit-server:/var/www/html/i-doit# php console.php contracts-outdated -u admin -p q1w2e3r4 -i 1
Contracts status update starts...
Found 0 outdated contracts
Contracts status update finished
root@idoit-server:/var/www/html/i-doit# php console.php extend-contracts -u admin -p q1w2e3r4 -i 1
Looking for contracts where 'Runtime period' is set and 'End of contract by' equals 'Notice of termination'.
Found 0 contracts to be processed.

日志归档:logbook:archive

把超过阈值(GUI 系统设置中定义,默认 90 天)的变更日志移入归档表,控制 logbook 主表膨胀:

root@idoit-server:/var/www/html/i-doit# php console.php logbook:archive -u admin -p q1w2e3r4 -i 1
Logbook archiving-handler initialized - 2026-11-03 04:51:29

Using local database
Archiving all entries older than 90 days (older than 2026-08-05 00:00:00)
Process will be done in 1000 entry batches
About to move 0 logbook entries
Memory peak: 24 MB

Finished the process - 2026-11-03 04:51:29

数据清理与表维护

root@idoit-server:/var/www/html/i-doit# php console.php system-objectcleanup --objectStatus 1 -u admin -p q1w2e3r4 -i 1
Starting cleanup...
Unused objects with status unfinished deleted Total of 0.
Done
root@idoit-server:/var/www/html/i-doit# php console.php system-refresh-table-configuration -a -u admin -p q1w2e3r4 -i 1
Starting refreshing...
Done

system-objectcleanup 按状态清理未使用对象(--objectStatus 支持逗号分隔多状态);system-refresh-table-configuration -a 重置全部列表视图配置(列宽/排序异常时有效)。system-convert-non-innodb-tables 不带 --convert 时是只列不改的安全模式,建议先跑一遍再决定:

root@idoit-server:/var/www/html/i-doit# php console.php system-convert-non-innodb-tables -u admin -p q1w2e3r4 -i 1
You did not pass the --convert option, the following output will only list the affected tables and NOT convert them to engine INNODB.

All tables are using the INNODB engine, no need for any conversion!

Processed 0 tables, 0 successful and 0 failed.

同类"慎用"命令还有 system-autoincrement(改全局自增起点,影响对象 ID)、system-convert-non-utf8-tables、system-categorycleanup、strip-description-html——上线初期先 --help 看清参数再执行。

应用设置:system-set-settings

参数是 JSON 映射 -s '{"key":"value"}'(不是 --key/--value),实测改时区并回读数据库验证(详见配置篇第二节):

root@idoit-server:/var/www/html/i-doit# php console.php system-set-settings -n -s '{"system.timezone": "Asia/Shanghai"}' -u admin -p q1w2e3r4
 --------------------------------------------------------------- --------
  Message                                                         Result
 --------------------------------------------------------------- --------
  Set system settings                                             OK
  Set system settings: 'system.timezone' set to 'Asia/Shanghai'   OK
 --------------------------------------------------------------- --------

用户凭据清理:clear-credentials

离职用户场景:删除人员对象"登录"类别里的密码(加 --include-username 连用户名一起清):

root@idoit-server:/var/www/html/i-doit# php console.php clear-credentials --help
It removes both attributes username and password from the users "login" category

Usage:
  clear-credentials [options]
  clear-credentials --object 123
  clear-credentials --object 123 --include-username
  clear-credentials --object 123,456,789 --include-username

Options:
      --object=OBJECT      The object id of the user
      --include-username   Clear the username, additionally to the password

导入:import-xml / import-hinventory / import-syslog

import-xml 走 i-doit XML 交换格式(--importFile=<file>),import-hinventory 兼容 hInventory XML,import-syslog 把 Syslog 文本文件灌入 Logbook。三者均接受 -u/-p/-i/-c 标准凭据组,适合做批量初始化的 cron 前置任务。

租户整库导出:system:tenant-export

导出租户数据库 + 附件文件为单个 zip(比 mysqldump 多覆盖了 upload/ 目录),是迁移与冷备的官方通道:

root@idoit-server:/var/www/html/i-doit# php console.php system:tenant-export -u admin -p q1w2e3r4 -i 1
Writing idoit.json file
Writing system.settings.json file
Writing tenant.settings.json file
Dump tenant database, this may take a moment...
...
Copy object type images...
All files collected!
Create idoit-tenant-export-1.zip file, located in /var/www/html/i-doit/temp/.

All done!
The exported files have been zipped into /var/www/html/i-doit/temp/idoit-tenant-export-1.zip.

实测产物 temp/idoit-tenant-export-1.zip(110186 字节)。重名文件会拒绝覆盖:Export file ... already exists.——先移走旧包再导出。恢复侧对应 system:tenant-import。

备份与恢复实操

i-doit 的完整状态 = 两个库 + 三个目录:系统库 idoit_system(9 张表)、租户库 idoit_data(实测 466 张表)、src/config.inc.php(连接与哈希)、upload/(附件)、log/+temp/(可再生,可不备)。

mysqldump 备份(实测)

root@idoit-server:~# mkdir -p /var/backups/idoit && cd /var/backups/idoit
root@idoit-server:/var/backups/idoit# mysqldump -uroot -pq1w2e3r4 --single-transaction --routines --triggers idoit_system > idoit_system_$(date +%F).sql
root@idoit-server:/var/backups/idoit# mysqldump -uroot -pq1w2e3r4 --single-transaction --routines --triggers idoit_data > idoit_data_$(date +%F).sql
root@idoit-server:/var/backups/idoit# ls -la
total 1108
-rw-r--r-- 1 root root 987355 Nov  3 03:52 idoit_data_2026-11-03.sql
-rw-r--r-- 1 root root 133120 Nov  3 03:52 idoit_system_2026-11-03.sql

附件目录用 tar 一并带走:tar czf upload_$(date +%F).tgz -C /var/www/html/i-doit upload。

恢复演练(实测)

恢复到校验库,比对表数后删除,不动生产:

root@idoit-server:/var/backups/idoit# mysql -uroot -pq1w2e3r4 -e "CREATE DATABASE idoit_data_verify CHARACTER SET utf8mb4;"
root@idoit-server:/var/backups/idoit# mysql -uroot -pq1w2e3r4 idoit_data_verify < idoit_data_2026-11-03.sql
root@idoit-server:/var/backups/idoit# mysql -uroot -pq1w2e3r4 -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='idoit_data_verify';"
+-----+
| 466 |
+-----+
root@idoit-server:/var/backups/idoit# mysql -uroot -pq1w2e3r4 -e "DROP DATABASE idoit_data_verify;"

466 张表与生产一致,备份可用。真灾难恢复时:建库 → 导入 → 把 src/config.inc.php 与 upload/ 放回原位 → chown -R www-data:www-data /var/www/html/i-doit → 登录验证。

备份 cron 化(实测环境已挂)

5 1 * * * php /var/www/html/i-doit/console.php search-index -c /var/www/html/i-doit/auth-cleanup.ini > /var/www/html/i-doit/log/search-index.log 2>&1

mysqldump 任务可同样加入 root crontab,保留策略建议:日备 7 天 + 周备 4 周 + system:tenant-export 月备一份异地。

升级流程(update 命令实测)

38 是当前 open 最新版,无法演示跨版本升级,但 update 命令的升级前检查可完整实测。update 必须给目标版本 --v(否则报 Following options has to be defined: v),-z <zip> 指定更新包,--check-versions 输出环境核查表:

root@idoit-server:/var/www/html/i-doit# php console.php update -n -u admin -p q1w2e3r4 --v 38 --check-versions
 ------------------------------------------------------------- --------
  Message                                                       Result
 ------------------------------------------------------------- --------
  i-doit update                                                 OK
  Environment Check                                             OK
  PHP Check                                                     OK
  PHP recommended check Version 8.3.36: >=8.4:  failed          WARN
  Configuration                                                 OK
  Ini Setting: max_input_vars > 10000:  failed                  WARN
  Ini Setting: post_max_size > 128M:  failed                   WARN
  php-ext: mod_rewrite:  failed                                 WARN
  Sql Check                                                     OK
  MariaDB recommended check Version 10.6.23: >=10.11:  failed   WARN
  Process update                                                OK
  File:  should exist:  failed                                  FAIL
  i-doit update: Undo                                           OK
  Process update: Undo                                          OK
  Environment Check: Undo                                       OK
  Sql Check: Undo                                               OK
  PHP Check: Undo                                               OK
  Configuration: Undo                                           OK
 ------------------------------------------------------------- --------

解读(全部来自实测):

  • WARN 项是推荐值未达:PHP 推荐 ≥8.4(当前 8.3.36 属支持范围)、MariaDB 推荐 ≥10.11(当前 10.6.23 属支持范围)、max_input_vars/post_max_size 要求严格大于 10000/128M(与安装器的"≥"判定不同,恰好等于 10000/128M 也会 WARN)。
  • php-ext: mod_rewrite: failed 是 CLI 上下文探测不到 Apache 模块所致,Web 端已 a2enmod rewrite 且 .htaccess 生效(见部署篇第四步),可忽略。
  • 末行 File: should exist: FAIL 是因为没给 -z 更新包;检查失败后整体 Undo,不留半成品,可放心试跑。

标准升级动作(open 38 实测的机制 + 官方文档流程):① 完整备份(上节);② 下载新版 zip;③ 停写入(tenant-disable 或停 Apache);④ 解压覆盖代码但保留 src/config.inc.php;⑤ php console.php update -n -u admin -p q1w2e3r4 --v <新版本号> -z <更新包> 或按 updates/ 目录向导执行库结构迁移;⑥ chown -R www-data:www-data;⑦ 登录验证 + search-index 重建索引。$g_enable_gui_update='1' 时也可在 Web Admin Center 内完成更新(配置篇第一节)。

卸载:uninstall(实测)

删除全部租户(含租户库)、系统库与 src/config.inc.php,代码文件保留。交互模式有确认提示,-n 直接执行——务必先备份:

root@idoit-server:/var/www/html/i-doit# php console.php uninstall -n -u admin -p q1w2e3r4
 -------------------------- --------
  Message                    Result
 -------------------------- --------
  i-doit uninstallation      OK
  Remove Tenant 1: deleted   OK
  Drop System DB             OK
  Remove Config              OK
 -------------------------- --------

实测卸载后状态:src/config.inc.php 消失、SHOW DATABASES 中 idoit 库全部清空、访问 http://localhost:8137/i-doit/ 返回 <title>i-doit Installation</title>(应用检测到无配置,自动落到 Web 安装向导)。DB 账号 idoit 及其授权不会被回收,需要的话手动 DROP USER 'idoit'@'localhost';。

排障实录

实录 1:system-checkforupdates 在 open 38 上必崩。

root@idoit-server:/var/www/html/i-doit# php console.php system-checkforupdates
Checking... Please wait..
PHP Fatal error:  Uncaught Error: Undefined constant "idoit\Console\Command\Idoit\C__IDOIT_UPDATES" in /var/www/html/i-doit/src/idoit/Console/Command/Idoit/UpdateCheckCommand.php:102

根因(源码实测):C__IDOIT_UPDATES 定义在 src/classes/modules/open/init.php,console 上下文不加载该模块初始化,命令取默认值即触发未定义常量致命错误。结论:open 版不要依赖此命令查更新,改看 SourceForge 项目 files 页或官网 changelog;升级前检查用 update --check-versions(上节实测可用)。

实录 2:admin-center-password-reset 加 -n 会写出空密码哈希。

该命令的"新密码"是隐藏输入(setHidden(true)),-n 下问题返回默认值 null,两次 null 相等通过校验,结果把 $g_admin_auth 写成了空密码哈希、并重新生成了 $g_crypto_hash(实测 diff 只有这两行变化)——后者会导致应用设置里已加密的 SMTP/LDAP 凭据无法解密。恢复方法(实测有效):

root@idoit-server:~# H=$(php -r "echo password_hash(\"q1w2e3r4\", PASSWORD_BCRYPT, [\"cost\"=>10]);")
root@idoit-server:~# python3 - "$H" <<'PY'
import re,sys
h=sys.argv[1]
p="/var/www/html/i-doit/src/config.inc.php"
s=open(p).read()
s=re.sub(r"'admin' => '[^']*',", f"'admin' => '{h}',", s)
open(p,"w").write(s)
PY
root@idoit-server:~# chown www-data:www-data /var/www/html/i-doit/src/config.inc.php

结论:admin-center-password-reset 只在真实终端里交互执行,永远不要配 -n。 实测该命令执行前会在 src/ 留下带时间戳的旧配置备份(本次事故产物:config.inc.20261103114519.php,其中保留了原 $g_admin_auth 与 $g_crypto_hash),误跑后可从备份文件找回旧哈希恢复;若备份也丢了,则需重新录入 SMTP/LDAP 等加密凭据。

实录 3:notifications-send / notifications-list / sync-dynamic-groups 报 Class not found。

Class "isys_notifications_dao" not found
Class "isys_cmdb_dao_category_s_group_type" not found

通知与动态组依赖 Pro/插件模块,open 38 源码树中不存在这些类(实测 grep 全库无定义)。命令虽在 list 中,但 open 上不可用,不要挂进 cron。

实录 4:cron/CLI 用 root 跑完后 Web 端报权限错误。

root 执行 search-index、tenant-export 等会在 temp/、log/ 生成 root 属主文件(实测 temp/idoit-tenant-export-1.zip -rw-r--r-- root root),www-data 无法覆盖。统一用 sudo -u www-data php console.php ... 执行(本文环境实测可行),或每次跑完 chown -R www-data:www-data /var/www/html/i-doit。

实录 5:命令报 Authorisation: failed 并 Undo。

九成是凭据类型用错:租户管理类命令要 DB root(install/tenant-*),业务命令要应用管理员(-u admin -p <登录密码>),tenant-disable/enable 属后者(实测不带 -u/-p 即失败)。先 --help 看选项再执行。

小结

console.php 是 i-doit open 运维的中枢:install/tenant-create 完成初始化,search-index/logbook:archive/contracts-outdated/auth-cleanup 撑起日常 cron,system:tenant-export + mysqldump 双通道做备份,update --check-versions 做升级前核查,uninstall 干净退场。记住三条铁律(-n、分凭据、ini 外置)和五个实测坑,绝大多数 CLI 问题可以避免。选型背景与 open/Pro 功能边界,见《i-doit 介绍与选型指南》。

i-doit 38 常用 CLI 命令与运维实操 - Quzuo