⚙️ Back up and restore n8n Docker workflows and credentials with GitHub and SSH
⚡ 125 views · ⚙️ DevOps & CI/CD
💡 Pro Tip — If you need GitHub data beyond what the REST API gives you, ScraperNode has a repository scraper that extracts metadata at scale without token rate limits.
Description
Quick Overview
This workflow backs up all n8n workflows and encrypted credentials from a self-hosted Docker instance to a GitHub repository on a schedule, and provides a Basic Auth–protected form to restore workflows and credentials by importing uploaded JSON backup files over SSH.
How it works
- Runs twice daily on a cron schedule to start a backup run.
- Creates timestamped
workflowsandcredentialsfolders (via placeholder files) in the target GitHub repository. - Connects to the Linux host over SSH and runs the n8n CLI in the Docker container to export all workflows and all encrypted credentials.
- Commits
workflows-all.jsonand individual<workflow name>.jsonworkflow backups to GitHub. - Commits
credentials-all.jsonand individual<name>_<type>.jsonencrypted credential backups to GitHub. - Builds and commits a combined
workflows-credentials.jsonfile containing both exports for easy restoration. - Accepts uploaded JSON files via a Basic Auth form, detects whether they contain workflows or credentials (single, bulk, or combined), and imports them into the target n8n Docker container over SSH.
Setup
- Create a private GitHub repository and add GitHub API credentials in n8n with permission to write files to that repository.
- Add SSH credentials for your Linux host and ensure the SSH user can run
docker exec/docker cpagainst the n8n container. - Update the Backup Configuration and Restore Configuration nodes with your GitHub owner, repository name, and the n8n Docker container name.
- Configure Basic Auth credentials for the restore form and deploy it behind HTTPS before activating the restore path.
- Ensure the destination n8n instance uses the same
N8N_ENCRYPTION_KEYas the source so encrypted credentials can be restored.
🔗 Nodes Used
GitHub, SSH, Schedule Trigger, n8n Form Trigger, Convert to File, Extract from File
📥 Import
Download workflow.json and import into n8n:
Workflow menu → Import from File