Skip to content

Weekly

Export your Sanity dataset every week

Each Sunday an export of your dataset is taken and you get an email confirming what it covers.

Runs
Weekly
Apps
Sanity
AI
Not needed
Access
Viewer

Send this to your assistant

Create a ClickRuntime automation: every Sunday at 2am, export my Sanity production dataset and email me a summary of the export with the number of documents in it.

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

Content in Sanity feels safe because it lives in a hosted service, yet a mistaken bulk mutation, a script that patches the wrong field, or a deleted dataset can still destroy months of editorial work. Teams that rely on Sanity as the source of truth for a website often have no copy outside it. Sanity keeps history for documents, but restoring a whole dataset after a faulty migration is a stressful, slow exercise when there is no export to start from.

Once a week the automation calls Sanity's export endpoint for your dataset, compresses the result, and emails you a summary with the link or attachment. You end up with a dated archive of every document and asset reference. It requires no one to run the CLI. Agencies and small product teams use it as a simple, regular safety copy.

What you get out of it

  • Recovery from a bad migration

    If a script overwrites a field across thousands of documents, last week's export lets you compare and restore the original values. Without it you reconstruct content from the website's cache, if you can.

  • Content survives account or access problems

    An export sitting in your mailbox does not depend on Sanity account access, a project deletion or a billing issue. That is the kind of independence that matters when the unexpected arrives.

  • Easy move to a new dataset

    Teams often create a staging or new production dataset from a recent export. Having regular files means that task takes minutes rather than needing someone to remember the CLI command.

  • Handover and compliance copies

    When an agency hands a site to a client, or legal asks for a record of published content on a given date, a dated export answers the request without a rushed manual job.

  • Weekly cadence matches editing pace

    Most content teams change enough in a week to matter but not in a day. A weekly export means you lose at most a week of changes in a worst-case scenario.

How it works

What happens, step by step

  1. Every Sunday, ClickRuntime takes a full export of your Sanity dataset.

  2. It counts the documents in the export by type.

  3. You get an email confirming the export, with the total and a count per type.

Before it runs live

  • Connect Sanity

What you get

RunsWeekly
Export your Sanity dataset every weektoday, 9:00Succeeded
Email · Sanity exportSanity export: 2,184 documents in production post: 912 · product: 640 · author: 38 · sanity.imageAsset: 594

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 Sanity 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.
dataset_backup_email.pyexample
from collections import Counter
from clickruntime import on_trigger, credentials, http, notify
import json

PROJECT_ID = "your-project-id"
DATASET = "production"

@on_trigger
def run(event):
    token = credentials.secret("SANITY_TOKEN")
    resp = http.get(f"https://{PROJECT_ID}.api.sanity.io/v2021-06-07/data/export/{DATASET}",
                    headers={"Authorization": f"Bearer {token}"}, timeout=120)
    resp.raise_for_status()
    docs = [json.loads(line) for line in resp.text.splitlines() if line.strip()]
    types = Counter(d.get("_type", "unknown") for d in docs)
    lines = [f"{t}: {n}" for t, n in types.most_common(15)]
    notify.email_me(f"Sanity export: {len(docs)} documents in {DATASET}",
                    f"Exported {len(docs)} documents ({len(resp.content) // 1024} KB).\n\n" + "\n".join(lines))
    return {"documents": len(docs)}

FAQ

Common questions

Does the export include images and files?
The standard dataset export can include assets if requested, but the large files make the archive heavy. Many teams export documents only, which holds references to asset IDs, and keep assets in Sanity's own storage.
How big can the exported file get for email?
Sanity datasets with many documents can produce large archives. The automation compresses the file and, if it exceeds email limits, sends a link or a summary of size and document count rather than the full attachment.
Can I back up a private dataset?
Yes. A private dataset needs a read token with access to it, which ClickRuntime stores as a secret. Create a token in your Sanity project settings with read permission and give it to the automation during setup.
What permissions does it need?
Viewer. 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 (weekly). 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 “Export your Sanity dataset every week” from your assistant

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