Permalink
Browse files

MDL-29262 backup: new setting to control the ttl of backup logs

Add one new backup setting, moving from the general CFG->loglifetime,
to be able to delete backup logged information often.

Conflicts:

	admin/settings/courses.php
	version.php
  • Loading branch information...
1 parent 93fb7b5 commit c3cc54fcce94a1e16f420a5caedc2886e15db821 @stronk7 stronk7 committed Apr 22, 2012
Showing with 36 additions and 9 deletions.
  1. +26 −3 admin/settings/courses.php
  2. +3 −0 lang/en/backup.php
  3. +6 −5 lib/cronlib.php
  4. +1 −1 version.php
View
29 admin/settings/courses.php
@@ -92,8 +92,29 @@
// Add a category for backups
$ADMIN->add('courses', new admin_category('backups', get_string('backups','admin')));
- // Create a page for general backup defaults
+ // Create a page for general backups configuration and defaults.
$temp = new admin_settingpage('backupgeneralsettings', get_string('generalbackdefaults', 'backup'), 'moodle/backup:backupcourse');
+
+ // General configuration section.
+ $temp->add(new admin_setting_configselect('backup/loglifetime', get_string('loglifetime', 'backup'), get_string('configloglifetime', 'backup'), 30, array(
+ 1 => get_string('numdays', '', 1),
+ 2 => get_string('numdays', '', 2),
+ 3 => get_string('numdays', '', 3),
+ 5 => get_string('numdays', '', 5),
+ 7 => get_string('numdays', '', 7),
+ 10 => get_string('numdays', '', 10),
+ 14 => get_string('numdays', '', 14),
+ 20 => get_string('numdays', '', 20),
+ 30 => get_string('numdays', '', 30),
+ 60 => get_string('numdays', '', 60),
+ 90 => get_string('numdays', '', 90),
+ 120 => get_string('numdays', '', 120),
+ 180 => get_string('numdays', '', 180),
+ 365 => get_string('numdays', '', 365)
+ )));
+
+ // General defaults section.
+ $temp->add(new admin_setting_heading('generalsettings', get_string('generalsettings', 'backup'), ''));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_users', get_string('generalusers','backup'), get_string('configgeneralusers','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_anonymize', get_string('generalanonymize','backup'), get_string('configgeneralanonymize','backup'), array('value'=>0, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_role_assignments', get_string('generalroleassignments','backup'), get_string('configgeneralroleassignments','backup'), array('value'=>1, 'locked'=>0)));
@@ -106,8 +127,10 @@
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', get_string('generalhistories','backup'), get_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
$ADMIN->add('backups', $temp);
-/// "backups" settingpage
+ // Create a page for automated backups configuration and defaults.
$temp = new admin_settingpage('automated', get_string('automatedsetup','backup'), 'moodle/backup:backupcourse');
+
+ // Automated configuration section.
$temp->add(new admin_setting_configselect('backup/backup_auto_active', get_string('active'), get_string('autoactivedescription', 'backup'), 0, array(
0 => get_string('autoactivedisabled', 'backup'),
1 => get_string('autoactiveenabled', 'backup'),
@@ -139,7 +162,7 @@
500 => '500');
$temp->add(new admin_setting_configselect('backup/backup_auto_keep', get_string('keep'), get_string('backupkeephelp'), 1, $keepoptoins));
-
+ // Automated defaults section.
$temp->add(new admin_setting_heading('automatedsettings', get_string('automatedsettings','backup'), ''));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', get_string('generalusers', 'backup'), get_string('configgeneralusers', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', get_string('generalroleassignments','backup'), get_string('configgeneralroleassignments','backup'), 1));
View
3 lang/en/backup.php
@@ -88,6 +88,7 @@
$string['configgeneralroleassignments'] = 'If enabled by default roles assignments will also be backed up.';
$string['configgeneraluserscompletion'] = 'If enabled user completion information will be included in backups by default.';
$string['configgeneralusers'] = 'Sets the default for whether to include users in backups.';
+$string['configloglifetime'] = 'This specifies the length of time you want to keep backup logs information. Logs that are older than this age are automatically deleted. It is recommended to keep this value small, because backup logged information can be huge.';
$string['confirmcancel'] = 'Cancel backup';
$string['confirmcancelquestion'] = 'Are you sure you wish to cancel?
Any information you have entered will be lost.';
@@ -126,6 +127,7 @@
$string['generalgradehistories'] = 'Include histories';
$string['generallogs'] = 'Include logs';
$string['generalroleassignments'] = 'Include role assignments';
+$string['generalsettings'] = 'General backup settings';
$string['generaluserscompletion'] = 'Include user completion information';
$string['generalusers'] = 'Include users';
$string['importfile'] = 'Import a backup file';
@@ -145,6 +147,7 @@
$string['includeditems'] = 'Included items:';
$string['includesection'] = 'Section {$a}';
$string['includeuserinfo'] = 'User data';
+$string['loglifetime'] = 'Keep logs for';
$string['locked'] = 'Locked';
$string['lockedbypermission'] = 'You don\'t have sufficient permissions to change this setting';
$string['lockedbyconfig'] = 'This setting has been locked by the default backup settings';
View
11 lib/cronlib.php
@@ -113,17 +113,18 @@ function cron_run() {
}
- // Delete old backup_controllers and logs
- if (!empty($CFG->loglifetime)) { // value in days
- $loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
- // Delete child records from backup_logs
+ // Delete old backup_controllers and logs.
+ $loglifetime = get_config('backup', 'loglifetime');
+ if (!empty($loglifetime)) { // Value in days.
+ $loglifetime = $timenow - ($loglifetime * 3600 * 24);
+ // Delete child records from backup_logs.
$DB->execute("DELETE FROM {backup_logs}
WHERE EXISTS (
SELECT 'x'
FROM {backup_controllers} bc
WHERE bc.backupid = {backup_logs}.backupid
AND bc.timecreated < ?)", array($loglifetime));
- // Delete records from backup_controllers
+ // Delete records from backup_controllers.
$DB->execute("DELETE FROM {backup_controllers}
WHERE timecreated < ?", array($loglifetime));
mtrace(" Deleted old backup records");
View
2 version.php
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2011120502.06; // 20111205 = branching date YYYYMMDD - do not modify!
+$version = 2011120502.07; // 20111205 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

0 comments on commit c3cc54f

Please sign in to comment.