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 --file
  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/, 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/

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

Disqus Comments Loading...

Recent Posts

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

May 14, 2019 8:22 am 08:22

Change Grub Default Boot Entry on Linux Mint

i'm dual booting windows and linux mint on my laptop. the grub default is to boot into linux mint, however… Read More

April 23, 2019 7:45 pm 19:45

How to Reset Secure Channel On Active Directory Domain Controller

when you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am 08:14

Run SystemD Script Before System Shutdown

for the sheer hell of it, a few weeks ago i wanted to see if i could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

Learn Systemctl Usage to Manage Systemd Service in Linux

systemd is new service manager for linux. it's a replacement for all previous init systems (sysv/sysvinit & ubuntu's upstart) and… Read More

April 20, 2019 7:55 am 07:55

Force Delete Windows Server DHCP Failover Relationship

if you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54