Encrypted packages (databases, PKI, client profiles) with safe restore and a pre-restore safety copy, usable for server-to-server migration across container and system-service installs. New Management page, ovp_backups volume, migrations code in the profiler image, server name in package names. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
13 KiB
Backup and Restore
Page Management > Backup and Restore in the web UI (API: Profiler API, section 4). It makes a package of the application data, sends it to one or more destinations and restores from it, also on another server and from containers to system services and back.
It is not the same as deploy/docker/backup.sh and deploy/native/backup.sh: those copy whole volumes or directories before an update and run from the command line. This function works on the level of the application data from the UI, whatever the installation method.
Status: destinations Local folder, S3, SFTP and FTP/FTPS work. SMB is coming in a later pass. There is no schedule yet: a backup is started by hand.
What is in a package
| In the package | Notes |
|---|---|
| monitoring database | statistics, administrator accounts, 2FA (consistent online copy, no downtime) |
| profiler database | profiles, notes, server and PKI settings (consistent online copy) |
pki/ |
CA, server and client keys and certificates, CRL, ta.key, dh.pem. Secret. |
client .ovpn files |
the issued profiles |
manifest.json |
format version, time (UTC, milliseconds), server name, host name, container or host, schema versions of both databases, SHA-256 of every file |
Not in the package, on purpose: server.conf (generated again from the settings), the JWT signing key and the environment file (each server has its own), the TLS certificate of the web interface, logs, and the backup destinations with their secrets (see Moving to another server).
A package is a tar.gz named ovpmon-backup_<server-name>_<YYYYMMDDTHHMMSS>Z.ovpbak, with .enc added when it is encrypted. The time is UTC, to the second, for example ovpmon-backup_vpn-main_20261007T101500Z.ovpbak.enc. If a destination already holds a package of the same second, -2, -3 ... is added after the Z; an existing file is never overwritten. Only files with such a name are listed, restored and rotated; everything else in a destination is ignored. Packages of the first pass (the host name in place of the server name) stay listed and restorable.
Server name
The Server name field is in the Backup panel of the page (letters, digits, . and -, up to 63 characters, starting with a letter or digit; API: server_name of PUT /backup/settings). The page shows the name that will really be used. If no name is set, the public address from the VPN settings is used, and if there is none, the host name (in a container this is a random identifier, so set a name). The name is stored in ovpmon_backup.db, not in the package and not in the profiler database: after a move to another server it is set again.
Encryption
A package holds the private key of the CA and the password hashes. Set a passphrase on the page (at least 8 characters): packages are then encrypted with AES-256-GCM, the key is derived from the passphrase with scrypt.
- Remote destinations (S3, SFTP, FTP and later SMB) refuse to work without a passphrase (the backup is rejected with an error).
- A local folder works without it; the page shows a warning. Folders are created with mode 700 and files with 600.
- The passphrase is stored on the server encrypted with a key derived from the JWT signing key, and never shown again. If the signing key is changed, enter the passphrase and the destination secrets again.
- Changing the passphrase does not touch old packages: each one keeps the passphrase it was made with. At restore the passphrase is typed in by hand. Without it an encrypted package cannot be opened.
Destinations
A destination is a named entry: type, parameters, secrets, enabled flag, number of copies to keep (default 14). Backup now sends the package to all ticked destinations; each result is shown separately, and a failure of one destination does not stop the others. Secrets are never returned by the API (the page shows them as ********); leave a secret field empty when editing to keep it. Use Test to check the connection, writing and deleting.
| Type | Parameters | Notes |
|---|---|---|
| Local folder | folder | a sub folder inside the backup root; paths outside the root and symbolic links are refused |
| S3 | endpoint (host[:port], without https://), TLS on/off, region (optional), bucket, prefix (optional), access key, secret key |
AWS S3 or a compatible store (Python library minio). The bucket must exist; it is never created. The key needs to list, write, read and delete in the bucket or prefix |
| SFTP | host, port (22), user, directory, password or private key (+ passphrase of the key) | Python library paramiko; see SFTP |
| FTP / FTPS | host, port (21), user, directory, TLS (explicit FTPS, on), verify the certificate (on), passive mode (on), password | Python library ftplib; see FTP |
Both SFTP and FTP: the directory is relative to the login directory of the user and checked like the local folder (letters, digits, ., _, -, no .., at most 4 levels; it is created if missing); a package is first written as .<name>.part and renamed when complete, so a broken transfer never leaves a package-looking file; only files with our package name are listed; connection timeout 15 s, a transfer waits up to 120 s for data; errors are shown as text without secrets. Secrets (password, private key, passphrase) are encrypted at rest and shown as ********.
SFTP and the host key
The server is identified by the SHA-256 fingerprint of its SSH host key, which is pinned:
- Add the destination and press Test. The server is not trusted yet, so the page shows the key type and fingerprint and a Trust button (nothing was sent to the server, not even the password). Compare the fingerprint with the one you know (
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pubon the server). - Trust saves the fingerprint in the destination (
POST /backup/destinations/{id}/trust-host-key; the server checks that it still shows the same key). - From now on every connection must present exactly that key. Backup, listing, restore and delete are refused while no key is trusted, and on a mismatch the connection is dropped before any credentials are sent. If the key changed (server reinstalled), Test shows the new fingerprint with a warning and offers to trust it again.
Unknown keys are never added automatically. Changing the host or the port clears the trusted key. Authentication by key: paste the private key text (RSA, ECDSA or Ed25519 in OpenSSH or PEM format) and, if the key is encrypted, its passphrase. Use a key that is allowed to write only into the backup directory.
FTP and FTPS
- TLS (explicit FTPS,
AUTH TLS) is on by default, and so is the verification of the server certificate. A server with a self-signed certificate needs the verification switched off explicitly; the page warns about that. - Without TLS the password and the packages travel in clear text; the page warns about that and the destination list shows a badge. Use plain FTP only inside a trusted network.
- Passive mode is on by default (needed behind NAT and in containers).
- The server should support
MLSDorNLST(list),SIZEandRNFR/RNTO(rename).
The backup root of local destinations is /var/lib/ovpmon/backups in system-service installs and /app/backups in containers (volume ovp_backups). Change it with OVPMON_BACKUP_LOCAL_ROOT.
Rotation. After a successful upload the oldest packages beyond "copies to keep" are deleted. Only packages of our name pattern with the same server name in the same folder are considered, so servers with different names that share a folder do not delete each other's packages (servers with the same name in one folder do rotate each other: give every server its own name). Packages with another name stay: those made before the name was changed, and the first-pass packages named by host name.
Make a backup
- Add a destination and press Test.
- For a remote destination set the passphrase first.
- Tick the destinations and press Backup now. The progress and the result of every destination appear below; the history keeps the last runs.
Only one backup or restore runs at a time (a second start is rejected with 409).
Restore
- Source: pick a destination. The page checks it (connection, read access) and finds the packages.
- Package: the list shows the server name, the time in UTC and in the local time of your browser, the size and whether the package is encrypted, newest first.
- Type the passphrase if the package is encrypted.
- Press the red Restore button and confirm. The confirmation lists what is replaced.
What the server does:
- Downloads the package, decrypts it, checks
manifest.jsonand the SHA-256 of every file. - Unpacks it safely: only the expected top-level names are accepted; absolute paths,
.., links, devices and oversized content are rejected. - Refuses a package with an unknown format or a newer database schema than this release knows. A package with an older schema is accepted and migrated (see below).
- Checks the databases and migrates them on the unpacked copies, before anything is changed.
- Saves the current state as a safety copy in
<backup root>/pre-restore/(the last 5 are kept, encrypted if a passphrase is set). If this fails, the restore does not start. - Stops OpenVPN if it runs, replaces the databases (atomic file replace), the PKI and the client profiles. If any replacement fails, everything is put back.
- Generates
server.confand publishes the CRL like Apply Configuration on the VPN page, then starts OpenVPN again if it was running.
While a restore runs, requests that change the PKI, profiles, settings or the OpenVPN process return 409. When it is done, the page offers to log in again: the accounts now come from the package. Clients are disconnected during the restart of OpenVPN.
To undo a restore, restore the package from pre-restore (add a Local destination with the folder pre-restore and pick the package there).
Migration of the monitoring database
The migrations of the monitoring database live in APP_CORE. The profiler runs its own migrations in-process. For the monitoring database it calls migrate.py on the unpacked copy, so the database is already migrated when it is put in place; a package with an older schema (also one from an older release) is therefore restored in every installation method. The code is found next to APP_PROFILER (system services, all-in-one container /app/APP_CORE) or in the directory set by OVPMON_CORE_DIR (the profiler image of the one-container-per-component variant: /opt/core, which holds migrations.py, migrate.py and db.py of APP_CORE; they use only the Python standard library). The profiler image gets them at build time through the build context core (additional_contexts in docker-compose.yml, docker compose 2.17 or newer; the all-in-one and system-service installs need nothing extra).
An image built before this change has no such directory. Then a package is accepted only if its monitoring schema version equals the one of the running installation, and otherwise the restore is refused with a clear message and nothing is changed: rebuild the profiler image.
Moving to another server
- Install the application on the new server (any method), log in once with the initial administrator.
- Add a destination that points to the same storage (S3 bucket with the same keys, the same SFTP or FTP directory, or a copy of the local folder; an SFTP host key is trusted again on the new server). Destination settings and secrets do not travel inside the package: enter them again on the new server. Copy the packages into the new server's backup root if you use a local destination.
- Set up the same passphrase (only needed for new backups) and restore: pick the source and the package, type the package passphrase.
- Log in again with the account of the old server.
- Set the server name of the new server on the Backup and Restore page (it is not part of the package). Open VPN and check the server address (
remote/public IP): it comes from the package and points to the old server unless you change it. Apply the configuration if you change it; client profiles already issued keep the old address and have to be reissued.
The package format does not depend on the installation method: containers (variants A and B) and system services (Alpine, Debian, Ubuntu) are interchangeable. Release rule: the new server must run the same or a newer release than the one that made the package.
Settings (environment)
| Variable | Default | Meaning |
|---|---|---|
OVPMON_BACKUP_LOCAL_ROOT |
/var/lib/ovpmon/backups (containers: /app/backups) |
root of the local destinations |
OVPMON_BACKUP_WORK_DIR |
<root>/.work |
temporary files of a job; needs room for about two copies of the data |
OVPMON_BACKUP_MAX_UNPACKED_BYTES |
20 GiB | size cap of an unpacked package |
OVPMON_CORE_DIR |
APP_CORE next to APP_PROFILER (profiler image: /opt/core) |
where migrate.py, migrations.py and db.py of the monitoring component are |
Settings, destinations and history are in their own SQLite file ovpmon_backup.db next to the profiler database. A restore replaces the two application databases but never this file.