Migrating a DNS server to PowerDNS

Today I had to migrate a customer’s DNS server to a new server… This because the old server (a very old plesk instance) was end of life.

As I have very good experiences with PowerDNS, we decided to migrate from Bind (Named) to PowerDNS.

PowerDNS provides you with the utilities to do so, but I did not find a straight forward way to export/import zones from Bind into PowerDNS.

Installation of PowerDNS and PowerAdmin (a PowerDNS Gui) is out of the scope of this document, so I assume you already have a working PowerDNS server.

These are the steps I had to perform to migrate from the Plesk 8.2 server to PowerDNS:

1) First of all, you need to allow zone transfer (AXFR) on your bind server from your new PowerDNS server IP. You need to change the contents of /etc/named.conf in something like this (add the allow-transfer lines in the Options block.

2) Reload or restart named to take effect:

3)Test a zone transfer, eg:

4) Now that you know zone transfer is working, create a list of domains that your Bind server is ‘serving’.  In my case i have to remove some extra .lock and .saved_by_psa files from my listing. If you use this tutorial, your command can look differently of course.

If needed: check if the domains in bind still use your old nameservers… (do not polute your new powerDNS server :))

Then delete all domains from /root/domainlist.dns if they not valid anymore
5) Import your zones by:
a) Create Zone Import SQL scripts

From these generated files, remove duplicate SOA records from all import files:

If needed: change TTLs:

Depending if your imported zones need to be set as NATIVE or MASTER

Change extra stuff with sed, like hostmaster and so on

b) Test import into mysql

c) Verify in poweradmin and drop the imported zone (or you’ll get an import error on the next step, which is not bad or something… but hey :))

d) Import all your zones, if you like what you have done:


Migrating wordpress sites to another host

When migrating wordpress sites, from one server/host to another… you might encounter some problems with 2 things:

  1.  Absolute vs Relative paths for e.g. images
  2. Serialized data.

This is how to fix both:

Absolute paths: can be fixed by my previous post here

Serialized Data: by modifying your absolute paths for URL’s of Image paths, your serialized data is no longer valid… I have found this script to be very usefull to fix the serialized data: BangHeadOnWall

How to use fix_serialization.php:

1. Download the script on the machine that has the db you need to fix
2. Change a couple of things in the script:

  • ‘db1′ to the actual database name
  • username
  • password
  • and maybe the table/column and index column (e.g. when using multisite)

3. type ‘php fix_serialization.php’ on the command line

The only real reason why I need to run this is because migrating the site can change the tite’s url length or absolute image paths.  For example ‘hard coded’ paths to images in some plugins:

The length of this string changes, and therefor the serialized string in the wp_options (or any other table using serialized string with url/data paths) is not longer valid.

The script goes through all that data and corrects the math in those couple of places automagically and you’re back online!

Migrating MySQL to a new server

When you need to migrate a MySQL server instance to a new server for any reason, eg upgrade of hardware, distri upgrade,… you can easily do the following:

Migrating the databases
On the “old” mysql server, you need to export all databases by:

Copy your sql dump file with eg rsync

On the new server, import your dumps:

Migrating the users

If you are migrating to the same MySQL version you can export all users and settings by dumping the mysql database itself.

and just copy & import of that file on the new server

However, when doing a MySQL version upgrade, we need to export all the Users and their privileges.

Here’s an easy bash script to do this.

Copy the lines between the ———————-

Login on your new server, go to the mysql shell via the admin user

And paste the output from our previous script.

Et Voila, your databases and users are migrated!