1 backup.inc backup_limit_cleanup($backup_limit)

Delete excess backups that exceed a certain count. Oldest first.

Parameters

int $backup_limit: The maximum number of backups to allow. Must be greater than 1. If deleting all backups entirely, use backup_delete() instead.

Return value

int: The number of backups removed.

File

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

Code

function backup_limit_cleanup($backup_limit) {
  $backups = backup_directory_list();

  if ($backup_limit <= 1) {
    return 0;
  }

  // Sort by reverse date order.
  backdrop_sort($backups, array('timestamp'), SORT_DESC);
  $backup_count = 0;
  $backups_deleted = 0;
  foreach ($backups as $backup_name => $backup) {
    if ($backup['valid']) {
      $backup_count++;
      if ($backup_count > $backup_limit) {
        if (backup_delete($backup_name)) {
          $backups_deleted++;
        }
      }
    }
  }
  return $backups_deleted;
}