Skip to content
GitLab
Explore
Sign in
project
provision
Compare revisions
aed3d531500e1604c5bcd215319019c2d23988ea to dev-purgebackup
Commits on Source (1)
Delete backup files older than the amount specified in the --delete_backups_older_than option.
· 8b154305
Adrian Rossouw
authored
Jun 21, 2010
8b154305
Hide whitespace changes
Inline
Side-by-side
platform/backup.provision.inc
View file @
8b154305
...
...
@@ -10,6 +10,7 @@
* Make sure the site is installed and enabled, and that we have a valid target to back up to.
*/
function
drush_provision_drupal_provision_backup_validate
(
$backup_file
=
NULL
)
{
if
(
!@
drush_bootstrap
(
DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION
))
{
if
(
drush_get_option
(
'force'
,
false
))
{
drush_log
(
"clearing error"
);
...
...
@@ -83,3 +84,32 @@ function drush_provision_drupal_provision_backup_rollback() {
->
fail
(
'Failed deleting backup file @path'
);
}
}
/**
* Post backup purge. delete older files if instructed too.
*/
function
drush_provision_drupal_post_provision_backup
()
{
if
(
$timestamp
=
drush_get_option
(
'delete_backups_older_than'
,
FALSE
))
{
$timestamp
=
mktime
()
-
$timestamp
;
$to_delete
=
array
();
$regex
=
sprintf
(
"/^%s-(.*)\.(.*)\.tar\.gz$/"
,
d
()
->
uri
);
$backup_path
=
d
(
'@server_master'
)
->
backup_path
;
$files
=
drush_scan_directory
(
$backup_path
,
$regex
,
array
(
'.'
,
'..'
,
'CVS'
,
'.svn'
),
0
,
FALSE
,
'basename'
);
if
(
sizeof
(
$files
))
{
foreach
(
$files
as
$filename
=>
$file
)
{
$matches
=
array
();
preg_match
(
$regex
,
$filename
,
$matches
);
$filetime
=
strtotime
(
$matches
[
1
]
.
' '
.
$matches
[
2
]);
if
(
$filetime
<
$timestamp
)
{
$to_delete
[]
=
$backup_path
.
'/'
.
$filename
;
}
}
foreach
(
$to_delete
as
$delete
)
{
provision_file
()
->
unlink
(
$delete
)
->
succeed
(
"Backup file @path has been deleted"
)
->
fail
(
"Backup file @path could not be deleted"
);
}
drush_set_option
(
'backup_files_deleted'
,
$to_delete
);
}
}
}