Example #1
0
function schedule_inc_backup_course_configure($course, $starttime = 0)
{
    global $CFG;
    $status = true;
    backup_add_to_log($starttime, $course->id, "    checking parameters", 'incrementalbackup');
    //Check the required variable
    if (empty($course->id)) {
        $status = false;
    }
    //Get scheduled backup preferences
    $incremental_config = backup_get_config();
    //Checks backup_config pairs exist
    if ($status) {
        if (!isset($incremental_config->backup_inc_modules)) {
            $incremental_config->backup_inc_modules = 1;
        }
        if (!isset($incremental_config->backup_inc_withuserdata)) {
            $incremental_config->backup_inc_withuserdata = 1;
        }
        if (!isset($incremental_config->backup_inc_metacourse)) {
            $incremental_config->backup_inc_metacourse = 1;
        }
        if (!isset($incremental_config->backup_inc_users)) {
            $incremental_config->backup_inc_users = 1;
        }
        if (!isset($incremental_config->backup_inc_logs)) {
            $incremental_config->backup_inc_logs = 0;
        }
        if (!isset($incremental_config->backup_inc_userfiles)) {
            $incremental_config->backup_inc_userfiles = 1;
        }
        if (!isset($incremental_config->backup_inc_coursefiles)) {
            $incremental_config->backup_inc_coursefiles = 1;
        }
        if (!isset($incremental_config->backup_inc_sitefiles)) {
            $incremental_config->backup_inc_sitefiles = 1;
        }
        if (!isset($incremental_config->backup_inc_messages)) {
            $incremental_config->backup_inc_messages = 0;
        }
        if (!isset($incremental_config->backup_inc_weekdays)) {
            $incremental_config->backup_inc_weekdays = "0000000";
        }
        if (!isset($incremental_config->backup_inc_hour)) {
            $incremental_config->backup_inc_hour = 00;
        }
        if (!isset($incremental_config->backup_inc_minute)) {
            $incremental_config->backup_inc_minute = 00;
        }
        if (!isset($incremental_config->backup_inc_destination)) {
            $incremental_config->backup_inc_destination = "";
        }
        if (!isset($incremental_config->backup_inc_keep)) {
            $incremental_config->backup_inc_keep = 1;
        }
        if (!isset($incremental_config->backup_sche_incrementals)) {
            $incremental_config->backup_sche_incrementals = 0;
        }
        if (!isset($incremental_config->backup_inc_privatedata)) {
            $incremental_config->backup_inc_privatedata = 0;
        }
    }
    if ($status) {
        //Checks for the required files/functions to backup every mod
        //And check if there is data about it
        //use the configured modules to backup.
        $count = 0;
        if (!empty($incremental_config->backup_inc_modules)) {
            $moduleselect = 'id=' . str_replace(',', ' OR id=', $incremental_config->backup_inc_modules);
            if ($allmods = get_records_select("modules", $moduleselect)) {
                foreach ($allmods as $mod) {
                    $modname = $mod->name;
                    $modfile = "{$CFG->dirroot}/mod/{$modname}/backuplib.php";
                    $modbackup = $modname . "_backup_mods";
                    $modcheckbackup = $modname . "_check_backup_mods";
                    if (file_exists($modfile)) {
                        include_once $modfile;
                        if (function_exists($modbackup) and function_exists($modcheckbackup)) {
                            $var = "exists_" . $modname;
                            ${$var} = true;
                            $count++;
                            // PENNY NOTES: I have moved from here to the closing brace inside
                            // by two sets of ifs()
                            // to avoid the backup failing on a non existant backup.
                            // If the file/function/whatever doesn't exist, we don't want to set this
                            // this module in backup preferences at all.
                            //Check data
                            //Check module info
                            $var = "backup_" . $modname;
                            if (!isset(${$var})) {
                                ${$var} = $incremental_config->backup_inc_modules;
                            }
                            //Now stores all the mods preferences into an array into preferences
                            $preferences->mods[$modname]->backup = ${$var};
                            //Check include user info
                            $var = "backup_user_info_" . $modname;
                            if (!isset(${$var})) {
                                ${$var} = $incremental_config->backup_inc_withuserdata;
                            }
                            //Now stores all the mods preferences into an array into preferences
                            $preferences->mods[$modname]->userinfo = ${$var};
                            //And the name of the mod
                            $preferences->mods[$modname]->name = $modname;
                        }
                    }
                }
            }
        }
        // now set instances
        if ($coursemods = get_course_mods($course->id)) {
            foreach ($coursemods as $mod) {
                if (array_key_exists($mod->modname, $preferences->mods)) {
                    // we are to backup this module
                    if (empty($preferences->mods[$mod->modname]->instances)) {
                        $preferences->mods[$mod->modname]->instances = array();
                        // avoid warnings
                    }
                    $preferences->mods[$mod->modname]->instances[$mod->instance]->backup = $preferences->mods[$mod->modname]->backup;
                    $preferences->mods[$mod->modname]->instances[$mod->instance]->userinfo = $preferences->mods[$mod->modname]->userinfo;
                    // there isn't really a nice way to do this...
                    $preferences->mods[$mod->modname]->instances[$mod->instance]->name = get_field($mod->modname, 'name', 'id', $mod->instance);
                }
            }
        }
        // finally, clean all the $preferences->mods[] not having instances. Nothing to backup about them
        if (!empty($preferences->mods)) {
            foreach ($preferences->mods as $modname => $mod) {
                if (!isset($mod->instances)) {
                    unset($preferences->mods[$modname]);
                }
            }
        }
    }
    //Convert other parameters
    if ($status) {
        $preferences->backup_metacourse = $incremental_config->backup_inc_metacourse;
        $preferences->backup_users = $incremental_config->backup_inc_users;
        $preferences->backup_logs = $incremental_config->backup_inc_logs;
        $preferences->backup_user_files = $incremental_config->backup_inc_userfiles;
        $preferences->backup_course_files = $incremental_config->backup_inc_coursefiles;
        $preferences->backup_site_files = $incremental_config->backup_inc_sitefiles;
        $preferences->backup_messages = $incremental_config->backup_inc_messages;
        $preferences->backup_gradebook_history = 1;
        $preferences->backup_course = $course->id;
        $preferences->backup_private_user_data = $incremental_config->backup_inc_privatedata;
        if (!empty($incremental_config->backup_inc_destination)) {
            if (!check_dir_exists($incremental_config->backup_inc_destination . '/' . $course->id, true, true)) {
                error('failed to create backup destination directory');
            } else {
                $preferences->backup_destination = $incremental_config->backup_inc_destination . '/' . $course->id;
            }
        }
        $preferences->backup_keep = $incremental_config->backup_inc_keep;
        $preferences->backup_sche_incrementals = $incremental_config->backup_sche_incrementals;
    }
    //Calculate various backup preferences
    if ($status) {
        backup_add_to_log($starttime, $course->id, "    calculating backup name", 'incrementalbackup');
        //Calculate the backup file name
        $backup_name = backup_get_zipfile_name($course);
        //Calculate the string to match the keep preference
        $keep_name = backup_get_keep_name($course);
        //Set them
        $preferences->backup_name = $backup_name;
        $preferences->keep_name = $keep_name;
        //Roleasignments
        $roles = get_records('role', '', '', 'sortorder');
        foreach ($roles as $role) {
            $preferences->backuproleassignments[$role->id] = $role;
        }
        //Another Info
        backup_add_static_preferences($preferences);
    }
    //Calculate the backup unique code to allow simultaneus backups (to define
    //the temp-directory name and records in backup temp tables
    if ($status) {
        $backup_unique_code = time();
        $preferences->backup_unique_code = $backup_unique_code;
    }
    //Calculate necesary info to backup modules
    if ($status) {
        backup_add_to_log($starttime, $course->id, "    calculating modules data", 'incrementalbackup');
        if ($allmods = get_records("modules")) {
            foreach ($allmods as $mod) {
                $modname = $mod->name;
                $modbackup = $modname . "_backup_mods";
                //If exists the lib & function
                $var = "exists_" . $modname;
                if (isset(${$var}) && ${$var}) {
                    //Add hidden fields
                    $var = "backup_" . $modname;
                    //Only if selected
                    if (${$var} == 1) {
                        $var = "backup_user_info_" . $modname;
                        //Call the check function to show more info
                        $modcheckbackup = $modname . "_check_backup_mods";
                        backup_add_to_log($starttime, $course->id, "      {$modname}", 'incrementalbackup');
                        $modcheckbackup($course->id, ${$var}, $backup_unique_code);
                    }
                }
            }
        }
    }
    //Now calculate the users
    if ($status) {
        backup_add_to_log($starttime, $course->id, "    calculating users", 'incrementalbackup');
        //Decide about include users with messages, based on SITEID
        if ($preferences->backup_messages && $preferences->backup_course == SITEID) {
            $include_message_users = true;
        } else {
            $include_message_users = false;
        }
        //Decide about include users with blogs, based on SITEID
        if (isset($preferences->backup_blogs) && isset($preferences->backup_course) && $preferences->backup_blogs && $preferences->backup_course == SITEID) {
            $include_blog_users = true;
        } else {
            $include_blog_users = false;
        }
        user_check_backup($course->id, $backup_unique_code, $preferences->backup_users, $include_message_users, $include_blog_users);
    }
    //Now calculate the logs
    if ($status) {
        if ($preferences->backup_logs) {
            backup_add_to_log($starttime, $course->id, "    calculating logs", 'incrementalbackup');
            log_check_backup($course->id);
        }
    }
    //Now calculate the userfiles
    if ($status) {
        if ($preferences->backup_user_files) {
            backup_add_to_log($starttime, $course->id, "    calculating user files", 'incrementalbackup');
            user_files_check_backup($course->id, $preferences->backup_unique_code);
        }
    }
    //Now calculate the coursefiles
    if ($status) {
        if ($preferences->backup_course_files) {
            backup_add_to_log($starttime, $course->id, "    calculating course files", 'incrementalbackup');
            course_files_check_backup($course->id, $preferences->backup_unique_code);
        }
    }
    //Now calculate the sitefiles
    if ($status) {
        if ($preferences->backup_site_files) {
            backup_add_to_log($starttime, $course->id, "    calculating site files", 'incrementalbackup');
            site_files_check_backup($course->id, $preferences->backup_unique_code);
        }
    }
    //If everything is ok, return calculated preferences
    if ($status) {
        $status = $preferences;
    }
    return $status;
}
Example #2
0
 function config_read($name)
 {
     global $CFG;
     if ($this->plugin === 'backup') {
         require_once $CFG->dirroot . '/backup/lib.php';
         $backupconfig = backup_get_config();
         if (isset($backupconfig->{$name})) {
             return $backupconfig->{$name};
         } else {
             return NULL;
         }
     } else {
         if (!empty($this->plugin)) {
             $value = get_config($this->plugin, $name);
             return $value === false ? NULL : $value;
         } else {
             if (isset($CFG->{$name})) {
                 return $CFG->{$name};
             } else {
                 return NULL;
             }
         }
     }
 }
