Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

Utility helper for automated backups run through cron.

Copyright: 2010 Sam Hemelryk
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 799 lines (33 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: backup_cron_automated_helper  - X-Ref

This class is an abstract class with methods that can be called to aid the
running of automated backups over cron.

get_courses($now = null)   X-Ref
Get the courses to backup.

When there are multiple courses to backup enforce some order to the record set.
The following is the preference order.
First backup courses that do not have an entry in backup_courses first,
as they are likely new and never been backed up. Do the oldest modified courses first.
Then backup courses that have previously been backed up starting with the oldest next start time.
Finally, all else being equal, defer to the sortorder of the courses.

param: null|int $now timestamp to use in course selection.
return: moodle_recordset The recordset of matching courses.

run_automated_backup($rundirective = self::RUN_ON_SCHEDULE)   X-Ref
Runs the automated backups if required

param: bool $rundirective

get_backup_status_array()   X-Ref
Gets the results from the last automated backup that was run based upon
the statuses of the courses that were looked at.

return: array

send_backup_status_to_admin($admin)   X-Ref
Collect details for all statuses of the courses
and send report to admin.

param: stdClass $admin
return: array

check_and_push_automated_backups($courses, $admin)   X-Ref
Loop through courses and push to course ad-hoc task if required

param: \record_set $courses
param: stdClass $admin
return: boolean

should_skip_course_backup($backupcourse, $course, $nextstarttime)   X-Ref
Check if we can skip this course backup.

param: stdClass $backupcourse
param: stdClass $course
param: int $nextstarttime
return: boolean

push_course_backup_adhoc_task($backupcourse, $admin)   X-Ref
Create course backup adhoc task

param: stdClass $backupcourse
param: stdClass $admin
return: void

calculate_next_automated_backup($ignoredtimezone, $now)   X-Ref
Works out the next time the automated backup should be run.

param: mixed $ignoredtimezone all settings are in server timezone!
param: int $now timestamp, should not be in the past, most likely time()
return: int timestamp of the next execution at server time

launch_automated_backup($course, $starttime, $userid)   X-Ref
Launches a automated backup routine for the given course

param: stdClass $course
param: int $starttime
param: int $userid
return: bool

outcome_from_results($results)   X-Ref
Returns the backup outcome by analysing its results.

param: array $results returned by a backup
return: int {@link self::BACKUP_STATUS_OK} and other constants

remove_deleted_courses_from_schedule()   X-Ref
Removes deleted courses fromn the backup_courses table so that we don't
waste time backing them up.

return: int

get_automated_backup_lock($rundirective = self::RUN_ON_SCHEDULE)   X-Ref
Try to get lock for automated backup.

param: int $rundirective
return: \core\lock\lock|boolean - An instance of \core\lock\lock if the lock was obtained, or false.

remove_excess_backups($course, $now = null)   X-Ref
Removes excess backups from a specified course.

param: stdClass $course Course object
param: int $now Starting time of the process
return: bool Whether or not backups is being removed

remove_excess_backups_from_course($course, $now)   X-Ref
Removes excess backups in the course backup filearea from a specified course.

param: stdClass $course Course object
param: int $now Starting time of the process
return: bool Whether or not backups are being removed

remove_excess_backups_from_directory($course, $now)   X-Ref
Removes excess backups in the specified external directory from a specified course.

param: stdClass $course Course object
param: int $now Starting time of the process
return: bool Whether or not backups are being removed

get_backups_to_delete($backupfiles, $now)   X-Ref
Get the list of backup files to delete depending on the automated backup settings.

param: array $backupfiles Existing backup files
param: int $now Starting time of the process
return: array Backup files to delete

is_course_modified($courseid, $since)   X-Ref
Check logs to find out if a course was modified since the given time.

param: int $courseid course id to check
param: int $since timestamp, from which to check
return: bool true if the course was modified, false otherwise. This also returns false if no readers are enabled. This is