Skip to content

Commit

Permalink
MDL-48179 Backup progress: Can time out when compressing large backup
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Nov 14, 2014
1 parent c106341 commit 94b084f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 20 additions & 2 deletions backup/moodle2/backup_stepslib.php
Expand Up @@ -1742,26 +1742,44 @@ protected function define_execution() {
// Get the zip packer
$zippacker = get_file_packer('application/vnd.moodle.backup');

// Track overall progress for the 2 long-running steps (archive to
// pathname, get backup information).
$reporter = $this->task->get_progress();
$reporter->start_progress('backup_zip_contents', 2);

// Zip files
$result = $zippacker->archive_to_pathname($files, $zipfile, true, $this);

// If any sub-progress happened, end it.
if ($this->startedprogress) {
$this->task->get_progress()->end_progress();
$this->startedprogress = false;
} else {
// No progress was reported, manually move it on to the next overall task.
$reporter->progress(1);
}

// Something went wrong.
if ($result === false) {
@unlink($zipfile);
throw new backup_step_exception('error_zip_packing', '', 'An error was encountered while trying to generate backup zip');
}
// Read to make sure it is a valid backup. Refer MDL-37877 . Delete it, if found not to be valid.
try {
backup_general_helper::get_backup_information_from_mbz($zipfile);
backup_general_helper::get_backup_information_from_mbz($zipfile, $this);
} catch (backup_helper_exception $e) {
@unlink($zipfile);
throw new backup_step_exception('error_zip_packing', '', $e->debuginfo);
}

// If any progress happened, end it.
// If any sub-progress happened, end it.
if ($this->startedprogress) {
$this->task->get_progress()->end_progress();
$this->startedprogress = false;
} else {
$reporter->progress(2);
}
$reporter->end_progress();
}

/**
Expand Down
8 changes: 6 additions & 2 deletions backup/util/helper/backup_general_helper.class.php
Expand Up @@ -230,11 +230,15 @@ public static function get_backup_information($tempdir) {
* This will only extract the moodle_backup.xml file from an MBZ
* file and then call {@link self::get_backup_information()}.
*
* This can be a long-running (multi-minute) operation for large backups.
* Pass a $progress value to receive progress updates.
*
* @param string $filepath absolute path to the MBZ file.
* @param file_progress $progress Progress updates
* @return stdClass containing information.
* @since Moodle 2.4
*/
public static function get_backup_information_from_mbz($filepath) {
public static function get_backup_information_from_mbz($filepath, file_progress $progress = null) {
global $CFG;
if (!is_readable($filepath)) {
throw new backup_helper_exception('missing_moodle_backup_file', $filepath);
Expand All @@ -245,7 +249,7 @@ public static function get_backup_information_from_mbz($filepath) {
$tmpdir = $CFG->tempdir . '/backup/' . $tmpname;
$fp = get_file_packer('application/vnd.moodle.backup');

$extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml'));
$extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml'), $progress);
$moodlefile = $tmpdir . '/' . 'moodle_backup.xml';
if (!$extracted || !is_readable($moodlefile)) {
throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile);
Expand Down

0 comments on commit 94b084f

Please sign in to comment.