In backup and migrate module, schedule tab is there in which we can schedule a backup with the number to keep which is use to store latest backups with entered numbers and delete oldest backups, which is used to save system memory

at number to keep field I added the value 5 which means once the 5 backups are reached then it should delete oldest backup on 6th backup. But it doesn't work after completing 5 backups process being stop and not adding 6th backup and not deleting oldest backup.

CommentFileSizeAuthor
#3 3221856-3.patch447 byteslarisse

Comments

PranaliMW created an issue. See original summary.

damienmckenna’s picture

Version: 5.0.0 » 5.0.x-dev
Issue summary: View changes
Issue tags: -backup and migrate module
larisse’s picture

Status: Active » Needs review
StatusFileSize
new447 bytes

Hi!
The problem was because the files have been delete in descending order, so the last backup created has been deleted.
I created a patch to solve this.

damienmckenna’s picture

Priority: Normal » Critical

Let's make that a critical bug... *gulp*

damienmckenna’s picture

Status: Needs review » Closed (duplicate)
Parent issue: » #3221636: Most recent backups in saved backups tab

It turns out this is a duplicate of #3221636: Most recent backups in saved backups tab , so I'm going to close this one and I'll give focus credit in the other issue.

larisse’s picture

I don't think that is a duplicated issue, because the problem here is because in schedule backup, the backup is not saved. In another issue, I don't think that is really a issue, cause the "issue" was the order that backups is been showing, and not that backups is not been saveds.

Applying the patch in #3221636, the problem here still occurs.

damienmckenna’s picture

Apologies, you are correct.

paulocs’s picture

Assigned: Unassigned » paulocs

I'll review it.

paulocs’s picture

Assigned: paulocs » Unassigned
Status: Needs review » Reviewed & tested by the community

Indeed the bug exists and it is fixed with patch #3.
When the Number to keep is set, the backup process stop to work, it is not added the next scheduled backup and it is not deleted the oldest backup.

We should add tests for this feature so we can prevent regression in the future as this is a key feature... For now I think this can be committed and we can open a follow-up issue to write the tests.

damienmckenna’s picture

Title: In Schedule backup,keep last backup not working. » In Schedule backup, "keep last backup" option not working.
Status: Reviewed & tested by the community » Fixed
Related issues: +#3223040: Test coverage for scheduler

I created a separate issue for test coverage: #3223040

Committed. Thank you.

paulocs’s picture

Thanks @DamienMcKenna

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

vzimmer’s picture

The applied fix let me doubtful.
By design, getting the N files to delete should be resolved by using the "SORT_DESC" filter combined with "start at N" parameter (aka "keep N files").
Doing an ascendent sorting will do the opposite (keep the N oldest files and remove the "total - N" newest ones => including the one we just have generated).

Looking closer, the bug is an historical one, implemented in Drupal\backup_migrate\Core\Destination::queryFiles().
If you take a look at the uasort() method, you will see that the comparison are made "upside down".
Actually, Drupal\backup_migrate\Core\Destination::queryFiles() returns ascendant sorted results when called with "SORT_DESC" and descendant when called with "SORT_ASC" !