# Backing up the panel

URL: https://docs.vaultpanel.net/getting-started/backing-up-the-panel

> Daily backups of VaultPanel itself, with its database, secret key and certificate, and how to restore one on the same or a new server.

Websites, apps and databases have their own [backups](https://docs.vaultpanel.net/guides/backups-and-automation/backups). This page is about the backup of **VaultPanel itself**: without it, losing the server means losing every account and setting, and the key that decrypts them.

## What a backup holds

Each backup is one file in `/var/backups/vaultpanel-panel` (root only, mode `600`) with a `.sha256` checksum next to it. It holds:

- the panel's database, as a `mariadb-dump`,
- `.env`, including `VAULTPANEL_SECRET_KEY`, which decrypts two-factor secrets, the agent signing key and every stored password,
- the HTTPS certificate and key, so agents on other servers keep trusting a restored panel,
- terminal recordings and the panel domain list,
- a `VERSION` file with when, where and from which version it was made.

## When backups are made

| Trigger | Label | Kept |
| --- | --- | --- |
| Every day, by `vaultpanel-backup.timer` | `scheduled` | `VAULTPANEL_BACKUP_KEEP` (14 by default) |
| `sudo vaultpanel backup` | `manual` | all, unless you pass `--keep` |
| Before every update | `pre-update` | the last 3 |
| Before every restore | `before-restore` | the last 3 |

Files are named after the time and label, such as `vaultpanel-20261020-031500-scheduled.tar.gz`.

## Make a backup now

```bash
sudo vaultpanel backup
```

| Option | What it does |
| --- | --- |
| `--dir <folder>` | Write the backup to another folder. |
| `--keep <n>` | Keep only the newest `n` backups with this label. |
| `--label <name>` | Label the backup (`a-z`, `0-9` and `-`, at most 32 characters). |

The backup needs the panel's MariaDB container that the installer set up. If you run the panel on your own database, back that database up yourself.

## Settings

Set these in `/opt/vaultpanel/.env`. The next backup uses them; no restart is needed.

| Setting | Default | What it does |
| --- | --- | --- |
| `VAULTPANEL_BACKUP_DIR` | `/var/backups/vaultpanel-panel` | Where backups go. |
| `VAULTPANEL_BACKUP_KEEP` | `14` | Daily backups kept. |
| `VAULTPANEL_BACKUP_PASSPHRASE_FILE` | | A file holding a passphrase. Backups are then encrypted (AES-256, PBKDF2) as `.tar.gz.enc`. |
| `VAULTPANEL_BACKUP_UPLOAD` | | A command run after each backup with the file as `$1`, to copy it off the server. |

For example, to copy every backup to another machine:

```ini
VAULTPANEL_BACKUP_UPLOAD=rclone copy "$1" remote:vaultpanel
```

If the upload command fails, the backup is still made and the command prints a warning.

> **Keep a copy off the server:**
A backup on the same disk does not help when the server is gone. Copy backups somewhere only you can read, and encrypt them when they go to someone else's storage: they hold the panel's secret key.

## Restore a backup

On the same server, or on a new one installed with the [installer](https://docs.vaultpanel.net/getting-started/installation):

```bash
sudo vaultpanel restore /var/backups/vaultpanel-panel/vaultpanel-20261020-031500-scheduled.tar.gz
```

The restore:

1. checks the file against its `.sha256` checksum, when there is one,
2. decrypts an `.enc` backup with `VAULTPANEL_BACKUP_PASSPHRASE_FILE`, or asks for the passphrase,
3. asks you to type `restore` (`--yes` skips the question),
4. takes a safety backup of the current panel,
5. puts back the database, the settings and secret key, the certificate and the panel's files,
6. updates the database to the installed version and restarts the panel.

The server keeps its own database and Redis passwords, ports and folders, so a backup from an old server restores onto a new one.

After restoring on a new server:

- If the new server has another address, run `sudo vaultpanel url <address>`, and `sudo vaultpanel https renew` so the certificate names it.
- A backup from a newer VaultPanel needs that version first: `sudo vaultpanel update --version <it>`, then restore again.
