{
  "id": "YeYi657TmrNBAlHy",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Airtable Full Backup",
  "tags": [],
  "nodes": [
    {
      "id": "2cfec4e1-08ad-4363-a3af-5aa77174ea1a",
      "name": "Airtable",
      "type": "n8n-nodes-base.airtable",
      "position": [
        380,
        -40
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "yourbase",
          "cachedResultUrl": "https://airtable.com/yourbase",
          "cachedResultName": "Sample Base"
        },
        "resource": "base",
        "operation": "getSchema"
      },
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "45e6e8e3-2b72-44ae-ae5a-84ade2dfb59b",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        600,
        -40
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "8c731bd7-54a7-443f-91de-1dedfcb79620",
      "name": "Create Table Metadata",
      "type": "n8n-nodes-base.set",
      "position": [
        1040,
        60
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "cea4432c-e31c-43bd-adea-446658a96ab5",
              "name": "fileName",
              "type": "string",
              "value": "={{ $json.name.replace(/[^\\p{L}\\p{N}\\s_-]+/gu, '').trim().replace(/\\s+/g, '_')                      \n}}"
            },
            {
              "id": "34f5e44c-1d62-47ac-875b-9bbe698ffc0d",
              "name": "tableName",
              "type": "string",
              "value": "={{ $json.name }}"
            },
            {
              "id": "4a06c76d-7ac3-4fe9-96e3-003e80e0bf1e",
              "name": "tableID",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "57d1b06e-5265-4beb-b53f-9be2f9f1f300",
      "name": "Pull Records",
      "type": "n8n-nodes-base.airtable",
      "position": [
        1260,
        60
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "yourbase",
          "cachedResultUrl": "https://airtable.com/yourbase",
          "cachedResultName": "LifeOS"
        },
        "table": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.tableID }}"
        },
        "options": {},
        "operation": "search"
      },
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "0872652a-6924-4a56-8058-69b51ecc8ee2",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1480,
        60
      ],
      "parameters": {
        "options": {
          "fileName": "={{ $('Create Table Metadata').item.json.fileName }}.csv"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "167783d9-3fad-4a3c-827b-911b8d3587f7",
      "name": "AWS S3",
      "type": "n8n-nodes-base.awsS3",
      "position": [
        1700,
        60
      ],
      "parameters": {
        "fileName": "={{ $('Create Table Metadata').item.json.fileName }}.csv",
        "operation": "upload",
        "bucketName": "aired-out",
        "additionalFields": {
          "parentFolderKey": "={{ $('Set Week').item.json.currentWeek }}"
        }
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c766b901-e06c-457c-9407-a999b7eaecd0",
      "name": "Monthly Prune",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -320,
        500
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3fb466cd-90ad-4757-9df1-b7e2c317b454",
      "name": "Set Timestamps",
      "type": "n8n-nodes-base.set",
      "position": [
        -80,
        500
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ca8f6d53-152c-44ea-b0c8-eb5a7ba7fbf4",
              "name": "cutoffDate",
              "type": "string",
              "value": "={{ $now.minus({ weeks: 4 }).toFormat(\"kkkk-'W'WW\") }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "dacaac6b-1025-4c57-82f2-d17b387c4258",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        340,
        500
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9c09f6cc-9313-42ba-b48e-c8cc2faaebac",
              "operator": {
                "type": "dateTime",
                "operation": "before"
              },
              "leftValue": "={{ $json.Key.replace(/\\/$/, '') }}",
              "rightValue": "={{ $('Set Timestamps').item.json.cutoffDate }}"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "e279fa0d-af6c-4dc2-9ac3-89e3a08280f8",
      "name": "Delete File",
      "type": "n8n-nodes-base.awsS3",
      "position": [
        560,
        420
      ],
      "parameters": {
        "resource": "folder",
        "folderKey": "={{ $('List Folders').item.json.Key }}",
        "operation": "delete",
        "bucketName": "aired-out"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "8a2e4f1e-8a07-4f77-a05d-90cfca9d96da",
      "name": "Create Folder",
      "type": "n8n-nodes-base.awsS3",
      "position": [
        140,
        -40
      ],
      "parameters": {
        "resource": "folder",
        "bucketName": "aired-out",
        "folderName": "={{ $json.currentWeek }}",
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "69d7bfdc-657a-402c-b9ef-f230660be1f9",
      "name": "List Folders",
      "type": "n8n-nodes-base.awsS3",
      "position": [
        120,
        500
      ],
      "parameters": {
        "options": {},
        "resource": "folder",
        "operation": "getAll",
        "bucketName": "aired-out"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "35a136e1-4acc-4754-952e-69cf940219b0",
      "name": "Set Week",
      "type": "n8n-nodes-base.set",
      "position": [
        -80,
        -40
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f5e7fb15-bf9c-4f6d-9476-15320ff150a6",
              "name": "currentWeek",
              "type": "string",
              "value": "={{ $now.toFormat(\"kkkk-'W'WW\") }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ca332df0-313d-44fe-81da-f4fabcad8cf6",
      "name": "Weekly Backup",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -320,
        -40
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtHour": 12
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "68d97be1-f32f-4ada-85c3-7db8d3639262",
      "name": "Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1260,
        -140
      ],
      "parameters": {
        "text": "=:floppy_disk: *Airtable Backup Complete*",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C08GPG2HTA4",
          "cachedResultName": "general"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "8f7bf5dd-1e42-4979-808a-99c6db31f89c",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        560,
        600
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c8ba25eb-0aed-42d0-8c55-420448eebce5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -220
      ],
      "parameters": {
        "width": 2240,
        "height": 520,
        "content": "## Airtable Weekly Backups\nEvery week backup all tables in an Airtable base into a dedicated week sub-folder in S3. Notify when complete."
      },
      "typeVersion": 1
    },
    {
      "id": "7c33f350-3f5c-4979-a176-bbdb3b8d663c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        360
      ],
      "parameters": {
        "width": 1140,
        "height": 480,
        "content": "## Airtable Monthly Prune\nDelete backups > 1 month old"
      },
      "typeVersion": 1
    },
    {
      "id": "dcbb30d5-90da-44ef-991f-0a25cf67e01d",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1040,
        -140
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6ae12e8e-f949-48f7-977e-65f5bb49be9b",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Delete File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AWS S3": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Week": {
      "main": [
        [
          {
            "node": "Create Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Folders": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pull Records": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Folder": {
      "main": [
        [
          {
            "node": "Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Monthly Prune": {
      "main": [
        [
          {
            "node": "Set Timestamps",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Backup": {
      "main": [
        [
          {
            "node": "Set Week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Timestamps": {
      "main": [
        [
          {
            "node": "List Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "AWS S3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Table Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Table Metadata": {
      "main": [
        [
          {
            "node": "Pull Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}