Effortless Automated Backups for Your Dockerized n8n (SQLite) to GitLab or GitHub

How to bulletproof your workflow automations with dead-simple, automated backups—even if you’re not a Linux wizard.
Why You Absolutely Need to Back Up n8n (Especially on Docker + SQLite)
n8n is the backbone of your workflow automation, orchestrating everything from business logic to personal productivity hacks. But if you’re running n8n in Docker (the way 90% of us do), and especially if you’re using the default SQLite database, you are one corrupted file, failed disk, or accidental docker rm
away from total workflow extinction.
Why?
- SQLite is a single file. Great for simplicity, terrible for resilience.
- Docker containers can be deleted, rebuilt, or migrated at any time.
- Automated backup = Zero downtime, zero tears.
- Storing backups offsite (like GitLab or GitHub) = Safety against ransomware and hardware failures.
Bottom line: If your n8n automations matter at all, you should automate your backups now—not after you lose everything.
Prerequisites
You’ll need:
- n8n running in Docker (hosted anywhere: VPS, home server, cloud).
- Your n8n instance uses SQLite (the default DB for new installs).
- Shell access to your Docker host (SSH or web console).
- A GitLab or GitHub account with a private repository for storing your backups.
- SSH keys configured for push access to your repo from the server.
Step 1: Verify n8n Is Using SQLite
Before you start, check that your n8n is using SQLite.
SSH into your Docker host and run:
If it returns sqlite
, you’re good.
Or, check for the file:
If you see database.sqlite
, you’re running SQLite.
Step 2: Set Up Your Backup Repo
1. Create a private repo on GitLab or GitHub (e.g., n8n-backups
).
2. Clone it to your server:
3. Configure your git user (inside the repo):
4. Make sure your SSH key is added to your git provider for passwordless pushes.
(a) Add your server public key into github or gitlab Check if There’s an SSH Key: ls -l ~/.ssh/id_rsa.pub
If not, generate one: ssh-keygen -t rsa -b 4096 -C "n8n-backup@yourhost" -N "" -f ~/.ssh/id_rsa
Add the Public Key to GitHub/Gitlab cat ~/.ssh/id_rsa.pub
(b) Once that is done, run this to test.
Step 3: The Automated Backup Script
Below is a no-nonsense, production-ready shell script to:
- Copy your live
database.sqlite
from the n8n container, - Save it with a unique timestamp,
- (Optionally) encrypt it,
- Commit and push to GitLab/GitHub only if the file changed,
- Automatically prune backups older than 14 days.
Save this as backup-n8n.sh
:
Make it executable:
Step 4: Automate with Cron
Schedule it (for example, daily at 2am):
Add:
Step 5: How to Restore a Backup
Stop your n8n Docker container:
If the backup is encrypted, decrypt it first:
Copy a backup into place:
Start n8n:
That’s it. You’re live again.
Troubleshooting Common Issues
Permission denied (publickey):
Double-check your SSH keys and make sure your backup user has push rights to your repo.Multiple backups with the same timestamp:
Use seconds in your filename as shown. You’ll never get duplicates.“Nothing to commit” in git:
The script now skips the commit if the file hasn’t changed—less noise in your Git history.Backup file encryption:
If you lose your GPG passphrase, you lose access to your backup. Use with care.
Final Thoughts: Paranoia is a Virtue
Automated backups aren’t “paranoid,” they’re smart. SQLite is fast and light, but not invincible.
With this setup, your n8n workflows can survive anything—hardware failures, accidental wipes, or the classic “I don’t know what happened, boss, it just disappeared.”
Make this script your insurance policy.
Set it, forget it, and sleep easy.
Comments