Skip to content
Permalink
Browse files

MDL-45714 backup: Less aggressive removal of old backup dirs

The old 4 hour standard was too aggressive and can cause backup files
to be removed while they were still in use. Now the same as cron,
1 week.
  • Loading branch information...
merrill-oakland committed May 27, 2014
1 parent 8e478c9 commit 1f3b23569e67f7c6088c222f33b7763afa1c022f
Showing with 7 additions and 9 deletions.
  1. +6 −8 backup/moodle2/backup_stepslib.php
  2. +1 −1 backup/moodle2/restore_stepslib.php
@@ -28,8 +28,7 @@
defined('MOODLE_INTERNAL') || die();
/**
* create the temp dir where backup/restore will happen,
* delete old directories and create temp ids table
* Create the temp dir where backup/restore will happen and create temp ids table.
*/
class create_and_clean_temp_stuff extends backup_execution_step {
@@ -38,19 +37,18 @@ protected function define_execution() {
$progress->start_progress('Deleting backup directories');
backup_helper::check_and_create_backup_dir($this->get_backupid());// Create backup temp dir
backup_helper::clear_backup_dir($this->get_backupid(), $progress); // Empty temp dir, just in case
backup_helper::delete_old_backup_dirs(time() - (4 * 60 * 60), $progress); // Delete > 4 hours temp dirs
backup_controller_dbops::drop_backup_ids_temp_table($this->get_backupid()); // Drop ids temp table
backup_controller_dbops::create_backup_ids_temp_table($this->get_backupid()); // Create ids temp table
$progress->end_progress();
}
}
/**
* delete the temp dir used by backup/restore (conditionally),
* delete old directories and drop tem ids table. Note we delete
* Delete the temp dir used by backup/restore (conditionally),
* delete old directories and drop temp ids table. Note we delete
* the directory but not the corresponding log file that will be
* there for, at least, 4 hours - only delete_old_backup_dirs()
* deletes log files (for easier access to them)
* there for, at least, 1 week - only delete_old_backup_dirs() or cron
* deletes log files (for easier access to them).
*/
class drop_and_clean_temp_stuff extends backup_execution_step {
@@ -60,7 +58,7 @@ protected function define_execution() {
global $CFG;
backup_controller_dbops::drop_backup_ids_temp_table($this->get_backupid()); // Drop ids temp table
backup_helper::delete_old_backup_dirs(time() - (4 * 60 * 60)); // Delete > 4 hours temp dirs
backup_helper::delete_old_backup_dirs(strtotime('-1 week')); // Delete > 1 week old temp dirs.
// Delete temp dir conditionally:
// 1) If $CFG->keeptempdirectoriesonbackup is not enabled
// 2) If backup temp dir deletion has been marked to be avoided
@@ -67,7 +67,7 @@ protected function define_execution() {
restore_controller_dbops::drop_restore_temp_tables($this->get_restoreid()); // Drop ids temp table
$progress = $this->task->get_progress();
$progress->start_progress('Deleting backup dir');
backup_helper::delete_old_backup_dirs(time() - (4 * 60 * 60), $progress); // Delete > 4 hours temp dirs
backup_helper::delete_old_backup_dirs(strtotime('-1 week'), $progress); // Delete > 1 week old temp dirs.
if (empty($CFG->keeptempdirectoriesonbackup)) { // Conditionally
backup_helper::delete_backup_dir($this->task->get_tempdir(), $progress); // Empty restore dir
}

0 comments on commit 1f3b235

Please sign in to comment.
You can’t perform that action at this time.