Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 62 #65

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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