mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Further integration of backup into main Moodle.
The database checks/upgrades are now done on the main admin page like the other modules. The database files are now standard format .sql and .php files PostgreSQL support was added - BUT HAS NOT BEEN TESTED YET!!
This commit is contained in:
parent
2e3e1ac76b
commit
10dcde409b
@ -209,6 +209,12 @@
|
||||
}
|
||||
|
||||
|
||||
/// Upgrade backup/restore system if necessary
|
||||
|
||||
require_once("$CFG->dirroot/backup/lib.php");
|
||||
upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
|
||||
/// Find and check all modules and load them up or upgrade them if necessary
|
||||
|
||||
if (!$mods = get_list_of_plugins("mod") ) {
|
||||
|
@ -14,8 +14,6 @@
|
||||
//Units used
|
||||
require_once ("$moodle_home/config.php");
|
||||
require_once ("$moodle_home/version.php");
|
||||
require_once ("version.php");
|
||||
require_once ("db/backup_$CFG->dbtype.php");
|
||||
require_once ("lib.php");
|
||||
require_once ("backuplib.php");
|
||||
|
||||
@ -39,7 +37,7 @@
|
||||
backup_required_functions();
|
||||
|
||||
//Check backup_version
|
||||
upgrade_backup_db($backup_version,$backup_release,"backup.php");
|
||||
upgrade_backup_db("backup.php");
|
||||
|
||||
//Get strings
|
||||
$strcoursebackup = get_string("coursebackup");
|
||||
|
27
backup/db/mysql.sql
Normal file
27
backup/db/mysql.sql
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# Table structure for table `prefix_backup_files`
|
||||
#
|
||||
|
||||
CREATE TABLE `prefix_backup_files` (
|
||||
`backup_code` int(10) unsigned NOT NULL default '0',
|
||||
`file_type` varchar(10) NOT NULL default '',
|
||||
`path` varchar(255) NOT NULL default '',
|
||||
`old_id` int(10) unsigned default NULL,
|
||||
`new_id` int(10) unsigned default NULL,
|
||||
PRIMARY KEY (`backup_code`,`file_type`,`path`)
|
||||
) TYPE=MyISAM COMMENT='To store and recode ids to user and course files.';
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table `prefix_backup_ids`
|
||||
#
|
||||
|
||||
CREATE TABLE `prefix_backup_ids` (
|
||||
`backup_code` int(12) unsigned NOT NULL default '0',
|
||||
`table_name` varchar(30) NOT NULL default '',
|
||||
`old_id` int(10) unsigned NOT NULL default '0',
|
||||
`new_id` int(10) unsigned default NULL,
|
||||
`info` mediumtext,
|
||||
PRIMARY KEY (`backup_code`,`table_name`,`old_id`)
|
||||
) TYPE=MyISAM COMMENT='To store and convert ids in backup/restore';
|
||||
|
34
backup/db/postgres7.php
Normal file
34
backup/db/postgres7.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?PHP //$Id$
|
||||
//
|
||||
// This file keeps track of upgrades to Moodle's
|
||||
// backup/restore utility.
|
||||
//
|
||||
// Sometimes, changes between versions involve
|
||||
// alterations to database structures and other
|
||||
// major things that may break installations.
|
||||
//
|
||||
// The upgrade function in this file will attempt
|
||||
// to perform all the necessary actions to upgrade
|
||||
// your older installtion to the current version.
|
||||
//
|
||||
// If there's something it cannot do itself, it
|
||||
// will tell you what you need to do.
|
||||
//
|
||||
// Versions are defined by backup_version.php
|
||||
//
|
||||
|
||||
function backup_upgrade($oldversion=0) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$result = true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
?>
|
34
backup/db/postgres7.sql
Normal file
34
backup/db/postgres7.sql
Normal file
@ -0,0 +1,34 @@
|
||||
# THIS FILE IS UNTESTED!!!
|
||||
# PLEASE HELP TEST/FIX IT AND CONTACT MARTIN OR ELOY!
|
||||
|
||||
#
|
||||
# Table structure for table prefix_backup_files
|
||||
#
|
||||
|
||||
CREATE TABLE prefix_backup_files (
|
||||
prefix_backup_codetypepath_idx PRIMARY KEY,
|
||||
backup_code integer NOT NULL default '0',
|
||||
file_type varchar(10) NOT NULL default '',
|
||||
path varchar(255) NOT NULL default '',
|
||||
old_id integer default NULL,
|
||||
new_id integer default NULL,
|
||||
) TYPE=MyISAM COMMENT='To store and recode ids to user and course files.';
|
||||
# --------------------------------------------------------
|
||||
|
||||
CREATE INDEX prefix_backup_codetypepath_idx ON prefix_backup_files (backup_code,file_type,path)
|
||||
|
||||
#
|
||||
# Table structure for table prefix_backup_ids
|
||||
#
|
||||
|
||||
CREATE TABLE prefix_backup_ids (
|
||||
prefix_backup_codenameid_idx PRIMARY KEY,
|
||||
backup_code int(12) unsigned NOT NULL default '0',
|
||||
table_name varchar(30) NOT NULL default '',
|
||||
old_id int(10) unsigned NOT NULL default '0',
|
||||
new_id int(10) unsigned default NULL,
|
||||
info mediumtext,
|
||||
) TYPE=MyISAM COMMENT='To store and convert ids in backup/restore';
|
||||
|
||||
CREATE INDEX prefix_backup_codenameid_idx ON prefix_backup_ids (backup_code,table_name,old_id)
|
||||
|
@ -287,53 +287,63 @@
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
//This function upgrades, if necesary, the backup-restore tables
|
||||
//It's called from backup.php and restore.php
|
||||
function upgrade_backup_db($updgradeto,$backup_release,$continueto) {
|
||||
|
||||
global $CFG,$db;
|
||||
|
||||
//Check backup_version
|
||||
if ($CFG->backup_version) {
|
||||
if ($updgradeto > $CFG->backup_version) { // upgrade
|
||||
$a->oldversion = $CFG->backup_version;
|
||||
$a->newversion = $updgradeto;
|
||||
$strdatabasechecking = get_string("databasechecking", "", $a);
|
||||
$strdatabasesuccess = get_string("databasesuccess");
|
||||
print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking);
|
||||
print_heading($strdatabasechecking);
|
||||
$db->debug=true;
|
||||
if (backup_upgrade($a->oldversion)) {
|
||||
$db->debug=false;
|
||||
if (set_config("backup_version", $a->newversion)) {
|
||||
notify($strdatabasesuccess, "green");
|
||||
notify("You are running Backup/Recovery version ".$backup_release,"black");
|
||||
print_continue($continueto);
|
||||
die;
|
||||
} else {
|
||||
notify("Upgrade failed! (Could not update version in config table)");
|
||||
die;
|
||||
}
|
||||
} else {
|
||||
$db->debug=false;
|
||||
notify("Upgrade failed! See version.php");
|
||||
die;
|
||||
}
|
||||
} else if ($updgradeto < $CFG->backup_version) {
|
||||
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
|
||||
}
|
||||
//Not exists. Starting installation
|
||||
} else {
|
||||
function upgrade_backup_db($continueto) {
|
||||
/// This function upgrades the backup tables, if necessary
|
||||
/// It's called from admin/index.php, also backup.php and restore.php
|
||||
|
||||
global $CFG, $db;
|
||||
|
||||
require_once ("$CFG->dirroot/backup/version.php"); // Get code versions
|
||||
|
||||
if (empty($CFG->backup_version)) { // Backup has never been installed.
|
||||
$strdatabaseupgrades = get_string("databaseupgrades");
|
||||
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
|
||||
|
||||
if (set_config("backup_version", "2003010100")) {
|
||||
print_heading("You are currently going to install the needed structures to Backup/Recover");
|
||||
print_continue($continueto);
|
||||
die;
|
||||
|
||||
$db->debug=true;
|
||||
if (modify_database("$CFG->dirroot/backup/db/$CFG->dbtype.sql")) {
|
||||
$db->debug = false;
|
||||
if (set_config("backup_version", $backup_version)) {
|
||||
notify(get_string("databasesuccess"), "green");
|
||||
notify(get_string("databaseupgradebackups", "", $backup_release));
|
||||
print_continue($continueto);
|
||||
exit;
|
||||
} else {
|
||||
error("Upgrade of backup system failed! (Could not update version in config table)");
|
||||
}
|
||||
} else {
|
||||
error("Backup tables could NOT be set up successfully!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($backup_version > $CFG->backup_version) { // Upgrade tables
|
||||
$strdatabaseupgrades = get_string("databaseupgrades");
|
||||
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
|
||||
|
||||
require_once ("$CFG->dirroot/backup/db/$CFG->dbtype.php");
|
||||
|
||||
$db->debug=true;
|
||||
if (backup_upgrade($CFG->backup_version)) {
|
||||
$db->debug=false;
|
||||
if (set_config("backup_version", $backup_version)) {
|
||||
notify(get_string("databasesuccess"), "green");
|
||||
notify(get_string("databaseupgradebackups", "", $backup_release));
|
||||
print_continue($continueto);
|
||||
exit;
|
||||
} else {
|
||||
error("Upgrade of backup system failed! (Could not update version in config table)");
|
||||
}
|
||||
} else {
|
||||
$db->debug=false;
|
||||
error("Upgrade failed! See backup/version.php");
|
||||
}
|
||||
|
||||
} else if ($backup_version < $CFG->backup_version) {
|
||||
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//This function is used to insert records in the backup_ids table
|
||||
//If the info field is greater than max_db_storage, then its info
|
||||
|
@ -3,21 +3,14 @@
|
||||
|
||||
//Define some globals for all the script
|
||||
|
||||
//MUST CHANGE WITH FINAL BACKUP LOCATION !! WITHOUT TRAILING SLASH !!
|
||||
//ALL RELATIVE FROM THE LOCATION OF THE restore.php SCRIPT !!!
|
||||
|
||||
$moodle_home = "..";
|
||||
$mods_home = "../mod";
|
||||
|
||||
//END MUST CHANGE
|
||||
|
||||
//Units used
|
||||
require_once ("$moodle_home/config.php");
|
||||
require_once ("$moodle_home/version.php");
|
||||
require_once ("$moodle_home/lib/xmlize.php");
|
||||
require_once ("$moodle_home/course/lib.php");
|
||||
require_once ("version.php");
|
||||
require_once ("db/backup_$CFG->dbtype.php");
|
||||
require_once ("lib.php");
|
||||
require_once ("restorelib.php");
|
||||
|
||||
@ -46,7 +39,8 @@
|
||||
} else {
|
||||
$linkto = "restore.php";
|
||||
}
|
||||
upgrade_backup_db($backup_version,$backup_release,$linkto);
|
||||
|
||||
upgrade_backup_db($linkto);
|
||||
|
||||
//Get strings
|
||||
$strcourserestore = get_string("courserestore");
|
||||
|
Loading…
x
Reference in New Issue
Block a user