public function save_controller() {
// Going to save controller to persistent storage, calculate checksum for later checks and save it
+ // TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
$this->log('saving controller to db', backup::LOG_DEBUG);
$this->checksum = $this->calculate_checksum();
backup_controller_dbops::save_controller($this, $this->checksum);
public static function load_controller($backupid) {
// Load controller from persistent storage
+ // TODO: flag the controller as available. Operations on it can continue
$controller = backup_controller_dbops::load_controller($backupid);
$controller->log('loading controller from db', backup::LOG_DEBUG);
return $controller;
// Copy the generated zip file to final destination
$this->add_step(new backup_store_backup_file('save_backupfile'));
+ // Clean the temp dir (conditionaly) and drop temp table
+ $this->add_step(new drop_and_clean_temp_stuff('drop_and_clean_temp_stuff'));
+
$this->built = true;
}
/**
* Define all the backup steps that will be used by common tasks in backup
*/
+
+/**
+ * create the temp dir where backup/restore will happen,
+ * delete old directories and create temp ids table
+ */
class create_and_clean_temp_stuff extends backup_execution_step {
protected function define_execution() {
}
}
+/**
+ * delete the temp dir used by backup/restore (conditionally),
+ * delete old directories and drop tem ids table. Note we delete
+ * the directory but not the correspondig log file that will be
+ * there for, at least, 4 hours - only delete_old_backup_dirs()
+ * deletes log files (for easier access to them)
+ */
+class drop_and_clean_temp_stuff extends backup_execution_step {
+
+ 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
+ if (empty($CFG->keeptempdirectoriesonbackup)) { // Conditionally
+ backup_helper::delete_backup_dir($this->get_backupid()); // Empty backup dir
+ }
+ }
+}
+
/**
* Create the directory where all the task (activity/block...) information will be stored
*/
}
/**
- * Given one backupid, ensure its temp dir is completelly empty
+ * Given one backupid, ensure its temp dir is completely empty
*/
static public function clear_backup_dir($backupid) {
global $CFG;
if (!self::delete_dir_contents($CFG->dataroot . '/temp/backup/' . $backupid)) {
throw new backup_helper_exception('cannot_empty_backup_temp_dir');
}
+ return true;
}
+ /**
+ * Given one backupid, delete completely its temp dir
+ */
+ static public function delete_backup_dir($backupid) {
+ global $CFG;
+ self::clear_backup_dir($backupid);
+ return rmdir($CFG->dataroot . '/temp/backup/' . $backupid);
+ }
+
/**
* Given one fullpath to directory, delete its contents recursively
* Copied originally from somewhere in the net.
if ($status && $moddate < $deletefrom) {
//If directory, recurse
if (is_dir($file_path)) {
- $status = self::delete_dir_contents($file_path);
- //There is nothing, delete the directory itself
- if ($status) {
- $status = rmdir($file_path);
- }
+ $status = self::delete_backup_dir($file_path);
//If file
} else {
unlink($file_path);
// course requiring users to be created.
// $CFG->disableusercreationonrestore = true;
//
+// Keep the temporary directories used by backup and restore without being
+// deleted at the end of the process. Use it if you want to debug / view
+// all the information stored there after the process has ended. Note that
+// those directories may be deleted (after some ttl) both by cron and / or
+// by new backup / restore invocations.
+// $CFG->keeptempdirectoriesonbackup = true;
+//
// Modify the restore process in order to force the "user checks" to assume
// that the backup originated from a different site, so detection of matching
// users is performed with different (more "relaxed") rules. Note that this is