⚙️ Scheduled workflow backups from n8n to Google Drive with auto cleanup

1,219 views · ⚙️ DevOps & CI/CD

Description

Auto Backup n8n Workflows to Google Drive

Imagine the sinking feeling: hours, weeks, or even months of meticulous work building your n8n workflows, suddenly gone. A server crash, an accidental deletion, data corruption, or an unexpected platform issue – and all your automated processes vanish. Without a reliable backup system, you’re facing a complete rebuild from scratch, a scenario that’s not just frustrating but can be catastrophic for business operations.

Furthermore, consider the daunting task of migrating your n8n instance to a new host or server. Manually exporting each workflow, one by one, then painstakingly importing them into the new environment is not only incredibly time-consuming, especially if you have tens or hundreds of workflows, but also highly prone to errors and omissions. You need a systematic, automated solution.

This workflow provides a robust solution for automatically backing up all your n8n workflows to Google Drive on schedule (default to every hour). It creates a uniquely named folder for each backup instance, incorporating the date and hour, and then systematically uploads each workflow as an individual JSON file. To manage storage space, the workflow also includes a cleanup mechanism that deletes backup folders older than a user-defined retention period (defaulting to 7 days).

Ideally, this backup workflow should be used in conjunction with a restore solution like our “Restore Workflows from Google Drive Backups” template.

For more powerful n8n templates, visit our website or contact us at AI Automation Pro. We help your business build custom AI workflow automation and apps.

Feature highlights

Who is this for?

This template is designed for:

What problem is this workflow solving? / use case

This workflow directly addresses these critical risks and challenges by:

What this workflow does

  1. Scheduled Trigger: Runs automatically every hour.
  2. Timestamping: Fetches the current date and hour to create a unique name for the backup folder.
  3. Folder Creation: Creates a new folder in a specified Google Drive location. The folder is named in the format: n8n_backup_YYYY-MM-DD_HH.
  4. Workflow Retrieval: Connects to your n8n instance via its API and fetches a list of all existing workflows.
  5. Individual Backup: Processes each workflow one by one:
    • Converts the workflow data to a binary JSON file.
    • Uploads the JSON file (named after the workflow) to the hourly backup folder in Google Drive.
    • Includes a short wait step between uploads to respect potential API rate limits.
  6. Old Backup Deletion:
    • Calculates a cut-off date based on the “Coverage Period” set in the “Settings” node (e.g., 7 days prior to the current date).
    • Searches Google Drive for backup folders (matching the naming convention) that are older than this cut-off date.
    • Deletes these identified old backup folders to free up storage space.

Step-by-step setup

  1. Import Template: Upload the provided JSON file into your n8n instance.
  2. Configure Credentials:
    • Google Drive Nodes: You will need to create or select existing Google Drive OAuth2 API credentials for these nodes.
    • n8n Node: n8n (node that fetches workflows) Configure n8n API credentials to allow the workflow to access your instance’s workflow data.
  3. Specify Google Drive Backup Location:
    • Open the “Google Drive Backup Folder Every Hour” node.
    • Under the “Drive ID” parameter: select it from the list or provide its ID.
    • Under the “Folder ID” parameter: select or input the ID of the parent folder in Google Drive where you want the n8n_backup_YYYY-MM-DD_HH folders to be created (e.g., a general “n8n_Backups” folder).
  4. Set Backup Retention Period:
    • Open the “Settings” node.
    • Modify the value for “Coverage Period” (default is 7). This number represents the number of days backups should be kept before being deleted.
  5. Activate Workflow: Toggle the “Active” switch for the workflow in your n8n dashboard.

How to customize this workflow to your needs

Important Considerations

🔗 Nodes Used

Google Drive, Convert to/from binary data, n8n, Schedule Trigger

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup