I am using this module to merge changes from my testing server to my production server. I have two identical installations of drupal, with constant changes to the live site I needed a way to make and test changes and update the live site with minimal downtime. I therefore make and test all my changes on the testing server and merge the changes with the production server were my live site is.

I immediately ran into an issue when trying to merge data and tables without destroying the information that was already there. So I modified 2 functions in backup_migrate.module file.

function _backup_migrate_get_dump_sql($file, $exclude_tables, $nodata_tables) {
  if ($dst = fopen($file, "w")) {
    $exclude = variable_get("backup_migrate_exclude_tables", _backup_migrate_default_exclude_tables());
    $nodata = variable_get("backup_migrate_nodata_tables", _backup_migrate_default_structure_only_tables());
    fwrite($dst, _backup_migrate_get_sql_file_header());
    $alltables = _backup_migrate_get_tables();
    foreach ($alltables as $table) {
      if ($table['Name'] && !isset($exclude[$table['Name']])) {
        fwrite($dst, _backup_migrate_get_table_structure_sql($table, $nodata));
        if (!in_array($table['Name'], $nodata)) {
          _backup_migrate_dump_table_data_sql_to_handle($dst, $table);
        }
      }
    }
    fwrite($dst, _backup_migrate_get_sql_file_footer());
    fclose($dst);
    return TRUE;
  }
  else {
    return FALSE;
  }
}
/**
 * Get the sql for the structure of the given table.
 */
function _backup_migrate_get_table_structure_sql($table, $nodata) {
  $out = "";
  $result = db_query("SHOW CREATE TABLE `". $table['Name'] ."`");
  if ($create = db_fetch_array($result)) {
    if (!in_array($table['Name'], $nodata)) {
    	$out .= "DROP TABLE IF EXISTS `". $table['Name'] ."`;\n";
        $out .= strtr($create['Create Table'], "\n", " ");
    } else {
    	$out .= str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', strtr($create['Create Table'], "\n", " "));
    }
    if ($table['Auto_increment']) {
      $out .= " AUTO_INCREMENT=". $table['Auto_increment'];
    }
    $out .= ";\n";
  }
  return $out;
}

This way you don't drop any tables with data you do not wish to update, while still creating any new tables as they are required. Its not pretty, but it is kinda getting the job done. I am open to suggestions on more efficient ways to merge site changes from a test site to a production site.

Comments

ronan’s picture

Status: Active » Closed (works as designed)

I don't recommend using this module to merge 2 sites. There's no way to deal with conflicting IDs and there's no way to be sure that you're not creating an inconsistent and damaged db. I can't support this method of content deployment I'm afraid.