DEV Community

Alec Asgari
Alec Asgari

Posted on

Backing up self-hosted n8n: what to save, how often, and how to prove a restore works

Self-hosting n8n is cheap and flexible, but it moves one job from the vendor to you: backups. Most small teams I work with have something in place, usually a snapshot of the whole server. That helps, but it often isn't enough to get a single broken workflow back quickly, and nobody has ever tested whether the snapshot actually restores.

This is the backup routine I set up for small teams running n8n in Docker. It's boring on purpose.

1. Know what actually needs saving

An n8n instance has four things you care about:

  1. The database. Workflows, credentials (encrypted), execution history and settings live here. On small installs this is often SQLite inside the n8n data folder; on larger ones it's Postgres.
  2. The encryption key. Credentials in the database are encrypted with N8N_ENCRYPTION_KEY (or the key n8n generated on first start and stored in its config file). Lose the key and your restored credentials are useless.
  3. Your environment and compose files. The docker-compose.yml, the .env file and any reverse-proxy config. Without these, rebuilding takes hours of guessing.
  4. Files your workflows write to disk, if any (exports, generated PDFs, uploaded files).

If you only take one thing from this post: store the encryption key somewhere separate from the server, such as a password manager. A backup of the database without the key is half a backup.

2. Two layers: whole-server and per-workflow

I use two layers because they solve different problems.

Layer 1: nightly file-level backup of the data folder and database. For SQLite, stop writes or use the SQLite backup command so you don't copy a file mid-write. For Postgres, a nightly pg_dump is simple and reliable. Push the result off the server to object storage with a tool that does encryption and versioning (Kopia, Restic and Borg are all fine). Keep at least 14 days, longer if the storage is cheap.

Layer 2: workflow exports to Git. The n8n CLI can export workflows as JSON:

docker exec n8n n8n export:workflow --all --separate --output=/home/node/backup/workflows
Enter fullscreen mode Exit fullscreen mode

Commit that folder to a private repository once a day. Now when someone "improves" a workflow on Friday afternoon and breaks it, you can diff Thursday's version and paste it back in minutes, without touching the database.

Credentials can be exported too, but only decrypted or encrypted with the instance key. I keep credential exports out of Git and rely on Layer 1 plus the stored key.

3. Schedule it, then alert on failure

Run both layers from cron or a systemd timer, not from inside n8n itself. If n8n is down, a backup workflow inside n8n is down with it.

Every backup job should end by reporting success somewhere a human will notice its absence. A simple pattern: the job pings a heartbeat URL (a monitoring service, or a small webhook) and that service alerts you if the ping doesn't arrive for 26 hours. Alerting on silence catches the failure mode that matters most: the backup that quietly stopped running weeks ago.

4. Test a restore every quarter

A backup you've never restored is a hope, not a backup. Once a quarter:

  1. Start a throwaway VM or a local Docker host.
  2. Restore the compose files, .env and the latest database dump.
  3. Set the same encryption key and start n8n.
  4. Log in, open three important workflows, and run one manually against a test endpoint.
  5. Write down how long it took and anything you had to look up.

The first test usually reveals something: a missing environment variable, a reverse-proxy setting nobody documented, a webhook URL hard-coded to the old hostname. Fixing those on a quiet Tuesday is much better than discovering them during an outage.

5. Watch the execution history size

Execution data is often the biggest part of the database. Keep enough history to debug (I like at least two weeks), but turn on pruning so the database doesn't grow forever and backups stay fast. Check the variables for execution data pruning and max age in your n8n version's docs and set them explicitly rather than trusting defaults.

6. A one-page runbook

Finally, write a single page that says:

  • where backups are stored and how to access them,
  • where the encryption key is,
  • the exact restore commands,
  • who to call.

Put it next to the server documentation, not on the server.

Summary

  • Back up the database, the encryption key, the config files and any written files.
  • Use a nightly off-site backup plus daily workflow exports to Git.
  • Run backups outside n8n and alert when they don't report in.
  • Test a full restore quarterly and keep a one-page runbook.

If you're moving to self-hosted n8n and want this set up properly from day one, I describe how I handle it on my n8n automation services page. If you're still on Zapier, my notes on a self-hosted Zapier to n8n migration cover what to inventory before you move.

Alec Asgari builds websites, n8n automations and ERP setups for small businesses. More at alecasgari.com.

Top comments (0)