Example #3
0
 /**
  * Apply a diff package against a file tree
  *
  * @param string $basepath Path to apply diff to
  * @param string $diff Path to diff package
  * @return bool
  */
 function apply_diff($basepath, $diff)
 {
     global $CFG, $COURSE;
     $xdelta = new xdelta();
     $incremental_config = backup_get_config();
     //get path to xdelta
     $xdeltacmd = $incremental_config->backup_inc_pathtoxdelta;
     if (strpos($xdeltacmd, '..') !== false) {
         //this is a relative path - convert it before using it!
         $xdeltacmd = realpath($CFG->dataroot . $xdeltacmd);
     }
     $temppath = $this->get_temp_dir();
     $filespath = $temppath . '/files';
     // Unpack diff into temp directory
     if (!unzip_file($diff, $temppath, false)) {
         return $this->error('Couldn\'t unzip package');
     }
     // Restore Manifest
     if (!($serialmanifest = file_get_contents($temppath . '/Manifest'))) {
         return $this->error('Couldn\'t open manifest');
     }
     if (!($manifest = unserialize($serialmanifest))) {
         return $this->error('Couldn\'t unserializse the manifest');
     }
     if ($manifest['version'] != $this->version) {
         return $this->error('Diff package was generated with xdelta class version ' . $manifest['version']);
     }
     // Get base tree
     $this->treea = $this->get_dir_tree($basepath);
     ksort($this->treea);
     // Check src tree against diff checksum
     if ($manifest['srcchecksum'] != md5(serialize($this->treea))) {
         return $this->error('Source file tree is different to that expected in diff');
     }
     // Copy new files to base path
     if (isset($manifest['added'])) {
         foreach ($manifest['added'] as $newfile => $type) {
             if ($type === 'directory') {
                 if (!is_dir($basepath . $newfile)) {
                     mkdir($basepath . $newfile, 0700, true);
                 }
             } else {
                 copy($filespath . $newfile, $basepath . $newfile);
             }
         }
     }
     // Removed deleted files
     if (isset($manifest['deleted'])) {
         krsort($manifest['deleted']);
         foreach ($manifest['deleted'] as $deletedfile => $type) {
             fulldelete($basepath . $deletedfile);
             //delete from new backup.
             if (strpos($deletedfile, 'course_files')) {
                 //need to delete from course as well.
                 $deletedfile = str_replace('/course_files', '', $deletedfile);
                 //strip out course_files
                 if (file_exists($CFG->dataroot . '/' . $COURSE->id . $deletedfile)) {
                     unlink($CFG->dataroot . '/' . $COURSE->id . $deletedfile);
                 }
             }
         }
     }
     //clean up good ole windows paths.
     $xdeltacmd = str_replace("\\", "/", $xdeltacmd);
     if (stripos($xdeltacmd, 'xdelta3')) {
         //this is an xdelta3 command - so use this
         $command = ' -d -s ';
     } else {
         $command = ' patch ';
     }
     if (stripos($_SERVER['SERVER_SOFTWARE'], 'win')) {
         $xdeltacmd = escapeshellcmd($xdeltacmd);
         // Apply diffs against modified files
         if (isset($manifest['different'])) {
             foreach ($manifest['different'] as $different => $checksum) {
                 $filea = escapeshellcmd($filespath . $different . '.diff');
                 $fileb = escapeshellcmd($basepath . $different);
                 $filediff = escapeshellcmd($basepath . $different . '.undiff');
                 $batchcommand = '"' . $xdeltacmd . '"' . $command . '"' . $fileb . '" "' . $filea . '" "' . $filediff . '"';
                 //system() call has a bug that only allows 2 " in the command. - we need 8 in case windows dirs have spaces - so write the command out to a batch file and then call it.
                 $tmpnam = tempnam($CFG->dataroot . '/temp', "temp") . ".bat";
                 $fp = fopen($tmpnam, "w");
                 fwrite($fp, $batchcommand);
                 fclose($fp);
                 system('"' . $tmpnam . '"', $return);
                 unlink($tmpnam);
                 unlink($basepath . $different);
                 if (!file_exists($basepath . $different . '.undiff')) {
                     return $this->error('Do you have the same XDELTA version as the server?');
                 }
                 unlink($filespath . $different . '.diff');
                 rename($basepath . $different . '.undiff', $basepath . $different);
             }
         }
     } else {
         //this is a linux box so do this:
         // Apply diffs against modified files
         if (isset($manifest['different'])) {
             foreach ($manifest['different'] as $different => $checksum) {
                 system(escapeshellcmd($xdeltacmd . $command . $filespath . $different . '.diff ' . $basepath . $different . ' ' . $basepath . $different . '.undiff'), $return);
                 unlink($filespath . $different . '.diff');
                 rename($basepath . $different . '.undiff', $basepath . $different);
             }
         }
     }
     // Checksum final result
     $this->treeb = $this->get_dir_tree($basepath);
     ksort($this->treeb);
     if ($manifest['dstchecksum'] != md5(serialize($this->treeb))) {
         return $this->error('Dest file tree is different to that expected in diff');
     }
     remove_dir($temppath);
     return true;
 }
