this post was submitted on 05 Oct 2024
6 points (100.0% liked)

btrfs

112 readers
1 users here now

founded 1 year ago
MODERATORS
 

Let's say i made 10 snapshots on top of the base.

Now can i delete snap no. 5? Will the snaps after 5 will be affected?

Solved

Yes, one can delete consecutive snapshots. The data won't be deleted unless all snaps ( reference points ) get deleted.

Note: If you delete the original file and delete all the snapshots made when the file is still there, the file will get deleted permanently.

top 4 comments
sorted by: hot top controversial new old
[–] seaQueue 4 points 1 month ago (1 children)

Yes, you can delete any snapshot at any time without risking data in others. Any unique data from the deleted snapshot will be discarded, any data still referenced by remaining snapshots will be kept.

[–] [email protected] 1 points 1 month ago (1 children)
[–] seaQueue 2 points 1 month ago (1 children)

If you want a better mental model of how snapshots work think of it like this: every file on disk is comprised of data blocks. The filesystem keeps a map of what data blocks belong to what files and how many references there are to these blocks. If a data block is referenced in the current running version of the filesystem as well as snapshots B C and D there will be 4 references in that block's count. If B C and D are removed the reference count drops to 1. If the file is then modified (ie: overwritten with new data) the number of references to the original block drops to zero and it will be marked to be freed for reuse.

How long data is kept around depends on whether or not anything on the filesystem (files or files contained in snapshots) still points to that data. It's a lot like reference counting and garbage collecting in memory if that helps. All of this to say: it doesn't matter if you delete snapshots from the middle of a sequence, later snapshots will retain references to data that they need so the data will be kept until the reference count for it drops to 0.

[–] [email protected] 1 points 1 month ago