See llms.txt for all machine-readable content.

Back to Templates

Back up n8n workflows to GitHub with change detection and email alerts

Quick overview

This workflow runs manually or daily on a schedule to export all workflows from an n8n instance and back them up as JSON files in a GitHub repository, only committing files when changes are detected and sending an email alert if a scheduled run fails.

How it works

  1. Runs either when you execute it manually or at the configured daily time via the schedule trigger.
  2. Retrieves all workflows from your n8n instance using the n8n API.
  3. Creates one JSON backup file per workflow (removing pinned test data) and assigns each a path like workflows/<id>_<name>.json.
  4. Checks GitHub to see whether each workflow file already exists and reads its current contents when available.
  5. Compares the GitHub version to the newly generated JSON and updates the file only when the content has changed, otherwise it does nothing.
  6. Creates the file in GitHub when it does not exist, and stops with an error for other GitHub read failures.
  7. Sends a failure email via SMTP when a scheduled execution errors using the workflow’s error trigger.

Setup

  1. Create a private GitHub repository for the backups, and a fine-grained personal access token limited to that repository with the permission Contents: Read and write. Add it as a GitHub credential in n8n.
  2. Create an n8n API key with read access to workflows. Add an n8n API credential: the Base URL is your instance address followed by /api/v1.
  3. Add an SMTP account credential for the alerts (with Gmail, use an app password: host smtp.gmail.com, port 465, SSL/TLS on).
  4. Select the credentials in the nodes: n8n API in Fetch All Workflows, GitHub API in Fetch File from GitHub, Create New GitHub File and Update GitHub File. Then fill in githubOwner, githubRepo and backupFolder in Set Configuration Fields, and alertFrom and alertTo in Set Alert Details.
  5. Run the workflow manually and check your repository. Run it a second time: no new commit should appear unless a workflow changed.
  6. Adjust the time in Daily Schedule Trigger (and the workflow timezone in the settings), then activate the workflow.

Requirements

  • An n8n API key with read access to workflows
  • A GitHub account, a private repository and a fine-grained token (Contents: Read and write)
  • An SMTP account to send the failure alert

Customization

  • Change the time or frequency in the Schedule Trigger, and set your timezone in the workflow settings
  • Change the backup folder in Set Configuration Fields (default: workflows)
  • Set the sender and recipient of the alert in Set Alert Details

Additional info

Keep the repository private: a workflow file contains node settings, credential names, URLs and any value written in a node. Credentials are not backed up. The first run creates one commit per workflow; after that, only changed workflows create a commit. Workflows deleted in n8n stay in the repository, and a renamed workflow creates a new file. The alert covers failed scheduled runs: if n8n is off at the scheduled time, no run starts and no alert is sent. GitHub tokens and n8n API keys expire: when one does, the workflow fails and you get the alert.