Deployment GuideUpdated August 22, 2026

Practical VPS tutorial

How to Backup Docker Apps on a VPS

Back up Docker volumes, PostgreSQL and secrets to encrypted off-server storage with restic. Follow an n8n example and restore it on a separate test VPS.

A Docker image can recreate your application, but it won't bring back the database, uploaded files or encryption keys. For that, you need a backup of the data and a restore procedure you can actually follow.

How to Backup Docker Apps on a VPS — overview

I'd start with one small stack and prove the whole trip: database dump, volume archive, encrypted off-server copy, then a restore on a spare VPS. This guide uses our n8n deployment as the example. Adapt the service names and paths for other applications.

What needs to be in a Docker backup?

PartWhat to preserve
ConfigurationCompose files, environment files and proxy configuration.
DatabaseA consistent dump or the database's supported physical backup.
Application volumeUploads, instance files and other persistent data.
KeysApp encryption keys and a separate copy of the backup password.

Named volumes usually live outside the Compose folder. Copying /opt/n8n alone misses them. RAID and provider snapshots also don't replace a separate backup destination.

Choose the schedule around the changes you can afford to lose. A nightly backup can lose almost a day's work. Larger databases may need PostgreSQL WAL archiving and point-in-time recovery; this small-stack dump example isn't that system.

How to Backup Docker Apps on a VPS — detail

1. Find the real volume names

Use a root shell on the VPS for this routine (sudo -i if needed):

cd /opt/n8n
docker compose ps
docker volume ls
docker inspect "$(docker compose ps -q n8n)" --format '{{json .Mounts}}'

Our example uses Compose project name n8n, so the application volume is n8n_n8n_data. Confirm the name in your deployment. A different project name means a different volume name.

Don't tar live database files as ordinary uploads. For PostgreSQL we'll use pg_dump. For an app using SQLite, such as a default Open WebUI install, stopping writers before archiving its data is one straightforward option.

2. Prepare encrypted storage outside the VPS

Install restic and openssl; on Ubuntu you can use apt update followed by apt install restic openssl. Prepare an SFTP account on a separate server, configure root's SSH key for unattended access and verify the destination's host key.

Generate the repository password once:

install -d -m 700 /root/.config/restic
umask 077
(set -o noclobber; openssl rand -base64 32 > /root/.config/restic/vps-password)
chmod 600 /root/.config/restic/vps-password

The command refuses to overwrite an existing password file. Save a second copy in your password manager. This is the password you'll need when the original VPS is gone.

Save the repository settings in /etc/restic-vps.env, replacing the example host and path:

export RESTIC_REPOSITORY='sftp:[email protected]:/srv/restic/vps01'
export RESTIC_PASSWORD_FILE='/root/.config/restic/vps-password'

Protect that file with chmod 600 /etc/restic-vps.env. Then initialize the repository:

. /etc/restic-vps.env
restic init

Run init only once. Restrict the SFTP account to the backup destination. Encryption protects the contents, but credentials that can delete the repository can still destroy backups.

3. Create a consistent n8n backup

Save this script as /usr/local/sbin/backup-n8n, owned by root, then run chmod 700 /usr/local/sbin/backup-n8n. It checks the volume, stops n8n and its runner, exports the database and archives application files. It resumes the app before uploading.

Finish active workflows and pause incoming jobs before the maintenance window. Expect requests to fail while n8n is stopped.

#!/usr/bin/env bash
set -euo pipefail
umask 077
. /etc/restic-vps.env
cd /opt/n8n

backup_dir=/var/backups/vps-apps/n8n
install -d -m 700 "$backup_dir"
docker volume inspect n8n_n8n_data > /dev/null
docker pull ubuntu:24.04 > /dev/null

cp compose.yml .env "$backup_dir/"
if [ -f Caddyfile ]; then
  cp Caddyfile "$backup_dir/"
fi

trap 'docker compose start n8n runners >/dev/null' EXIT
docker compose stop n8n runners

docker compose exec -T postgres \
  pg_dump -U n8n -d n8n -Fc > "$backup_dir/postgres.dump"

docker run --rm \
  --mount type=volume,src=n8n_n8n_data,dst=/data,readonly \
  --mount "type=bind,src=$backup_dir,dst=/backup" \
  ubuntu:24.04 tar -czpf /backup/n8n-data.tar.gz -C /data .

docker compose start n8n runners
trap - EXIT

