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 expired snapshots #29

Merged
merged 10 commits into from
Sep 12, 2024
Merged

Remove expired snapshots #29

merged 10 commits into from
Sep 12, 2024

Conversation

in0rdr
Copy link
Collaborator

@in0rdr in0rdr commented Sep 9, 2024

In AWS S3 you can use lifecycle rules to remove expired objects.

However, I was wondering how this works in other S3 compatible storage servers, where the lifecycle rules are not implemented, such as Exoscale (see limitations) or cloudscale?

I think there needs to be some process that regularly iterates all the objects and decides which ones to prune, no?

Let's discuss..

This adds the variable S3_EXPIRE_DAYS.

The idea of this feature is to allow the script to prune expired
snapshot files on the S3 compatible remote storage. Files are considered
expired once they exceed the threshold defined by S3_EXPIRE_DAYS.

This feature is usefull for S3 compatible storage where there exist no
lifecycle rules to clean up the storage of expired or old files, such
as:
* cloudscale object storage
* Exoscale simple object storage (SOS)

It is recommended to also configure a "Governance" lock on the files, to
ensure no files are deleted by accident before the defined
S3_EXPIRE_DAYS threshold.
@in0rdr in0rdr requested a review from eyenx September 9, 2024 07:01
@in0rdr in0rdr requested a review from 4censord September 9, 2024 07:18
kubernetes/vault-snapshot.sh Outdated Show resolved Hide resolved
@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

date: invalid date '1 days ago'
sh: out of range

@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

also tried with -1 day format, same error in my test env

@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

Seems like this busybox date thingy has some different logic. This works, for example, extract 1 day:

date --date @$((`date +%s` - 86400*1)) +%s

The date manipulation did not work in my tests with busybox on
OpenShift.

This should work even in the busybox environments. It simply subtracts
seconds.
@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

Ok, new logic seems to work fine. For example, it deletes all snapshots except for the ones from today with S3_EXPIRE_DAYS=1:

$ oc logs test-vw276 
upload: '/vault-snapshots/vault_2024-09-12-1526.snapshot' -> 's3://vault-snapshots/vault_2024-09-12-1526.snapshot' (23246 bytes in 0.0 seconds, 1484.17 KB/s) [1 of 1]
delete: 's3://vault-snapshots/s3://vault-snapshots/vault_2024-09-09-1348.snapshot'
delete: 's3://vault-snapshots/s3://vault-snapshots/vault_2024-09-09-1354.snapshot'
...
delete: 's3://vault-snapshots/s3://vault-snapshots/vault_2024-09-11-0827.snapshot'

However, when i do mc ls, I can see that none of the snapshot are actually deleted 😆

So, I think I'm back to my issue with "what API commands s3cmd is actually doing"..

@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

Had a bug in my script. Was evident from the output ('s3://vault-snapshots/s3://vault-snapshots/vault_2024-09-09-1354.snapshot'). Now that this is fixed, it actually deletes the files 🎉

@in0rdr in0rdr requested a review from tongpu September 12, 2024 15:57
@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

@tongpu the scripting is on the next level now. It was actually tested on an OpenShift cluster. I still have some confusion regarding what a Governance lock does exactly (I could not notice any difference in the deletion behavior, the files are "archived" not deleted), but we can also take this discussion offline. Thank you for another round of review 🙏

@in0rdr
Copy link
Collaborator Author

in0rdr commented Sep 12, 2024

I hope the auto-tagging workflow does not explode 🤞

@in0rdr in0rdr merged commit 43416ce into master Sep 12, 2024
1 check passed
@in0rdr in0rdr deleted the feat/remove-expired-snapshots branch September 12, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants