Review Board 8.1 常用 CLI 与运维命令详解

系统整理 Review Board 8.1 命令行运维:rb-site 三大子命令、manage 高频命令、扩展与数据库演进管理、export-db/mysqldump 备份导出、rbssh 用法、rb-site upgrade 升级步骤与日志排障速查,全部命令与回显实测。

Review BoardReview Board代码审查Python 编程DevOps工程2026/10/28

Review Board 8.1 常用 CLI 与运维命令详解

目标:系统整理 Review Board 8.1 的三个命令行工具——站点生命周期工具 rb-site(install / manage / upgrade)、Django 管理命令集 rb-site manage(60 余个子命令的高频子集)、SSH 辅助工具 rbssh,并给出数据库备份导出(export-db / mysqldump)、升级流程、日志排障的完整实操实录。全部命令与回显均来自真实站点(2026-10-28)。安装与配置分别见 《Review Board 8.1 Ubuntu 22.04 安装指南》 与 《Review Board 8.1 配置参数详解》。

一、环境信息

项目值
操作系统Ubuntu 22.04.5 LTS
Review Board8.1(rb-site 8.1 / Python 3.10.12)
站点目录/opt/reviewboard/site
虚拟环境/opt/reviewboard/venv
数据库MySQL 8.0.46(库名 reviewboard,账号 reviewboard / q1w2e3r4)
服务托管systemd reviewboard.service(uWSGI,www-data 运行)
管理员账号admin / q1w2e3r4

约定:下文 RB 指代完整命令前缀 /opt/reviewboard/venv/bin/rb-site;管理命令统一写全形 rb-site manage /opt/reviewboard/site <子命令>。

二、命令行工具总览

Review Board 8.1 的命令行入口只有 rb-site 一个(另有独立的 rbssh),--help 实测全文:

usage: rb-site [-h] [-d] [--version] [--no-color] [--noinput]
               {install,manage,upgrade} ...

  rb-site helps create, upgrade, and manage Review Board installations (or
  "sites"). A site is located on the local file system, identified as a
  directory, which you'll pass to all rb-site commands.

options:
  -h, --help            show this help message and exit
  -d, --debug           display debug output
  --version
  --no-color            disable color output in the terminal
  --noinput             run non-interactively using configuration provided in
                        command-line options

subcommands:
  {install,manage,upgrade}
    install             install a new Review Board site, setting up the
                        database and web server configuration
    manage              run a management command on the site
    upgrade             upgrade an existing site to Review Board 8.1
# rb-site --version
Review Board/rb-site 8.1

三个子命令的分工:install 建站(见安装指南)、upgrade 升级(第九章)、manage 承载日常运维(它把 Django 的 manage.py 全部子命令在站点上下文中执行)。manage 的完整子命令清单实测(10 组,按功能归类节选):

分组命令用途
reviewsfill-database、fixreviewcounts、reset-issue-counts、clean-orphaned-data、index数据修复与重建索引
diffviewerfind-large-diffs、condensediffs大 diff 扫描与合并
extensionslist-extensions、enable-extension、disable-extension、install-extension-media扩展管理
siteconfiglist-siteconfig、get-siteconfig、set-siteconfig站点配置读写
importexportexport-db、import-db数据库导出导入
django_evolutionlist-evolutions、evolve、mark-evolution-applied数据库结构演进
haystackupdate_index、rebuild_index、clear_index、haystack_info全文搜索索引
authchangepassword、createsuperuser账号管理
sessionsclearsessions过期会话清理
djangodbshell、shell、showmigrations、diffsettings、sendtestemail 等Django 框架命令

完整清单可在服务器上执行 rb-site manage /opt/reviewboard/site help 查看。

三、rb-site install:站点创建与非交互安装

rb-site install 的 15 问交互实录见安装指南第六章。批量/脚本化场景可用 --noinput 非交互模式,关键参数实测自 rb-site install --help:

