You are here

function backup_migrate_perform_restore in Backup and Migrate 6.2

Same name and namespace in other branches
  1. 8.4 backup_migrate.module \backup_migrate_perform_restore()
  2. 8.2 backup_migrate.module \backup_migrate_perform_restore()
  3. 8.3 backup_migrate.module \backup_migrate_perform_restore()
  4. 5.2 backup_migrate.module \backup_migrate_perform_restore()
  5. 6.3 backup_migrate.module \backup_migrate_perform_restore()
  6. 7.3 backup_migrate.module \backup_migrate_perform_restore()
  7. 7.2 backup_migrate.module \backup_migrate_perform_restore()
  8. 5.0.x backup_migrate.module \backup_migrate_perform_restore()

Restore from a file in the given destination.

4 calls to backup_migrate_perform_restore()
backup_migrate_destination_db::save_file in includes/destinations.db.inc
Save the info by importing it into the database.
backup_migrate_drush_restore in includes/backup_migrate.drush.inc
Restore to the default database.
backup_migrate_ui_destination_restore_file_confirm_submit in includes/destinations.inc
Do the file restore.
backup_migrate_ui_manual_restore_form_submit in ./backup_migrate.module
The restore submit. Do the restore.

File

./backup_migrate.module, line 700
Create (manually or scheduled) and restore backups of your Drupal MySQL database with an option to exclude table data (e.g. cache_*)

Code

function backup_migrate_perform_restore($destination_id, $file, $settings = array()) {
  backup_migrate_include('files', 'filters');
  timer_start('backup_migrate_restore');

  // If not in 'safe mode', increase the maximum execution time:
  if (!ini_get('safe_mode') && strpos(ini_get('disable_functions'), 'set_time_limit') === FALSE && ini_get('max_execution_time') != 0 && ini_get('max_execution_time') < variable_get('backup_migrate_restore_max_time', 1200)) {
    set_time_limit(variable_get('backup_migrate_restore_max_time', 1200));
  }

  // Make the settings into a default profile.
  if (!is_object($settings)) {
    $settings = backup_migrate_crud_create_item('profile', $settings);
    $settings->source_id = empty($settings->source_id) ? 'db' : $settings->source_id;
  }

  // Register shutdown callback.
  register_shutdown_function('backup_migrate_shutdown', $settings);
  if (!is_object($file)) {

    // Load the file from the destination.
    $file = backup_migrate_destination_get_file($destination_id, $file);
    if (!$file) {
      _backup_migrate_message("Could not restore because the file could not be loaded from the destination.", array(), 'error');
      backup_migrate_cleanup();
      return FALSE;
    }
  }

  // Filter the file and perform the restore.
  $file = backup_migrate_filters_restore($file, $settings);
  if (!$file) {
    if (_backup_migrate_check_timeout()) {
      backup_migrate_restore_fail('Could not perform the restore because the script timed out. Try increasing your PHP <a href="!url">max_execution_time setting</a>.', array(
        '!url' => 'http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time',
      ), 'error');
    }
    else {
      backup_migrate_restore_fail("Could not perform the restore.", array(), 'error');
    }
    backup_migrate_cleanup();
    return FALSE;
  }
  $time = timer_stop('backup_migrate_restore');
  if ($file) {
    $destination = backup_migrate_get_destination($destination_id);
    $message = '%source restored from %dest file %file in !time ms. !action';
    $params = array(
      '%file' => $file
        ->filename(),
      '%source' => $settings
        ->get_source_name(),
      '%dest' => $destination
        ->get_name(),
      '!time' => $time['time'],
      '!action' => !empty($settings->performed_action) ? $settings->performed_action : '',
    );
    if ($destination && $destination
      ->op('list files')) {
      $params['!links'] = t('<a href="!restoreurl">Restore again</a>', array(
        '!restoreurl' => url(BACKUP_MIGRATE_MENU_PATH . '/destination/list/restorefile/' . $destination_id . "/" . $file
          ->filename()),
      ));
    }
    backup_migrate_restore_succeed($message, $params, $settings);
  }

  // Delete any temp files we've created.
  backup_migrate_cleanup();

  // No errors. Return the file.
  return $file;
}