function backup_migrate_schedule::delete_backups in Backup and Migrate 8.3
Same name and namespace in other branches
- 6.3 includes/schedules.inc \backup_migrate_schedule::delete_backups()
- 7.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 699 - All of the schedule handling code needed for Backup and Migrate.
Class
- backup_migrate_schedule
- A schedule class for crud operations.
Code
function delete_backups($destination, $files, $num_to_keep) {
backup_migrate_include('destinations');
$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);
}
}
}