# Backup and restore

> Save and restore the databases, the stored files and the secrets of a server with the scansuite command.

Source: https://scansuite.eu/documentation/administration/backup-and-restore
Last reviewed: 2026-11-19

Back up and restore the ScanSuite and DefectDojo databases, the stored scan files, and the secrets (`.env` and `key/`: licence and encryption keys) with `./scansuite` in `/opt/scansuite`.

## Before you start

Run the commands as the account that installed ScanSuite. Check that it runs and the target has room:

```bash
cd /opt/scansuite && ./scansuite status    # every service Up; migrate Exited (0)
df -h <BACKUP_DIR>                        # e.g. /mnt/backup, best on another disk
```

## The commands

| Command | Does |
|---|---|
| ./scansuite --backup-db [zip or directory] | Saves both databases into one zip. |
| ./scansuite --restore-db <ZIP_FILE> | Replaces the databases with a backup. |
| ./scansuite --backup-secrets [zip or directory] | Saves .env and key/ into a password-protected zip. |
| ./scansuite --restore-secrets <ZIP_FILE> | Puts .env and key/ back. |

Also written `./scansuite backup db`, `restore db`, `backup secrets`, `restore secrets`. `<ZIP_FILE>` is the path the backup printed.

| Option | For | Effect |
|---|---|---|
| --with-files | backup db | Adds scan reports, artifacts and DefectDojo uploads. Stops file storage while copying; needs free space equal to the files. Off by default. |
| --encrypt | backup db | Password-protects the zip; the password is printed once, to a terminal only. Off by default. |
| --password-file <file> | all four | Reads the password from the file; a missing file is created with a new password (owner-only). Implies --encrypt on backup db. |
| --no-dojo | backup db | Leaves out DefectDojo (included when it runs). |
| --yes, -y | restore db, restore secrets | No confirmation prompt. |
| --no-safety-backup | restore db | Skips saving the present databases first. |
| --no-restart | restore secrets | No restart afterwards. |

Without a terminal (cron), a password-protected backup needs `--password-file`, or it is refused. Default location: `/opt/scansuite/backups/scansuite-teams-db-YYYYMMDD-HHMMSS.zip` (or `-secrets-`). A directory argument keeps that name; existing files are never replaced. Zips are owner-readable only.

> **Warning:** Copy the backups off the server: a backup on the disk it protects is lost with it.

## Back up the databases

```bash
cd /opt/scansuite && ./scansuite --backup-db <BACKUP_DIR>
```

ScanSuite keeps running. Expected: `[+] Databases saved to <ZIP_FILE> (size)`. `unzip -l <ZIP_FILE>` lists `MANIFEST`, `scansuite.dump`, `defectdojo.dump` (if DefectDojo runs) and `files/` (with `--with-files`).

> **Note:** Without --with-files, a restore brings back scans and findings but not the stored report files.

### A nightly backup

In `sudo crontab -e`: a protected backup at 02:00 and deletion of database backups older than 14 days. The first run creates the password file; later runs reuse it.

```bash
0 2 * * * cd /opt/scansuite && ./scansuite --backup-db /mnt/backup --password-file /root/scansuite-backup.pass > /var/log/scansuite-backup.log 2>&1
30 3 * * * find /mnt/backup -name 'scansuite-teams-db-*.zip' -mtime +14 -delete
```

> **Warning:** Keep the password file off the backup disk and copy the password into a password manager after the first run: the zips do not open without it.

Check next morning: `tail -3 /var/log/scansuite-backup.log` shows *Databases saved to /mnt/backup/…*.

## Restore the databases

> **Warning:** Scans, findings, accounts and settings created after the backup are lost.

```bash
cd /opt/scansuite && ./scansuite --restore-db <ZIP_FILE>
```

The command checks the zip first, then:

- refuses a backup from a newer release or schema (run `./scansuite update` first) or a newer PostgreSQL;
- warns if the backup used other encryption keys: restore its secrets backup too;
- asks *Restore the databases?* (unless `--yes`);
- saves the present databases to `backups/before-restore-<date>.zip` (unless `--no-safety-backup`);
- stops ScanSuite for a few minutes, restores, upgrades an older backup and starts again.

Expected: `[+] Databases restored from <ZIP_FILE>`. On failure the message names the command that puts the `before-restore` zip back. Then `./scansuite doctor` should report *No problems found*.

> **Warning:** The before-restore copy holds no stored files and has no password. Before restoring a --with-files backup, make your own --with-files backup if you may need the current files.

## Back up the secrets

```bash
cd /opt/scansuite && ./scansuite --backup-secrets <BACKUP_DIR>
```

The zip holds `.env`, the licence and `key/scansuite-secrets.env` (the keys that encrypt stored credentials):

*Output*

```
[+] Secrets saved to /mnt/backup/scansuite-teams-secrets-20261011-132509.zip
[!] The file opens only with this password. It is shown once and stored nowhere:

    <32 characters>

[*] Keep it apart from the file.
```

Write the password down (password manager) when it is shown. Make a new secrets backup whenever `.env`, the licence or the keys change.

> **Danger:** A database backup is useless without the secrets backup of the same installation: other keys cannot decrypt the stored credentials.

## Restore the secrets

```bash
cd /opt/scansuite && ./scansuite --restore-secrets <ZIP_FILE>
```

It asks for the password (or reads `--password-file` or `SCANSUITE_BACKUP_PASSWORD`), asks *Restore the secrets?*, moves the present files to `.replaced-<date>/`, restores them and restarts the services if ScanSuite was running. Expected: `[+] Restored .env and key/`. Otherwise run `./scansuite restart`; if it says the release has no images here, run `./scansuite update`.

## Move to a new server

1. **Back up the old server**

   Note the secrets password.

   ```bash
   cd /opt/scansuite && ./scansuite --backup-db --with-files && ./scansuite --backup-secrets
   ```
2. **Copy both zips to the new server**

   For example with scp to /root/restore.
3. **Install ScanSuite on the new server**

   With your licence ([Install ScanSuite Teams](https://scansuite.eu/documentation/installation/install-scansuite-server)). Do not create an account on /setup: the restore brings the accounts back. Without the release images yet, first run sudo apt install -y zip unzip.
4. **Restore the secrets first**

   ```bash
   cd /opt/scansuite && ./scansuite --restore-secrets <ZIP_FILE>
   ```
5. **Restore the databases**

   ```bash
   ./scansuite --restore-db <ZIP_FILE>
   ```
6. **Check**

   Same release as the old server, No problems found, and an old account can sign in.

   ```bash
   ./scansuite version && ./scansuite doctor
   ```

## How the zips are protected

Standard zip password protection: any zip program opens them with the password. It is weaker than modern encryption, so store the zips like any other secret.

> **Tip:** Installs on Google Cloud or Azure use managed services with their own backups: [Install on Google Cloud](https://scansuite.eu/documentation/installation/install-on-google-cloud), [Install on Microsoft Azure](https://scansuite.eu/documentation/installation/install-on-azure).