function schedule_backup_course_configure($course, $starttime = 0)
{
    global $CFG;
    $status = true;
    schedule_backup_log($starttime, $course->id, "    checking parameters");
    //Check the required variable
    if (empty($course->id)) {
        $status = false;
    }
    //Get scheduled backup preferences
    $backup_config = backup_get_config();
    //Checks backup_config pairs exist
    if ($status) {
        if (!isset($backup_config->backup_sche_modules)) {
            $backup_config->backup_sche_modules = 1;
        }
        if (!isset($backup_config->backup_sche_withuserdata)) {
            $backup_config->backup_sche_withuserdata = 1;
        }
        if (!isset($backup_config->backup_sche_metacourse)) {
            $backup_config->backup_sche_metacourse = 1;
        }
        if (!isset($backup_config->backup_sche_users)) {
            $backup_config->backup_sche_users = 1;
        }
        if (!isset($backup_config->backup_sche_logs)) {
            $backup_config->backup_sche_logs = 0;
        }
        if (!isset($backup_config->backup_sche_userfiles)) {
            $backup_config->backup_sche_userfiles = 1;
        }
        if (!isset($backup_config->backup_sche_coursefiles)) {
            $backup_config->backup_sche_coursefiles = 1;
        }
        if (!isset($backup_config->backup_sche_messages)) {
            $backup_config->backup_sche_messages = 0;
        }
        if (!isset($backup_config->backup_sche_active)) {
            $backup_config->backup_sche_active = 0;
        }
        if (!isset($backup_config->backup_sche_weekdays)) {
            $backup_config->backup_sche_weekdays = "0000000";
        }
        if (!isset($backup_config->backup_sche_hour)) {
            $backup_config->backup_sche_hour = 00;
        }
        if (!isset($backup_config->backup_sche_minute)) {
            $backup_config->backup_sche_minute = 00;
        }
        if (!isset($backup_config->backup_sche_destination)) {
            $backup_config->backup_sche_destination = "";
        }
        if (!isset($backup_config->backup_sche_keep)) {
            $backup_config->backup_sche_keep = 1;
        }
    }
    if ($status) {
        //Checks for the required files/functions to backup every mod
        //And check if there is data about it
        $count = 0;
        if ($allmods = get_records("modules")) {
            foreach ($allmods as $mod) {
                $modname = $mod->name;
                $modfile = "{$CFG->dirroot}/mod/{$modname}/backuplib.php";
                $modbackup = $modname . "_backup_mods";
                $modcheckbackup = $modname . "_check_backup_mods";
                if (file_exists($modfile)) {
                    include_once $modfile;
                    if (function_exists($modbackup) and function_exists($modcheckbackup)) {
                        $var = "exists_" . $modname;
                        ${$var} = true;
                        $count++;
                        // PENNY NOTES: I have moved from here to the closing brace inside
                        // by two sets of ifs()
                        // to avoid the backup failing on a non existant backup.
                        // If the file/function/whatever doesn't exist, we don't want to set this
                        // this module in backup preferences at all.
                        //Check data
                        //Check module info
                        $var = "backup_" . $modname;
                        if (!isset(${$var})) {
                            ${$var} = $backup_config->backup_sche_modules;
                        }
                        //Now stores all the mods preferences into an array into preferences
                        $preferences->mods[$modname]->backup = ${$var};
                        //Check include user info
                        $var = "backup_user_info_" . $modname;
                        if (!isset(${$var})) {
                            ${$var} = $backup_config->backup_sche_withuserdata;
                        }
                        //Now stores all the mods preferences into an array into preferences
                        $preferences->mods[$modname]->userinfo = ${$var};
                        //And the name of the mod
                        $preferences->mods[$modname]->name = $modname;
                    }
                }
            }
        }
        // now set instances
        if ($coursemods = get_course_mods($course->id)) {
            foreach ($coursemods as $mod) {
                if (array_key_exists($mod->modname, $preferences->mods)) {
                    // we are to backup this module
                    if (empty($preferences->mods[$mod->modname]->instances)) {
                        $preferences->mods[$mod->modname]->instances = array();
                        // avoid warnings
                    }
                    $preferences->mods[$mod->modname]->instances[$mod->instance]->backup = $preferences->mods[$mod->modname]->backup;
                    $preferences->mods[$mod->modname]->instances[$mod->instance]->userinfo = $preferences->mods[$mod->modname]->userinfo;
                    // there isn't really a nice way to do this...
                    $preferences->mods[$mod->modname]->instances[$mod->instance]->name = get_field($mod->modname, 'name', 'id', $mod->instance);
                }
            }
        }
        // finally, clean all the $preferences->mods[] not having instances. Nothing to backup about them
        foreach ($preferences->mods as $modname => $mod) {
            if (!isset($mod->instances)) {
                unset($preferences->mods[$modname]);
            }
        }
    }
    //Convert other parameters
    if ($status) {
        $preferences->backup_metacourse = $backup_config->backup_sche_metacourse;
        $preferences->backup_users = $backup_config->backup_sche_users;
        $preferences->backup_logs = $backup_config->backup_sche_logs;
        $preferences->backup_user_files = $backup_config->backup_sche_userfiles;
        $preferences->backup_course_files = $backup_config->backup_sche_coursefiles;
        $preferences->backup_messages = $backup_config->backup_sche_messages;
        $preferences->backup_course = $course->id;
        $preferences->backup_destination = $backup_config->backup_sche_destination;
        $preferences->backup_keep = $backup_config->backup_sche_keep;
    }
    //Calculate the backup string
    if ($status) {
        schedule_backup_log($starttime, $course->id, "    calculating backup name");
        //Calculate the backup word
        //Take off some characters in the filename !!
        $takeoff = array(" ", ":", "/", "\\", "|");
        $backup_word = str_replace($takeoff, "_", moodle_strtolower(get_string("backupfilename")));
        //If non-translated, use "backup"
        if (substr($backup_word, 0, 1) == "[") {
            $backup_word = "backup";
        }
        //Calculate the date format string
        $backup_date_format = str_replace(" ", "_", get_string("backupnameformat"));
        //If non-translated, use "%Y%m%d-%H%M"
        if (substr($backup_date_format, 0, 1) == "[") {
            $backup_date_format = "%%Y%%m%%d-%%H%%M";
        }
        //Calculate the shortname
        $backup_shortname = clean_filename($course->shortname);
        if (empty($backup_shortname) or $backup_shortname == '_') {
            $backup_shortname = $course->id;
        }
        //Calculate the final backup filename
        //The backup word
        $backup_name = $backup_word . "-";
        //The shortname
        $backup_name .= moodle_strtolower($backup_shortname) . "-";
        //The date format
        $backup_name .= userdate(time(), $backup_date_format, 99, false);
        //The extension
        $backup_name .= ".zip";
        //And finally, clean everything
        $backup_name = clean_filename($backup_name);
        //Calculate the string to match the keep preference
        $keep_name = $backup_word . "-";
        //The shortname
        $keep_name .= moodle_strtolower($backup_shortname) . "-";
        //And finally, clean everything
        $keep_name = clean_filename($keep_name);
        $preferences->backup_name = $backup_name;
        $preferences->keep_name = $keep_name;
    }
    //Calculate the backup unique code to allow simultaneus backups (to define
    //the temp-directory name and records in backup temp tables
    if ($status) {
        $backup_unique_code = time();
        $preferences->backup_unique_code = $backup_unique_code;
    }
    //Calculate necesary info to backup modules
    if ($status) {
        schedule_backup_log($starttime, $course->id, "    calculating modules data");
        if ($allmods = get_records("modules")) {
            foreach ($allmods as $mod) {
                $modname = $mod->name;
                $modbackup = $modname . "_backup_mods";
                //If exists the lib & function
                $var = "exists_" . $modname;
                if (isset(${$var}) && ${$var}) {
                    //Add hidden fields
                    $var = "backup_" . $modname;
                    //Only if selected
                    if (${$var} == 1) {
                        $var = "backup_user_info_" . $modname;
                        //Call the check function to show more info
                        $modcheckbackup = $modname . "_check_backup_mods";
                        schedule_backup_log($starttime, $course->id, "      {$modname}");
                        $modcheckbackup($course->id, ${$var}, $backup_unique_code);
                    }
                }
            }
        }
    }
    //Now calculate the users
    if ($status) {
        schedule_backup_log($starttime, $course->id, "    calculating users");
        //Decide about include users with messages, based on SITEID
        if ($preferences->backup_messages && $preferences->backup_course == SITEID) {
            $include_message_users = true;
        } else {
            $include_message_users = false;
        }
        user_check_backup($course->id, $backup_unique_code, $preferences->backup_users, $include_message_users);
    }
    //Now calculate the logs
    if ($status) {
        if ($preferences->backup_logs) {
            schedule_backup_log($starttime, $course->id, "    calculating logs");
            log_check_backup($course->id);
        }
    }
    //Now calculate the userfiles
    if ($status) {
        if ($preferences->backup_user_files) {
            schedule_backup_log($starttime, $course->id, "    calculating user files");
            user_files_check_backup($course->id, $preferences->backup_unique_code);
        }
    }
    //Now calculate the coursefiles
    if ($status) {
        if ($preferences->backup_course_files) {
            schedule_backup_log($starttime, $course->id, "    calculating course files");
            course_files_check_backup($course->id, $preferences->backup_unique_code);
        }
    }
    //If everything is ok, return calculated preferences
    if ($status) {
        $status = $preferences;
    }
    return $status;
}
Example #5
0
<?php

