You are here

function backup_migrate_db_restore in Backup and Migrate 5.2

Same name and namespace in other branches
  1. 8.2 includes/db.inc \backup_migrate_db_restore()

Restore from a previously backed up files. File must be a decompressed SQL file.

1 call to backup_migrate_db_restore()
backup_migrate_perform_restore_file in ./backup_migrate.module
Restore from a file in the given destination.

File

includes/db.inc, line 12
General database dump/restore code for Backup and Migrate.

Code

function backup_migrate_db_restore($file) {

  // Open the file (with fopen or gzopen depending on file format).
  if ($handle = @fopen($file['filepath'], "r")) {
    $num = 0;

    // Read one line at a time and run the query.
    while ($line = fgets($handle)) {
      $line = trim($line);
      if ($line) {

        // Use the helper instead of the api function to avoid substitution of '{' etc.
        _db_query($line);
        $num++;
      }
    }

    // Close the file with fclose/gzclose.
    fclose($handle);
  }
  else {
    drupal_set_message(t("Unable to open file %file to restore database", array(
      "%file" => $file['filepath'],
    )), 'error');
  }
  return $num;
}