参数说明
<site-path>站点目录,如 /opt/reviewboard/site
--domain-name / --site-root域名与路径前缀(对应交互的 Domain Name / Root Path)
--db-type / --db-name / --db-host / --db-user / --db-pass数据库五件套
--cache-type {memcached,file} / --cache-info缓存类型与连接串
--allowed-host HOSTNAME额外域名白名单,可多次提供
--admin-user / --admin-password / --admin-email管理员账号三件套
--company组织名
--secret-key显式指定 50 位密钥(多机共用数据库时必传且须一致)
--opt-in-support-data / --opt-out-support-data支持数据收集开关(默认 opt-out)
--sitelist站点登记清单文件路径(默认 /etc/reviewboard/sites)
--allow-non-empty-sitedir允许装入非空目录(官方标注危险,慎用)

要点:非交互安装前同样要先装好数据库驱动(pip install "ReviewBoard[mysql]")并建库授权,原因与复现见安装指南排障章 11.1。

四、rb-site manage 高频运维命令

统一前缀省略写法:以下命令均在站点服务器以 root 执行 rb-site manage /opt/reviewboard/site <子命令>。

4.1 账号管理

# 修改指定用户密码(交互式,会两次要求输入新密码且不回显)
... changepassword admin
# 创建超级用户(交互式:用户名/邮箱/密码)
... createsuperuser

两条命令均为交互式输入,无回显输出,执行后立即生效,无需重启服务。

4.2 数据库直连与 shell

# 用站点配置里的连接串直接进数据库命令行(等价 mysql -u reviewboard -p reviewboard)
... dbshell
# 进入带 Django ORM 的 Python shell
... shell

4.3 会话与索引维护

# 清理已过期的会话记录(官方 cron 每日 2 点自动执行)
... clearsessions
# 增量更新全文搜索索引(官方 cron 每 10 分钟自动执行,-a 1 表示最近 1 天)
... update_index -- -a 1
# 重建整个搜索索引
... rebuild_index

官方生成的 conf/cron.conf 实测内容(对应上面两条维护命令的定时化):

# Update search index every 10 minutes
0,10,20,30,40,50 * * * * "/opt/reviewboard/site/venv/bin/rb-site" manage "/opt/reviewboard/site" update_index -- -a 1

# Clear expired sessions once a day at 2am
0 2 * * * "/opt/reviewboard/site/venv/bin/rb-site" manage "/opt/reviewboard/site" clearsessions

4.4 数据修复命令

命令用途
fill-database从各仓库补抓提交信息,重建数据库中的历史数据
fixreviewcounts重算各评审请求分组的计数(显示数不准时用)
reset-issue-counts重置评审请求的议题(issue)计数
clean-orphaned-data清理无引用的孤立数据
condensediffs合并历史 diff 存储以省空间

五、扩展管理命令

list-extensions 实测全文(全新安装自带两个官方扩展,均处启用态):

* Name: rbintegrations
  Status: enabled
  ID: rbintegrations.extension.RBIntegrationsExtension

* Name: ReviewBoardPowerPack
  Status: enabled
  ID: rbpowerpack.extension.PowerPackExtension

配套命令:enable-extension <ID> 启用、disable-extension <ID> 停用、install-extension-media 安装/刷新扩展的静态媒体文件(升级扩展后执行)。扩展的 ID 即 list-extensions 输出的 ID: 行。

六、数据库演进(evolution)命令

Review Board 的数据库结构变更由 django_evolution 管理。list-evolutions 实测回显(全新安装时已应用的演进):

Applied evolutions for 'admin':
    admin_move_to_migrations

Applied evolutions for 'auth':
    auth_delete_message
    auth_unique_together_baseline
    auth_move_to_migrations

Applied evolutions for 'contenttypes':
    contenttypes_unique_together_baseline
    contenttypes_move_to_migrations

Applied evolutions for 'sites':
    sites_move_to_migrations

Applied evolutions for 'sessions':
    session_expire_date_db_index
    sessions_move_to_migrations

Applied evolutions for 'djblets_extensions':
    update_app_label

Applied evolutions for 'djblets_privacy':
    audit_indentifier
    update_app_label

配套:evolve 执行待应用演进(升级后通常由 rb-site upgrade 自动完成)、mark-evolution-applied 手动标记演进为已应用(跳过执行,排障用)。日常运行中一般不需要手动碰这组命令。

七、数据导出与备份

7.1 export-db / import-db:跨库导出

export-db 生成数据库无关的导出包,可导入任何类型数据库的 Review Board(不能导入更老版本)。实测全库导出:

