1 backup.inc backup_restore_execute($restore_target_name, $restore_target, $backup_directory, array $backup_settings)

Run a backup process.

Parameters

string $restore_target_name: The name of the backup target, used as the base name of the created backup file, such as "db_default" or "config_active".

string $restore_target: The target to which the backup should be restored. Typically an indicator such as "db:default" (for the database) or "config:active" (for config).

string $backup_directory: The directory containing the backup file to restore.

array $backup_settings: An array of settings that are read by the Backup class, modifying its behavior. Each Backup class may have different settings. Check the defaultSettings() method within each class for a full list.

Return value

bool: TRUE if the restore was successful, FALSE on failure.

File

core/includes/backup.inc, line 660
Contains functionality related to creating and restoring site backups.

Code

function backup_restore_execute($restore_target_name, $restore_target, $backup_directory, array $backup_settings) {
  // Safety check that restore target has an associate backup handler.
  $backup_class = backup_get_handler_name($restore_target);
  if (!is_subclass_of($backup_class, 'Backup', TRUE)) {
    return FALSE;
  }

  /** @var Backup $backup_instance */
  $backup_instance = new $backup_class($restore_target_name, $restore_target, $backup_settings);

  // Create the BackupFile instance to hold the backup output.
  $file = new BackupFile($restore_target_name, $backup_directory);
  // @todo: Determine these extensions in a more flexible way.
  if (strpos($restore_target, 'db:') === 0) {
    $file->pushExtension('sql');
    $file->pushExtension('gz');
  }
  elseif (strpos($restore_target, 'config:') === 0) {
    $file->pushExtension('tar');
    $file->pushExtension('gz');
  }

  // Pre and post steps are separate to allow offloading compression and
  // decompression into separate requests (eventually).
  $backup_instance->preRestore($file);
  $success = $backup_instance->restore($file);
  $backup_instance->postRestore($file);

  return $success;
}