BookStack System CLI
The BookStack System CLI allows easy running of BookStack infrastructure-level tasks such as backing up, restoring or updating. The CLI is distributed with the BookStack project source code, although the CLI is self-contained and can run independently of a BookStack instance.
Warning: The System CLI was added in BookStack v23.05 in an alpha state and currently remains in that non-production state until it has been well tested. Please use the CLI with caution, and ensure you fully & periodically test any processes where the CLI is relied upon.
CLI Usage
The CLI is included with the BookStack codebase, so you can usually run it like so:
The CLI is built using PHP. Depending on operating system and permissions, you may need to instead run it directly via PHP like so:
|
|
By default, without any arguments provided, the CLI will list the available commands which are documented in more detail below.
With any command, you can pass a -h
option to show additional per-command details and options.
Standalone Usage
It’s possible to use the CLI without it being part of a BookStack instance. This can be useful if using it to create a new BookStack install instance.
You can grab a copy of the CLI from the release
branch of the core project GitHub repo.
Below is how you might fetch the CLI, and make it globally available on the command line, on a Linux server:
|
|
Available Commands
backup
Backup a BookStack installation to a single compressed ZIP file.
By default this will attempt to backup anything that may be expected to be user-generated, or admin edited, within an install.
This includes a database dump of everything within the connected BookStack database instance, along with the current .env
file in use.
The backup will also attempt to include a copy of the CLI itself in the backup, so the exact same CLI can be used for restore where required.
Note that this won’t attempt backup of anything on remote systems, like those uploaded when BookStack is configured to use S3 file storage.
If a backup target output ZIP is not provided as a first additional argument, it will be saved to the storage/backups
folder, relative to
the BookStack root installation folder, with a name in the format:
|
|
When successful, the CLI will report the backup ZIP location upon completion.
Usage Examples
Command Options
--no-database
Skip inclusion of a database dump, containing your main BookStack content.--no-uploads
Skip backup of any local file or image uploads.--no-themes
Skip backup of any custom theme files.--app-directory=<path>
Provide a path to the BookStack instance to back up. When not provided, the CLI will attempt to locate the BookStack install based upon current working directory and the location of the CLI itself.
restore
Restore the provided ZIP file into an existing BookStack installation.
The ZIP file should be one created via the backup
command, or at least in a compatible format.
When ran, the command will attempt to resolve any APP_URL, or database, .env
changes that might need to be made
when the backed-up .env
file is restored.
Usage Examples
Command Options
--app-directory=<path>
Provide a path to the BookStack instance to back up. When not provided, the CLI will attempt to locate the BookStack install based upon current working directory and the location of the CLI itself.
update
Update the existing BookStack installation to the latest version. This runs an instance through the standard BookStack update commands to bring it up to the latest release version.
Usage Examples
Command Options
--app-directory=<path>
Provide a path to the BookStack instance to back up. When not provided, the CLI will attempt to locate the BookStack install based upon current working directory and the location of the CLI itself.
init
Initialize a new BookStack installation in the given folder.
This clones down the BookStack project, installs PHP dependencies, creates a fresh .env
file for editing, then generates a key for the .env
file.
Note that this won’t do everything for a new BookStack install, you’ll still need to configure your database details then migrate the database, and configure your system’s web-server (and any required permissions).
Usage Examples
CLI Source Code & Project
The CLI is maintained as its own project within the BookStackApp/system-cli GitHub project. There you can find the source code, development details and known issues.