--- backup_migrate.module	2007-11-24 01:28:43.000000000 +0100
+++ backup_migrate.module	2007-12-02 08:57:19.875000000 +0100
@@ -584,6 +584,8 @@ function _backup_migrate_get_table_struc
       $out .= " AUTO_INCREMENT=". $table['Auto_increment'];
     }
     $out.=";\n";
+    global $db_prefix;
+    $out=strtr($out, array($table['Name'] => strtr($table['Name'], array($db_prefix => '{__PREFIX__}'))));
   }
   return $out;
 }
@@ -592,6 +594,7 @@ function _backup_migrate_get_table_struc
  *  Get the sql to insert the data for a given table
  */
 function _backup_migrate_dump_table_data_sql_to_handle( $dst, $table ) {
+  global $db_prefix;
   $data    = db_query("SELECT * FROM `". $table['Name'] ."`");
   while ( $row = db_fetch_array($data) ) {
     $items = array();
@@ -601,7 +604,7 @@ function _backup_migrate_dump_table_data
     if ( $items ) {
       fwrite( 
         $dst, 
-        "INSERT INTO `". $table['Name'] ."` VALUES (". implode( ",", $items ) .");\n"
+        "INSERT INTO `". strtr($table['Name'], array($db_prefix => '{__PREFIX__}')) ."` VALUES (". implode( ",", $items ) .");\n"
        );
     }
   }
@@ -649,7 +652,8 @@ function _backup_migrate_get_tables( ) {
   // get auto_increment values and names of all tables
   $tables = db_query("show table status");
   while ( $table = db_fetch_array($tables) ) {
-    $out[] = $table;
+    global $db_prefix;
+    if (substr($table['Name'],0,strlen($db_prefix))==$db_prefix) $out[] = $table;
   }
   return $out;
 }
@@ -662,7 +666,8 @@ function _backup_migrate_get_table_names
   // get auto_increment values and names of all tables
   $tables = db_query("show table status");
   while ( $table = db_fetch_array($tables) ) {
-    $out[$table['Name']] = $table['Name'];
+    global $db_prefix;
+    if (substr($table['Name'],0,strlen($db_prefix))==$db_prefix) $out[$table['Name']] = $table['Name'];
   }
   return $out;
 }
@@ -673,6 +678,7 @@ function _backup_migrate_get_table_names
  * Restore from a previously backed up files. Accepts any file created by the backup function.
  */ 
 function _backup_migrate_restore_file( $filepath, $filename="", $delete=false ) {
+  set_time_limit(0);
   if ( !$filename ) {
     $filename = $filepath;
   }
@@ -773,6 +779,8 @@ function _backup_migrate_restore_file( $
     // read one line at a time and run the query
     while ( $line = $read_func( $handle ) ) {
       $line = trim( $line );
+      global $db_prefix;
+      $line=strtr($line, array('{__PREFIX__}' => $db_prefix));
       if ( $line ) {
         // use the helper instead of the api function to avoid substitution of '{' etc
         _db_query( $line );
@@ -1100,22 +1108,23 @@ function _backup_migrate_default_exclude
  *  important to back up or migrate during development (such ass access log and watchdog)
  */
 function _backup_migrate_default_structure_only_tables() {
+  global $db_prefix;
   $core = array(
-    'cache', 
-    'cache_filter', 
-    'cache_calendar_ical', 
-    'cache_menu', 
-    'cache_page',
-    'cache_views',
-    'sessions',
-    'search_dataset',
-    'search_index',
-    'search_keywords_log',
-    'search_total',
-    'watchdog',
-    'accesslog',
-    'devel_queries',
-    'devel_times',
+    "{$db_prefix}cache", 
+    "{$db_prefix}cache_filter", 
+    "{$db_prefix}cache_calendar_ical", 
+    "{$db_prefix}cache_menu", 
+    "{$db_prefix}cache_page",
+    "{$db_prefix}cache_views",
+    "{$db_prefix}sessions",
+    "{$db_prefix}search_dataset",
+    "{$db_prefix}search_index",
+    "{$db_prefix}search_keywords_log",
+    "{$db_prefix}search_total",
+    "{$db_prefix}watchdog",
+    "{$db_prefix}accesslog",
+    "{$db_prefix}devel_queries",
+    "{$db_prefix}devel_times",
   );
   $alltables = array_merge($core, module_invoke_all('devel_caches'));
   return $alltables;
