大网数据广告活动
服务器运维问答

How to export a hosted zone in AWS Route 53?

· 52CE 我爱测

I see no option to export a backup of the settings for a domain. Maybe I should save the results of public DNS with dig but I would question whether a friend knows a better way.

问题原文

原帖链接 · gpupo · CC BY-SA 3.0

I see no option to export a backup of the settings for a domain.

Maybe I should save the results of public DNS with dig but I would question whether a friend knows a better way.

社区高分解答

原帖链接 · Peycho Dimitrov · CC BY-SA 3.0

No need of additional software installations. You need only awscli.

Here is what I just wrote. It is simple and works like charm.

#!/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!"

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-09-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。