dbaclone icon indicating copy to clipboard operation
dbaclone copied to clipboard

Remove Image unused and keep is per image instead of per database.

Open DatKyle opened this issue 3 years ago • 3 comments

Before submitting the bug

  • [x] Ensure you are able to reproduce it on the latest released version (we release often)
  • [x] Verified this bug is not already reported in an issue
  • [x] Verified errors are not related to permissions
  • [x] Can reproduce in a clean PowerShell session (clean = powershell -NoProfile)

Describe the bug When running the command: Remove-DcnImage -unused -keep 1 I would expect the command to remove unused images and keep the most recent image for each database. However, removes all unused and keeps the most recent image.

For example, I have 3 database images created on 1/7 and generate a new image for each database on 2/7. This gives me the below table:

ImageID Database Used? Created
1 Db1 unused 1/7/2021
4 Db1 unused 2/7/2021
2 Db2 unused 1/7/2021
5 Db2 unused 2/7/2021
3 Db3 unused 1/7/2021
6 Db3 unused 2/7/2021

When you run the above command it would remove all images, leaving only 1 image (ImageID 6). I would expect it to only remove the oldest image per database, leaving us with ImageID 4, 5, and 6.

Is this intended? Are you meant to specify the database when using -unused -keep [x]?

I'm using dbaclone version: 0.10.38

DatKyle avatar Jul 13 '21 11:07 DatKyle

For the time being I'm using the below code:

Get-DcnImage |
Select-Object -Unique -Property DatabaseName |
ForEach-Object {
    Remove-DcnImage -Database $_.DatabaseName -Unused -keep 1
}

DatKyle avatar Jul 13 '21 11:07 DatKyle

We could make the default value for -Keep to be 1 so that it would always keep the latest one? The parameter Unused is meant to delete all the images that are unused without looking at new ones at all.

Would that be a solution?

sanderstad avatar Sep 09 '21 07:09 sanderstad

The main issue is when I run Remove-dcnImage with the 2 params I would expect it to apply per database, not to all images. I have 10 images all for different databases. I run the remove command with the -unused -keep 1 and it removes 9 images. I would expect it to remove none because each image is for a different database.

We have 2 automated scripts one to create new images which we run every month, and one to remove the old images which we run every day.

The removal script original just did the below:

Remove-dcnImage -unused -keep 1

But we found that removes all unused images instead of per database. We changed the script to run the below instead:

Get-DcnImage | Select -Unique DatabaseName |
ForEach-Object {
    Remove-DcnImage -Database $_ -Unused -keep 1
}

I guess the question is: Should these 2 parameters be treated as per database instance or as all images?

DatKyle avatar Sep 09 '21 10:09 DatKyle