3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Automated backups CLI cron
21 * This script executes
25 * @copyright 2010 Sam Hemelryk
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 define('CLI_SCRIPT', true);
31 require(__DIR__
.'/../../config.php');
32 require_once($CFG->libdir
.'/clilib.php'); // cli only functions
33 require_once($CFG->libdir
.'/cronlib.php');
35 // now get cli options
36 list($options, $unrecognized) = cli_get_params(array('help'=>false),
40 $unrecognized = implode("\n ", $unrecognized);
41 cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
44 if ($options['help']) {
46 "Execute automated backups.
48 This script executes automated backups completely and is designed to be
52 -h, --help Print out this help
55 \$sudo -u www-data /usr/bin/php admin/cli/automated_backups.php
61 if (CLI_MAINTENANCE
) {
62 echo "CLI maintenance mode active, backup execution suspended.\n";
66 if (moodle_needs_upgrading()) {
67 echo "Moodle upgrade pending, backup execution suspended.\n";
71 require_once($CFG->libdir
.'/adminlib.php');
72 require_once($CFG->libdir
.'/gradelib.php');
74 if (!empty($CFG->showcronsql
)) {
77 if (!empty($CFG->showcrondebugging
)) {
78 set_debugging(DEBUG_DEVELOPER
, true);
81 $starttime = microtime();
83 /// emulate normal session
89 mtrace("Server Time: ".date('r',$timenow)."\n\n");
91 // Run automated backups if required.
92 require_once($CFG->dirroot
.'/backup/util/includes/backup_includes.php');
93 require_once($CFG->dirroot
.'/backup/util/helper/backup_cron_helper.class.php');
94 backup_cron_automated_helper
::run_automated_backup(backup_cron_automated_helper
::RUN_IMMEDIATELY
);
96 mtrace("Automated cron backups completed correctly");
98 $difftime = microtime_diff($starttime, microtime());
99 mtrace("Execution took ".$difftime." seconds");