protected static function remove_excess_backups_from_course($course, $now) {
        $fs = get_file_storage();
        $context = context_course::instance($course->id);
        $component = 'backup';
        $filearea = 'automated';
        $itemid = 0;
        $backupfiles = array();
        $backupfilesarea = $fs->get_area_files($context->id, $component, $filearea, $itemid, 'timemodified DESC', false);
        // Store all the matching files into timemodified => stored_file array.
        foreach ($backupfilesarea as $backupfile) {
            $backupfiles[$backupfile->get_timemodified()] = $backupfile;
        }

        $backupstodelete = self::get_backups_to_delete($backupfiles, $now);
        if ($backupstodelete) {
            foreach ($backupstodelete as $backuptodelete) {
                $backuptodelete->delete();
            }
            mtrace('Deleted ' . count($backupstodelete) . ' old backup file(s) from the automated filearea');
            return true;
        } else {
            return false;
        }
    }