Commit ae26999a authored by Adrian Rossouw's avatar Adrian Rossouw

Delete files older than a week when doing a backup task.

parent 32e930ef
......@@ -25,6 +25,11 @@ function drush_hosting_site_pre_hosting_task($task) {
$backup = hosting_site_get_backup($task->task_args['bid']);
$task->args[1] = $backup['filename'];
}
if ($task->task_type == 'backup') {
//default is older than 7 days.
$task->options['delete_backups_older_than'] = mktime() - strtotime("-7 days");
}
}
......@@ -122,9 +127,21 @@ function hosting_site_post_hosting_delete_task($task, $data) {
* This is needed to be able to restore.
*/
function hosting_site_post_hosting_backup_task($task, $data) {
if ($data['context']['backup_file'] && $task->ref->type == 'site') {
if ($task->ref->type == 'site') {
$platform = node_load($task->ref->platform);
hosting_site_add_backup($task->ref->nid, $platform->web_server, $data['context']['backup_file'], t('Generated on request'));
if ($data['context']['backup_file']) {
hosting_site_add_backup($task->ref->nid, $platform->web_server, $data['context']['backup_file'], t('Generated on request'));
}
// delete old backup files that have been removed.
if (is_array($data['context']['backup_files_deleted'])) {
foreach ($data['context']['backup_files_deleted'] as $filename) {
$backup = hosting_site_get_backup_by_filename($filename);
if (isset($backup['bid'])) {
hosting_site_delete_backup($backup['bid']);
}
}
}
}
}
......
......@@ -707,6 +707,13 @@ function hosting_site_get_backup($bid) {
return db_fetch_array(db_query("SELECT bid, site, web_server, filename, description, timestamp FROM {hosting_site_backups} WHERE bid = %d", $bid));
}
/**
* Get a site backup record
*/
function hosting_site_get_backup_by_filename($filename) {
return db_fetch_array(db_query("SELECT bid, site, web_server, filename, description, timestamp FROM {hosting_site_backups} WHERE filename = '%s'", $filename));
}
/**
* Retrieve a list of backup generated for a site.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment