← Back to Tools
Open Source Tool
Cloudflare DNS Backup
Automated Bash script that backs up every DNS record across all your Cloudflare zones via the API. Exports records in BIND-compatible format to timestamped .txt files — run it before DNS changes, on a cron schedule, or after incidents to maintain a dated record of your DNS state.
Run before and after every DNS change. If something breaks, you have a dated record of what existed — recovery depends on the saved fields, access, provider behaviour and a tested procedure.
What it does
- Backs up all DNS record types — A, AAAA, CNAME, MX, TXT, NS, SRV, CAA
- Exports all zones in your Cloudflare account automatically
- Saves timestamped BIND-compatible .txt files per zone in a /domains directory
- Uses Cloudflare API v4 with Bearer token auth — no password required
- Minimal dependencies — bash, curl, and jq
- Designed for cron scheduling — suitable for scheduled backups, with monitoring for failed runs and periodic verification of saved records
Quick start
# Clone the repo git clone https://github.com/mylesagnew/cloudflare-backup cd cloudflare-backup # Configure credentials (never commit this file) cp .env.example .env && chmod 600 .env # Edit .env: CLOUDFLARE_API_TOKEN=your_api_token_here # Make executable and run — exports all zones to ./domains/ chmod +x cf-dns-backup.sh ./cf-dns-backup.sh # Optional: schedule daily via cron crontab -e # 0 2 * * * /path/to/cloudflare-backup/cf-dns-backup.sh >> /var/log/cf-backup.log 2>&1
Check a backup before relying on it
- Confirm the expected zones were exported and that pagination or permission limits did not omit records.
- Inspect representative web, mail and verification records, including TTLs and metadata supported by the export.
- Keep the copy off-platform with restricted access; DNS records can expose operational details.
- Record settings outside the export and test recovery away from production.
Related resources
Get notified when new tools and checklists drop.
Join Security Tool Updates →Subscribe for updates
Get new security tools, checklists and guides by email. No spam — unsubscribe anytime.