Do you understand the ZFS snapshot command?
It’s simple, but important. I was in doubt about the USED reports by the zfs list command, and did some tests to gurarantee the understanding…
First, let’s create a simple ZFS filesystem, and see what zfs list command tells us:
# zfs create MYPOOL/test # zfs list MYPOOL/test NAME USED AVAIL REFER MOUNTPOINT MYPOOL/test 24,5K 24,1G 24,5K /MYPOOL/test
Ok, now we can copy some data to that filesystem, and start some action…
# ls -l /var/solaris.tar -rw-r--r-- 1 root root 74567680 abr 29 10:27 solaris.tar # cp -pRf /var/solaris.tar /MYPOOL/test/ # zfs list MYPOOL/test NAME USED AVAIL REFER MOUNTPOINT MYPOOL/test 71,2M 24,0G 71,2M MYPOOL/test
Ok, now we need to take a snapshot to see what zfs can do for us…
# zfs snapshot MYPOOL/test@testsnap # zfs list | grep test MYPOOL/test 71,2M 24,0G 71,2M /MYPOOL/test MYPOOL/test@testsnap 0 - 71,2M -
To understand that, we need to know the header line for the zfs list command:
NAME USED AVAIL REFER MOUNTPOINT
So, as we can see, the snapshot is not using any aditional space of our pool, and the amount of space referenced by the snapshot is the whole filesystem (71,2M). More action…
# cp -pRf /MYPOOL/test/solaris.tar /MYPOOL/test/solaris2.tar # zfs list | grep test MYPOOL/test 142M 23,9G 142M /MYPOOL/test MYPOOL/test@testsnap 23,5K - 71,2M - # zfs snapshot /MYPOOL/test@testsnap2 # zfs list | grep test MYPOOL/test 142M 23,9G 142M /MYPOOL/test MYPOOL/test@testsnap 23,5K - 71,2M - MYPOOL/test@testsnap2 0 - 142M - # rm /MYPOOL/test/solaris.tar # zfs list | grep test MYPOOL/test 142M 23,9G 71,2M /MYPOOL/test MYPOOL/test@testsnap 23,5K - 71,2M - MYPOOL/test@testsnap2 23,5K - 142M -
Now the nice part… everything has changed! Let’s see each point:
1) We have just a file (71,2M) in the live filesystem, but the test filesystem has 142M used. That’s because the other(71,2M) file we have deleted, is referenced by the two snapshots. So, it’s there (using space on the filesystem test).
2) The first snapshot is referencing just one file (solaris.tar), because that was the only file present on test filesystem when we take the first snapshot (the file is older than the snapshot creation).
# ls /MYPOOL/test/.zfs/snapshot/testsnap/ solaris.tar
3) The second snapshot is newer than the two files (solaris.tar and solaris2.tar), that’s why it is referencing these files.
4) Here i think is the complicated part… note that the two snapshots are using just 23,5K each, so you can not see in USED colunm, where is the other 71,2M used on the test filesystem. You can see that information on the REFER colunm for the test filesystem, there you can see how much space is beeing used by snapshots. In this case, we have two filesystem referencing the same 71,2M file!
We can make it more complicated than that…
# rm /MYPOOL/test/solaris2.tar # zfs list | grep test MYPOOL/test 142M 23,9G 24,5K MYPOOL/test MYPOOL/test@testsnap 23,5K - 71,2M - MYPOOL/test@testsnap2 71,2M - 142M -
Just kidding… the last zfs list command tells us that all the USED data is on the snapshots, 71,2M is USED by the second snapshot (that data is just there), and the other 71,2M is referenced by both snapshots. It’s important to see that we are talking about two files 142M, and while that data is present on the filesytem (even snapshots), the files will be using space. By the other side, does not matter how many times we have that files present (referenced) by snapshots, they will use the same size.
Keep in mind:
– Everything present on the filesystem is showed on the USED colunm for that filesystem
– You will see a snapshot at USED colunm, just if the data is just present in that snapshot, otherwise is just REFER
– You must combine the USED and REFER colunms to see where is your data (to know how much space the snapshots are consuming).