Sauvegarde de Postgres en CSV vers GitHub

Avancé

Ceci est unDevOps, Multimodal AIworkflow d'automatisation du domainecontenant 17 nœuds.Utilise principalement des nœuds comme If, Code, Github, Postgres, ItemLists. Sauvegarde quotidienne de la table Postgres au format CSV vers GitHub

Prérequis
  • Personal Access Token GitHub
  • Informations de connexion à la base de données PostgreSQL
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
{
  "id": "oBJaQvcNxODDoAl1",
  "meta": {
    "instanceId": "52254486b159b349334953c1738da94e90477c7604aa8db2062d11afc0120739",
    "templateCredsSetupCompleted": true
  },
  "name": "backup postgres as csv to github",
  "tags": [],
  "nodes": [
    {
      "id": "20477146-5542-4701-a92f-4300c95a0c5d",
      "name": "Planification quotidienne",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1712,
        -96
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3f5ec59d-374f-421c-a333-155c06443e5d",
      "name": "Lister les tables",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -544,
        64
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $json.table_name }}"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "select",
        "returnAll": true
      },
      "credentials": {
        "postgres": {
          "id": "0bZEnNx2jwoEznOw",
          "name": "pg - n8n-discord-trigger-bot"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "8d8af1f2-5b28-449d-a354-a624f9e2a53c",
      "name": "Boucle sur les éléments",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -912,
        -96
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "680847b4-e704-4728-8ee2-44642d931d58",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        -752,
        64
      ],
      "parameters": {
        "jsCode": "return $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "0ec30d45-c281-4d65-a966-29f615eade3a",
      "name": "Convertir en fichier1",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -336,
        64
      ],
      "parameters": {
        "options": {
          "fileName": "={{ $('List tables1').item.json.table_name }}"
        },
        "binaryPropertyName": "=data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "09466877-0cdb-4011-809f-87c696ab3717",
      "name": "Lister les tables1",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -1104,
        -96
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tables",
          "cachedResultName": "tables"
        },
        "where": {
          "values": [
            {
              "value": "public",
              "column": "table_schema"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "information_schema",
          "cachedResultName": "information_schema"
        },
        "options": {},
        "operation": "select"
      },
      "credentials": {
        "postgres": {
          "id": "0bZEnNx2jwoEznOw",
          "name": "pg - n8n-discord-trigger-bot"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "014fa66c-4acc-4698-97cc-142efaae9376",
      "name": "Lister les fichiers du dépôt [GITHUB]",
      "type": "n8n-nodes-base.github",
      "position": [
        -1536,
        -96
      ],
      "webhookId": "f7310d6a-1573-4848-9757-f9a75e359e73",
      "parameters": {
        "owner": {
          "__rl": true,
          "mode": "name",
          "value": "user"
        },
        "filePath": "=",
        "resource": "file",
        "operation": "list",
        "repository": {
          "__rl": true,
          "mode": "list",
          "value": "github-repo",
          "cachedResultUrl": "https://github.com/user/github-repo",
          "cachedResultName": "github-repo"
        },
        "authentication": "oAuth2"
      },
      "credentials": {
        "githubOAuth2Api": {
          "id": "g3sESgnuArjRvV8F",
          "name": "GitHub account"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "5942926d-b940-4ba4-a0c1-7209c04c0a3c",
      "name": "Combiner les noms de fichiers [GITHUB]",
      "type": "n8n-nodes-base.itemLists",
      "position": [
        -1344,
        -96
      ],
      "parameters": {
        "options": {},
        "operation": "aggregateItems",
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "name"
            }
          ]
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "00aa6a0e-b5c1-4093-8ee0-94b35bcdd934",
      "name": "Note adhésive2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1584,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 390,
        "height": 547,
        "content": "## Get list of current tables\nReturn a list of existing files in GitHub repository. \nSome of them are tables, \nSome are readme files"
      },
      "typeVersion": 1
    },
    {
      "id": "863c59ef-6ce2-4c22-8c0e-00b9abcfdbd9",
      "name": "Diviser en éléments individuels",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -80,
        -112
      ],
      "parameters": {
        "options": {},
        "batchSize": 1
      },
      "typeVersion": 2
    },
    {
      "id": "ccee7881-77c8-419e-ad99-ac3bb113ae6b",
      "name": "Vérifier si le fichier existe dans le dépôt",
      "type": "n8n-nodes-base.if",
      "position": [
        160,
        -128
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $node['Combine file names [GITHUB]'].json.name }}",
              "value2": "={{ $binary.data.fileName }}",
              "operation": "contains"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f6d53dcc-1e40-43f5-b793-4d06a55ccbed",
      "name": "Mettre à jour le fichier [GITHUB]",
      "type": "n8n-nodes-base.github",
      "position": [
        384,
        -128
      ],
      "webhookId": "fb5f5095-cf60-4421-8b83-91041cfc8929",
      "parameters": {
        "owner": {
          "__rl": true,
          "mode": "name",
          "value": "user"
        },
        "filePath": "={{ $binary.data.fileName }}",
        "resource": "file",
        "operation": "edit",
        "binaryData": true,
        "repository": {
          "__rl": true,
          "mode": "list",
          "value": "github-repo",
          "cachedResultUrl": "https://github.com/user/github-repo",
          "cachedResultName": "github-repo"
        },
        "commitMessage": "=backup-{{ $now.toMillis() }}",
        "authentication": "oAuth2"
      },
      "credentials": {
        "githubOAuth2Api": {
          "id": "g3sESgnuArjRvV8F",
          "name": "GitHub account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ebcd65d3-37ac-4d47-90dc-fede45adb9c0",
      "name": "Téléverser le fichier [GITHUB]",
      "type": "n8n-nodes-base.github",
      "position": [
        384,
        80
      ],
      "webhookId": "17b56fbd-32da-4e39-ae22-8c01a7b4bbb6",
      "parameters": {
        "owner": {
          "__rl": true,
          "mode": "name",
          "value": "user"
        },
        "filePath": "={{ $binary.data.fileName }}",
        "resource": "file",
        "binaryData": true,
        "repository": {
          "__rl": true,
          "mode": "list",
          "value": "github-repo",
          "cachedResultUrl": "https://github.com/user/github-repo",
          "cachedResultName": "github-repo"
        },
        "commitMessage": "=backup-{{ $node['Set commit date'].json.commitDate }}",
        "authentication": "oAuth2"
      },
      "credentials": {
        "githubOAuth2Api": {
          "id": "g3sESgnuArjRvV8F",
          "name": "GitHub account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6bcbeffb-b036-45f3-88a8-dd5f1ac0fa39",
      "name": "Note adhésive",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1168,
        -256
      ],
      "parameters": {
        "color": 5,
        "width": 998,
        "height": 547,
        "content": "## Get postgres table data\nReturn a list of existing tables and data in the postgres.  \nConvert them to csv"
      },
      "typeVersion": 1
    },
    {
      "id": "88cc96e5-fc5b-4d28-8e57-82c193efb19d",
      "name": "Note adhésive1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 694,
        "height": 547,
        "content": "## Make a list of existing files\nCreate backup if its a new table. \nUpdate backup if there is new data in the table"
      },
      "typeVersion": 1
    },
    {
      "id": "4b4f32d2-2138-4d9a-8d48-6b35b387270a",
      "name": "Note adhésive3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -848,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 374,
        "height": 195,
        "content": "![postgres table](https://articles.emp0.com/wp-content/uploads/2025/08/backup-postgres-to-github-tables.png)"
      },
      "typeVersion": 1
    },
    {
      "id": "02ddc44f-7c23-4022-9978-c43876593274",
      "name": "Note adhésive4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 694,
        "height": 259,
        "content": "![github backup](https://articles.emp0.com/wp-content/uploads/2025/08/backup-postgres-to-github-repo.png)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "747a3b1e-5b2a-4f61-875c-250bd44fbf01",
  "connections": {
    "680847b4-e704-4728-8ee2-44642d931d58": {
      "main": [
        [
          {
            "node": "3f5ec59d-374f-421c-a333-155c06443e5d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3f5ec59d-374f-421c-a333-155c06443e5d": {
      "main": [
        [
          {
            "node": "0ec30d45-c281-4d65-a966-29f615eade3a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "09466877-0cdb-4011-809f-87c696ab3717": {
      "main": [
        [
          {
            "node": "8d8af1f2-5b28-449d-a354-a624f9e2a53c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "20477146-5542-4701-a92f-4300c95a0c5d": {
      "main": [
        [
          {
            "node": "014fa66c-4acc-4698-97cc-142efaae9376",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8d8af1f2-5b28-449d-a354-a624f9e2a53c": {
      "main": [
        [
          {
            "node": "863c59ef-6ce2-4c22-8c0e-00b9abcfdbd9",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "680847b4-e704-4728-8ee2-44642d931d58",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "0ec30d45-c281-4d65-a966-29f615eade3a": {
      "main": [
        [
          {
            "node": "8d8af1f2-5b28-449d-a354-a624f9e2a53c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f6d53dcc-1e40-43f5-b793-4d06a55ccbed": {
      "main": [
        [
          {
            "node": "863c59ef-6ce2-4c22-8c0e-00b9abcfdbd9",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ebcd65d3-37ac-4d47-90dc-fede45adb9c0": {
      "main": [
        [
          {
            "node": "863c59ef-6ce2-4c22-8c0e-00b9abcfdbd9",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "863c59ef-6ce2-4c22-8c0e-00b9abcfdbd9": {
      "main": [
        [
          {
            "node": "ccee7881-77c8-419e-ad99-ac3bb113ae6b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5942926d-b940-4ba4-a0c1-7209c04c0a3c": {
      "main": [
        [
          {
            "node": "09466877-0cdb-4011-809f-87c696ab3717",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ccee7881-77c8-419e-ad99-ac3bb113ae6b": {
      "main": [
        [
          {
            "node": "f6d53dcc-1e40-43f5-b793-4d06a55ccbed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ebcd65d3-37ac-4d47-90dc-fede45adb9c0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "014fa66c-4acc-4698-97cc-142efaae9376": {
      "main": [
        [
          {
            "node": "5942926d-b940-4ba4-a0c1-7209c04c0a3c",
            "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

Auteur
Jay Emp0

Jay Emp0

@jay-emp0

AI and Automation developer. Im implementing n8n and ai tools to automate marketing and sales in companies

Liens externes
Voir sur n8n.io

Partager ce workflow

Catégories

Catégories: 34