Automated Backup Of AWS Route 53 Record Sets

cli53 - Command line tool for Amazon Route 53

If you’re using AWS Route 53 to manage DNS records, it’s a good idea to backup in case of accidental deletion and other such misfortunes.Of course you’ll want it automated so here’s a way to do with cron on a linux system:Install the AWS Command Line Interface. This tool allows you to administer your various AWS services via the command line.

  1. Install cli53 (direct link). This tool extends the AWS CLI by offering more high-level commands for easy Route 53 administration
  2. Once you have those setup, the following command will export a zone record to a file:
    $ cli53 export example.com --file example.com.bk
  3. You need to specify what domain you want the zone record for, there’s no “all” option. So, you could go ahead an run the command repeatedly for all your domains, but who wants to do that? To do it programmatically, this following command will get the list of domains, iterate through them, and export each one, piping the result to a separate file:
    $ cli53 list | grep 'Name:*' | cut -f6- -d' ' | while read line; do cli53 export ${line} >> ~/backup/${line}bk; done
  4. To have this happen automatically, you can simply create a bash script and have cron run it once per day or whatever you like:
    $ cli53 list | grep 'Name:*' | cut -f6- -d' ' | while read line; do cli53 export${line} >> ~/backup/${line}bk; done

    Note: the cli53command won’t work in a bash script unless you provide the full path or add to the $PATH
    variable e.g /usr/local/bin/cli53

  5. Save it, let’s say to /path/to/script.sh, make that file executeable, and add it to cron:
    $ crontab -e

    Add this to the bottom of the file to run the script once per day:

    00 00 * * * sh /path/to/script.sh

Note that your backups will be overwritten each time the script runs, so you might add a date to the file name to create daily snapshots.Or better still: why not upload your backup files to a versioned S3 bucket for safe storage? That also be done with AWS CLI, here’s a modified version of the bash script to do just that:

 cli53 list | grep 'Name:*' | cut -f6- -d' ' | while read line; do cli53 export${line} > ~/backup/${line}bk; aws s3 cp ~/backup/${line}bk s3://mybucket; rm ~/backup/${line}bk; done

Share
Disqus Comments Loading...

Recent Posts

VMWare vSphere 6.7 ESXTOP Output Garbled

If your VMWare vSphere 6.x environment command output of esxtop looks like a bunch of garbled gibberish (it's actually CSV… Read More

February 28, 2019 7:39 pm 19:39

How To Run RoboCopy Backup in Parallel

From time to time Windows Admins will surprise you with band-aid and bubble gum scripts, that's entirely expected I think.… Read More

February 28, 2019 12:20 pm 12:20

Windows 10 GodMode - The Ultimate Administrator Shortcut

Have you ever wondered what life might be like if the Windows 10 OS somehow had a single folder that… Read More

February 28, 2019 7:58 am 07:58

Samsung Galaxy S9 G960/G965 Stock ROM Firmware Download

There could be any number of reasons for needing to flash manufacturer stock OEM firmware on a Samsung Galaxy S9… Read More

January 24, 2019 7:42 am 07:42

Output IP Address with ipconfig Findstr Ethernet Adapter

How many times have you entered  ipconfig /all at the command line to return a single IP address, then have to strain… Read More

January 20, 2019 12:39 am 00:39

AWS SES Assistance in Enterprise Market - A Must Read

Designing e-mail solutions on a large scale can be a complex and costly challenge for a business: you need to… Read More

December 25, 2018 4:01 pm 16:01