From 1f3b23569e67f7c6088c222f33b7763afa1c022f Mon Sep 17 00:00:00 2001 From: Eric Merrill Date: Tue, 27 May 2014 12:11:28 -0400 Subject: [PATCH] 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. --- backup/moodle2/backup_stepslib.php | 14 ++++++-------- backup/moodle2/restore_stepslib.php | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 53cce228356..f767133a090 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_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,7 +37,6 @@ class create_and_clean_temp_stuff extends backup_execution_step { $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(); @@ -46,11 +44,11 @@ class create_and_clean_temp_stuff extends backup_execution_step { } /** - * 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 @@ class drop_and_clean_temp_stuff extends backup_execution_step { 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 diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 512f64d848b..afa5a981092 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -67,7 +67,7 @@ class restore_drop_and_clean_temp_stuff extends restore_execution_step { 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 }