Domain-Name-System

如何在 AWS Route 53 中導出託管區域?

  • February 28, 2022

我看不到導出域設置備份的選項。

也許我應該用 dig 保存公共 DNS 的結果,但我會質疑朋友是否知道更好的方法。

是的,它可以是更友好的方式。我建議使用 cli53 工具,https://github.com/barnybug/cli53

設置好後試試

cli53 導出 –full sciworth.com

你會得到綁定格式的導出區域。

無需額外的軟體安裝。您只需要 awscli。

這是我剛剛寫的。它很簡單,就像魅力一樣。

#!/bin/bash -e
#
#  Author: Peycho Dimitrov
#
#  DESCRIPTION
#
#  Create full backup of all hosted Route53 zones / domains in your account.
#
#  REQUIREMENTS
#
#  Available s3 bucket (where your json files will be saved)
#  awscli (with cofigured credentials or IAM role)
#  gzip
#  awk
#
####################################

#  CONFIGURATION

region="us-east-1" # Your aws region
b_route53_tmp="/tmp/r53_backup" # Your temp directory
b_route53_bucket="s3://my-backups/route53" # Your backup folder in s3.

# END OF CONFIGURATION

# Do not edit here if you don't know what your're doing! #

mkdir -p $b_route53_tmp
echo "$(date) Backup all Route53 zones and resource records."
p_aws="$(which aws) --region $region"
r53_zones=$($p_aws route53 list-hosted-zones --query '[HostedZones[*].[Id, Name]]' --output text | awk -F'/' '{print $3}')
if [ ! -z "$r53_zones" ]; then
       while read route; do
               zone=$(echo "$route" | awk '{print $1}')
               domain=$(echo "$route" | awk '{print $2}')
               echo "Processing $zone / $domain"
               $p_aws route53 list-resource-record-sets --hosted-zone-id "$zone" --output json > "$b_route53_tmp"/$(date +%Y%m%d%H%M%S)-"$zone"-"$domain"backup.json
       done <<<"$r53_zones"

       echo "Archive json files."
       gzip "$b_route53_tmp"/*backup.json
       echo "Backup $zone / $domain data to $b_route53_bucket/$(date +%Y)/$(date +%m)/$(date +%d)/"
       $p_aws s3 cp "$b_route53_tmp"/ $b_route53_bucket/$(date +%Y)/$(date +%m)/$(date +%d)/ --exclude "*" --include "*.gz" --recursive
fi

echo "$(date) Done!"

引用自:https://serverfault.com/questions/535631