Data is referenced in as many snapshots you take and it will be deleted from disk only if you delete all snapshots that referenced said data as well as the data from the running volume, this holds true for both, btrfs and ZFS.
For example, in btrfs if I create ~/mifyle.txt
and then take an snapshot of @home
, my file will not be deleted from disk unless I delete this snapshot and ~/myfile.txt
, the same happens with ZFS.
But what if I'm taking snapshots from @
and @home
? Will ~/myfile.txt
be referenced in @ and @home snapshots or just in @home snapshots?
And does ZFS behave differently? If I create a file rpool/home/myfile.txt
, where rpool
is the parent and rpool/home
is a child dataset, then take snapshots for rpool
and rpool/home
, will myfile.txt be referenced in both datasets snapshots or just in the children dataset snapshot?
Each dataset, whether child or parent, is its own file system. The file system is where files and directories are referenced and saved.
Snapshots done to rpool only affect the dataset rpool. Snapshots done to rpool/home only affect the dataset home.
Remember that home is not simply a directory within rpool, it is a file system that so happens to be mounted in the path /mnt/rpool/home.
If you save files within the home dataset, and then later destroy the home dataset, all files and folders within the home dataset are gone: including those saved in its snapshots! No such files were ever saved in the rpool dataset during the time home was mounted at /mnt/rpool/home.
This is true for snapshots as well. Taking snapshots for rpool/home does not create snapshots for rpool; only home snapshots are made.
The only reason you might be interested in rpool affecting rpool/home is when you use recursive actions on rpool, where any such recursive action will affect rpool and all of its children, including rpool/home.
If you make a recursive snapshot for rpool, it doesn't create a single snapshot. It creates multiple snapshots, one for each dataset.
This command will yield the following snapshots. -r is "recursive":
You can choose to destroy all of the snapshots with the following command. Notice the -r option:
If you prefer to be selective, you can destroy only specific snapshots without harming any of the others. Notice there is no -r option used:
Now you will be left with only the snapshots you have spared: