Export DNS zone

Hello,

i have a site with over 150 domains and i want to export all the DNS zones for backup.

Is there a way to export them all or do i need to enter on each domain DNS zone and export manually each one?

Use the API. Something like this will give you a starting point. You will have to work on the pagination as you have more zones than the zones API will return in one go.

#!/bin/bash
auth_token="XXX"

zone_list=( $(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/?per_page=100" -H "Authorization: Bearer $auth_token" -H "Content-Type: application/json"| jq -r '.result[].id') )

for zoneid in "${zone_list[@]}"
do
    zonename=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${zoneid}" -H "Authorization: Bearer $auth_token" -H "Content-Type: application/json"| jq -r '.result.name')
    curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${zoneid}/dns_records/export" -H "Authorization: Bearer $auth_token" -H "Content-Type: application/json" -o ${zonename}.txt
done
3 Likes

Thank you for the answer.

Will try it out :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.