1 backup.inc backup_batch(array $backup_targets, array $options = array(), $redirect = NULL, $url = 'batch', array $batch = array(), $redirect_callback = 'backdrop_goto')

Starts a batch process to create a backup.

Parameters

array $backup_targets: An array of backup settings, keyed by the backup name. For example a common set of keys would be:

  • db_default
  • config_active

The value of each array is another array of backup settings, as would be passed to backup_execute().

array $options: Additional options to control the Backup process. Available keys:

  • backup_limit: Integer indicating how many total backups should be allowed. Backups exceeding this count will be removed, oldest first. A value of FALSE will not enforce a limit.
  • name: The name of the overall backup directory. If not provided, a timestamp-based directory name will be used.
  • label: A human-readable label for this backup. If not provided, the name will be used.
  • description: A description of the backup.

string $redirect: Path to redirect to when the batch has finished processing.

string $url: URL of the batch processing page (should only be used for separate scripts like update.php).

array $batch: Optional parameters to pass into the batch API.

string $redirect_callback: (optional) Specify a function to be called to redirect to the progressive processing page.

File

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

Code

function backup_batch(array $backup_targets, array $options = array(), $redirect = NULL, $url = 'batch', array $batch = array(), $redirect_callback = 'backdrop_goto') {
  $operations = array();

  // Ensure a default backup limit exists. Excess backups are removed upon
  // completion.
  $backup_limit = config_get('system.backup', 'backup_limit');
  $options += array(
    'backup_limit' => isset($backup_limit) ? $backup_limit : 5,
    'name' => NULL,
    'label' => NULL,
    'description' => NULL,
  );

  foreach ($backup_targets as $backup_target) {
    $settings = isset($backup_target['settings']) ? $backup_target['settings'] : array();
    if ($options['name']) {
      $settings['backup_directory'] = backup_get_backup_directory() . '/' . $options['name'];
    }
    $operations[] = array('backup_execute', array(
      $backup_target['name'],
      $backup_target['target'],
      $settings,
    ));
  }

  if ($options['backup_limit']) {
    $operations[] = array('backup_limit_cleanup', array(
      $options['backup_limit'],
    ));
  }

  $batch['operations'] = $operations;
  $batch += array(
    'title' => t('Creating backup'),
    'init_message' => t('Starting backup'),
    'error_message' => t('A backup could not be created.'),
    'finished' => 'backup_batch_finished',
    'file' => 'core/includes/backup.inc',
  );
  batch_set($batch);
  batch_process($redirect, $url, $redirect_callback);
}