{
  "name": "Database Backup to Google Drive",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Daily at 2am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT * FROM your_table",
        "options": {}
      },
      "id": "postgres-query",
      "name": "Export PostgreSQL",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "method": "csv",
        "data": "={{ $json }}"
      },
      "id": "convert-csv",
      "name": "Convert to CSV",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "operation": "upload",
        "name": "={{ 'backup-' + new Date().toISOString().split('T')[0] + '.csv' }}",
        "mimeType": "text/csv",
        "parents": [
          {
            "id": {
              "value": "your-backup-folder-id",
              "mode": "raw"
            }
          }
        ]
      },
      "id": "drive-upload",
      "name": "Upload to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        1000,
        300
      ]
    },
    {
      "parameters": {
        "channel": "#ops",
        "text": "=Database backup completed: {{ new Date().toLocaleString() }} \u2014 {{ $json.name }} uploaded to Drive"
      },
      "id": "slack-confirm",
      "name": "Confirm on Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        1250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "search",
        "searchQuery": "=name contains 'backup-'",
        "returnAll": true,
        "options": {
          "fields": "files(name, createdTime)",
          "orderBy": "createdTime desc",
          "pageSize": 100
        }
      },
      "id": "list-backups",
      "name": "List Old Backups",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        1250,
        500
      ]
    },
    {
      "parameters": {
        "operation": "delete",
        "fileId": "={{ $json.id }}",
        "options": {}
      },
      "id": "delete-old",
      "name": "Delete > 7 Days Old",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        1500,
        500
      ]
    }
  ],
  "connections": {
    "Daily at 2am": {
      "main": [
        [
          {
            "node": "Export PostgreSQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Export PostgreSQL": {
      "main": [
        [
          {
            "node": "Convert to CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to CSV": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Confirm on Slack",
            "type": "main",
            "index": 0
          },
          {
            "node": "List Old Backups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Old Backups": {
      "main": [
        [
          {
            "node": "Delete > 7 Days Old",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {},
  "staticData": null
}