Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do ZFS snapshots use space in practice?

  1. Created a snapshot
  2. Deleted a huge file
  3. Delta is still 0 (snapshot not using anymore space) in zfs list for past three snapshots

Should the delta or used space not be the size of the deleted file. I know ZFS is COW but I'm confused as to why I can't rollback the /usr/home/xxxx child

# ls /home/xxxxx/testing12345.txt 
/home/xxxxx/testing12345.txt
# ls -alh /home/xxxxx/testing12345.txt                                                                                                                                 
-rw-r--r--  1 root  xxxxx   254M Aug 28 00:06 /home/xxxxx/testing12345.txt
# zfs list -rt snapshot tank1/usr/home/xxxxx
NAME                                        USED  AVAIL  REFER  MOUNTPOINT
tank1/usr/home/xxxxx@myRecursiveSnapshot   291M      -   804M  -
tank1/usr/home/xxxxx@devEnv                 71K      -  1.39G  -
tank1/usr/home/xxxxx@xfce                     0      -  1.39G  -
tank1/usr/home/xxxxx@testhome                 0      -  1.39G  -
tank1/usr/home/xxxxx@testagain               1K      -  1.39G  -
tank1/usr/home/xxxxx@27082015                 0      -  1.39G  -
tank1/usr/home/xxxxx@270820150                0      -  1.39G  -
tank1/usr/home/xxxxx@2708201501               0      -  1.39G  -
# 
# 
# 
# 
# zfs snapshot -r tank1@28082015                                                                                                                                        
# zfs list -rt snapshot tank1/usr/home/xxxxx                                                                                                                           
NAME                                        USED  AVAIL  REFER  MOUNTPOINT
tank1/usr/home/xxxxx@myRecursiveSnapshot   291M      -   804M  -
tank1/usr/home/xxxxx@devEnv                 71K      -  1.39G  -
tank1/usr/home/xxxxx@xfce                     0      -  1.39G  -
tank1/usr/home/xxxxx@testhome                 0      -  1.39G  -
tank1/usr/home/xxxxx@testagain               1K      -  1.39G  -
tank1/usr/home/xxxxx@27082015                 0      -  1.39G  -
tank1/usr/home/xxxxx@270820150                0      -  1.39G  -
tank1/usr/home/xxxxx@2708201501               0      -  1.39G  -
tank1/usr/home/xxxxx@28082015                 0      -  1.39G  -
# rm /home/xxxxx/testing12345.txt                                                                                                                                      
# zfs list -rt snapshot tank1/usr/home/xxxxx                                                                                                                           
NAME                                        USED  AVAIL  REFER  MOUNTPOINT
tank1/usr/home/xxxxx@myRecursiveSnapshot   291M      -   804M  -
tank1/usr/home/xxxxx@devEnv                 71K      -  1.39G  -
tank1/usr/home/xxxxx@xfce                     0      -  1.39G  -
tank1/usr/home/xxxxx@testhome                 0      -  1.39G  -
tank1/usr/home/xxxxx@testagain               1K      -  1.39G  -
tank1/usr/home/xxxxx@27082015                 0      -  1.39G  -
tank1/usr/home/xxxxx@270820150                0      -  1.39G  -
tank1/usr/home/xxxxx@2708201501               0      -  1.39G  -
tank1/usr/home/xxxxx@28082015                 0      -  1.39G  -
# 

I've been tried rolling back using various snapshots the /usr, /usr/home, and /usr/home/xxxx directories. I've read the FreeBSD forums, the handbook, and I've also tried rolling back just tank1@[snapshot name]--all to no effect. Something odd, when I change files in /usr/home/xxxxx files in the hidden .zfs/snapshots/[snapshot name]/usr/home/xxxxx directory change as well.

like image 605
sjt003 Avatar asked Aug 28 '15 05:08

sjt003


People also ask

Do ZFS snapshots take up space?

A ZFS snapshot is a copy of a data set or a volume that takes up nearly zero space and can be created almost instantly due to ZFS's copy-on-write (CoW) architecture. Unlike other traditional filesystems, when data is modified in ZFS, the data is written to a new block rather than overwriting the old data in its place.

Where are ZFS snapshots stored?

Snapshots of file systems are accessible in the . zfs/snapshot directory within the root of the file system. For example, if tank/home/ahrens is mounted on /home/ahrens , then the tank/home/ahrens@thursday snapshot data is accessible in the /home/ahrens/. zfs/snapshot/thursday directory.

Are ZFS snapshots recursive?

Recursive ZFS snapshots are created quickly as one atomic operation. The snapshots are created together (all at once) or not created at all. The benefit of such an operation is that the snapshot data is always taken at one consistent time, even across descendent file systems.

Are ZFS snapshots backups?

Since these snapshots contain all blocks for the data in question and since they are read only and immutable, they are IMO a backup.


1 Answers

Use this command to see space used for all snapshots of a vdev - relevant property you want is usedsnap:

zfs list -o name,used,avail,refer,creation,usedds,usedsnap,origin,compression,compressratio,refcompressratio,mounted,atime,lused

I've added a few more properties since I use compression on my zfs pools.

zfs snapshots directories are read-only by the way.

You said you cannot roll back? If that's the case specify -r or -R and possibly -f if you have clones, sample:

zfs rollback -r poolname/dataset@oldersnaphot
zfs rollback -R poolname/dataset@oldersnaphot

Read the manual before issuing zfs rollback:

       -r
           Destroy any snapshots and bookmarks more recent than the one specified.
       -R
           Recursively destroy any more recent snapshots and bookmarks, as well as any clones of those snapshots.
       -f
           Used with the -R option to force an unmount of any clone file systems that are to be destroyed.
like image 51
soyayix Avatar answered Oct 22 '22 22:10

soyayix