If I understand correctly, btrfs snapshots store just what changed with respect to a base filesystem called the "first root filesystem". My first root filesystem was created in 2017 and thus snapshots are pretty big because a lot changed since then. Is it possible to make my current file system the "first root filesystem" so that snapshots are not that heavy?
-
BTRFS snapshots reference data at the time the snapshots were taken. When you attempt to change that data, it first gets copied leaving the original data intact. If you keep many snapshots, then sure they can use up a lot of storage space in total, but the individual snapshots themselves don't grow in size. It sounds like you have snapshots referencing old data don't use anymore. To free up space, simply delete the snapshots you don't need.– Emmanuel RosaOct 23, 2020 at 8:52
-
Thanks for the answer. However, my first root file system (snapshot number #1) has the date: Wed 31 May 2017. If I restore to that snapshot, wouldn't I move to the fielsystem that I had on that date?– M. BuilOct 26, 2020 at 17:52
-
Yes. Snapshots are also directories, so you can even take a peak to see what's in the snapshot.– Emmanuel RosaOct 26, 2020 at 19:16
-
But that means the changes between my today's filesystem and my filesystem on Wed 31 May 2017 must be kept somewhere. The amount of changes must be huge and growing everyday and thus the required space to store those changes, or? So, how can the snapshots not grow in size?– M. BuilOct 27, 2020 at 11:52
-
I think you are equating BTRFS snapshots to diffs, such as those used in Git. I made the same assumption at first. A snapshot is the data frozen in time; No diffs are involved. Here's a simple experiment to prove it: Create a subvolume, change the data in it, and snapshot it. Repeat, say... a handful of times to simulate recording changes in Git. Then, delete some intermediate snapshots. You'll notice that the remaining snapshots remain unaffected. In fact, if diffs were being used deleting intemediate snapshots would wreck the filesystem.– Emmanuel RosaOct 27, 2020 at 22:13
1 Answer
BTRFS snapshots reference data at the time the snapshots were taken. When you attempt to change that data, it first gets copied, leaving the original data intact. If you keep many snapshots, then sure they can use up a lot of storage space in total, but the individual snapshots themselves don't grow in size. It sounds like you have snapshots referencing old data don't use anymore. To free up space, simply delete the snapshots you don't need.
Explanation
Simply put, a snapshot is data frozen in time; No diffs are involved, nor is it similar in implementation to LVM snapshots. Here's a simple experiment to prove it:
- Create a subvolume.
- Change the data in it.
- Snapshot it.
- Repeat, say... a handful of times to simulate recording various changes.
- Delete some of the intermediate snapshots.
You'll notice that the remaining snapshots remain unaffected. If diffs were being used, then deleting intemediate snapshots would not be allowed because they would destroy the filesystem.