source: moodle/trunk/fuentes/admin/cli/automated_backups.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 2.7 KB
Line 
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
19 * Automated backups CLI cron
20 *
21 * This script executes
22 *
23 * @package    core
24 * @subpackage cli
25 * @copyright  2010 Sam Hemelryk
26 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28
29define('CLI_SCRIPT', true);
30
31require(dirname(dirname(dirname(__FILE__))).'/config.php');
32require_once($CFG->libdir.'/clilib.php');      // cli only functions
33require_once($CFG->libdir.'/cronlib.php');
34
35// now get cli options
36list($options, $unrecognized) = cli_get_params(array('help'=>false),
37                                               array('h'=>'help'));
38
39if ($unrecognized) {
40    $unrecognized = implode("\n  ", $unrecognized);
41    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
42}
43
44if ($options['help']) {
45    $help =
46"Execute automated backups.
47
48This script executes automated backups completely and is designed to be
49called via cron.
50
51Options:
52-h, --help            Print out this help
53
54Example:
55\$sudo -u www-data /usr/bin/php admin/cli/automated_backups.php
56";
57
58    echo $help;
59    die;
60}
61if (CLI_MAINTENANCE) {
62    echo "CLI maintenance mode active, backup execution suspended.\n";
63    exit(1);
64}
65
66if (moodle_needs_upgrading()) {
67    echo "Moodle upgrade pending, backup execution suspended.\n";
68    exit(1);
69}
70
71require_once($CFG->libdir.'/adminlib.php');
72require_once($CFG->libdir.'/gradelib.php');
73
74if (!empty($CFG->showcronsql)) {
75    $DB->set_debug(true);
76}
77if (!empty($CFG->showcrondebugging)) {
78    set_debugging(DEBUG_DEVELOPER, true);
79}
80
81$starttime = microtime();
82
83/// emulate normal session
84cron_setup_user();
85
86/// Start output log
87$timenow = time();
88
89mtrace("Server Time: ".date('r',$timenow)."\n\n");
90
91// Run automated backups if required.
92require_once($CFG->dirroot.'/backup/util/includes/backup_includes.php');
93require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
94backup_cron_automated_helper::run_automated_backup(backup_cron_automated_helper::RUN_IMMEDIATELY);
95
96mtrace("Automated cron backups completed correctly");
97
98$difftime = microtime_diff($starttime, microtime());
99mtrace("Execution took ".$difftime." seconds");
Note: See TracBrowser for help on using the repository browser.