restic backup "$backup_dir" --tag n8n-vps

Run /usr/local/sbin/backup-n8n manually first. Check its exit status and confirm n8n is healthy afterward. The exit trap attempts to restart the app on failure, but it doesn't send an alert or prove a healthy restart.

The dump uses the database container's own PostgreSQL client. It includes one database, not all cluster roles and databases. Record extra roles, extensions and external storage if your actual setup uses them.

4. Schedule it and check that it keeps working

Add this to root's crontab after the manual run succeeds:

15 3 * * * /usr/bin/flock -n /run/backup-n8n.lock /usr/local/sbin/backup-n8n >> /var/log/backup-n8n.log 2>&1

flock prevents overlapping scheduled jobs. Use the same lock when running manually alongside the schedule. The time uses the server timezone; add failure alerts and rotate the log.

Check snapshots and preview retention:

. /etc/restic-vps.env
restic snapshots --tag n8n-vps
restic forget --tag n8n-vps --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --dry-run
restic check
7daily snapshots in the retention preview
4weekly snapshots in the same preview
6monthly snapshots in the same preview

Review the preview before removing recovery points. If it matches your policy, remove --dry-run and add --prune to reclaim unused data. The retention documentation explains how snapshots are grouped and retained.

restic check checks repository structure. Periodically use restic check --read-data to read stored data too; that takes more time and transfer. Neither check replaces an application restore test.

5. Restore on a spare VPS

Select a snapshot ID from restic snapshots, then restore it:

. /etc/restic-vps.env
restic restore SNAPSHOT_ID --target /srv/restore-check

Replace SNAPSHOT_ID with the chosen ID. For this backup, files appear under /srv/restore-check/var/backups/vps-apps/n8n. Inspect the restored Compose file and original .env; the n8n encryption key must match the database.

Create a fresh database under a separate project name:

cd /srv/restore-check/var/backups/vps-apps/n8n
docker compose -p n8n-restore up -d --wait postgres
docker compose -p n8n-restore exec -T postgres \
  pg_restore -U n8n -d n8n --no-owner --no-privileges --exit-on-error < postgres.dump

Restore the application archive into an empty volume:

restore_dir=/srv/restore-check/var/backups/vps-apps/n8n
docker volume create n8n-restore_n8n_data
docker run --rm \
  --mount type=volume,src=n8n-restore_n8n_data,dst=/data \
  --mount "type=bind,src=$restore_dir,dst=/backup,readonly" \
  ubuntu:24.04 sh -c 'test -z "$(ls -A /data)" && tar -xzpf /backup/n8n-data.tar.gz -C /data'

The empty-volume check prevents copying over an existing instance. Don't run these commands against your live volume or database.

Before starting the restored instance, unpublish its workflows so schedules and triggers don't resume automatically:

docker compose -p n8n-restore run --rm --no-deps n8n unpublish:workflow --all

This uses the current n8n Server CLI. Keep outbound integrations isolated too; use test credentials for the restore drill.

Now start only the app and runner, leaving the public proxy stopped:

docker compose -p n8n-restore up -d n8n runners
curl --fail http://127.0.0.1:5678/healthz

Allow startup time if needed. Use private access to verify login, a saved credential and representative application files. Run one controlled workflow with test integrations. Record the recovery time and anything you had to look up.

FAQ

Does copying my Compose folder back up Docker volumes?

Usually not. Inspect mounts and include the actual volume data or mapped host paths.

Can I back up PostgreSQL without stopping it?

pg_dump can take a consistent database dump while PostgreSQL runs. This example stops application writers as well to keep the database and related app files aligned. Larger systems need a design suited to their recovery requirements.

Are exported n8n workflows a complete backup?

No. Credentials, their encryption key, instance data and configuration are also needed for full recovery.

Are encrypted backups protected from deletion?

Encryption alone doesn't prevent deletion. Separate credentials and storage protections matter alongside having multiple recovery points.

  1. Install the n8n stack used here
  2. Secure SSH and application ports
  3. Deploy Open WebUI with persistent storage

Next step

Keep the deployment moving

Sources and further reading

Commands assume a fresh Ubuntu server. Replace domains, users, database names and provider-specific values before running them. VPS sizing is a practical starting point, not a guarantee: monitor the real workload and resize when CPU, memory, disk or network headroom becomes tight.

Where to run this

Affiliate links: you pay the same price as buying direct.