500 => '500');
$temp->add(new admin_setting_configselect('backup/backup_auto_keep', new lang_string('keep'), new lang_string('backupkeephelp'), 1, $keepoptoins));
$temp->add(new admin_setting_configcheckbox('backup/backup_shortname', new lang_string('backup_shortname', 'admin'), new lang_string('backup_shortnamehelp', 'admin'), 0));
+ $temp->add(new admin_setting_configcheckbox('backup/backup_auto_skip_hidden', new lang_string('skiphidden', 'backup'), new lang_string('skiphiddenhelp', 'backup'), 1));
+ $temp->add(new admin_setting_configselect('backup/backup_auto_skip_modif_days', new lang_string('skipmodifdays', 'backup'), new lang_string('skipmodifdayshelp', 'backup'), 30, array(
+ 0 => new lang_string('never'),
+ 1 => new lang_string('numdays', '', 1),
+ 2 => new lang_string('numdays', '', 2),
+ 3 => new lang_string('numdays', '', 3),
+ 5 => new lang_string('numdays', '', 5),
+ 7 => new lang_string('numdays', '', 7),
+ 10 => new lang_string('numdays', '', 10),
+ 14 => new lang_string('numdays', '', 14),
+ 20 => new lang_string('numdays', '', 20),
+ 30 => new lang_string('numdays', '', 30),
+ 60 => new lang_string('numdays', '', 60),
+ 90 => new lang_string('numdays', '', 90),
+ 120 => new lang_string('numdays', '', 120),
+ 180 => new lang_string('numdays', '', 180),
+ 365 => new lang_string('numdays', '', 365)
+ )));
+ $temp->add(new admin_setting_configcheckbox('backup/backup_auto_skip_modif_prev', new lang_string('skipmodifprev', 'backup'), new lang_string('skipmodifprevhelp', 'backup'), 0));
// Automated defaults section.
$temp->add(new admin_setting_heading('automatedsettings', new lang_string('automatedsettings','backup'), ''));
$status = true;
$emailpending = false;
$now = time();
+ $config = get_config('backup');
mtrace("Checking automated backup status",'...');
$state = backup_cron_automated_helper::get_automated_backup_state($rundirective);
$backupcourse = $DB->get_record('backup_courses', array('courseid'=>$course->id));
}
- // Skip courses that do not yet need backup
+ // The last backup is considered as successful when OK or SKIPPED.
+ $lastbackupwassuccessful = ($backupcourse->laststatus == self::BACKUP_STATUS_SKIPPED ||
+ $backupcourse->laststatus == self::BACKUP_STATUS_OK) && (
+ $backupcourse->laststarttime > 0 && $backupcourse->lastendtime > 0);
+
+ // Skip courses that do not yet need backup.
$skipped = !(($backupcourse->nextstarttime > 0 && $backupcourse->nextstarttime < $now) || $rundirective == self::RUN_IMMEDIATELY);
- if ($skipped && $backupcourse->nextstarttime != $nextstarttime) {
- $backupcourse->nextstarttime = $nextstarttime;
- $backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
- $DB->update_record('backup_courses', $backupcourse);
- mtrace('Backup of \'' . $course->fullname . '\' is scheduled on ' . $showtime);
+ $skippedmessage = 'Does not require backup';
+
+ // If config backup_auto_skip_hidden is set to true, skip courses that are not visible.
+ if (!$skipped && $config->backup_auto_skip_hidden) {
+ $skipped = ($config->backup_auto_skip_hidden && !$course->visible);
+ $skippedmessage = 'Not visible';
}
- // Skip backup of unavailable courses that have remained unmodified in a month
- if (!$skipped && empty($course->visible) && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + settings were unmodified last month
- //Check log if there were any modifications to the course content
- $sqlwhere = "course=:courseid AND time>:time AND ". $DB->sql_like('action', ':action', false, true, true);
- $params = array('courseid' => $course->id, 'time' => $now-31*24*60*60, 'action' => '%view%');
+ // If config backup_auto_skip_modif_days is set to true, skip courses
+ // that have not been modified since the number of days defined.
+ if (!$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_days) {
+ $sqlwhere = "course=:courseid AND time>:time AND ".$DB->sql_like('action', ':action', false, true, true);
+ $timenotmodifsincedays = $now - ($config->backup_auto_skip_modif_days * DAYSECS);
+ // Check log if there were any modifications to the course content.
+ $params = array('courseid' => $course->id,
+ 'time' => $timenotmodifsincedays,
+ 'action' => '%view%');
$logexists = $DB->record_exists_select('log', $sqlwhere, $params);
- if (!$logexists) {
- $backupcourse->laststatus = self::BACKUP_STATUS_SKIPPED;
- $backupcourse->nextstarttime = $nextstarttime;
- $DB->update_record('backup_courses', $backupcourse);
- mtrace('Skipping unchanged course '.$course->fullname);
- $skipped = true;
- }
+
+ $skipped = ($course->timemodified <= $timenotmodifsincedays && !$logexists);
+ $skippedmessage = 'Not modified in the past '.$config->backup_auto_skip_modif_days.' days';
+ }
+
+ // If config backup_auto_skip_modif_prev is set to true, skip courses
+ // that have not been modified since previous backup.
+ if (!$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_prev) {
+ // Check log if there were any modifications to the course content.
+ $params = array('courseid' => $course->id,
+ 'time' => $backupcourse->laststarttime,
+ 'action' => '%view%');
+ $logexists = $DB->record_exists_select('log', $sqlwhere, $params);
+
+ $skipped = ($course->timemodified <= $backupcourse->laststarttime && !$logexists);
+ $skippedmessage = 'Not modified since previous backup';
}
- //Now we backup every non-skipped course
- if (!$skipped) {
+ // Skip courses not needed for backup.
+ if ($skipped) {
+ // Output the next execution time when it has been updated.
+ if ($backupcourse->nextstarttime != $nextstarttime) {
+ mtrace('Backup of \'' . $course->fullname . '\' is scheduled on ' . $showtime);
+ }
+ $backupcourse->laststatus = self::BACKUP_STATUS_SKIPPED;
+ $backupcourse->nextstarttime = $nextstarttime;
+ $DB->update_record('backup_courses', $backupcourse);
+ mtrace('Skipping '.$course->fullname.' ('.$skippedmessage.')');
+ } else {
+ // Backup every non-skipped courses.
mtrace('Backing up '.$course->fullname.'...');
- //We have to send a email because we have included at least one backup
+ // We have to send an email because we have included at least one backup.
$emailpending = true;
- //Only make the backup if laststatus isn't 2-UNFINISHED (uncontrolled error)
- if ($backupcourse->laststatus != 2) {
- //Set laststarttime
+ // Only make the backup if laststatus isn't 2-UNFINISHED (uncontrolled error).
+ if ($backupcourse->laststatus != self::BACKUP_STATUS_UNFINISHED) {
+ // Set laststarttime.
$starttime = time();
$backupcourse->laststarttime = time();