etherpad-lite/doc/cli.md
John McLear d6a55c2283
feat(7642): bin/compactStalePads — staleness-gated bulk compaction (#7708)
* feat(7642): bin/compactStalePads — staleness-gated bulk compaction

Adds bin/compactStalePads with --older-than / --keep / --dry-run.
Composes listAllPads → getLastEdited → compactPad so hot pads in
active timeslider use are left alone and only the cold tail is
compacted. Targeting stays a CLI concern; compactPad's API surface
is unchanged.

Per-pad failures (including a getLastEdited fault) don't stop the
run — same error-tolerance shape as compactAllPads. End-to-end test
plumbs through the real /api/1.3.1/getLastEdited + compactPad
endpoints to lock the adapter contract.

Daily-cron variant (cleanup.compactOlderThanDays setting) deferred
to a follow-up so this PR stays focused on the on-demand operator
tool from the issue's primary acceptance bullet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(7642): TOCTOU recheck before compaction + admin CLI docs

Qodo flagged two real issues:

1. Race window between staleness selection and compaction. On a long
   bulk run a pad could become active between first-pass filtering and
   compactPad, which would then kick those sessions. Added a getLastEdited
   recheck right before each compact call; if the pad is now fresh it's
   reclassified as skippedFresh rather than failed (the user did the
   right thing — edited it — and we bow out).

2. doc/cli.md had nothing on pad compaction at all (gap predates this
   PR; #6194 landed without doc updates). Added a Pad compaction section
   covering all three CLIs — compactPad, compactAllPads, compactStalePads
   — so the toolset is discoverable as a unit.

Tests cover both the recheck-skip path and a recheck-failure path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 22:41:52 +02:00

2.6 KiB

CLI

You can find different tools for migrating things, checking your Etherpad health in the bin directory. One of these is the migrateDB command. It takes two settings.json files and copies data from one source to another one. In this example we migrate from the old dirty db to the new rustydb engine. So we copy these files to the root of the etherpad-directory.

{
  "dbType": "dirty",
  "dbSettings": {
    "filename": "./var/rusty.db"
  }
}
{
  "dbType": "rustydb",
  "dbSettings": {
    "filename": "./var/rusty2.db"
  }
}

After that we need to move the data from dirty to rustydb. Therefore, we call pnpm run --filter bin migrateDB --file1 test1.json --file2 test2.json with these two files in our root directories. After some time the data should be copied over to the new database.

Pad compaction

Long-lived pads with heavy edit history accumulate revisions in the database. Three CLIs reclaim that space, in increasing scope:

Tool Targets When to use
bin/compactPad.js <padID> one pad you know which pad is fat
bin/compactAllPads.js every pad bulk reclaim across the whole instance
bin/compactStalePads.js --older-than N pads not edited in N days reclaim the cold tail without touching pads still in active use

All three are gated on cleanup.enabled = true in settings.json and are destructive: history is collapsed (or trimmed). Export anything you can't afford to lose with getEtherpad first.

Common flags:

  • --keep N — retain the last N revisions instead of collapsing all history.
  • --dry-run — list pads and revision counts without writing.

Examples

# Compact a specific pad, collapsing all history.
node bin/compactPad.js my-pad

# Keep only the last 50 revisions of one pad.
node bin/compactPad.js my-pad --keep 50

# Compact every pad on the instance (per-pad failures don't stop the run).
node bin/compactAllPads.js
node bin/compactAllPads.js --dry-run

# Compact only pads not edited in the last 90 days, keeping the last 50 revisions.
node bin/compactStalePads.js --older-than 90 --keep 50
node bin/compactStalePads.js --older-than 90 --dry-run

bin/compactStalePads.js is the right tool for periodic operator runs on long-lived instances — hot pads that users are still navigating in timeslider stay untouched, and only the cold tail is rewritten. Per-pad failures (including a getLastEdited fault) are counted but do not abort the bulk run; the exit code reflects whether anything failed.

See the compactPad HTTP API in doc/api/http_api.md for the same primitive over the wire (issues #6194, #7642).