r/CloudFlare • u/carwash2016 • 6d ago
Question Workers backup ?
Is there a way to backup my workers , they are already connected to GitHub and set to auto deploy but what about the dns, r2, d1 and variables in the worker
Basically I want to say backup worker abc and have an offsite copy of everything needed to put that worker back together
5
Upvotes
•
u/AutoModerator 6d ago
For faster advice with technical questions, we'd recommend asking in the Orange Cloud Discord server; the unofficial Cloudflare Discord server by the community, for the community. https://discord.gg/TrPNVKaagR
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Lumethys 6d ago
terraform
2
u/winner_68 2d ago
Git covers the code, but the part that actually bit me was the restore, not the backup. A Worker is really code plus config plus state, and the state is the bit that quietly doesn't come back with a git clone.
What I do now for my small Workers, including a Telegram bot Worker backed by D1, is keep the wrangler config in the repo so the bindings, routes, cron triggers and non-secret variables are all in one place, and keep a short restore note in the same repo listing every binding, custom domain, route and secret name, just the names, never the values, because secrets can't be read back once they're set. I store the actual secret values in a password manager.
For the data, I run a nightly export of D1 into an R2 bucket in a different account, then pull a copy down to my VPS as well, so the backup isn't sitting in the same account as the thing it backs up. That covers the database, but it doesn't cover KV, Durable Objects or the objects in R2 themselves, so those get their own export or sync. I also export the DNS zone as a file every now and then, it's a thirty second job and it's the cheapest insurance in the whole setup.
The bit I'd really push is testing the restore. The first time I tried rebuilding one of my Workers from my notes, it failed on a missing binding I'd forgotten to write down. Now I rebuild it on a staging Worker every couple of months and fix the notes when something's missing. A backup you've never restored is just a hope, and it's much better to find the gap on a quiet afternoon than when you're actually trying to put a Worker back together.
2
u/zhiqingl 2d ago
What I do for mine: keep wrangler.jsonc in the repo so bindings, routes, crons and non-secret vars are versioned; secrets can't be read back, so they live in a password manager. D1 gets a scheduled wrangler d1 export <db> --remote --output=backup-$(date +%F).sql (and Time Travel covers the "oops" cases for recent changes). R2 is S3-compatible, so rclone sync to another bucket/provider works. DNS you can export as a BIND zone file from the dashboard or the API. If you want it all as code, cf-terraforming will generate Terraform from your existing account, which is a decent starting point.
5
u/Known_Currency7966 6d ago
You might looking something like this ? https://github.com/gateweavehq/backup
2
u/Opening-Commercial97 11h ago
The test I’d use is whether you can restore the app into a throwaway environment. Start with one D1 export, a small R2 sample, and the Worker config. If it boots but can’t read its data, you’ll know which bindings or settings are missing before you rely on the backup.
1
u/RelayForgeDev 6d ago
Git covers the code, but the Worker is really code + wrangler config + state, so back up those separately. Keep wrangler.jsonc in the repo so bindings, routes, cron and non-secret vars are rebuilt on deploy, and re-set secrets with
wrangler secret put(store them in a password manager, since they can't be read back). For D1 runwrangler d1 export <db> --remote --output=backup.sqlon a nightly GitHub Action and push it to a private repo or an R2 bucket in another account. For R2, rclone oraws s3 syncagainst the S3-compatible endpoint works fine for offsite copies. DNS you can export as a BIND file from the dashboard (or via the API) and that's the 30-second 'oh no' insurance; Terraform is nice but overkill if this is just a few Workers.