Automated Daily Backup and Cleanup for Workflows - n8n Workflow

Use this robust n8n workflow template to automatically back up all your critical n8n workflows daily to Google Drive, including smart folder cleanup to manage storage space.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

n8n administrators and DevOps teams needing reliable infrastructure backups.
Developers who manage many critical automation flows and require version history.


  • Any n8n user who wants a "set-it-and-forget-it" disaster recovery solution for their automation setup.

Overview

Maintaining a reliable backup system is crucial for any production automation environment. This sophisticated n8n workflow template solves the problem of manual workflow exports and storage clutter.

It ensures that every active n8n workflow is captured nightly and securely stored in Google Drive. More importantly, it features an intelligent cleanup mechanism. After running the daily backup, the workflow uses n8n nodes to check for existing folders and automatically deletes those older than a specified retention period (default 30 days). This dual-action n8n automation provides peace of mind while preventing excessive storage consumption.

How it Works

This comprehensive n8n solution is divided into two major phases: Backup and Cleanup.


  1. Trigger and Configuration: The automation begins with the Schedule Trigger n8n node, running daily at 3 AM. It first consults the configuration n8n node to fetch the Google Drive folder ID and the count of backupsToKeep.

  2. Backup Creation: The workflow uses a Google Drive n8n node to create a new, dated folder (e.g., 'Workflows backup - 2025-01-01'). It then uses the internal n8n node to retrieve a list of all current n8n templates/workflows on the instance.

  3. File Upload: The list is processed via a Split In Batches n8n node. For each individual n8n workflow, the data is converted to a .json file format. A final Google Drive n8n node uploads this .json file into the newly created daily backup folder.

  4. Automated Cleanup: Parallel to the backup process, the cleanup sequence initiates. It searches Google Drive for all folders matching the backup naming convention.

  5. Retention Logic: A specialized Code n8n node processes the list, sorting folders by creation date and slicing the list to isolate only the excess, old folders based on the configured retention number. These excess folders are then iterated over using a Split In Batches n8n node.

  6. Deletion: Finally, a Google Drive n8n node deletes each identified old backup folder, completing the automated maintenance cycle for this n8n workflow.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. Configure Credentials: You require two sets of credentials:

Google Drive: Set up OAuth2 credentials to allow the workflow to create folders and upload files.
n8n API: Create an API key credential to allow the workflow to access its own list of n8n workflows.

  1. Configure Variables: Locate the n8n node named "CONFIG - Set your variables here".

parentFolderId: Paste the ID of the main Google Drive folder where you want all your daily backups to be stored.
backupsToKeep: Adjust the number (default is 30) of the most recent backup folders you wish the n8n workflow to preserve.

  1. Activate: Ensure the Schedule Trigger is enabled and activate the entire n8n workflow. The next time the n8n trigger fires, the backup process will begin.

Node Details

This n8n workflow utilizes several key n8n nodes for comprehensive automation:

Schedule Trigger / Manual trigger: The starting n8n trigger node that dictates when the backup runs (scheduled daily or manually executed).
CONFIG - Set your variables here (Set n8n node): Stores global variables used throughout the n8n workflow, specifically parentFolderId and backupsToKeep (30 days).
Create new backup folder (Google Drive): Creates a uniquely named folder based on the current date, ensuring organized storage for the new set of n8n templates.
Get all n8n workflows (n8n n8n node): Connects to the local n8n API to retrieve a JSON list containing the details of every single active n8n workflow on the instance. This is essential for the backup process.
Convert workflow to file (Convert To File n8n node): Converts the JSON data for each n8n workflow into a storable binary file with the correct .json extension.
Upload workflow to Google Drive (Google Drive): The final step in the backup phase, uploading the .json file for the current n8n workflow iteration.
Search files and folders (Google Drive): Used in the cleanup path to find all previously created backup folders based on the naming convention.
Sort and isolate old folders (Code n8n node): Contains custom JavaScript to implement the core retention logic, sorting all folders and identifying which ones must be deleted to adhere to the backupsToKeep configuration. This demonstrates the flexibility of n8n nodes for complex logic.


  • Delete old folder (Google Drive): Executes the final cleanup action, permanently removing the outdated backup folder identified by the n8n workflow.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by

Featured*