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.
This commit is contained in:
Eric Merrill 2014-05-27 12:11:28 -04:00
parent 1132d30d1f
commit 0babaf208d
2 changed files with 7 additions and 9 deletions

View file

@ -28,8 +28,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/** /**
* create the temp dir where backup/restore will happen, * Create the temp dir where backup/restore will happen and create temp ids table.
* delete old directories and create temp ids table
*/ */
class create_and_clean_temp_stuff extends backup_execution_step { 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'); $progress->start_progress('Deleting backup directories');
backup_helper::check_and_create_backup_dir($this->get_backupid());// Create backup temp dir 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::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::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 backup_controller_dbops::create_backup_ids_temp_table($this->get_backupid()); // Create ids temp table
$progress->end_progress(); $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 the temp dir used by backup/restore (conditionally),
* delete old directories and drop tem ids table. Note we delete * delete old directories and drop temp ids table. Note we delete
* the directory but not the corresponding log file that will be * the directory but not the corresponding log file that will be
* there for, at least, 4 hours - only delete_old_backup_dirs() * there for, at least, 1 week - only delete_old_backup_dirs() or cron
* deletes log files (for easier access to them) * deletes log files (for easier access to them).
*/ */
class drop_and_clean_temp_stuff extends backup_execution_step { 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; global $CFG;
backup_controller_dbops::drop_backup_ids_temp_table($this->get_backupid()); // Drop ids temp table 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: // Delete temp dir conditionally:
// 1) If $CFG->keeptempdirectoriesonbackup is not enabled // 1) If $CFG->keeptempdirectoriesonbackup is not enabled
// 2) If backup temp dir deletion has been marked to be avoided // 2) If backup temp dir deletion has been marked to be avoided

View file

@ -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 restore_controller_dbops::drop_restore_temp_tables($this->get_restoreid()); // Drop ids temp table
$progress = $this->task->get_progress(); $progress = $this->task->get_progress();
$progress->start_progress('Deleting backup dir'); $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 if (empty($CFG->keeptempdirectoriesonbackup)) { // Conditionally
backup_helper::delete_backup_dir($this->task->get_tempdir(), $progress); // Empty restore dir backup_helper::delete_backup_dir($this->task->get_tempdir(), $progress); // Empty restore dir
} }