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

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

Open
4 tasks done
DatKyle opened this issue Jul 13, 2021 · 3 comments
Open
4 tasks done

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

DatKyle opened this issue Jul 13, 2021 · 3 comments
Assignees
Labels
question Further information is requested waiting for answer

Comments

@DatKyle
Copy link

DatKyle commented Jul 13, 2021

Before submitting the bug

  • Ensure you are able to reproduce it on the latest released version (we release often)
  • Verified this bug is not already reported in an issue
  • Verified errors are not related to permissions
  • 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
Copy link
Author

DatKyle commented Jul 13, 2021

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
}

@sanderstad
Copy link
Collaborator

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 sanderstad self-assigned this Sep 9, 2021
@sanderstad sanderstad added question Further information is requested waiting for answer labels Sep 9, 2021
@DatKyle
Copy link
Author

DatKyle commented Sep 9, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting for answer
Projects
None yet
Development

No branches or pull requests

2 participants