Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/cli/automated_backups.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00029 define('CLI_SCRIPT', true);
00030 
00031 require(dirname(dirname(dirname(__FILE__))).'/config.php');
00032 require_once($CFG->libdir.'/clilib.php');      // cli only functions
00033 require_once($CFG->libdir.'/cronlib.php');
00034 
00035 // now get cli options
00036 list($options, $unrecognized) = cli_get_params(array('help'=>false),
00037                                                array('h'=>'help'));
00038 
00039 if ($unrecognized) {
00040     $unrecognized = implode("\n  ", $unrecognized);
00041     cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
00042 }
00043 
00044 if ($options['help']) {
00045     $help =
00046 "Execute automated backups.
00047 
00048 This script executes automated backups completely and is designed to be
00049 called via cron.
00050 
00051 Options:
00052 -h, --help            Print out this help
00053 
00054 Example:
00055 \$sudo -u www-data /usr/bin/php admin/cli/automated_backups.php
00056 ";
00057 
00058     echo $help;
00059     die;
00060 }
00061 if (CLI_MAINTENANCE) {
00062     echo "CLI maintenance mode active, backup execution suspended.\n";
00063     exit(1);
00064 }
00065 
00066 if (moodle_needs_upgrading()) {
00067     echo "Moodle upgrade pending, backup execution suspended.\n";
00068     exit(1);
00069 }
00070 
00071 require_once($CFG->libdir.'/adminlib.php');
00072 require_once($CFG->libdir.'/gradelib.php');
00073 
00074 if (!empty($CFG->showcronsql)) {
00075     $DB->set_debug(true);
00076 }
00077 if (!empty($CFG->showcrondebugging)) {
00078     $CFG->debug = DEBUG_DEVELOPER;
00079     $CFG->debugdisplay = true;
00080 }
00081 
00082 $starttime = microtime();
00083 
00085 cron_setup_user();
00086 
00088 $timenow = time();
00089 
00090 mtrace("Server Time: ".date('r',$timenow)."\n\n");
00091 
00092 // Run automated backups if required.
00093 require_once($CFG->dirroot.'/backup/util/includes/backup_includes.php');
00094 require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
00095 backup_cron_automated_helper::run_automated_backup(backup_cron_automated_helper::RUN_IMMEDIATELY);
00096 
00097 mtrace("Automated cron backups completed correctly");
00098 
00099 $difftime = microtime_diff($starttime, microtime());
00100 mtrace("Execution took ".$difftime." seconds");
 All Data Structures Namespaces Files Functions Variables Enumerations