{
  "name": "Logixb2b — Backup diario de workflows n8n",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Cada noche (02:00): lista workflows vía Public API, publica checklist en Slack (Sheets opcional). Complemento operativo al backup de volúmenes/DB en self-hosted."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "backup"
    },
    {
      "name": "ops"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Backup diario de workflows n8n\n\n**Recurso:** `/recursos/n8n-backup-export-diario`\n**Guía:** /n8n-self-hosted-vs-n8n-cloud\n**Zona:** Europe/Madrid · `active: false` al importar (tú lo activas).\n\n### 1) Importar\n1. n8n → ⋯ → **Import from File** → este JSON.\n2. El flujo llega **inactive**. No pegues secretos en el lienzo ni en el archivo.\n\n### 2) Credenciales y configuración por nodo\n- **Cada noche 02:00** (`schedule`): sin credencial. Revisa expresión cron / intervalo y zona **Europe/Madrid** (settings del workflow). Solo dispara si n8n está **Active** 24/7.\n- **Config backup** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **GET workflows (Public API)** (`HTTP Request` API n8n): Credentials → **Header Auth** con API key de n8n (`X-N8N-API-KEY`). URL base = tu instancia (`https://n8n.tudominio.com`).\n- **Armar checklist resumen** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **Append Google Sheets (opcional)** (`HTTP Request` Sheets): mejor migrar a nodo Google Sheets; si dejas HTTP, usa OAuth2 Bearer de Google.\n- **Slack — backup checklist del día** (`HTTP Request` → Slack/Teams): crea Incoming Webhook en Slack (o Adaptive Card URL en Teams). Pega la URL en **Config** o en este nodo. Auth: none (la URL ya es secreta).\n\n### 3) Orden recomendado de puesta en marcha\n1. Rellena el nodo **Config** (URLs reales, umbrales, webhooks de Slack).\n2. Crea Credentials en n8n (candado de cada nodo HTTP / Sheets / OpenAI) y **enlázalas**.\n3. Ejecuta **una vez** (Manual / Test URL del Webhook / \"Execute workflow\").\n4. Verifica CRM + Slack/Sheets (y que la IA no escriba en producción sin HITL).\n5. Solo entonces: interruptor **Active**.\n\n### 4) Producción 24/7 en VPS (UE)\nImportar en localhost no basta: webhooks y cron necesitan n8n encendido.\n\n1. VPS en UE (Hetzner/OVH/IONOS…) + Docker Compose + **Postgres** + HTTPS (Caddy/Nginx).\n2. Variables mínimas: `GENERIC_TIMEZONE=Europe/Madrid`, `WEBHOOK_URL=https://n8n.tudominio.com/`, `N8N_ENCRYPTION_KEY`, `N8N_HOST` / `N8N_PROTOCOL=https`.\n3. Firewall: solo 80/443 (+ SSH). Backups del volumen Postgres + export de workflows.\n4. Importa este JSON en la instancia de producción, vuelve a crear Credentials (no se copian solas), actualiza URLs del Config al dominio real.\n5. Pon **Active**. Prueba el Webhook de producción o espera el próximo cron.\n6. Alternativa: **n8n Cloud** (mismo JSON; Credentials en la UI Cloud).\n\n### 5) RGPD + EU AI Act (resumen)\nSi hay nodos IA sois **deployers** (Reglamento UE 2024/1689). Art. 4 alfabetización. **HITL** antes de outreach, scores masivos o pausas de cuenta. Minimiza PII en Slack/logs. Informativo — no es asesoramiento legal. /uso-responsable-de-ia-y-transparencia\n",
        "height": 1500,
        "width": 580,
        "color": 4
      }
    },
    {
      "id": "bak-trigger-schedule",
      "name": "Cada noche 02:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 2 * * *"
            }
          ]
        }
      }
    },
    {
      "id": "bak-set-config",
      "name": "Config backup",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "bak-c1",
              "name": "n8nApiBase",
              "value": "https://TU-N8N.ejemplo",
              "type": "string"
            },
            {
              "id": "bak-c2",
              "name": "apiKey",
              "value": "sustituye-con-tu-clave-de-acceso-n8n",
              "type": "string"
            },
            {
              "id": "bak-c3",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            },
            {
              "id": "bak-c4",
              "name": "sheetsAppendUrl",
              "value": "https://sheets.googleapis.com/v4/spreadsheets/TU_SHEET_ID/values/Backup!A1:append?valueInputOption=USER_ENTERED",
              "type": "string"
            },
            {
              "id": "bak-c5",
              "name": "checkedAt",
              "value": "={{ $now.setZone('Europe/Madrid').toFormat('yyyy-MM-dd HH:mm') }}",
              "type": "string"
            },
            {
              "id": "bak-c6",
              "name": "checkedDate",
              "value": "={{ $now.setZone('Europe/Madrid').toFormat('yyyy-MM-dd') }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "bak-http-list",
      "name": "GET workflows (Public API)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        600,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ $json.n8nApiBase }}/api/v1/workflows",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-N8N-API-KEY",
              "value": "={{ $json.apiKey }}"
            }
          ]
        },
        "options": {
          "timeout": 20000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      }
    },
    {
      "id": "bak-set-summary",
      "name": "Armar checklist resumen",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "bak-s1",
              "name": "statusCode",
              "value": "={{ $json.statusCode }}",
              "type": "number"
            },
            {
              "id": "bak-s2",
              "name": "apiOk",
              "value": "={{ Number($json.statusCode) >= 200 && Number($json.statusCode) < 300 }}",
              "type": "boolean"
            },
            {
              "id": "bak-s3",
              "name": "workflowCount",
              "value": "={{ Array.isArray($json.body?.data) ? $json.body.data.length : (Array.isArray($json.body) ? $json.body.length : 0) }}",
              "type": "number"
            },
            {
              "id": "bak-s4",
              "name": "workflowNames",
              "value": "={{ (Array.isArray($json.body?.data) ? $json.body.data : (Array.isArray($json.body) ? $json.body : [])).map(w => w.name || w.id).slice(0, 40).join(', ') || '(sin nombres)' }}",
              "type": "string"
            },
            {
              "id": "bak-s5",
              "name": "checkedAt",
              "value": "={{ $('Config backup').item.json.checkedAt }}",
              "type": "string"
            },
            {
              "id": "bak-s6",
              "name": "checkedDate",
              "value": "={{ $('Config backup').item.json.checkedDate }}",
              "type": "string"
            },
            {
              "id": "bak-s7",
              "name": "slackWebhookUrl",
              "value": "={{ $('Config backup').item.json.slackWebhookUrl }}",
              "type": "string"
            },
            {
              "id": "bak-s8",
              "name": "sheetsAppendUrl",
              "value": "={{ $('Config backup').item.json.sheetsAppendUrl }}",
              "type": "string"
            },
            {
              "id": "bak-s9",
              "name": "n8nApiBase",
              "value": "={{ $('Config backup').item.json.n8nApiBase }}",
              "type": "string"
            },
            {
              "id": "bak-s10",
              "name": "checklistText",
              "value": "={{ ':floppy_disk: *Backup checklist del día* — ' + $('Config backup').item.json.checkedDate + '\\nInstancia: `' + $('Config backup').item.json.n8nApiBase + '`\\nWorkflows listados: *' + (Array.isArray($json.body?.data) ? $json.body.data.length : (Array.isArray($json.body) ? $json.body.length : 0)) + '*\\nHTTP API: ' + $json.statusCode + '\\nNombres: ' + ((Array.isArray($json.body?.data) ? $json.body.data : (Array.isArray($json.body) ? $json.body : [])).map(w => w.name || w.id).slice(0, 40).join(', ') || '(sin nombres)') + '\\nHora: ' + $('Config backup').item.json.checkedAt + ' (Europe/Madrid)\\nAcción Ops: confirmar volumen/DB backup + esta lista.' }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "bak-http-sheets",
      "name": "Append Google Sheets (opcional)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.sheetsAppendUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ values: [[ $json.checkedDate, $json.workflowCount, $json.statusCode, $json.workflowNames, $json.checkedAt ]] }) }}",
        "options": {
          "timeout": 15000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      }
    },
    {
      "id": "bak-slack",
      "name": "Slack — backup checklist del día",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1500,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $('Armar checklist resumen').item.json.slackWebhookUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.slackText || 'Actualización Logixb2b' }) }}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Cada noche 02:00": {
      "main": [
        [
          {
            "node": "Config backup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config backup": {
      "main": [
        [
          {
            "node": "GET workflows (Public API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET workflows (Public API)": {
      "main": [
        [
          {
            "node": "Armar checklist resumen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Armar checklist resumen": {
      "main": [
        [
          {
            "node": "Append Google Sheets (opcional)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Google Sheets (opcional)": {
      "main": [
        [
          {
            "node": "Slack — backup checklist del día",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
