# Archive a daily D1 SQL export in R2

Export database schema and data as SQL and save a dated copy in the selected R2 bucket.

[Use template](https://dashboard.fasthook.io/workflow/new?templateKey=cloudflare-d1-backups-to-r2&templateName=Archive+a+daily+D1+SQL+export+in+R2)

**Required accounts**

- Cloudflare D1
- Cloudflare R2

## Archive a daily D1 SQL export in R2

### 1. Trigger · Daily schedule

**Schedule**. Run automatically on the configured schedule.

### 2. Action · Export the database as SQL

**Cloudflare D1**. Wait for the database export and return its SQL file for a storage step. Use the bookmark action for larger exports.

### 3. Action · Archive the SQL file

**Cloudflare R2**. Run the R2 S3-compatible PutObject operation.

## Set up your workflow

1. **Select the source database** Connect D1, then select the database in “Export the database as SQL”. This step includes schema and data and returns an inline SQL file up to 5 MiB.
2. **Choose an archive bucket** Connect R2 with write access to your archive bucket. Keep File mapped to the export step. The object key starts with d1-archives/ and includes the scheduled time so you can identify each backup.
3. **Set the backup window** Choose a quiet daily window. Cloudflare pauses queries to the source database during an export. Check the timezone before activating the schedule.
4. **Verify a restore** After a run, download the .sql object from R2. Import it into a separate, empty D1 database. Query a table for a known row and compare its ID and value with the source.

## Related integrations

- [Schedule trigger](https://www.fasthook.io/docs/triggers/schedule)
- [Cloudflare D1 integrations](https://www.fasthook.io/apps/cloudflare-d1/integrations)
- [Cloudflare R2 integrations](https://www.fasthook.io/apps/cloudflare-r2/integrations)

## Related workflow templates

- [Archive DNS records to R2 on a schedule](https://www.fasthook.io/templates/cloudflare-dns-zone-exports-to-r2.md): Save a dated BIND zone file in a private R2 bucket.
- [Back up a group of KV keys to R2](https://www.fasthook.io/templates/cloudflare-kv-prefix-backups-to-r2.md): Export a selected prefix with binary values, metadata and absolute expiry times.
- [Send overdue paid orders to Slack](https://www.fasthook.io/templates/cloudflare-d1-overdue-orders-to-slack.md): Post the IDs of paid orders still awaiting shipment after two business days.
- [Report R2 bucket storage to Discord](https://www.fasthook.io/templates/cloudflare-r2-storage-report-to-discord.md): Post a daily report of object counts and bytes in one selected R2 bucket, grouped by storage class.
