
Module 2 Lesson 5: Backups & Migrations
Protect your logic. Learn how to export your workflows, backup your database, and move your n8n instance from one server to another without losing work.
Module 2 Lesson 5: Backups & Migrations
If your server crashes, do you lose 6 months of automation work? Not if you have a backup strategy. In n8n, your "Logic" (Workflows) and your "Vault" (Credentials) are the most important assets.
1. Backing up the File System
If you use Docker, backing up n8n is as simple as copying your n8n_data folder.
- Tip: Shutdown n8n before copying to ensure the database file (
n8n.dbor Postgres) is not "In Use."
2. Exporting Workflows via CLI
n8n has a built-in command to export all your work to JSON files:
docker exec -it n8n n8n export:workflow --all --output=/home/node/backups/
Pro Tip: You can automate this script to run every night and push the results to a Private Git Repository.
Visualizing the Process
graph TD
Start[Input] --> Process[Processing]
Process --> Decision{Check}
Decision -->|Success| End[Complete]
Decision -->|Retry| Process
3. The "Secret" Migration
When you move to a new server:
- Copy the
n8n_datafolder. - CRITICAL: Use the exact SAME
N8N_ENCRYPTION_KEYon the new server.
- If you change the key, you will see your workflows, but all your passwords/API keys will be unreadable "Garbage" because they were encrypted with the old key.
4. Database Snapshotting
If you used Postgres (Module 2, Lesson 3), use pg_dump to create an "Image" of your data. This is much faster and safer than copying raw files.
Exercise: The Disaster Drill
- Manually export one of your workflows as a JSON file.
- Open the JSON in a text editor. Can you see the names of your nodes?
- Imagine you want to "Sync" your workflows to GitHub automatically. How would you design that n8n workflow? (Trigger: Cron -> Action: Execute Command
n8n export). - Why should you store your
N8N_ENCRYPTION_KEYin a physical location (or a paper backup) separate from your server? - Research: What is "Restic" and how can it help backup Docker volumes to the cloud (like S3)?
Summary
You have completed Module 2: Self-Hosting n8n. You now have the skills to install, secure, scale, and protect your own private automation server. You are ready to start building.
Next Module: The logic begins: Module 3: The n8n Workflow: Triggers and Nodes.