// $Id$
// index.php - scheduled backup logs
require_once '../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/backup/lib.php';
$courseid = optional_param('courseid', 0, PARAM_INT);
admin_externalpage_setup('reportbackups');
admin_externalpage_print_header();
/// Scheduled backups are disabled by the server admin
if (!empty($CFG->disablescheduledbackups)) {
    print_error('scheduledbackupsdisabled', '', '', NULL, true);
}
/// Scheduled backups aren't active by the site admin
$backup_config = backup_get_config();
if (empty($backup_config->backup_sche_active)) {
    notify(get_string('scheduledbackupsinactive'));
}
/// Get needed strings
$backuploglaststatus = get_string("backuploglaststatus");
$backuplogdetailed = get_string("backuplogdetailed");
$stradmin = get_string("administration");
$strconfiguration = get_string("configuration");
$strbackup = get_string("backup");
$strbackupdetails = get_string("backupdetails");
$strlogs = get_string("logs");
$strftimedatetime = get_string("strftimerecent");
$strftimetime = get_string("strftimetime") . ":%S";
$strerror = get_string("error");
$strok = get_string("ok");
Example #6
0
function get_incremental($currenthash)
{
    global $CFG;
    $incremental_config = backup_get_config();
    $crnt = get_record('incremental_instance', 'hash', $currenthash);
    if (!empty($crnt)) {
        $crnt_course = get_records('incremental_instance', 'courseid', $crnt->courseid, 'timecreated');
        //print_object($crnt_course);
        $newbkup = array_pop($crnt_course);
        //get latest course hash.
        while ($newbkup->hash == $newbkup->filename) {
            //make sure the record is valid - if both hash and filename are exact - this is related to a client update - not the server backup.
            $newbkup = array_pop($crnt_course);
            //get latest course hash.
        }
        $returnfile = new object();
        if ($currenthash == $newbkup->hash) {
            $returnfile->name = 'uptodate';
            return $returnfile;
        }
        //set directory paths
        if (!empty($incremental_config->backup_inc_destination)) {
            $backuppath = $incremental_config->backup_inc_destination . '/' . $crnt->courseid . '/';
        } else {
            $backuppath = $CFG->dataroot . '/' . $crnt->courseid . '/backupdata/';
        }
        //now check to see if an incremental is available for the $currenthash
        if (file_exists($backuppath . 'incrementals/' . $currenthash . '-' . $newbkup->hash . '.zip')) {
            $returnfile->name = $currenthash . '-' . $newbkup->hash . '.zip';
            $returnfile->path = $backuppath . 'incrementals/';
        } else {
            $returnfile->name = $newbkup->filename;
            //incremental doesn't exist so send a full backup file instead.
        }
        return $returnfile;
    } else {
        return false;
    }
}
Example #7
0
 function get_setting()
 {
     $backup_config = backup_get_config();
     if (isset($backup_config->{$this->name})) {
         $currentsetting = $backup_config->{$this->name};
         return array('u' => substr($currentsetting, 0, 1), 'm' => substr($currentsetting, 1, 1), 't' => substr($currentsetting, 2, 1), 'w' => substr($currentsetting, 3, 1), 'r' => substr($currentsetting, 4, 1), 'f' => substr($currentsetting, 5, 1), 's' => substr($currentsetting, 6, 1));
     } else {
         return NULL;
     }
 }
