Skip to content

Commit

Permalink
Merge pull request #65 from chesio/fix-62
Browse files Browse the repository at this point in the history
Fix for issue 62
  • Loading branch information
Arsenal21 authored Nov 16, 2016
2 parents c173668 + 825b301 commit cbab8a0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions all-in-one-wp-security/classes/wp-security-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ function execute_backup()
return false;
}

// Delete old backup files now to avoid polluting backups directory
// with incomplete backups on websites where max execution time is too
// low for database content to be written to a file:
// https://github.com/Arsenal21/all-in-one-wordpress-security/issues/62
$this->aiowps_delete_backup_files($dirpath);

$fw_res = $this->write_db_backup_file($handle, $tables);
@fclose( $handle );

Expand Down Expand Up @@ -204,7 +210,6 @@ function execute_backup()
}

$this->aiowps_send_backup_email(); //Send backup file via email if applicable
$this->aiowps_delete_backup_files();
return true;
}

Expand Down Expand Up @@ -237,19 +242,18 @@ function aiowps_send_backup_email()
}
}
}
function aiowps_delete_backup_files()

function aiowps_delete_backup_files($backups_dir)
{
global $aio_wp_security;
$files_to_keep = absint($aio_wp_security->configs->get_value('aiowps_backup_files_stored'));
if ( $files_to_keep > 0 )
{
$backups_dir = dirname($this->last_backup_file_path);
$aio_wp_security->debug_logger->log_debug(sprintf('DB Backup - Deleting all but %d latest backup file(s) in %s directory.', $files_to_keep, $backups_dir));
$files = AIOWPSecurity_Utility_File::scan_dir_sort_date( $backups_dir );
$count = 0;

foreach ( $files as $file )
foreach ( $files as $file )
{
if ( strpos( $file, 'database-backup' ) !== false )
{
Expand Down

0 comments on commit cbab8a0

Please sign in to comment.