Backups n8n en GitHub
Itops
Aitor
(@TuXeD)
Copiar
Guía paso a paso para configurar un workflow en n8n que realice backups automáticos de tus workflows y credenciales en un repositorio privado de GitHub, con instrucciones para restaurar versiones específicas fácilmente.
Creado: 2024-11-27
11 nodos
{
"name": "Backup",
"nodes": [
{
"parameters": {},
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"position": [
140,
740
],
"typeVersion": 1,
"id": "de7bdc81-7750-419b-a942-5ff3cb3ddab6"
},
{
"parameters": {
"command": "npx n8n export:credentials --backup --output repo/$N8N_HOST/credentials/"
},
"name": "Export Credentials",
"type": "n8n-nodes-base.executeCommand",
"position": [
700,
1020
],
"typeVersion": 1,
"id": "57c3a731-d539-428a-8acb-f867fa6a0259"
},
{
"parameters": {
"command": "git -C repo add ."
},
"name": "git add",
"type": "n8n-nodes-base.executeCommand",
"position": [
900,
1020
],
"typeVersion": 1,
"id": "0f6072c6-1c1a-47b4-a322-d773ba4bf12a"
},
{
"parameters": {
"command": "=cd /home/node/repo/; git commit -am \"Auto backup - $N8N_HOST ({{ new Date().toISOString() }})\""
},
"name": "git commit",
"type": "n8n-nodes-base.executeCommand",
"position": [
1080,
1020
],
"typeVersion": 1,
"id": "c179aef2-9f58-4946-aec6-eaf84df74edc"
},
{
"parameters": {
"command": "cd /home/node/repo/; git push"
},
"name": "git push",
"type": "n8n-nodes-base.executeCommand",
"position": [
1280,
1020
],
"typeVersion": 1,
"id": "c3eaddbe-de16-4eb4-939a-b328feedb176"
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"hour": 0
},
{
"hour": 12
},
{
"hour": 6
},
{
"hour": 18
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"position": [
140,
560
],
"typeVersion": 1,
"id": "b9c31b30-8d31-45fe-9a64-aa67742d9848"
},
{
"parameters": {
"content": "## Configuraci\u00f3n Inicial del repo",
"height": 274,
"width": 512
},
"id": "ac3560e0-7faa-4fa4-9ebd-98d26548e095",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
460,
460
]
},
{
"parameters": {
"command": "git -C repo pull; npx n8n export:workflow --backup --output repo/$N8N_HOST/workflows/"
},
"name": "Export Workflows",
"type": "n8n-nodes-base.executeCommand",
"position": [
500,
1020
],
"typeVersion": 1,
"id": "b48c9114-483f-43ed-b97d-7a738197c182"
},
{
"parameters": {
"command": "=# Verifica si el directorio /home/node/repo NO existe\n## rm -Rf /home/node/repo\nif [ ! -d \"/home/node/repo\" ]; then\n # Clona el repositorio en el directorio especificado\n git clone https://{{ $json[\"github_username\"] }}:{{ $json[\"github_token\"] }}@{{ $json[\"repo\"] }} /home/node/repo\n \n # Configura el email y nombre de usuario global de git\n git config --global user.email \"{{ $json[\"email\"] }}\"\n git config --global user.name \"{{ $json[\"nombre\"] }}\"\nfi\n"
},
"id": "2b92038b-aced-43a8-8c5b-34944656fd84",
"name": "Configura repo",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [
800,
560
]
},
{
"parameters": {
"content": "## Creaci\u00f3n del backup versionado",
"height": 365,
"width": 973
},
"id": "511004af-f48a-484b-b398-4ed00d117731",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
460,
900
]
},
{
"parameters": {
"fields": {
"values": [
{
"name": "nombre",
"stringValue": "Aitor"
},
{
"name": "email",
"stringValue": "tuxed@redaven.com"
},
{
"name": "repo",
"stringValue": "github.com/aitorroma/n8n-backup"
},
{
"name": "github_token",
"stringValue": "ghp_aquivatutoken"
},
{
"name": "github_username",
"stringValue": "aitorroma"
}
]
},
"options": {}
},
"id": "c546635a-ed1f-4b3f-bf90-9100c2bae7a3",
"name": "Configurar",
"type": "n8n-nodes-base.set",
"typeVersion": 3.2,
"position": [
520,
560
]
}
],
"pinData": {},
"connections": {
"On clicking 'execute'": {
"main": [
[
{
"node": "Configurar",
"type": "main",
"index": 0
}
]
]
},
"Export Credentials": {
"main": [
[
{
"node": "git add",
"type": "main",
"index": 0
}
]
]
},
"git add": {
"main": [
[
{
"node": "git commit",
"type": "main",
"index": 0
}
]
]
},
"git commit": {
"main": [
[
{
"node": "git push",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Configurar",
"type": "main",
"index": 0
}
]
]
},
"Export Workflows": {
"main": [
[
{
"node": "Export Credentials",
"type": "main",
"index": 0
}
]
]
},
"Configura repo": {
"main": [
[
{
"node": "Export Workflows",
"type": "main",
"index": 0
}
]
]
},
"Configurar": {
"main": [
[
{
"node": "Configura repo",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1"
},
"versionId": "947c9216-71b4-474e-a769-4c98fc1b1cf7",
"id": "RKgEHgCOvn2N4Grm",
"meta": {
"instanceId": "7f10d86e89b48fa8aec09915dd753bb0235f16d55a7b759c6d3762ab9ca02bd6"
},
"tags": []
}