Skip to content

Backup and restore

Your certificate authorities are among the most valuable things in your organization. If you lose them, you cannot issue or renew certificates, and every device and server that trusts them must be set up again. This page explains what to back up, how to do it while BastionXP runs, and how to restore.

This page is for people who run BastionXP themselves. If you use the BastionXP cloud service, BastionXP backs up your organization for you.

What you must back up

BastionXP keeps its state in three places. You need all three to restore.

What Where it is Why you need it
The data The database, and the other files in the data directory (/var/lib/bastionxp by default). It holds your root CA, your authorities and their keys (encrypted), your certificates, your users and the audit log.
The configuration file /etc/bastionxp/config.yaml It tells BastionXP how to connect to its database and its keys.
The key-encryption key (KEK) The file named by kek_file, for example /etc/bastionxp/kek. It decrypts the private keys in the database.

The KEK and the data must be backed up separately

The private keys of your CAs are in the database, but only in encrypted form. The KEK is the key that decrypts them. If one backup holds both the data and the KEK, a person who steals that backup gets your CA keys. So keep the KEK in a different place from the data backups, for example in a password manager or in a safe.

The opposite is also true. If you lose the KEK, you lose every certificate authority. The data is of no use without it. Make at least two copies of the KEK, in two safe places, when you create it.

BastionXP does not put the configuration file or the KEK in its backup, on purpose.

Back up the data

With SQLite, the default

Run bastionxp backup with a new folder as the destination:

sudo bastionxp backup --config /etc/bastionxp/config.yaml \
    --out /backup/bastionxp-$(date +%F)

The command prints:

Backed up 3 files from /var/lib/bastionxp to /backup/bastionxp-2026-11-28
Back up the configuration file and the KEK separately, never next to this backup.

The command:

  • is safe to run while BastionXP is running. It makes a consistent copy of the database, so you do not have to stop the server,
  • copies every file in the data directory, which includes the database and the server's own HTTPS certificate and key, and
  • makes the new folder readable only by its owner.

The backup folder contains the private key of the server's HTTPS certificate. Protect it like any private key, and encrypt it when you copy it off the machine.

With PostgreSQL

When BastionXP uses PostgreSQL, the database is not in the data directory. Back it up with PostgreSQL's own tool, pg_dump:

pg_dump --host db.example.com --username bastionxp --format custom \
    --file /backup/bastionxp-$(date +%F).dump bastionxp

Also run bastionxp backup, as above. In this case it copies only the other files of the data directory, such as the server's HTTPS certificate and key.

How often

Back up the data every day, and also right after you:

  • create a root CA or an authority,
  • rotate or replace a CA, and
  • change the key-encryption key.

You back up the KEK once, and again every time you rotate it. Back up the configuration file when you change it.

Copy the backups to another machine, and keep several generations. A backup that sits on the same disk as the data is lost with it.

Restore

To restore, you need the data backup, the configuration file and the KEK. Restore on the same machine or on a new one, with the BastionXP package installed.

With SQLite

  1. Stop BastionXP:

    sudo systemctl stop bastionxp
    
  2. Keep the current data directory, in case you need it:

    sudo mv /var/lib/bastionxp /var/lib/bastionxp.old
    
  3. Put the backup in its place. The folder must belong to the user that runs BastionXP, and only that user may use it:

    sudo cp -a /backup/bastionxp-2026-11-28 /var/lib/bastionxp
    sudo chown -R root:root /var/lib/bastionxp
    sudo chmod 700 /var/lib/bastionxp
    

    BastionXP runs as root when you install it from the package. If you run it as another user, use that user.

  4. Put the configuration file and the KEK back, if they are not on the machine, with the same paths as before. The kek_file setting must name the same KEK that the backup was made with.

  5. The data directory of the BastionXP packages also holds the files of the web portal (webapp/dist) and the bxp-cli downloads (download). The backup contains them. If you restore on a new machine from a newer package, install the package first, and copy only the database and the server certificate and key from the backup.

  6. Start BastionXP:

    sudo systemctl start bastionxp
    

With PostgreSQL

  1. Stop BastionXP.
  2. Restore the database with pg_restore, into an empty database:

    pg_restore --host db.example.com --username bastionxp \
        --dbname bastionxp --clean --if-exists /backup/bastionxp-2026-11-28.dump
    
  3. Restore the server's certificate and key into the data directory, from the backup that bastionxp backup made.

  4. Make sure the configuration file and the KEK are in place.
  5. Start BastionXP.

Check that the restore worked

Read the log:

sudo journalctl -u bastionxp --no-pager -n 30

You should see that the key-encryption key was loaded, and that the server started. If BastionXP does not start, and the message says that the KEK is not the one the database was encrypted with, you gave it the wrong KEK. The message shows the ID of the KEK that is needed. Find that KEK. See If BastionXP does not start.

Then open the portal, sign in, and check:

  • Authority Manager shows your root CA and your authorities.
  • Certificates shows your certificates.
  • Activity shows the events from before the backup.

Test your restore

A backup that you have never restored is a hope, not a backup. At least once, restore to a test machine, with the copies of the KEK and the configuration file that you keep, and check the three things above. Do it again after big changes. A test machine needs its own domain name and its own copy of the server certificate.

What you do not need to back up

If you run several servers with high availability, Redis holds only temporary data: ACME nonces, rate limit counters, portal sessions and change notices. Nothing in Redis needs to be restored. After a restore, administrators sign in again.