Skip to content

Daily

Create a dated backup branch every night

Your main branch is copied to a dated branch each night, and only the last seven are kept.

Runs
Daily
Apps
Neon
AI
Not needed
Access
read+write

Send this to your assistant

Create a ClickRuntime automation: every night at 1am, create a Neon branch named backup-YYYY-MM-DD from main, delete backup- branches older than 7 days, and email me a one-line summary.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

Developers using Neon often rely on point-in-time restore, which has a limited window on lower plans, and may not have a separate backup at all. A destructive migration, a bad data script or a dropped table is found three days later, after the window or at least after someone has typed more changes on top. Restoring then becomes guesswork about when the data last looked right.

Every night ClickRuntime creates a branch from your default branch with the date in its name, such as backup-2026-10-18, lists existing branches, deletes backup branches older than seven days, and emails a short summary. You always have the last seven nightly snapshots, ready to query or restore from.

Teams with production data in Neon and no other backup process tend to adopt it first.

What you get out of it

  • A known good copy from each of the last 7 days

    If a migration goes wrong on Thursday, Wednesday night's branch has the data as it was. You can query it, compare, or promote it instead of reconstructing rows. You can compare tables side by side to find what changed.

  • Restores are fast and cheap to inspect

    Branches are copy-on-write, so a nightly one is quick to create and available instantly. You can connect to it and check a table without any restore job. That makes checking a table before a restore a matter of one connection string.

  • Retention is automatic

    Backups older than seven days are removed by the same run, so they do not accumulate. The project does not slowly fill with dozens of dated branches nobody dares delete.

  • Confidence before risky changes

    Knowing last night's copy exists makes a schema change less worrying. Teams ship migrations more readily when they know the previous state is one connection string away. Teams ship migrations more readily when the old state is easy to reach.

  • Daily confirmation that it happened

    The summary email shows the new branch and what was pruned. A missing email is itself the signal that the backup did not run. If the email stops arriving, you know straight away that the backup did not run.

How it works

What happens, step by step

  1. Every night ClickRuntime copies your main Neon branch to a new branch named with the date.

  2. It deletes backup branches older than seven days, so only the last week is kept.

  3. You get an email listing the backup created and any removed.

Before it runs live

  • Connect Neon

What you get

RunsDaily
Create a dated backup branch every nighttoday, 9:00Succeeded
Email · Nightly backup branchNeon backup: created backup-2026-10-19, removed 1 backup-2026-10-11

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Neon steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
take_a_nightly_backup_branch.pyexample
from datetime import date, datetime, timedelta, timezone
from clickruntime import on_trigger, credentials, http, notify

NEON = "https://console.neon.tech/api/v2"

def neon(method, path, **kwargs):
    resp = http.request(method, f"{NEON}{path}", headers={"Authorization": f"Bearer {credentials.secret('NEON_API_KEY')}"}, **kwargs)
    resp.raise_for_status()
    return resp.json()

PROJECT_ID = "your-neon-project-id"

@on_trigger
def run(event):
    branches = neon("GET", f"/projects/{PROJECT_ID}/branches")["branches"]
    main = next(b for b in branches if b.get("default"))
    name = f"backup-{date.today()}"
    neon("POST", f"/projects/{PROJECT_ID}/branches", json={"branch": {"name": name, "parent_id": main["id"]}})
    cutoff = datetime.now(timezone.utc) - timedelta(days=7)
    removed = []
    for b in branches:
        if b["name"].startswith("backup-") and datetime.fromisoformat(b["created_at"].replace("Z", "+00:00")) < cutoff:
            neon("DELETE", f"/projects/{PROJECT_ID}/branches/{b['id']}")
            removed.append(b["name"])
    notify.email_me(f"Neon backup: created {name}, removed {len(removed)}", ", ".join(removed) or "No old backups removed.")
    return {"created": name, "removed": removed}

FAQ

Common questions

Is a branch a real backup?
A branch is a copy within the same Neon project and region, so it protects against logical errors such as bad migrations or deletes, but not against a loss of the whole project. For that, also export data elsewhere.
Can I keep more than 7 backups?
Yes. The retention count is a setting, so you could keep 14 nightly branches or add weekly ones. Remember that each branch adds storage as data diverges from its parent. Pruning keeps the project tidy as time passes.
Does creating the branch affect my database?
Creating a branch does not lock or slow the parent. Neon uses copy-on-write, so the operation is quick and the main branch continues serving queries normally while the snapshot is made. Neon only copies data lazily, so the cost grows with changes.
What permissions does it need?
read+write. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run each time it runs (daily). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Create a dated backup branch every night” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.