You are here

public function backup_migrate_schedule::delete_backups in Backup and Migrate 7.3

Same name and namespace in other branches
  1. 8.3 includes/schedules.inc \backup_migrate_schedule::delete_backups()
  2. 6.3 includes/schedules.inc \backup_migrate_schedule::delete_backups()

Remove older backups keeping only the number specified by the aministrator.

1 call to backup_migrate_schedule::delete_backups()
backup_migrate_schedule::remove_expired_backups in includes/schedules.inc
Remove older backups keeping only the number specified by the aministrator.

File

includes/schedules.inc, line 750
All of the schedule handling code needed for Backup and Migrate.

Class

backup_migrate_schedule
A schedule class for crud operations.

Code

public function delete_backups($destination, $files, $num_to_keep) {
  require_once dirname(__FILE__) . '/destinations.inc';
  $num_to_keep = $this->keep;

  // Sort the files by modified time.
  $i = 0;
  foreach ($files as $id => $file) {
    if ($file
      ->is_recognized_type()) {
      $time = $file
        ->info('filetime');
      $sorted[$id] = $time;
    }
  }
  asort($sorted);

  // If we are beyond our limit, remove as many as we need.
  $num_files = count($files);
  if ($num_files > $num_to_keep) {
    $num_to_delete = $num_files - $num_to_keep;

    // Delete from the start of the list (earliest).
    foreach ($sorted as $id => $time) {
      if (!$num_to_delete--) {
        break;
      }
      $destination
        ->delete_file($id);
    }
  }
}