Commit bac233d3 authored by Sam Hemelryk's avatar Sam Hemelryk
Browse files

backup MDL-22184 Scheduled backups are now possible again through cron.

AMOS BEGIN
 MOV [move scheduledsetup,core_backup],[automatedsetup,core_backup]
 MOV [scheduledsettings,core_backup],[automatedsettings,core_backup]
 MOV [scheduledstorage,core_backup],[automatedstorage,core_backup]
 MOV [scheduledstoragehelp,core_backup],[automatedstoragehelp,core_backup]
 MOV [scheduledbackupsinactive,core],[automatedbackupsinactive,core_backup]
 MOV [scheduledbackupstatus,core],[automatedbackupstatus,core_backup]
 CPY [schedule,core],[automatedbackupschedule,core_backup]
 MOV [backupschedulehelp,core],[automatedbackupschedulehelp,core_backup]
AMOS END
parent 87142168
......@@ -10,15 +10,10 @@
admin_externalpage_setup('reportbackups');
echo $OUTPUT->header();
/// Scheduled backups are disabled by the server admin
if (!empty($CFG->disablescheduledbackups)) {
print_error('scheduledbackupsdisabled', 'error');
}
/// Scheduled backups aren't active by the site admin
/// Automated backups aren't active by the site admin
$backup_config = backup_get_config();
if (empty($backup_config->backup_sche_active)) {
echo $OUTPUT->notification(get_string('scheduledbackupsinactive'));
if (empty($backup_config->backup_auto_active)) {
echo $OUTPUT->notification(get_string('automatedbackupsinactive', 'backup'));
}
/// Get needed strings
......
......@@ -108,19 +108,18 @@ if ($hassiteconfig
$ADMIN->add('backups', $temp);
/// "backups" settingpage
$temp = new admin_settingpage('scheduled', get_string('scheduledsettings','backup'), 'moodle/backup:backupcourse');
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_modules', get_string('includemodules'), get_string('backupincludemoduleshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_withuserdata', get_string('includemoduleuserdata'), get_string('backupincludemoduleuserdatahelp'), 0));
$temp->add(new admin_setting_configselect('backup/backup_sche_users', get_string('users'), get_string('backupusershelp'),
0, array(0 => get_string('all'), 1 => get_string('course'))));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_logs', get_string('logs'), get_string('backuplogshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_userfiles', get_string('userfiles'), get_string('backupuserfileshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_coursefiles', get_string('coursefiles'), get_string('backupcoursefileshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_sitefiles', get_string('sitefiles'), get_string('backupsitefileshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup_sche_gradebook_history', get_string('gradebookhistories', 'grades'), get_string('backupgradebookhistoryhelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_messages', get_string('messages', 'message'), get_string('backupmessageshelp','message'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_blogs', get_string('blogs', 'blog'), get_string('backupblogshelp','blog'), 0));
$temp = new admin_settingpage('automated', get_string('automatedsetup','backup'), 'moodle/backup:backupcourse');
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_active', get_string('active'), get_string('backupactivehelp'), 0));
$temp->add(new admin_setting_special_backupdays());
$temp->add(new admin_setting_configtime('backup/backup_auto_hour', 'backup_auto_minute', get_string('executeat'),
get_string('backupexecuteathelp'), array('h' => 0, 'm' => 0)));
$storageoptions = array(
0 => get_string('storagecourseonly', 'backup'),
1 => get_string('storageexternalonly', 'backup'),
2 => get_string('storagecourseandexternal', 'backup')
);
$temp->add(new admin_setting_configselect('backup/backup_auto_storage', get_string('automatedstorage', 'backup'), get_string('automatedstoragehelp', 'backup'), 0, $storageoptions));
$temp->add(new admin_setting_configdirectory('backup/backup_auto_destination', get_string('saveto'), get_string('backupsavetohelp'), ''));
$keepoptoins = array(
0 => get_string('all'), 1 => '1',
2 => '2',
......@@ -135,13 +134,24 @@ if ($hassiteconfig
300 => '300',
400 => '400',
500 => '500');
$temp->add(new admin_setting_configselect('backup/backup_sche_keep', get_string('keep'),
get_string('backupkeephelp'), 1, $keepoptoins));
$temp->add(new admin_setting_configcheckbox('backup/backup_sche_active', get_string('active'), get_string('backupactivehelp'), 0));
$temp->add(new admin_setting_special_backupdays());
$temp->add(new admin_setting_configtime('backup/backup_sche_hour', 'backup_sche_minute', get_string('executeat'),
get_string('backupexecuteathelp'), array('h' => 0, 'm' => 0)));
$temp->add(new admin_setting_configdirectory('backup/backup_sche_destination', get_string('saveto'), get_string('backupsavetohelp'), ''));
$temp->add(new admin_setting_configselect('backup/backup_auto_keep', get_string('keep'), get_string('backupkeephelp'), 1, $keepoptoins));
$temp->add(new admin_setting_heading('automatedsettings', get_string('automatedsettings','backup'), ''));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', get_string('users'), get_string('backupusershelp'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', get_string('generalroleassignments','backup'), get_string('configgeneralroleassignments','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_user_files', get_string('generaluserfiles', 'backup'), get_string('configgeneraluserfiles','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', get_string('generalactivities','backup'), get_string('configgeneralactivities','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_blocks', get_string('generalblocks','backup'), get_string('configgeneralblocks','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_filters', get_string('generalfilters','backup'), get_string('configgeneralfilters','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_comments', get_string('generalcomments','backup'), get_string('configgeneralcomments','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_userscompletion', get_string('generaluserscompletion','backup'), get_string('configgeneraluserscompletion','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', get_string('logs'), get_string('backuplogshelp'), 0));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_histories', get_string('generalhistories','backup'), get_string('configgeneralhistories','backup'), 0));
//$temp->add(new admin_setting_configcheckbox('backup/backup_auto_messages', get_string('messages', 'message'), get_string('backupmessageshelp','message'), 0));
//$temp->add(new admin_setting_configcheckbox('backup/backup_auto_blogs', get_string('blogs', 'blog'), get_string('backupblogshelp','blog'), 0));
$ADMIN->add('backups', $temp);
......
......@@ -49,10 +49,11 @@ abstract class backup implements checksumable {
const INTERACTIVE_NO = false;
// Predefined modes (purposes) of the backup
const MODE_GENERAL = 10;
const MODE_IMPORT = 20;
const MODE_HUB = 30;
const MODE_SAMESITE = 40;
const MODE_GENERAL = 10;
const MODE_IMPORT = 20;
const MODE_HUB = 30;
const MODE_SAMESITE = 40;
const MODE_AUTOMATED = 50;
// Target (new/existing/current/adding/deleting)
const TARGET_CURRENT_DELETING = 0;
......
......@@ -72,7 +72,7 @@ class backup_controller extends backup implements loggable {
* @param int $id The ID of the item to backup; e.g the course id
* @param int $format The backup format to use; Most likely backup::FORMAT_MOODLE
* @param bool $interactive Whether this backup will require user interaction; backup::INTERACTIVE_YES or INTERACTIVE_NO
* @param int $mode One of backup::MODE_GENERAL, MODE_IMPORT, MODE_SAMESITE, MODE_HUB
* @param int $mode One of backup::MODE_GENERAL, MODE_IMPORT, MODE_SAMESITE, MODE_HUB, MODE_AUTOMATED
* @param int $userid The id of the user making the backup
*/
public function __construct($type, $id, $format, $interactive, $mode, $userid){
......
......@@ -152,4 +152,20 @@ $renderer = $PAGE->get_renderer('core', 'backup');
echo $renderer->backup_files_viewer($treeview_options);
echo $OUTPUT->container_end();
$automatedbackups = get_config('backup', 'backup_auto_active');
if (!empty($automatedbackups)) {
echo $OUTPUT->heading_with_help(get_string('choosefilefromautomatedbackup', 'backup'), 'choosefilefromautomatedbackup', 'backup');
echo $OUTPUT->container_start();
$treeview_options = array();
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
$treeview_options['filecontext'] = $context;
$treeview_options['currentcontext'] = $context;
$treeview_options['component'] = 'backup';
$treeview_options['context'] = $context;
$treeview_options['filearea'] = 'automated';
$renderer = $PAGE->get_renderer('core', 'backup');
echo $renderer->backup_files_viewer($treeview_options);
echo $OUTPUT->container_end();
}
echo $OUTPUT->footer();
This diff is collapsed.
......@@ -229,6 +229,11 @@ abstract class backup_helper {
break;
}
if ($backupmode == backup::MODE_AUTOMATED) {
// Automated backups have there own special area!
$filearea = 'automated';
}
// Backups of type HUB (by definition never have user info)
// are sent to user's "user_tohub" file area. The upload process
// will be responsible for cleaning that filearea once finished
......
......@@ -406,8 +406,8 @@ class core_backup_renderer extends plugin_renderer_base {
$files = $viewer->files;
$table = new html_table();
$table->attributes['class'] = 'backup-files-table generaltable';
$table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore'));
$table->align = array('left', 'left', 'left', 'center', 'left', 'center');
$table->width = '100%';
$table->data = array();
......
......@@ -155,10 +155,6 @@ $CFG->admin = 'admin';
// any existing key.
// $CFG->mnetkeylifetime = 28;
//
// Prevent scheduled backups from operating (and hide the GUI for them)
// Useful for webhost operators who have alternate methods of backups
// $CFG->disablescheduledbackups = true;
//
// Allow user passwords to be included in backup files. Very dangerous
// setting as far as it publishes password hashes that can be unencrypted
// if the backup file is publicy available. Use it only if you can guarantee
......
......@@ -23,6 +23,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['automatedbackupschedule'] = 'Schedule';
$string['automatedbackupschedulehelp'] = 'Choose which days of the week to perform automated backups.';
$string['automatedbackupsinactive'] = 'Automated backups haven\'t been enabled by the site admin';
$string['automatedbackupstatus'] = 'Automated backup status';
$string['backupactivity'] = 'Backup activity: {$a}';
$string['backupcourse'] = 'Backup course: {$a}';
$string['backupcoursedetails'] = 'Course details';
......@@ -54,6 +60,8 @@ $string['choosefilefromuserbackup'] = 'User private backup area';
$string['choosefilefromuserbackup_help'] = 'When backup courses with "Anonymize user information" option ticked, backup files will be stored here';
$string['choosefilefromactivitybackup'] = 'Activity backup area';
$string['choosefilefromactivitybackup_help'] = 'When backup activities using default settings, backup files will be stored here';
$string['choosefilefromautomatedbackup'] = 'Automated backups';
$string['choosefilefromautomatedbackup_help'] = 'Contains automatically generated backups.';
$string['configgeneralactivities'] = 'Sets the default for including activities in a backup.';
$string['configgeneralanonymize'] = 'If enabled all information pertaining to users will be anonymised by default.';
$string['configgeneralblocks'] = 'Sets the default for including blocks in a backup.';
......@@ -187,7 +195,13 @@ $string['rootsettingcomments'] = 'Include comments';
$string['rootsettinguserscompletion'] = 'Include user completion details';
$string['rootsettinglogs'] = 'Include course logs';
$string['rootsettinggradehistories'] = 'Include grade history';
$string['scheduledsettings'] = 'Scheduled backup settings';
$string['automatedsetup'] = 'Automated backup setup';
$string['automatedsettings'] = 'Automated backup settings';
$string['automatedstorage'] = 'Automated backup storage';
$string['automatedstoragehelp'] = 'Choose the location where you want backups to be stored when they are automatically created.';
$string['storagecourseonly'] = 'Course backup filearea';
$string['storagecourseandexternal'] = 'Course backup filearea and the specified directory';
$string['storageexternalonly'] = 'Specified directory for automated backups';
$string['sectionincanduser'] = 'Included in backup along with user information';
$string['sectioninc'] = 'Included in backup (no user information)';
$string['sectionactivities'] = 'Activities';
......
......@@ -185,7 +185,6 @@ $string['backupnonisowarning'] = 'Warning: this backup is from a non-Unicode ver
$string['backuporiginalname'] = 'Backup name';
$string['backuproleassignments'] = 'Backup role assignments for these roles';
$string['backupsavetohelp'] = 'Full path to the directory where you want to save the backup files<br />(leave blank to save in its course default dir)';
$string['backupschedulehelp'] = 'Choose which days of the week to perform automated backups.';
$string['backupsitefileshelp'] = 'If enabled then site files used in courses will be included in automated backups';
$string['backuptakealook'] = 'Please take a look at your backup logs in:
{$a}';
......@@ -1508,8 +1507,6 @@ $string['showthishelpinlanguage'] = 'Show this help in language: {$a}';
$string['showtopicfromothers'] = 'Show topic';
$string['showweekfromothers'] = 'Show week';
$string['schedule'] = 'Schedule';
$string['scheduledbackupsinactive'] = 'Scheduled backups haven\'t been enabled by the site admin';
$string['scheduledbackupstatus'] = 'Scheduled backup status';
$string['since'] = 'Since';
$string['sincelast'] = 'since last login';
$string['site'] = 'Site';
......
......@@ -153,6 +153,7 @@ $string['save'] = 'Save';
$string['saveas'] = 'Save as';
$string['saved'] = 'Saved';
$string['saving'] = 'Saving';
$string['automatedbackup'] = 'Automated backups';
$string['search'] = 'Search';
$string['searching'] = 'Search in';
$string['select'] = 'Select';
......
......@@ -3514,7 +3514,7 @@ class admin_setting_special_backupdays extends admin_setting_configmulticheckbox
* Calls parent::__construct with specific arguments
*/
public function __construct() {
parent::__construct('backup_sche_weekdays', get_string('schedule'), get_string('backupschedulehelp'), array(), NULL);
parent::__construct('backup_auto_weekdays', get_string('automatedbackupschedule','backup'), get_string('automatedbackupschedulehelp','backup'), array(), NULL);
$this->plugin = 'backup';
}
/**
......
......@@ -333,28 +333,10 @@ function cron_run() {
} // End of occasional clean-up tasks
// Disabled until implemented. MDL-21432, MDL-22184
if (1 == 2 && empty($CFG->disablescheduledbackups)) { // Defined in config.php
//Execute backup's cron
//Perhaps a long time and memory could help in large sites
@set_time_limit(0);
raise_memory_limit(MEMORY_EXTRA);
if (file_exists("$CFG->dirroot/backup/backup_scheduled.php") and
file_exists("$CFG->dirroot/backup/backuplib.php") and
file_exists("$CFG->dirroot/backup/lib.php") and
file_exists("$CFG->libdir/blocklib.php")) {
include_once("$CFG->dirroot/backup/backup_scheduled.php");
include_once("$CFG->dirroot/backup/backuplib.php");
include_once("$CFG->dirroot/backup/lib.php");
mtrace("Running backups if required...");
if (! schedule_backup_cron()) {
mtrace("ERROR: Something went wrong while performing backup tasks!!!");
} else {
mtrace("Backup tasks finished.");
}
}
}
// Run automated backups if required.
require_once($CFG->dirroot.'/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
backup_cron_automated_helper::run_automated_backup();
/// Run the auth cron, if any
/// before enrolments because it might add users that will be needed in enrol plugins
......
......@@ -257,6 +257,14 @@ $capabilities = array(
'clonepermissionsfrom' => 'moodle/restore:restorecourse'
),
'moodle/restore:viewautomatedfilearea' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
),
'moodle/restore:restoretargethub' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
......
......@@ -41,4 +41,8 @@ $messageproviders = array (
'instantmessage' => array (
),
'backup' => array (
'capability' => 'moodle/site:config'
)
);
......@@ -5414,6 +5414,12 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint(true, 2010110800);
}
if ($oldversion < 2010111000) {
// Clean up the old scheduled backup settings that are no longer relevant
update_fix_automated_backup_config();
upgrade_main_savepoint(true, 2010111000);
}
return true;
}
......
......@@ -598,3 +598,48 @@ function upgrade_cleanup_unwanted_block_contexts($contextidarray) {
$DB->delete_records_select('role_names', 'contextid IN ('.$blockcontextidsstring.')');
$DB->delete_records_select('context', 'id IN ('.$blockcontextidsstring.')');
}
/**
* This function is used to establish the automated backup settings using the
* original scheduled backup settings.
*
* @since 2010111000
*/
function update_fix_automated_backup_config() {
$mappings = array(
// Old setting => new setting
'backup_sche_active' => 'backup_auto_active',
'backup_sche_hour' => 'backup_auto_hour',
'backup_sche_minute' => 'backup_auto_minute',
'backup_sche_destination' => 'backup_auto_destination',
'backup_sche_keep' => 'backup_auto_keep',
'backup_sche_userfiles' => 'backup_auto_user_files',
'backup_sche_modules' => 'backup_auto_activities',
'backup_sche_logs' => 'backup_auto_logs',
'backup_sche_messages' => 'backup_auto_messages',
'backup_sche_blocks' => 'backup_auto_blocks',
'backup_sche_weekdays' => 'backup_auto_weekdays',
'backup_sche_users' => 'backup_auto_users',
'backup_sche_blogs' => 'backup_auto_blogs',
'backup_sche_coursefiles' => null,
'backup_sche_sitefiles' => null,
'backup_sche_withuserdata' => null,
'backup_sche_metacourse' => null,
'backup_sche_running' => null,
);
$oldconfig = get_config('backup');
foreach ($mappings as $oldsetting=>$newsetting) {
if (!isset($oldconfig->$oldsetting)) {
continue;
}
if ($newsetting !== null) {
$oldvalue = $oldconfig->$oldsetting;
set_config($newsetting, $oldvalue, 'backup');
}
unset_config($oldsetting, 'backup');
}
unset_config('backup_sche_gradebook_history');
unset_config('disablescheduleddbackups');
}
\ No newline at end of file
......@@ -189,6 +189,44 @@ class file_info_context_course extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('coursebackup', 'repository'), false, $downloadable, $uploadable, false);
}
/**
* Gets a stored file for the automated backup filearea directory
*
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info_context_course
*/
protected function get_area_backup_automated($itemid, $filepath, $filename) {
global $CFG;
if (!has_capability('moodle/restore:viewautomatedfilearea', $this->context)) {
return null;
}
if (is_null($itemid)) {
return $this;
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'automated', 0, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'backup', 'automated', 0);
} else {
// not found
return null;
}
}
$downloadable = has_capability('moodle/site:config', $this->context);
$uploadable = false;
$urlbase = $CFG->wwwroot.'/pluginfile.php';
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('automatedbackup', 'repository'), true, $downloadable, $uploadable, false);
}
protected function get_area_backup_section($itemid, $filepath, $filename) {
global $CFG, $DB;
......@@ -264,6 +302,9 @@ class file_info_context_course extends file_info {
if ($child = $this->get_area_backup_course(0, '/', '.')) {
$children[] = $child;
}
if ($child = $this->get_area_backup_automated(0, '/', '.')) {
$children[] = $child;
}
if ($child = $this->get_area_course_legacy(0, '/', '.')) {
$children[] = $child;
}
......
......@@ -633,6 +633,21 @@ if ($component === 'blog') {
session_get_instance()->write_close();
send_stored_file($file, 60*60, 0, $forcedownload);
} else if ($filearea === 'automated' and $context->contextlevel == CONTEXT_COURSE) {
// Backup files that were generated by the automated backup systems.
require_login($course);
require_capability('moodle/site:config', $context);
$filename = array_pop($args);
$filepath = $args ? '/'.implode('/', $args).'/' : '/';
if (!$file = $fs->get_file($context->id, 'backup', 'automated', 0, $filepath, $filename) or $file->is_directory()) {
send_file_not_found();
}
session_get_instance()->write_close(); // unlock session during fileserving
send_stored_file($file, 0, 0, $forcedownload);
} else {
send_file_not_found();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment