Migrating a site from one Aegir to another

I've recently begun to develop locally on my laptop, in a Virtualbox running Aegir. This is great for developing Aegir itself, as well as testing installs and such. Not to mention standard Drupal site builds, such as this very site.

Previously, I'd always developed on a VPS, and so never really had to worry too much about deploying sites. Now I find myself with a couple local sites that I'd like to move to one of my servers. I also plan to migrate all my sites off one of my servers (and onto another), so it can be rebuilt as a true production system for the upcoming launch of OpenAtria.com. Finally, at Koumbit, we're looking at deploying staging servers for each of our development teams, which will involve migrating all their development sites from the main production server to per-team staging envorinments.

To start we need to create an appropriate platform on the destination Aegir (if one doesn't already exist). This is trivially easy if you maintain good makefiles, which I think will be the subject of a future blog post. Then make a backup of the site through the Aegir interface, scp/rsync the tarball to the destination server, and untar it in a folder under sites/ on the platform we just created.

Since all the code is now where it should be, we now need to add the database and import the dump from the backup (database.sql). First, Look in settings.php for the values of:

  • db_host (probably 'localhost'),
  • db_name,
  • db_user, and
  • db_passwd.

Login to MySQL as root and run the following commands. First, create the database:

mysql> CREATE DATABASE <db_name>;
Query OK, 1 row affected (0.00 sec)

Then create the user:

mysql> CREATE USER '<db_user>'@'localhost' identified by '<db_passwd>';
Query OK, 0 rows affected (0.11 sec)

Grant this new user proper privileges on the new database:

mysql> GRANT ALL PRIVILEGES ON <db_name>.* TO '<db_user>'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Finally, import the database dump from the backup (database.sql).

[email protected]:/var/aegir/platforms/<platform>/sites/<sitename># mysql -u <db_user> -p -h localhost <db_name> Enter password: <db_passwd>

Then (re-)verify the platform, and Aegir should pickup the new site.

So, it turns out that this method is described (more-or-less) in the Administrator Manual in the Aegir Handbook as "Import a website using the sites directory". Another option involves importing the entire codebase, if you can't reliably rebuild an identical platform.

Finally, there's the "Aegir way", which involves rsync'ing a backup and running a couple provision commands to manually create a site alias, then provision the site from the backup. I'll have a try at that one next.

In the long run, it would be cool to be able to just upload the backup tarball into the Aegir front-end, but that would be complicated by needing to build a suitable platform (among other things). Moving to (or at least supporting) the Acquia backup format may solve that, since, as I understand it, it backs up the entire platform.

So, while this successfully moved a site from one server to another, it doesn't really help with the workflow for ongoing development on a site. For that, Miguel Jacq (mig5) has a great write-up: Drupal deployments & workflows with version control, drush_make, and Aegir. To that, Adrian Simmons (adrinux) adds some useful tips: Four tips for developing Drupal under Aegir.

Based on Miguel's workflow, Adrian drew up this diagram:

The only problem I see is with step 3, "clone to dev platform", since my dev platform is on my locally installed Aegir. The Drush core-rsync and sql-sync commands seem quite powerful, and may help solve this issue. But drush aliases are something I have yet to figure out (how and why do they differ from Provision aliases?), so that'll take some more experimentation and another blog post.