This documment shows the current status of the backup/restore option.
-Backup: WORKING. Only xml generation into temp dir. Header, info,
- course data, sections, user data and logs.
+Backup: WORKING. COMPLETED but only assignments and resources.
Restore: NOT WORKING. No comments.
+ files........................................NO EXISTS
x user files to temp..............................DONE
x course files to temp............................DONE
- - Compress the backup (zip)..................................IN PROGRESS
- - XML File................................................IN PROGRESS
- - moddata files...........................................IN PROGRESS
- - Course Files............................................IN PROGRESS
- - User Files..............................................IN PROGRESS
- - Copy finished file to browseable dir.......................NO EXISTS
- - Delete old entries at backup end...........................NO EXISTS
- - From database...........................................NO EXISTS
- - From filesystem.........................................NO EXISTS
- - Browse backup files........................................DONE. TO FILE MANAGER
- - Obtain info about backup files.............................NO EXISTS
- - Download backup files......................................DONE. TO FILE MANAGER
- - Delete backup files........................................DONE. TO FILE MANAGER
+ - Compress the backup (zip)..................................DONE. PROBLEMS PCLZIP/UNZIP
+ - XML File................................................DONE. PROBLEMS PCLZIP/UNZIP
+ - moddata files...........................................DONE. PROBLEMS PCLZIP/UNZIP
+ - Course Files............................................DONE. PROBLEMS PCLZIP/UNZIP
+ - User Files..............................................DONE. PROBLEMS PCLZIP/UNZIP
+ - Copy finished file to browseable dir.......................DONE
+ - Delete old entries at backup end...........................DONE
+ - From database...........................................DONE
+ - From filesystem.........................................DONE
+ - Browse backup files........................................DONE
+ - Download backup files......................................DONE
+ - Delete backup files........................................DONE
- Program automatic backups..................................NO EXISTS
Restore Details:
$coursedirs = get_directory_list($rootdir,$CFG->moddata);
foreach ($coursedirs as $dir) {
//Insert them into backup_files
- $status = execute_sql("INSERT INTO {$CFG->prefix}backup_files
+ $status = execute_sql("INSERT INTO {$CFG->prefix}backup_files
(backup_code, file_type, path)
VALUES
('$backup_unique_code','course','$dir')",false);
//in temp/backup/$backup_code dir
$status = check_and_create_course_files_dir($preferences->backup_unique_code);
- //Now iterate over files and directories except $CFG->moddata to be
+ //Now iterate over files and directories except $CFG->moddata and get_string("backupdir") to be
//copied to backup
$rootdir = $CFG->dataroot."/".$preferences->backup_course;
+
+ $name_moddata = $CFG->moddata;
+ $name_backupdata = get_string("backupdir");
//Check if directory exists
if (is_dir($rootdir)) {
$list = list_directories_and_files ($rootdir);
if ($list) {
//Iterate
foreach ($list as $dir) {
- if ($dir !== $CFG->moddata) {
+ if ($dir !== $name_moddata and $dir !== $name_backupdata) {
$status = backup_copy_file($rootdir."/".$dir,
$CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/course_files/".$dir);
}
//Base dir where everything happens
$basedir = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code;
- //Backup xip file name
+ //Backup zip file name
$name = $preferences->backup_name;
//List base_dir files and directories
$filelist = list_directories_and_files ($basedir);
if (empty($CFG->zip)) { // Use built-in php-based zip function
$files = array();
foreach ($filelist as $file) {
-// //If directory, append "/"
-// if (is_dir($basedir."/".$file)) {
-// $file = $file."/";
-// }
+ //If directory, append "/"
+ if (is_dir($basedir."/".$file)) {
+ $file = $file."/";
+ }
//Include into array
$files[] = $basedir."/".$file;
}
if (($list = $archive->create($files,PCLZIP_OPT_REMOVE_PATH,$basedir)) == 0) {
error($archive->errorInfo(true));
$status = false;
- }
- $list = $archive->listContent();
- for ($i=0; $i<sizeof($list); $i++) {
- for(reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
- echo "File $i / [$key] = ".$list[$i][$key]."<br>";
- }
+ }
+ //Debug zip contents
+ //true->do it, false->don't do it. To debug if necessary.
+ if (false) {
echo "<br>";
+ $list = $archive->listContent();
+ for ($i=0; $i<sizeof($list); $i++) {
+ for(reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
+ echo "File $i / [$key] = ".$list[$i][$key]."<br>";
+ }
+ echo "<br>";
+ }
}
} else { // Use external zip program
$files = "";
}
+ //This function copies the final zip to the course dir
+ function copy_zip_to_course_dir ($preferences) {
+
+ global $CFG;
+
+ //Backup zip file name
+ $from_zip_file = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/".$preferences->backup_name;
+ $to_zip_file = $CFG->dataroot."/".$preferences->backup_course."/".get_string("backupdir")."/".$preferences->backup_name;
+
+ //Check to directory
+ $status = check_dir_exists(dirname($to_zip_file),true);
+
+ //Copy zip file
+ if ($status) {
+ $status = backup_copy_file ($from_zip_file,$to_zip_file);
+ }
+
+ return $status;
+ }
+
+ //This function clean data from backup tables and
+ //delete all temp files used
+ function clean_temp_data ($preferences) {
+
+
+ global $CFG;
+
+ $status = true;
+
+ //true->do it, false->don't do it. To debug if necessary.
+ if (true) {
+ //Now delete from tables
+ $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids
+ WHERE backup_code < '$preferences->backup_unique_code'",false);
+ if ($status) {
+ $status = execute_sql("DELETE FROM {$CFG->prefix}backup_files
+ WHERE backup_code < '$preferences->backup_unique_code'",false);
+ }
+ //Now, delete temp directory (if exists)
+ $file_path = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code;
+ if (is_dir($file_path)) {
+ $status = delete_dir_contents($file_path);
+ //There is nothing, delete the directory itself
+ if ($status) {
+ $status = rmdir($file_path);
+ }
+ }
+ }
+ return $status;
+ }
+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//This functions are used to copy any file or directory ($from_file)
///Ends copy file/dirs functions
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-
-
-
?>