Example #8
0
function backup_execute(&$preferences, &$errorstr)
{
    global $CFG;
    $status = true;
    //Check for temp and backup and backup_unique_code directory
    //Create them as needed
    if (!defined('BACKUP_SILENTLY')) {
        echo "<li>" . get_string("creatingtemporarystructures") . '</li>';
    }
    $status = check_and_create_backup_dir($preferences->backup_unique_code);
    //Empty dir
    if ($status) {
        $status = clear_backup_dir($preferences->backup_unique_code);
    }
    //Delete old_entries from backup tables
    if (!defined('BACKUP_SILENTLY')) {
        echo "<li>" . get_string("deletingolddata") . '</li>';
    }
    $status = backup_delete_old_data();
    if (!$status) {
        $errorstr = "An error occurred deleting old backup data";
        backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
        if (!defined('BACKUP_SILENTLY')) {
            notify($errorstr);
        }
    }
    //Create the moodle.xml file
    if ($status) {
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("creatingxmlfile");
            //Begin a new list to xml contents
            echo "<ul>";
            echo "<li>" . get_string("writingheader") . '</li>';
        }
        //Obtain the xml file (create and open) and print prolog information
        $backup_file = backup_open_xml($preferences->backup_unique_code);
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("writinggeneralinfo") . '</li>';
        }
        //Prints general info about backup to file
        if ($backup_file) {
            if (!($status = backup_general_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up general info";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("writingcoursedata");
            //Start new ul (for course)
            echo "<ul>";
            echo "<li>" . get_string("courseinfo") . '</li>';
        }
        //Prints course start (tag and general info)
        if ($status) {
            if (!($status = backup_course_start($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up course start";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Metacourse information
        if ($status && $preferences->backup_metacourse) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("metacourse") . '</li>';
            }
            if (!($status = backup_course_metacourse($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up metacourse info";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("blocks") . '</li>';
        }
        //Blocks information
        if ($status) {
            if (!($status = backup_course_blocks($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up course blocks";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("sections") . '</li>';
        }
        //Section info
        if ($status) {
            if (!($status = backup_course_sections($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up course sections";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //End course contents (close ul)
        if (!defined('BACKUP_SILENTLY')) {
            echo "</ul></li>";
        }
        //User info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writinguserinfo") . '</li>';
            }
            if (!($status = backup_user_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up user info";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //If we have selected to backup messages and we are
        //doing a SITE backup, let's do it
        if ($status && $preferences->backup_messages && $preferences->backup_course == SITEID) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writingmessagesinfo") . '</li>';
            }
            if (!($status = backup_messages($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up messages";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //If we have selected to backup blogs and we are
        //doing a SITE backup, let's do it
        if ($status && isset($preferences->backup_blogs) && $preferences->backup_blogs && $preferences->backup_course == SITEID) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writingblogsinfo") . '</li>';
            }
            if (!($status = backup_blogs($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up blogs";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //If we have selected to backup quizzes or other modules that use questions
        //we've already added ids of categories and questions to backup to backup_ids table
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writingcategoriesandquestions") . '</li>';
            }
            require_once $CFG->dirroot . '/question/backuplib.php';
            if (!($status = backup_question_categories($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up quiz categories";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Print logs if selected
        if ($status) {
            if ($preferences->backup_logs) {
                if (!defined('BACKUP_SILENTLY')) {
                    echo "<li>" . get_string("writingloginfo") . '</li>';
                }
                if (!($status = backup_log_info($backup_file, $preferences))) {
                    $errorstr = "An error occurred while backing up log info";
                    backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                    if (!defined('BACKUP_SILENTLY')) {
                        notify($errorstr);
                    } else {
                        return false;
                    }
                }
            }
        }
        //Print scales info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writingscalesinfo") . '</li>';
            }
            if (!($status = backup_scales_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up scales";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Print groups info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writinggroupsinfo") . '</li>';
            }
            if (!($status = backup_groups_info($backup_file, $preferences))) {
                $errostr = "An error occurred while backing up groups";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Print groupings info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writinggroupingsinfo") . '</li>';
            }
            if (!($status = backup_groupings_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up groupings";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Print groupings_groups info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writinggroupingsgroupsinfo") . '</li>';
            }
            if (!($status = backup_groupings_groups_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up groupings groups";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Print events info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writingeventsinfo") . '</li>';
            }
            if (!($status = backup_events_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up events";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Print gradebook info
        if ($status) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("writinggradebookinfo") . '</li>';
            }
            if (!($status = backup_gradebook_info($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up gradebook";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Module info, this unique function makes all the work!!
        //db export and module fileis copy
        if ($status) {
            $mods_to_backup = false;
            //Check if we have any mod to backup
            if (!empty($preferences->mods)) {
                foreach ($preferences->mods as $module) {
                    if ($module->backup) {
                        $mods_to_backup = true;
                    }
                }
            }
            //If we have to backup some module
            if ($mods_to_backup) {
                if (!defined('BACKUP_SILENTLY')) {
                    echo "<li>" . get_string("writingmoduleinfo");
                }
                //Start modules tag
                if (!($status = backup_modules_start($backup_file, $preferences))) {
                    $errorstr = "An error occurred while backing up module info";
                    backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                    if (!defined('BACKUP_SILENTLY')) {
                        notify($errorstr);
                    } else {
                        return false;
                    }
                }
                //Open ul for module list
                if (!defined('BACKUP_SILENTLY')) {
                    echo "<ul>";
                }
                //Iterate over modules and call backup
                foreach ($preferences->mods as $module) {
                    if ($module->backup and $status) {
                        if (!defined('BACKUP_SILENTLY')) {
                            echo "<li>" . get_string("modulenameplural", $module->name) . '</li>';
                        }
                        if (!($status = backup_module($backup_file, $preferences, $module->name))) {
                            $errorstr = "An error occurred while backing up '{$module->name}'";
                            backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                            if (!defined('BACKUP_SILENTLY')) {
                                notify($errorstr);
                            } else {
                                return false;
                            }
                        }
                    }
                }
                //Close ul for module list
                if (!defined('BACKUP_SILENTLY')) {
                    echo "</ul></li>";
                }
                //Close modules tag
                if (!($status = backup_modules_end($backup_file, $preferences))) {
                    $errorstr = "An error occurred while finishing the module backups";
                    backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                    if (!defined('BACKUP_SILENTLY')) {
                        notify($errorstr);
                    } else {
                        return false;
                    }
                }
            }
        }
        //Backup course format data, if any.
        if (!defined('BACKUP_SILENTLY')) {
            echo '<li>' . get_string("courseformatdata") . '</li>';
        }
        if ($status) {
            if (!($status = backup_format_data($backup_file, $preferences))) {
                $errorstr = "An error occurred while backing up the course format data";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Prints course end
        if ($status) {
            if (!($status = backup_course_end($backup_file, $preferences))) {
                $errorstr = "An error occurred while closing the course backup";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
        //Close the xml file and xml data
        if ($backup_file) {
            backup_close_xml($backup_file);
        }
        //End xml contents (close ul)
        if (!defined('BACKUP_SILENTLY')) {
            echo "</ul></li>";
        }
    }
    //Now, if selected, copy user files
    if ($status) {
        if ($preferences->backup_user_files) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("copyinguserfiles") . '</li>';
            }
            if (!($status = backup_copy_user_files($preferences))) {
                $errorstr = "An error occurred while copying user files";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
    }
    //Now, if selected, copy course files
    if ($status) {
        if ($preferences->backup_course_files) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("copyingcoursefiles") . '</li>';
            }
            if (!($status = backup_copy_course_files($preferences))) {
                $errorstr = "An error occurred while copying course files";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
    }
    //Now, if selected, copy site files
    if ($status) {
        if ($preferences->backup_site_files) {
            if (!defined('BACKUP_SILENTLY')) {
                echo "<li>" . get_string("copyingsitefiles") . '</li>';
            }
            if (!($status = backup_copy_site_files($preferences))) {
                $errorstr = "An error occurred while copying site files";
                backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
                if (!defined('BACKUP_SILENTLY')) {
                    notify($errorstr);
                } else {
                    return false;
                }
            }
        }
    }
    //Now, zip all the backup directory contents
    if ($status) {
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("zippingbackup") . '</li>';
        }
        if (!($status = backup_zip($preferences))) {
            $errorstr = "An error occurred while zipping the backup";
            backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
            if (!defined('BACKUP_SILENTLY')) {
                notify($errorstr);
            } else {
                return false;
            }
        }
    }
    //Now, copy the zip file to course directory
    if ($status) {
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("copyingzipfile") . '</li>';
        }
        if (!($status = copy_zip_to_course_dir($preferences))) {
            $errorstr = "An error occurred while copying the zip file to the course directory";
            backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
            if (!defined('BACKUP_SILENTLY')) {
                notify($errorstr);
            } else {
                return false;
            }
        }
    }
    //Now, clean temporary data (db and filesystem)
    if ($status) {
        if (!defined('BACKUP_SILENTLY')) {
            echo "<li>" . get_string("cleaningtempdata") . '</li>';
        }
        if (!($status = clean_temp_data($preferences))) {
            $errorstr = "An error occurred while cleaning up temporary data";
            backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
            if (!defined('BACKUP_SILENTLY')) {
                notify($errorstr);
            } else {
                return false;
            }
        }
    }
    //now call incremental backup if required.
    if (isset($preferences->backup_generate_incrementals) && $preferences->backup_generate_incrementals) {
        $backup_config = backup_get_config();
        require_once "incremental_backuplib.php";
        if (!check_xdelta_installed()) {
            $errorstr = "ERROR: XDELTA not installed - incrementals cannot run";
            backup_add_to_log(time(), $preferences->backup_course, $errorstr, 'manual');
            notify($errorstr);
        } elseif (isset($backup_config->backup_incrementals) && $backup_config->backup_incrementals) {
            require_once "{$CFG->libdir}/xdelta.class.php";
            echo '<li>' . get_string("generateincrementals", 'local') . '</li>';
            generate_incrementals($preferences->backup_course);
        }
    }
    return $status;
}
Example #9
0
 public function execute()
 {
     global $CFG;
     require_once $CFG->dirroot . '/backup/backup_scheduled.php';
     require_once $CFG->dirroot . '/backup/backuplib.php';
     require_once $CFG->dirroot . '/backup/lib.php';
     error_reporting(0);
     $CFG->debugdisplay = 0;
     $status = true;
     $emailpending = false;
     $config = backup_get_config();
     //Check for required functions...
     if (!function_exists('utf8_encode')) {
         echo "        ERROR: You need to add XML support to your PHP installation!";
         exit(1);
     }
     //Get now
     $now = time();
     //First of all, we have to see if the scheduled is active and detect
     //that there isn't another cron running
     echo "    Checking backup status...\n";
     //check if course id exists
     if ($course = get_record('course', 'id', $this->arguments[0])) {
         $this->setDefaultParams();
         $backup_config = backup_get_config();
         backup_set_config("backup_sche_running", "1");
         //Now we get the main admin user (we'll use his timezone, mail...)
         $admin = get_admin();
         if (!$admin) {
             $status = false;
         }
         if ($status) {
             echo "    Checking course";
             //Now process existing course
             //For each course, we check (insert, update) the backup_course table
             //with needed data
             if ($status) {
                 echo " '{$course->fullname}'\n";
                 //We check if the course exists in backup_course
                 if (get_record("backup_courses", "courseid", $course->id)) {
                     delete_records('backup_courses', 'courseid', "{$course->id}");
                 }
                 $temp_backup_course->courseid = $course->id;
                 $newid = insert_record("backup_courses", $temp_backup_course);
                 //And get it from db
                 $backup_course = get_record("backup_courses", "id", $newid);
                 //If it doesn't exist now, error
                 if (!$backup_course) {
                     echo "            ERROR (in backup_courses detection)";
                     $status = false;
                 }
                 //Now we backup every non-skipped course
                 //We have to send a email because we have included at least one backup
                 $emailpending = true;
                 //Only make the backup if laststatus isn't 2-UNFINISHED (uncontrolled error)
                 if ($backup_course->laststatus != 2) {
                     //Set laststarttime
                     $starttime = time();
                     set_field("backup_courses", "laststarttime", $starttime, "courseid", $backup_course->courseid);
                     //Set course status to unfinished, the process will reset it
                     set_field("backup_courses", "laststatus", "2", "courseid", $backup_course->courseid);
                     //Launch backup
                     $course_status = schedule_backup_launch_backup($course, $starttime);
                     //Set lastendtime
                     set_field("backup_courses", "lastendtime", time(), "courseid", $backup_course->courseid);
                     //Set laststatus
                     if ($course_status) {
                         set_field("backup_courses", "laststatus", "1", "courseid", $backup_course->courseid);
                     } else {
                         set_field("backup_courses", "laststatus", "0", "courseid", $backup_course->courseid);
                     }
                 }
                 //Save it to db
                 set_field("backup_courses", "nextstarttime", 0, "courseid", $backup_course->courseid);
             }
         }
         //Delete old logs
         if (!empty($CFG->loglifetime)) {
             mtrace("    Deleting old logs");
             $loglifetime = $now - $CFG->loglifetime * 86400;
             delete_records_select("backup_log", "laststarttime < '{$loglifetime}' AND courseid = {$course->id}");
         }
         //Everything is finished stop backup_sche_running
         backup_set_config("backup_sche_running", "0");
         $this->resetParams($config);
     }
 }
Example #10
0
        }
    }
}
if (empty($currenthash)) {
    //need to run backup for this course.
    // now do other stuff.!!!
    $navlinks = array();
    $navlinks[] = array('name' => get_string('exportcourse', 'local'), 'link' => '', 'type' => 'activity');
    $navigation = build_navigation($navlinks);
    print_header_simple(get_string('exportcourse', 'local'), get_string('exportcourse', 'local'), $navigation, "", "", true, '', '');
    print_box(get_string('errornobackup', 'local'), 'generalbox', 'intro');
    $course_status = schedule_backup_launch_inc_backup($course, time());
    if ($course_status) {
        redirect("export_incremental.php?id=" . $id);
    } else {
        error("please run a backup manually for this course");
    }
    exit;
}
$incremental_config = backup_get_config();
//set directory paths
if (!empty($incremental_config->backup_inc_destination)) {
    $backuppath = $incremental_config->backup_inc_destination . '/' . $crnt->courseid . '/';
} else {
    $backuppath = $CFG->dataroot . '/' . $course->id . '/backupdata/';
}
if (file_exists($backuppath . $currenthash->filename)) {
    send_file($backuppath . $currenthash->filename, $currenthash->hash . '.zip');
} else {
    error(get_string('errornobackup', 'local'));
}