Backing up your Cloudflare DNS records

Using a command line tool to backup your Cloudflare DNS records.

For my personal project, I use Cloudflare to set up DNS records.

If you are also using Cloudflare and need a backup of your DNS records, you can use the following tutorial to download your data and store it in a secure location for future reference. All you need is an npm module and a command line.

Prerequisites

Set up

The first thing we’re going to do is use a tool called cloudflare-backup from npm.

To set this up run the following commands in your terminal:

$ npm install -g cloudflare-backup

Script setup

Now that we have confirmed we have the prerequisites for the backup, create a file called cf-backup.sh in your chosen folder.

Inside that file add the following script:

#!/bin/bash

CF_EMAIL=[email protected] CF_TOKEN=abc123 cf-backup > zones.bind.txt

Account setup

To run this with your account

Run the script

Now you can run the script to retreive a copy of your records:

$ sh cf-backup.sh

A new file zones.bind.txt should appear in your folder with all of your DNS records.

Future improvements

I am looking to update this in the future to closer match my Route 53 DNS Backups utilinsing one file per zone, Cloudflare API Tokens with just “read” access, and a date stamped folder.