{
  "name": "Database Backup",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 2
            }
          ]
        }
      },
      "id": "daily-backup",
      "name": "Daily at 2AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "command": "pg_dump -h postgres -U easycv -d easycv -F c -f /backups/easycv_$(date +%Y%m%d_%H%M%S).dump"
      },
      "id": "pg-dump",
      "name": "PostgreSQL Dump",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "command": "find /backups -name 'easycv_*.dump' -mtime +7 -delete"
      },
      "id": "cleanup-old",
      "name": "Cleanup Old Backups",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.exitCode }}",
              "operation": "notEqual",
              "value2": 0
            }
          ]
        }
      },
      "id": "check-error",
      "name": "Backup Failed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "easycv@yourdomain.com",
        "toEmail": "admin@yourdomain.com",
        "subject": "\u26a0\ufe0f EasyCV Backup Failed",
        "text": "Database backup failed at {{ $now }}\n\nError: {{ $json.stderr }}"
      },
      "id": "alert-failure",
      "name": "Alert on Failure",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        1050,
        200
      ]
    }
  ],
  "connections": {
    "Daily at 2AM": {
      "main": [
        [
          {
            "node": "PostgreSQL Dump",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PostgreSQL Dump": {
      "main": [
        [
          {
            "node": "Cleanup Old Backups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cleanup Old Backups": {
      "main": [
        [
          {
            "node": "Backup Failed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Backup Failed?": {
      "main": [
        [
          {
            "node": "Alert on Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "easycv",
    "backup",
    "maintenance"
  ]
}