function backup_migrate_cron in Backup and Migrate 6
Same name and namespace in other branches
- 8.4 backup_migrate.module \backup_migrate_cron()
- 8.2 backup_migrate.module \backup_migrate_cron()
- 8.3 backup_migrate.module \backup_migrate_cron()
- 5.2 backup_migrate.module \backup_migrate_cron()
- 5 backup_migrate.module \backup_migrate_cron()
- 6.3 backup_migrate.module \backup_migrate_cron()
- 6.2 backup_migrate.module \backup_migrate_cron()
- 7.3 backup_migrate.module \backup_migrate_cron()
- 7.2 backup_migrate.module \backup_migrate_cron()
- 5.0.x backup_migrate.module \backup_migrate_cron()
Implementation of hook_cron(),
Takes care of scheduled backups.
File
- ./
backup_migrate.module, line 95 - Create (manually or scheduled) and restore backups of your Drupal MySQL database with an option to exclude table data (f.e. cache_*)
Code
function backup_migrate_cron() {
// Backing up requires a full bootstrap as it uses the file functionality in
// files.inc. Running poormanscron with caching on can cause cron to run without
// a full bootstrap so we manually finish bootstrapping here.
require_once './includes/common.inc';
_drupal_bootstrap_full();
if ($backup_schedule_period = variable_get("backup_migrate_schedule_backup_period", 0)) {
$last_backup = variable_get("backup_migrate_schedule_last_backup", 0);
$now = time();
if ($last_backup < $now - $backup_schedule_period * 60 * 60) {
// time to run the backup
_backup_migrate_dump_tables(variable_get("backup_migrate_file_name", _backup_migrate_default_file_name()), variable_get("backup_migrate_exclude_tables", _backup_migrate_default_exclude_tables()), variable_get("backup_migrate_nodata_tables", _backup_migrate_default_structure_only_tables()), 'sql', "save", variable_get("backup_migrate_compression", "none"), "scheduled", variable_get("backup_migrate_timestamp_format", 'Y-m-d\\TH-i-s'));
// Set the timestamp to indecate last backup time.
variable_set("backup_migrate_schedule_last_backup", $now);
// Delete older backups if needed.
_backup_migrate_remove_expired_backups();
}
}
// Delete temp files abandoned for 6 or more hours.
$dir = file_directory_temp();
$expire = time() - variable_get('backup_migrate_cleanup_time', 21600);
if (file_exists($dir) && is_dir($dir) && is_readable($dir) && ($handle = opendir($dir))) {
while (FALSE !== ($file = @readdir($handle))) {
// Delete 'backup_migrate_' files in the temp directory that are older than the expire time.
// We should only attempt to delete writable files to prevent errors in shared environments.
// This could still cause issues in shared environments with poorly configured file permissions.
if (strpos($file, 'backup_migrate_') === 0 && is_writable("{$dir}/{$file}") && @filectime("{$dir}/{$file}") < $expire) {
unlink("{$dir}/{$file}");
}
}
closedir($handle);
}
}