fix: storage retention setting
- feat: add storage retention to local storage as well - fix: UI input for max storage now allows exact decimals so MB input is now also possible - fix: Database column is now decimal instead of integer - fix: variable naming of storage check no longer overwrites $backup - renamed it to $backupExecution
This commit is contained in:
@@ -263,8 +263,9 @@ function deleteOldBackupsLocally($backup): Collection
|
||||
|
||||
$retentionAmount = $backup->database_backup_retention_amount_locally;
|
||||
$retentionDays = $backup->database_backup_retention_days_locally;
|
||||
$maxStorageGB = $backup->database_backup_retention_max_storage_locally;
|
||||
|
||||
if ($retentionAmount === 0 && $retentionDays === 0) {
|
||||
if ($retentionAmount === 0 && $retentionDays === 0 && $maxStorageGB === 0) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
@@ -281,6 +282,26 @@ function deleteOldBackupsLocally($backup): Collection
|
||||
$backupsToDelete = $backupsToDelete->merge($oldBackups);
|
||||
}
|
||||
|
||||
if ($maxStorageGB > 0) {
|
||||
$maxStorageBytes = $maxStorageGB * pow(1024, 3);
|
||||
$totalSize = 0;
|
||||
$backupsOverLimit = collect();
|
||||
|
||||
$backupsToCheck = $successfulBackups->skip(1);
|
||||
|
||||
foreach ($backupsToCheck as $backupExecution) {
|
||||
$totalSize += (int) $backupExecution->size;
|
||||
if ($totalSize > $maxStorageBytes) {
|
||||
$backupsOverLimit = $successfulBackups->filter(
|
||||
fn ($b) => $b->created_at->utc() <= $backupExecution->created_at->utc()
|
||||
)->skip(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$backupsToDelete = $backupsToDelete->merge($backupsOverLimit);
|
||||
}
|
||||
|
||||
$backupsToDelete = $backupsToDelete->unique('id');
|
||||
$processedBackups = collect();
|
||||
|
||||
@@ -345,14 +366,18 @@ function deleteOldBackupsFromS3($backup): Collection
|
||||
}
|
||||
|
||||
if ($maxStorageGB > 0) {
|
||||
$maxStorageBytes = $maxStorageGB * 1024 * 1024 * 1024;
|
||||
$maxStorageBytes = $maxStorageGB * pow(1024, 3);
|
||||
$totalSize = 0;
|
||||
$backupsOverLimit = collect();
|
||||
|
||||
foreach ($successfulBackups as $backup) {
|
||||
$totalSize += (int) $backup->size;
|
||||
$backupsToCheck = $successfulBackups->skip(1);
|
||||
|
||||
foreach ($backupsToCheck as $backupExecution) {
|
||||
$totalSize += (int) $backupExecution->size;
|
||||
if ($totalSize > $maxStorageBytes) {
|
||||
$backupsOverLimit = $successfulBackups->filter(fn ($b) => $b->created_at->utc() <= $backup->created_at->utc());
|
||||
$backupsOverLimit = $successfulBackups->filter(
|
||||
fn ($b) => $b->created_at->utc() <= $backupExecution->created_at->utc()
|
||||
)->skip(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user