{
  "name": "Backup Database + Thông Báo Telegram",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [{ "field": "cronExpression", "expression": "0 2 * * *" }]
        }
      },
      "id": "c1b2c3d4-3333-4aaa-bbbb-000000000001",
      "name": "Cron Daily 2AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [260, 300]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SHOW DATABASES"
      },
      "id": "c1b2c3d4-3333-4aaa-bbbb-000000000002",
      "name": "List Databases",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [480, 300],
      "credentials": {
        "mySql": { "id": "4", "name": "MySQL Production" }
      }
    },
    {
      "parameters": {
        "command": "mysqldump -u root -p$DB_PASSWORD --all-databases | gzip > /backups/db_backup_$(date +%Y%m%d_%H%M%S).sql.gz && echo '{\"status\":\"success\",\"file\":\"/backups/db_backup_'$(date +%Y%m%d_%H%M%S)'.sql.gz\"}'"
      },
      "id": "c1b2c3d4-3333-4aaa-bbbb-000000000003",
      "name": "Run Backup",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [700, 300]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.stdout }}",
              "rightValue": "success",
              "operator": { "type": "string", "operation": "contains" }
            }
          ]
        }
      },
      "id": "c1b2c3d4-3333-4aaa-bbbb-000000000004",
      "name": "Check Result",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [920, 300]
    },
    {
      "parameters": {
        "chatId": "YOUR_CHAT_ID",
        "text": "=✅ *Backup thành công!*\n📅 Thời gian: {{ $now.format('dd/MM/yyyy HH:mm') }}\n📦 File: {{ $json.stdout }}",
        "additionalFields": { "parse_mode": "Markdown" }
      },
      "id": "c1b2c3d4-3333-4aaa-bbbb-000000000005",
      "name": "Notify Success",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [1160, 200],
      "credentials": {
        "telegramApi": { "id": "2", "name": "Telegram Bot" }
      }
    },
    {
      "parameters": {
        "chatId": "YOUR_CHAT_ID",
        "text": "=❌ *Backup THẤT BẠI!*\n📅 Thời gian: {{ $now.format('dd/MM/yyyy HH:mm') }}\n⚠️ Lỗi: {{ $json.stderr }}",
        "additionalFields": { "parse_mode": "Markdown" }
      },
      "id": "c1b2c3d4-3333-4aaa-bbbb-000000000006",
      "name": "Notify Failure",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [1160, 420],
      "credentials": {
        "telegramApi": { "id": "2", "name": "Telegram Bot" }
      }
    }
  ],
  "connections": {
    "Cron Daily 2AM": { "main": [[{ "node": "List Databases", "type": "main", "index": 0 }]] },
    "List Databases": { "main": [[{ "node": "Run Backup", "type": "main", "index": 0 }]] },
    "Run Backup": { "main": [[{ "node": "Check Result", "type": "main", "index": 0 }]] },
    "Check Result": {
      "main": [
        [{ "node": "Notify Success", "type": "main", "index": 0 }],
        [{ "node": "Notify Failure", "type": "main", "index": 0 }]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
