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

Added null option for unlimited backup storage size #1788

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions config/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
/*
* After cleaning up the backups remove the oldest backup until
* this amount of megabytes has been reached.
* Set null for unlimited size.
*/
'delete_oldest_backups_when_using_more_megabytes_than' => 5000,
],
Expand Down
1 change: 1 addition & 0 deletions docs/cleaning-up-old-backups/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ This portion of the configuration determines which backups should be deleted.
/*
* After cleaning up the backups remove the oldest backup until
* this amount of megabytes has been reached.
* Set null for unlimited size.
*/
'delete_oldest_backups_when_using_more_megabytes_than' => 5000,
],
Expand Down
1 change: 1 addition & 0 deletions docs/installation-and-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ return [
/*
* After cleaning up the backups remove the oldest backup until
* this amount of megabytes has been reached.
* Set null for unlimited size.
*/
'delete_oldest_backups_when_using_more_megabytes_than' => 5000,
],
Expand Down
5 changes: 2 additions & 3 deletions src/Tasks/Cleanup/Strategies/DefaultStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ protected function removeOldBackupsUntilUsingLessThanMaximumStorage(BackupCollec
return;
}

$maximumSize = $this->config->get('backup.cleanup.default_strategy.delete_oldest_backups_when_using_more_megabytes_than')
* 1024 * 1024;
$maximumSize = $this->config->get('backup.cleanup.default_strategy.delete_oldest_backups_when_using_more_megabytes_than');

if (($backups->size() + $this->newestBackup->sizeInBytes()) <= $maximumSize) {
if ($maximumSize === null || ($backups->size() + $this->newestBackup->sizeInBytes()) <= $maximumSize * 1024 * 1024) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting a bit unreadable. Could you extract this check to a separate function with a good name and early returns so we can avoid using ||

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

return;
}
$oldest->delete();
Expand Down