Sauvegarde automatisée des workflows vers Google Drive avec nettoyage intelligent

Avancé

Ceci est unDevOps, Multimodal AIworkflow d'automatisation du domainecontenant 17 nœuds.Utilise principalement des nœuds comme N8n, Set, Code, GoogleDrive, ConvertToFile. Sauvegarde automatisée des workflows vers Google Drive avec nettoyage intelligent

Prérequis
  • Informations d'identification Google Drive API
Aperçu du workflow
Visualisation des connexions entre les nœuds, avec support du zoom et du déplacement
Exporter le workflow
Copiez la configuration JSON suivante dans n8n pour importer et utiliser ce workflow
{
  "meta": {
    "instanceId": "c582d54231d7262c638a00ee408faa972b8030c20ecfa02b3d445f84745245ff",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "b7a4ebea-711b-473d-b18a-7bf84a888a17",
      "name": "Déclencheur planifié",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1456,
        -72
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 3
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c7d51e5b-0add-4c66-8d85-e98d3a09f72e",
      "name": "Manual trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1456,
        -264
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "73b8a7f5-d038-4366-b30b-a92195db3a35",
      "name": "Rechercher fichiers et dossiers",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -16,
        -480
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $('CONFIG - Set your variables here').item.json.parentFolderId }}"
          }
        },
        "options": {},
        "resource": "fileFolder",
        "returnAll": true,
        "queryString": "Workflows backup - "
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "adc967fc-746c-462c-9de8-f823100d833d",
      "name": "Début cleanup (run once)",
      "type": "n8n-nodes-base.set",
      "position": [
        -240,
        -480
      ],
      "parameters": {
        "options": {}
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "1f4ad497-fbf8-4053-80fc-f22c9200370c",
      "name": "Trier and isolate old folders",
      "type": "n8n-nodes-base.code",
      "position": [
        208,
        -480
      ],
      "parameters": {
        "jsCode": "// Get the number of backups to keep from the config node\nconst backupsToKeep = $json.backupsToKeep;\n\n// 'items' contains the list of folders from the previous node\nconst folders = $input.all(); \nconst sortedFolders = folders.map(item => item.json);\n\n// 1. Sort the folders from newest to oldest\nsortedFolders.sort((a, b) => new Date(b.createdTime) - new Date(a.createdTime));\n\n// 2. Get only the excess folders to delete\nconst foldersToDelete = sortedFolders.slice(backupsToKeep);\n\n// 3. Return the final list to be passed to the loop\nreturn foldersToDelete;"
      },
      "typeVersion": 2
    },
    {
      "id": "ff6c6c87-2751-4429-a196-edc65f898e43",
      "name": "Loop over folders to delete",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        432,
        -480
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7669d1df-6225-47aa-841b-c14f48cbd2e3",
      "name": "Loop over each workflow",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -560,
        -144
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "c7a911aa-e8a2-42a3-a64b-5c2c4318720a",
      "name": "Get all n8n workflows",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -784,
        -144
      ],
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "iV99kO3Ts0Yartt4",
          "name": "N8n"
        }
      },
      "executeOnce": false,
      "retryOnFail": false,
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "20acb740-7157-4e30-bd4d-04b8663a8f8d",
      "name": "Create new backup folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1008,
        -144
      ],
      "parameters": {
        "name": "=Workflows backup - {{ $now.format('yyyy-MM-dd') }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('CONFIG - Set your variables here').item.json.parentFolderId }}"
        },
        "resource": "folder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "82b9a618-2765-4c53-baa7-66a025808c2d",
      "name": "Convert workflow to file",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -240,
        16
      ],
      "parameters": {
        "options": {
          "format": true,
          "fileName": "={{ $json.name + \".json\" }} "
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "1f14d31c-9ab6-4b4f-b054-a02f1b75336f",
      "name": "Upload workflow to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -16,
        16
      ],
      "parameters": {
        "name": "={{ $('Loop over each workflow').item.json.name + \".json\" }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Create new backup folder').item.json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "db4893e5-8a63-4d3d-9067-6a6d68ed3119",
      "name": "Delete old folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        656,
        -480
      ],
      "parameters": {
        "options": {},
        "resource": "folder",
        "operation": "deleteFolder",
        "folderNoRootId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d6769f88-ffc4-4c1d-b8be-082109b12dde",
      "name": "CONFIG - Définir your variables here",
      "type": "n8n-nodes-base.set",
      "position": [
        -1232,
        -144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5da1b756-88b7-4ba2-bc87-0ea4298b78ce",
              "name": "parentFolderId",
              "type": "string",
              "value": "PASTE_YOUR_GOOGLE_DRIVE_PARENT_FOLDER_ID_HERE"
            },
            {
              "id": "79da4836-d768-4b7d-b64f-bc820583613a",
              "name": "backupsToKeep",
              "type": "number",
              "value": 30
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "06268a9d-854e-47ee-b6f5-38c8dd57ee20",
      "name": "Note adhésive",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2112,
        -336
      ],
      "parameters": {
        "width": 560,
        "height": 432,
        "content": "## How to find your Google Drive Folder ID\nTo tell the workflow where to save your backups, you need to provide the ID of a parent folder in your Google Drive.\n\n1.  Go to [Google Drive](https://drive.google.com) and navigate to the folder you want to use. You can also create a new one (e.g., a folder named \"n8n Backups\").\n2.  Click on the folder to open it.\n3.  Look at the URL in your browser's address bar. The Folder ID is the long string of characters at the end of the URL.\n\n**Example:**\nIf your browser URL is:\n`https://drive.google.com/drive/folders/`**`1Fs3gg7pSVhbvODJQLcgAfP-V0rCGC_Oc`**\n\nThen your Folder ID is:\n**`1Fs3gg7pSVhbvODJQLcgAfP-V0rCGC_Oc`**\n\nCopy this ID and paste it into the `parentFolderId` field in the **\"CONFIG - Set your variables here\"** node."
      },
      "typeVersion": 1
    },
    {
      "id": "1907cd86-02d6-473a-a605-4518d83c2b1b",
      "name": "Note adhésive1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -608
      ],
      "parameters": {
        "color": 7,
        "width": 1168,
        "height": 336,
        "content": "## Cleanup Logic: Finds and deletes old backup folders\nThis first part of the workflow handles automatic maintenance. It searches for all existing backup folders in your Google Drive, sorts them by creation date, and keeps only the most recent ones (the number is configurable). All older folders are then automatically deleted to save space.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "dcad82b1-69e9-484f-8d06-cadc311a5ac7",
      "name": "Note adhésive2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -208
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 432,
        "content": "## Backup Logic: Fetches all workflows and uploads them to a new daily folder\nThis is the core backup process. It begins by creating a new, dated folder for the current day's backup. It then fetches a complete list of all your n8n workflows, converts each one into a .json file, and uploads them to the new folder, creating a complete and organized daily snapshot."
      },
      "typeVersion": 1
    },
    {
      "id": "fb976047-3811-437a-b19c-de8def3fe06c",
      "name": "Note adhésive3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2736,
        -560
      ],
      "parameters": {
        "width": 560,
        "height": 848,
        "content": "## Backup n8n workflows to Google Drive with automatic cleanup\n\nThis template automates the process of backing up all your n8n workflows to Google Drive, ensuring you always have a safe copy of your automations. It also includes a smart cleanup mechanism to automatically delete old backups, keeping your Drive organized and saving space.\n\n## Who’s it for\nThis workflow is ideal for any n8n user, from solo developers to teams, who want a reliable and automated \"set-it-and-forget-it\" backup solution for their critical workflows.\n\n## What it does\n* **Daily Execution**: The workflow runs automatically every night (or can be triggered manually).\n* **Automated Cleanup**: After running a new backup, it searches for all previous backup folders. It keeps the most recent ones (you can define how many) and deletes all the older folders.\n* **Creates Daily Folders**: It creates a new, neatly named folder in your Google Drive for each day's backup (e.g., `Workflows backup - 2025-08-17`).\n* **Fetches and Saves**: It connects to your n8n instance via API, fetches all your workflows, and saves each one as a `.json` file inside the daily folder.\n\n## How to set up\n1.  **Configure Credentials**: Make sure you have valid credentials for:\n    * **n8n API**: To allow the workflow to access its own list of workflows.\n    * **Google Drive**: To allow the workflow to create folders and upload files.\n2.  **Set Your Variables**: In the first `Set` node named **\"CONFIG - Set your variables here\"**:\n    * `parentFolderId`: Paste the ID of the main Google Drive folder where you want all your daily backup folders to be stored.\n    * `backupsToKeep`: Set the number of recent backups you wish to keep (e.g., 30 for a month's worth).\n\nActivate the workflow, and you're all set!"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "c7d51e5b-0add-4c66-8d85-e98d3a09f72e": {
      "main": [
        [
          {
            "node": "CONFIG - Set your variables here",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "CONFIG - Set your variables here",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "db4893e5-8a63-4d3d-9067-6a6d68ed3119": {
      "main": [
        [
          {
            "node": "ff6c6c87-2751-4429-a196-edc65f898e43",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "c7a911aa-e8a2-42a3-a64b-5c2c4318720a": {
      "main": [
        [
          {
            "node": "7669d1df-6225-47aa-841b-c14f48cbd2e3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7669d1df-6225-47aa-841b-c14f48cbd2e3": {
      "main": [
        [
          {
            "node": "Start cleanup (run once)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "82b9a618-2765-4c53-baa7-66a025808c2d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "82b9a618-2765-4c53-baa7-66a025808c2d": {
      "main": [
        [
          {
            "node": "1f14d31c-9ab6-4b4f-b054-a02f1b75336f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "20acb740-7157-4e30-bd4d-04b8663a8f8d": {
      "main": [
        [
          {
            "node": "c7a911aa-e8a2-42a3-a64b-5c2c4318720a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search files and folders": {
      "main": [
        [
          {
            "node": "Sort and isolate old folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start cleanup (run once)": {
      "main": [
        [
          {
            "node": "Search files and folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ff6c6c87-2751-4429-a196-edc65f898e43": {
      "main": [
        [],
        [
          {
            "node": "db4893e5-8a63-4d3d-9067-6a6d68ed3119",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort and isolate old folders": {
      "main": [
        [
          {
            "node": "ff6c6c87-2751-4429-a196-edc65f898e43",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1f14d31c-9ab6-4b4f-b054-a02f1b75336f": {
      "main": [
        [
          {
            "node": "7669d1df-6225-47aa-841b-c14f48cbd2e3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CONFIG - Set your variables here": {
      "main": [
        [
          {
            "node": "20acb740-7157-4e30-bd4d-04b8663a8f8d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Foire aux questions

Comment utiliser ce workflow ?

Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.

Dans quelles scénarios ce workflow est-il adapté ?

Avancé - DevOps, IA Multimodale

Est-ce payant ?

Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.

Informations sur le workflow
Niveau de difficulté
Avancé
Nombre de nœuds17
Catégorie2
Types de nœuds9
Description de la difficulté

Adapté aux utilisateurs avancés, avec des workflows complexes contenant 16+ nœuds

Liens externes
Voir sur n8n.io

Partager ce workflow

Catégories

Catégories: 34