6/30/2025 Aegis

n8n Backup Strategy: How to Keep Your Workflows Safe

n8n backup self-hosting automation postgres database

🔐 Why You Need a Backup Strategy for n8n

Whether you’re running n8n for a hobby project or managing mission-critical automations, data loss = workflow loss.

“A single failed VPS reboot or docker rm could wipe your entire automation setup.”

In this guide, you’ll learn how to back up your self-hosted n8n instance properly, including:

  • ✅ Workflows & credentials
  • ✅ Environment variables
  • ✅ PostgreSQL or SQLite data
  • ✅ Docker volume tips
  • ✅ Automation tools for daily backups

📦 What You Need to Back Up

The key components of your n8n setup:

ComponentDescriptionBackup Method
Workflows & DataStored in DB (Postgres or SQLite)DB Dump (pg_dump)
CredentialsEncrypted, stored in DBDB Dump
.env ConfigEnv variables used by n8n (e.g., API keys)Copy .env file
Binary DataIf using binary mode, media may be on diskBackup /files folder
Static ConfigDocker Compose or systemd service configBackup .yml/.service

🗃️ Option 1: PostgreSQL Backup

If you’re using PostgreSQL (recommended for production):

pg_dump -U n8n -h localhost -Fc n8n > n8n_backup_$(date +%F).dump
  • Replace n8n with your DB name & user.
  • Automate it with cron or n8n itself.
  • Store the backup on a mounted drive or cloud bucket.

Restore example:

pg_restore -U n8n -d n8n_restored n8n_backup_2025-06-07.dump

🗃️ Option 2: SQLite Backup (For Lightweight Setups)

If you use SQLite (default for local installs):

cp ~/.n8n/database.sqlite ~/.n8n/database_backup_$(date +%F).sqlite

Or use rsync:

rsync -a ~/.n8n/ /backups/n8n/

⚠️ Note: Avoid copying while n8n is running, or you risk corrupted DB snapshots.


📂 Don’t Forget: .env and Config Files

Your .env file often contains:

  • N8N_HOST
  • N8N_ENCRYPTION_KEY
  • DB credentials
  • Webhook secrets

Example:

cp /home/ubuntu/n8n/.env /backups/n8n_env_backup.env

Also back up your docker-compose.yml, nginx.conf, and systemd service files if you’re running n8n as a service.


Example daily backup script (/opt/n8n-backup.sh):

#!/bin/bash
pg_dump -U n8n -h localhost -Fc n8n > /backups/n8n_$(date +%F).dump
cp /home/ubuntu/n8n/.env /backups/n8n_env_$(date +%F).env

Then add to crontab:

crontab -e
0 3 * * * /opt/n8n-backup.sh >> /var/log/n8n-backup.log 2>&1

This runs every day at 3 AM.


☁️ Optional: Upload Backups to the Cloud

Use tools like:

  • rclone to sync to Google Drive or S3
  • [scp] to send to another server
  • [n8n + WebDAV/FTP node] to automate it inside n8n itself

🧾 Summary Checklist

✅ ItemDescription
📂 .env backupSensitive config
🗃 DB dumpWorkflows, credentials
⚙️ Docker/YML/systemdSetup scripts
📁 Files directoryIf binary data used
🔁 Cron jobDaily auto-backup
☁️ Remote storageOffsite or cloud

🚨 Restore Test: Do This Once!

Make sure you can restore from backup. Don’t wait until disaster strikes.

“A backup isn’t real until you’ve successfully restored from it.”


🧠 Final Thoughts

Self-hosting n8n gives you freedom and control, but that means you are the sysadmin. Backing up takes just a few minutes and can save you hours of panic.

If you’re not sure how to set up automated backups or recovery, I offer support and maintenance services.

👉 Contact me here to secure your n8n setup with peace of mind.