# rb-site manage /opt/reviewboard/site export-db -o /tmp/rb-export
Writing 0 users...
Writing 0 review groups...
Writing 0 hosting service accounts...
Writing 0 repositories...
Writing 0 WebHooks...
Writing 0 default reviewers...
Writing 0 review requests...
Writing 0 starred review groups...
Writing 0 starred review requests...
Writing 0 review request visits...

产物为目录式 bundle(实测内容):

/tmp/rb-export/bundle/   # 导出主体
    bundle_version
    default-reviewers.dat
    diffs
    diffs-index.dat
    files
    hosting-service-accounts.dat
    rb_version
    repositories.dat
    ...
/tmp/rb-export/key       # 站点 SECRET_KEY 相关密钥文件,导入端需要

常用参数(export-db --help 实测):-o OUT_DIR 输出目录、-r ID1[,ID2,...] 按评审请求 ID 导出部分数据、--all-users 导出全部用户、--review-requests-file FILENAME 按清单导出。官方注意事项(help 原文要点):导出过程不加数据库锁,大库导出前建议在 General Settings 开只读模式,或直接从备份导出。恢复端用 import-db 导入。

7.2 mysqldump:原生全库备份

官方已废弃 dumpdb 命令(help 原文:"[No longer supported] ... Please use your database's native tools instead"),MySQL 部署的原生备份即 mysqldump。实测:

# mysqldump reviewboard > /tmp/rb-db-backup.sql
# ls -l /tmp/rb-db-backup.sql
-rw-r--r-- 1 root root 288507 Oct 28 00:29 /tmp/rb-db-backup.sql
# head -n 5 /tmp/rb-db-backup.sql
-- MySQL dump 10.13  Distrib 8.0.46, for Linux (x86_64)
--
-- Host: localhost    Database: reviewboard
-- ------------------------------------------------------
-- Server version	8.0.46-0ubuntu0.22.04.4

备份策略建议:每日 mysqldump 全库(库文件不大、恢复最快)+ 每周 export-db bundle(跨库迁移用)+ conf/ 目录(settings_local.py 含 SECRET_KEY,丢失即库中加密数据不可解,见配置参数详解 3.3)。恢复演练:mysql reviewboard < /tmp/rb-db-backup.sql 后 systemctl restart reviewboard。

八、rbssh:SSH 辅助工具

Review Board 通过仓库拉取 diff 时会用自带的 rbssh(基于 paramiko)代替系统 ssh。直接运行会因找不到站点配置报错(实测):

# /opt/reviewboard/venv/bin/rbssh --help
ERROR: Unable to import settings_local.py: No module named
       'settings_local'

解法:带 RBSITE_PYTHONPATH 环境变量指向站点 conf 目录后正常运行(实测 --help 全文):

# RBSITE_PYTHONPATH=/opt/reviewboard/site/conf /opt/reviewboard/venv/bin/rbssh --help
Usage: rbssh [options] [user@]hostname [command]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -l USERNAME           the user to log in as on the remote machine
  -p PORT, --port=PORT  the port to connect to
  -q, --quiet           suppress any unnecessary output
  -s SUBSYSTEM          the subsystem to use (ssh or sftp)
  -V                    display the version information and exit
  --rb-disallow-agent   disable using the SSH agent for authentication
  --rb-local-site=NAME  the local site name containing the SSH keys to use

配套命令 rb-site manage /opt/reviewboard/site import-ssh-keys 可把已有私钥导入 Review Board 的 SSH 密钥库(管理界面 SSH Settings 的命令行等价物)。

九、rb-site upgrade:升级流程

软件包升级后必须对每个站点执行 rb-site upgrade(站点目录结构、数据库结构、媒体文件随之迁移)。--help 实测全文:

usage: rb-site upgrade [-h] [-d] [--version] [--no-color] [--noinput]
                       [--copy-media] [--no-db-upgrade] [--all-sites]
                       [--sitelist SITELIST]
                       [<site-path>]

  This will upgrade your existing Review Board site directory, applying any
  changes needed to your database, configuration, and media files to move to a
  newer version of Review Board.

  An upgrade is required any time the Review Board software has been upgraded.
  Please note that an upgrade may take some time.

positional arguments:
  <site-path>          the path to the Review Board site directory

