Docs: CLI tools

Command-line tools

The command-line tools Tilspire ships with: scheduled jobs, migrations, backups, updates, content sync, off-site restores and installing, and a nightly schedule.

These scripts cover the tasks you might want to run by hand or from a scheduled task. The examples run from your site's root folder.

Scheduled jobs #

Since 1.15.0 Tilspire has one runner for its regular jobs: email digests, off-site backups and their restore test, the search index, and clearing old chats and decided proposals. Run it every 5 minutes:

php core/cli/cron.php
  • --status: list every job and its state, change nothing.
  • --verbose: say what ran.
  • --only=<id>: run one job now.

Run quietly, it prints only failures, so a cron mails you only when something broke.

It is optional, and stays so in 1.21.0, which adds jobs that also run from page visits: ban expiry (every 15 minutes), webhooks, social posting, recycle bin cleanup (daily), export file cleanup (hourly) and profile picture thumbnails. Since 1.17.1 the site runs its due jobs itself, from visits and from an open admin panel, and they also run whenever update.php --auto does. Since 1.20.0 only off-site backups are the exception: they run only from this runner or from update.php --auto. Email digests and automatic forum moderation also run from page visits, and stop at the time a visit has left, so a cron gives them their full time. The dashboard's health check says so, as it says when a job is overdue.

Migrations #

Applies any database migrations that haven't run yet: the core's first, then each enabled module's.

php core/cli/migrate.php
php core/cli/migrate.php --status

--status lists what's waiting without applying anything.

Backup #

Writes a content backup — your pages, posts, menus, redirects, content-model templates and settings — to site/backups/, and keeps the newest 14. Secret settings, such as your SMTP password, are left out unless you ask for them:

php core/cli/backup.php
php core/cli/backup.php --include-secrets

This content backup leaves out the direct message tables and the recycle bin. The off-site archive below takes every table, messages included, and carries the bin.

A backup made with --include-secrets holds credentials, so store it like one. Neither kind contains the key that decrypts two-factor secrets, which lives in site/config/config.php: keep a copy of that file with your backups, or members who use two-factor sign-in can't sign in to a restored site. The same file holds the key for your AI providers' keys (since 1.13.0); without it a restored site only asks for each provider key again. It also holds the keys for sign-in providers (OAUTH_KEY, since 1.19.0), import sources (IMPORT_KEY, since 1.19.2), content sync (SYNC_KEY) and social posting (SOCIAL_KEY, since 1.21.0, made the first time a social account is connected). Keep the file with your backups like the other keys.

For complete, encrypted copies stored away from the server, see Off-site backups; php core/cli/offsite.php opens and restores them:

  • decrypt <archive> <out.tar.gz>: remove the encryption.
  • inspect <archive>: check the copy and say what it holds.
  • restore <archive> --yes: replace the tables; the old ones are kept as _tsold_ tables.
  • --files: with restore, bring uploaded files back too.
  • --force-version: with restore, accept a copy from another release.
  • --key-file=<file>: the key (the recovery kit works). Without it: BACKUP_KEY in the environment, else this site's config.php.

Update #

php update.php
php update.php --apply
php update.php --auto
php update.php --undo
php update.php --verify-promotion

With no option, it only checks. --apply installs an available update. --auto does what the Automatic updates setting on the Updates page allows — the one to run from a scheduled task. --undo undoes the last update, as the Updates page does. Run it from the site's root folder: since 1.13.0 update.php sits there, so it works on Windows as well as Linux. Whenever it may change your site, it also applies any waiting migrations, the core's and each enabled module's. Since 1.21.0 --apply and --auto install only from a feed answer fetched in that run. --verify-promotion is new: it is read-only, runs alone, and prints one line each for Stable and Preview, ok or FAIL, and exits 0 when both verify. It checks that this site accepts the promotion statements its feed serves now.

Content sync #

On a staging site, sends its changes to production as drafts for a person to approve there, as System ▸ Content sync does:

php core/cli/sync.php status
php core/cli/sync.php test
php core/cli/sync.php compare
php core/cli/sync.php push --yes
  • status: the connection to production and the newest run.
  • test: check the saved credential against production.
  • compare: list what a push would propose; sends nothing.
  • push --yes: send the changes as drafts. Without --yes nothing is sent.
  • --include-conflicts, --include-deletions: send those too.
  • --kinds=page,post,...: limit what is sent.

Install #

Installs Tilspire without a browser, running the same steps as the setup wizard. See Installation.

php core/cli/install.php --help
  • Give the site address, the database and the first administrator as options.
  • Passwords come only from files: --db-pass-file, --admin-pass-file. Or --generate-admin-pass with --admin-pass-out makes one.
  • --check: test everything, write nothing.
  • --json: print one JSON result.
  • It installs into an empty database only.
  • Exit codes: 0 installed, 1 refused or failed, 2 usage, 3 already installed.

A nightly schedule #

A typical crontab makes a backup first and updates afterwards:

15 3 * * * cd /path/to/site && php core/cli/backup.php
45 3 * * * cd /path/to/site && php update.php --auto
*/5 * * * * cd /path/to/site && php core/cli/cron.php