Pages

Wednesday, January 5, 2011

How to work with ZFS snapshot and clone

ZFS clone is a clone from zfs filesystem whose intial contents are the same with the filesystem from which it was created. Clones can only be created from snapshot. Below is tips to create sanpshot from ZFS filesystem and then create clone.

  1. See ZFS file system on your host.
    bash-3.00# zfs list
    NAME USED AVAIL REFER MOUNTPOINT
    mirrpool 132K 976M 19K /mirrpool
    mirrpool/fs1 18K 976M 18K /mirrpool/fs1
  2. See the content of your file system.
    bash-3.00# ls -al /mirrpool/fs1
    total 7
    drwxr-xr-x 2 root root 3 Nov 2 11:54 .
    drwxr-xr-x 3 root root 3 Nov 2 11:54 ..
    -rw-r--r-- 1 root root 0 Nov 2 11:54 data1
  3. Create a snapshot from your filesystem. In this example you create snapshot from mirrpool/fs1.
    bash-3.00# zfs snapshot mirrpool/fs1@today
    bash-3.00# zfs list
    NAME USED AVAIL REFER MOUNTPOINT
    mirrpool 133K 976M 19K /mirrpool
    mirrpool/fs1 18K 976M 18K /mirrpool/fs1
    mirrpool/fs1@today 0 - 18K -
  4. See that your snapshot also contain same data with your original filesystem (step 2).
    bash-3.00# ls -al /mirrpool/fs1/.zfs/snapshot/today
    total 4
    drwxr-xr-x 2 root root 3 Nov 2 11:54 .
    dr-xr-xr-x 3 root root 3 Nov 2 11:54 ..
    -rw-r--r-- 1 root root 0 Nov 2 11:54 data1
  5. Create clone from the snapshot. In this example you create a clone named mirrpool/fs2. Initial content of clone is same with the original file system.
    bash-3.00# ls -al /mirrpool/fs2
    total 7
    drwxr-xr-x 2 root root 3 Nov 2 11:54 .
    drwxr-xr-x 4 root root 4 Nov 2 13:44 ..
    -rw-r--r-- 1 root root 0 Nov 2 11:54 data1
  6. See that origin from the clone is the snapshot.
    bash-3.00# zfs get -r origin mirrpool
    NAME PROPERTY VALUE SOURCE
    mirrpool origin - -
    mirrpool/fs1 origin - -
    mirrpool/fs1@today origin - -
    mirrpool/fs2 origin mirrpool/fs1@today -

No comments:

Post a Comment