From 4784696533ca219ab8ed9e29a1fe0cdd58b9ad1c Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 11 May 2003 17:45:56 +0000 Subject: [PATCH] Backup finished. Limitations: - Only assignment and resource mods are exported. Little problems persit: - PCLZIP/UNZIP incompatibility - Do not count backup files in course_files_check_backup --- backup/STATUS.txt | 28 ++++++------ backup/backup_execute.html | 16 +++++++ backup/lib.php | 91 ++++++++++++++++++++++++++++++-------- 3 files changed, 102 insertions(+), 33 deletions(-) diff --git a/backup/STATUS.txt b/backup/STATUS.txt index 47fbe47586..6483e54d15 100644 --- a/backup/STATUS.txt +++ b/backup/STATUS.txt @@ -3,8 +3,7 @@ STATUS $Id$ 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. @@ -87,19 +86,18 @@ Backup Details: + 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: diff --git a/backup/backup_execute.html b/backup/backup_execute.html index d0305b17ab..46b55ae15c 100644 --- a/backup/backup_execute.html +++ b/backup/backup_execute.html @@ -230,7 +230,18 @@ if ($status) { echo "
  • Zipping backup"; $status = backup_zip ($preferences,$moodle_home); + } + //Now, copy the zip file to course directory + if ($status) { + echo "
  • Copying zip file"; + $status = copy_zip_to_course_dir ($preferences); + } + + //Now, clean temporary data (db and filesystem) + if ($status) { + echo "
  • Cleaning up temp data"; + $status = clean_temp_data ($preferences); } if (!$status) { @@ -245,4 +256,9 @@ //End the main table echo ""; + + //Print final message + print_simple_box(get_string("backupfinished"),"CENTER"); + print_continue($moodle_home."/files/index.php?id=".$preferences->backup_course."&wdir=/".get_string("backupdir")); + ?> diff --git a/backup/lib.php b/backup/lib.php index 5ca57c0257..860472ef55 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -176,7 +176,7 @@ $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); @@ -933,17 +933,20 @@ //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); } @@ -998,7 +1001,7 @@ //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); @@ -1006,10 +1009,10 @@ 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; } @@ -1018,13 +1021,18 @@ if (($list = $archive->create($files,PCLZIP_OPT_REMOVE_PATH,$basedir)) == 0) { error($archive->errorInfo(true)); $status = false; - } - $list = $archive->listContent(); - for ($i=0; $i"; - } + } + //Debug zip contents + //true->do it, false->don't do it. To debug if necessary. + if (false) { echo "
    "; + $list = $archive->listContent(); + for ($i=0; $i"; + } + echo "
    "; + } } } else { // Use external zip program $files = ""; @@ -1040,6 +1048,57 @@ } + //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) @@ -1079,8 +1138,4 @@ ///Ends copy file/dirs functions // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - - - ?> -- 2.39.5