David - Musings of an SRE

Migrate all DNS Zones from Zerigo over to AWS Route 53

So yesterday there was another major downtime on Zerigo and its about the last straw I had with the service.

Not only the service was down for most of the day, causing some of my domains to fail updating, not a single e-mail or communication was made on the part of the management team to inform us about what has happened.

If I didn’t check zerigostatus.com, I wouldn’t have realized that the entire service was down. I spent most of the morning yesterday trying to figure out why my zones were not updating.

Service downtime is generally tolerable for me, but when it is down for so long and no communication, it feels as though the management has something to hide.

As such, I’m moving over to Route53. Its much more pricey ($0.50/zone/month) but at least I’m assured of the reliability and high availability that Amazon had provided me so far.

I’ve forked a ruby script from thewebfellas and modified the script to migrate all zones out of Zerigo directly to Route53.

I hope this helps all those who may/decide to leave Zerigo.

#!/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
require 'rubygems'
require 'zerigo_dns'
require 'route53'
Zerigo::DNS::Base.user = 'username@email.com'
Zerigo::DNS::Base.api_key = 'yourkeyhere'
# iterate through all domain names
domains = Zerigo::DNS::Zone.find(:all)
domains.each do |z|
puts "#{z.domain} (id: #{z.id})"
hosts = Zerigo::DNS::Host.find(:all, :params=>{ :zone_id => z.id, :per_page=>100, :page=>1 })
host_map = {}
hosts.each do |host|
host.hostname = '' if host.hostname.nil?
host_map[host.hostname] = {} unless host_map[host.hostname].present?
host_map[host.hostname][host.host_type] = [] unless host_map[host.hostname][host.host_type].present?
host_map[host.hostname][host.host_type] << { :fqdn => host.fqdn, :priority => host.priority, :hostname => host.hostname, :data => host.data }
end
puts "Connecting to Route 53"
aws = Route53::Connection.new('access_key_id', 'secret_key')
puts "Creating zone on Route 53"
new_zone = Route53::Zone.new("#{z.domain}.", nil, aws)
response = new_zone.create_zone
exit 1 if response.error?
while response.pending?
sleep 1
end
puts "Zone created on Route 53"
host_map.each do |hostname, records|
puts " Hostname: #{hostname.blank? ? 'domain apex' : hostname}"
records.each do |record_type, values|
puts " Record type: #{record_type}"
case record_type
when "A", "CNAME"
values.each do |record|
new_record = Route53::DNSRecord.new("#{ record[:fqdn] }.", record_type, "600", [ "#{ record[:data] }#{ '.' if record_type != 'A' }" ], new_zone)
resp = new_record.create
end
when "MX"
fqdn = values.first[:fqdn]
new_mx_record = Route53::DNSRecord.new("#{fqdn}.", "MX", "600", values.collect{ |record| "#{ record[:priority] } #{ record[:data] }." }, new_zone)
resp = new_mx_record.create
when "TXT", "SPF"
fqdn = values.first[:fqdn]
new_txt_record = Route53::DNSRecord.new("#{fqdn}.", record_type, "600", values.collect{ |record| "\"#{ record[:data] }\"" }, new_zone)
resp = new_txt_record.create
end
end
end
end