diff --git a/drush/Provision/Service/remote/import/hostmaster.php b/drush/Provision/Service/remote/import/hostmaster.php
index 40c10a9..04e4400 100644
--- a/drush/Provision/Service/remote/import/hostmaster.php
+++ b/drush/Provision/Service/remote/import/hostmaster.php
@@ -52,25 +52,61 @@ class Provision_Service_remote_import_hostmaster extends Provision_Service_remot
     $result = $this->remote_execute('@hostmaster status', array());
     drush_print_r($result);
 
-    // We talk to the remote Aegir, and get it to list the sites it has.
-    // We need to bootstrap the remote hostmaster.
-    $lines[] = 'drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)';
-    $lines[] = '$sites = array()';
-    $lines[] = '$results = db_query("SELECT sn.title as site, pn.title as platform
-                                      FROM {hosting_site} hs
-                                INNER JOIN {node} sn
-                                        ON hs.nid = sn.nid
-                                INNER JOIN {hosting_platform} hp
-                                        ON hs.platform = hp.nid
-                                INNER JOIN {node} pn
-                                        ON hp.nid = pn.nid
-                                     WHERE hs.status = :status", array(":status" => HOSTING_SITE_ENABLED))';
-    $lines[] = 'foreach ($results as $result) {';
-    $lines[] = '  $sites[$result->site] = $result->platform';
-    $lines[] = '}';
-    // Set the $sites array into the backend result, so we can extract it easily
-    // later.
-    $lines[] = 'drush_backend_set_result($sites)';
+    $aegir3_regex = '/7\.[0-9][0-9]/';
+
+    drush_print_r('Drupal info: ' . $result[0]);
+
+    if (preg_match($aegir3_regex, $result[0])) {
+      $aegir_version = 3;
+    }
+    else {
+      $aegir_version = 2;
+    }
+
+    if ($aegir_version == 3) {
+       // We talk to the remote Aegir, and get it to list the sites it has.
+       // We need to bootstrap the remote hostmaster.
+       $lines[] = 'drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)';
+       $lines[] = '$sites = array()';
+       $lines[] = '$results = db_query("SELECT sn.title as site, pn.title as platform
+                                         FROM {hosting_site} hs
+                                   INNER JOIN {node} sn
+                                           ON hs.nid = sn.nid
+                                   INNER JOIN {hosting_platform} hp
+                                           ON hs.platform = hp.nid
+                                   INNER JOIN {node} pn
+                                           ON hp.nid = pn.nid
+                                        WHERE hs.status = :status", array(":status" => HOSTING_SITE_ENABLED))';
+       $lines[] = 'foreach ($results as $result) {';
+       $lines[] = '  $sites[$result->site] = $result->platform';
+       $lines[] = '}';
+       // Set the $sites array into the backend result, so we can extract it easily
+       // later.
+       $lines[] = 'drush_backend_set_result($sites)';
+    }
+    // Assume Aegir2
+    else {
+       // We talk to the remote Aegir, and get it to list the sites it has.
+       // We need to bootstrap the remote hostmaster.
+       $lines[] = 'drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)';
+       $lines[] = '$sites = array()';
+       $lines[] = '$results = db_query("SELECT sn.title as site, pn.title as platform
+                                         FROM {hosting_site} hs
+                                   INNER JOIN {node} sn
+                                           ON hs.nid = sn.nid
+                                   INNER JOIN {hosting_platform} hp
+                                           ON hs.platform = hp.nid
+                                   INNER JOIN {node} pn
+                                           ON hp.nid = pn.nid
+                                        WHERE hs.status = 1")';
+       $lines[] = 'while ($r = db_fetch_object($results)) {';
+       $lines[] = '  $sites[$r->site] = $r->platform';
+       $lines[] = '}';
+       // Set the $sites array into the backend result, so we can extract it easily
+       // later.
+       $lines[] = 'drush_backend_set_result($sites)';
+    }
+
 
     // Execute the PHP we wrote in $lines on the remote server.
     $result = $this->remote_execute('@hostmaster php-eval', array(implode(';', $lines) . ';'));
diff --git a/hosting_remote_import.drush.inc b/hosting_remote_import.drush.inc
index c888470..9a02fc9 100644
--- a/hosting_remote_import.drush.inc
+++ b/hosting_remote_import.drush.inc
@@ -9,11 +9,13 @@ function hosting_remote_import_post_hosting_remote_import_list_sites_task($task,
   if ($task->ref->type == 'server') {
     if (isset($data['context']['remote_sites_list']) && is_array($data['context']['remote_sites_list'])) {
       foreach ($data['context']['remote_sites_list'] as $url => $platform) {
-        $id = db_insert('remote_import_sites')->fields(array(
-          'tid' => $task->vid,
-          'site' => $url,
-          'platform' => $platform,
-        ))->execute();
+        if (!empty($platform)) {
+          $id = db_insert('remote_import_sites')->fields(array(
+            'tid' => $task->vid,
+            'site' => $url,
+            'platform' => $platform,
+          ))->execute();
+        }
       }
     }
   }