]> git.mjollnir.org Git - moodle.git/commitdiff
Backup finished.
authorstronk7 <stronk7>
Sun, 11 May 2003 17:45:56 +0000 (17:45 +0000)
committerstronk7 <stronk7>
Sun, 11 May 2003 17:45:56 +0000 (17:45 +0000)
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
backup/backup_execute.html
backup/lib.php

index 47fbe47586a98966f53ae5257d473d7dccaf9ef5..6483e54d15bb5d95ef8f6b8254707f642a797a4b 100644 (file)
@@ -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:
index d0305b17ab728c4e86d20bd52f7b0da160325334..46b55ae15cd27a753b333546687a719204bf830d 100644 (file)
     if ($status) {
         echo "<li>Zipping backup";
         $status = backup_zip ($preferences,$moodle_home);
+    }
 
+    //Now, copy the zip file to course directory
+    if ($status) {
+        echo "<li>Copying zip file";
+        $status = copy_zip_to_course_dir ($preferences);
+    }
+
+    //Now, clean temporary data (db and filesystem)
+    if ($status) {
+        echo "<li>Cleaning up temp data";
+        $status = clean_temp_data ($preferences); 
     }
 
     if (!$status) {
 
     //End the main table
     echo "</table>";
+
+    //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"));    
+
 ?>
index 5ca57c02572c33899be53ad34d2a1f774ce90415..860472ef551bd426f067d34c2b357da9ac1311a8 100644 (file)
             $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
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-        
-
-
 ?>