options:
  -h, --help            show this help message and exit
  -d, --debug           display debug output
  --version
  --no-color            disable color output in the terminal
  --noinput             run non-interactively using configuration provided in
                        command-line options
  --copy-media          copy media files instead of symlinking
  --no-db-upgrade       don't upgrade the database
  --all-sites           Upgrade all installed sites
  --sitelist SITELIST   the path to a file storing a list of installed sites

标准升级步骤(生产顺序):

  1. 备份数据库与 conf/ 目录(第七章);
  2. venv 内升级包:/opt/reviewboard/venv/bin/pip install --upgrade ReviewBoard(锁定版本时写 ReviewBoard==<目标版本>);
  3. 停服务:systemctl stop reviewboard;
  4. 执行站点升级:/opt/reviewboard/venv/bin/rb-site upgrade /opt/reviewboard/site(多站点可加 --all-sites);
  5. 启服务并验证:systemctl start reviewboard 后按安装指南第十章做 Web/API 三关验证。

--no-db-upgrade 仅迁移文件不动库(需分步操作时用);--copy-media 把媒体从符号链接改为实体拷贝。

十、日志与排障

10.1 日志文件分布

站点 logs/ 目录实测三件套:

nginx_access_log    # Nginx 访问日志
nginx_error_log     # Nginx 错误日志
reviewboard.log     # Review Board 应用日志

应用日志一行实测样例:

2026-10-28 00:29:11,539 - DEBUG -  - reviewboard.scmtools.clearcase - Using cleartool cleartool

格式为 时间 - 级别 - 模块 - 消息。属主或权限不对时日志写不进文件、降级走 stderr,现象与修复见安装指南排障章 11.3。

10.2 systemd 层日志

uWSGI 的启动/进程日志在 journal:

# journalctl -u reviewboard -n 8 --no-pager
Oct 28 00:46:51 <主机名> uwsgi[3593]: spawned uWSGI worker 3 (pid: 3599, cores: 30)
Oct 28 00:46:51 <主机名> uwsgi[3593]: spawned uWSGI worker 4 (pid: 3639, cores: 30)
...
Oct 28 00:46:55 <主机名> uwsgi[3716]: [pid: 3716|app: 0|req: 1/1] 127.0.0.1 () {32 vars in 355 bytes} [Wed Oct 28 00:46:55 2026] HEAD / => generated 0 bytes in 678 msecs (HTTP/1.1 302) 9 headers in 284 bytes (2 switches on core 5)

每条请求的处理进程、耗时、状态码都在这层可见,是排查慢请求与 5xx 的第一入口。

10.3 大 diff 扫描:find-large-diffs

不带参数直接跑会报错(实测):

CommandError: Either --num-days or --start-id must be specified.

带参数运行(--num-days 365 扫最近一年,确认提示回车 Y;实测):

# rb-site manage /opt/reviewboard/site find-large-diffs --num-days 365
This will scan 0 review requests. Continue? [Y/n] Y
Review Request ID,Last Updated,User ID,Max Files,Max Diff Size,Max Parent Diff Size,Diffset ID for Max Files,Diffset ID for Max Diff Size,Diffset ID for Max Parent Diff Size

输出为 CSV,可直接重定向存档,用于定位拖慢页面的大 diff(配合配置侧 diffviewer_* 参数调优,见配置参数详解第九章)。

10.4 排障速查表

现象先看哪里命令
服务起不来/反复重启journaljournalctl -u reviewboard -n 50 --no-pager
页面 5xx应用日志tail -n 50 /opt/reviewboard/site/logs/reviewboard.log
请求 400settings_local.py核对 ALLOWED_HOSTS(安装指南排障章 11.2)
Nginx 502socket 状态ls -l /opt/reviewboard/site/data/uwsgi.sock
缓存失联变慢memcachedprintf "version\r\n" | nc 127.0.0.1 11211
搜索结果过期索引任务手动 ... update_index -- -a 1
忘记管理员密码账号命令... changepassword admin

十一、参考链接


本系列其余篇目:组件定位与同类对比见 《Review Board 介绍与选型指南》;安装全流程实测见 《Review Board 8.1 Ubuntu 22.04 安装指南》;配置参数逐项解释见 《Review Board 8.1 配置参数详解》。