November 4, 2024
Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

Continuing from part 5, we’ll learn about ZFS snapshots and ZFS clones in this post:

In last post, we created a ZFS data set ‘myPool/myData’. Let’s see how we can backup and restore data using ZFS snapshots and ZFS clones.

1. ZFS snapshot is a point-in-time checkpoint of a dataset. ZFS snapshot is read-only and cannot be modified. You can create a ZFS snapshot of a ZFS data set using the following command –

sudo zfs snapshot <ZFS data set name>@<ZFS snapshot name>

In our case, we’ll create a snapshot called monday by issuing the following command –

sudo zfs snapshot myPool/myData@monday

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

In similar way we have created more snapshots for tuesday, wednesday, thursday and friday. Note that it will be a better idea to name the snapshot according to the date and time the snapshot was created.

2. To list all the ZFS data sets and ZFS snapshots and ZFS clones, issue the following command at the terminal –

sudo zfs list -t all

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

You see that we have 5 ZFS snapshots listed for ZFS data set ‘myPool/myData’.

3. To do a simple file / folder restore, we will use ZFS clone to mount a ZFS snapshot. Once mounted, once can read/write from/to a ZFS clone but all the changes to the ZFS clone will be lost once the ZFS clone is unmounted/destroyed. Let’s say we want a file from monday’s ZFS snapshot. Hence, to mount monday’s snapshot we’ll clone it using the following command –

sudo zfs clone <ZFS snapshot path/name> <ZFS clone path/name>

Hence, in our case, the command will be –

sudo zfs clone myPool/myData@monday myPool/mondayClone

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

This will create a clone of the ‘myPool/myData@monday’ snapshot and mount it to ‘/myPool/mondayClone’ directory. You can now browse the directory using the terminal or file manager and restore any file/folder that you need to.

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

4. When you are done restoring the file/folder, you can destroy the ZFS clone using the following command –

sudo zfs destroy <ZFS clone path/name>

In our case –

sudo zfs destroy myPool/mondayClone

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

You can verify the clone was destroyed by running ‘sudo zfs list -t all’ command again.

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

5. If you need to rollback the whole ZFS data set back to a point-in-time using a snapshot, you can use the following command –

sudo zfs rollback -r <ZFS snapshot path/name>

In our case, to rollback the ZFS data set back to wednesday’s snapshot, we’ll issue the following command –

sudo zfs rollback -r myPool/myData@wednesday

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

This will rollback the ZFS data set back to the state when the wednesday snapshot was taken, however, following things should be kept in mind –

a) All the newer snapshots after wednesday would be destroyed as the parent ZFS data set ‘myPool/myData’ will change after the rollback.

b) Any changes made after wednesday snapshot in the ZFS data set ‘myPool/myData’ will lost.

To confirm the above two points, run ‘sudo zfs list -t all’ at the terminal and note that the ZFS snapshots for thursday and friday are gone. Also, note the change in amount of data referred by ZFS dataset ‘myPool/myData’.

Installing And Using ZFS In Linux Mint / Ubuntu – Part 6

[To be continued in Part 7…]

By admin

Related Post

6 thoughts on “Installing And Using ZFS In Linux Mint / Ubuntu – Part 6”
  1. Thanks for the help. I can’t seen to get this command to work for me.
    sudo usermod -m -d [path to new home directory] [existing user name]
    (for e.g. sudo usermod -m -d /mypool/homeDirs ihaveapc)

    stan@phoenix:~$ sudo usermod -m -d /storage/home stan
    usermod: user stan is currently used by process 2797
    stan@phoenix:~$

    Do I need to be in single user mod or something?
    I am using LMDE.

    Thanks again for all the help.
    Stan

  2. I am really enjoying this tutorial. This is what I really need to know. I am running ZFS on a real machine. Four hard drives one 500GB 3- 3TB hard drives set up as an Raidz. I need to know how to set it up so I can move the /home directory to exist only in the ZFS pool so when I add a new user it will automatically create an account in the pool. I appreciate your help.

    Stan

    1. Let’s assume that ‘/dev/sda’ is the 500 GB drive and ‘/dev/sdb’, ‘/dev/sdc’ and ‘/dev/sdd’ are the 3 TB HDDs. Now setup a RAID-Z pool by running the following command –
      sudo zpool create mypool raidz /dev/sdb /dev/sdc /dev/sdd
      Now, create a ZFS data set in mypool –
      sudo zfs create mypool/homeDirs
      Now, enable compression and deduplication on ‘mypool/homeDirs’ –
      sudo zfs set compression = on mypool/homeDirs
      sudo zfs set dedup = on mypool/homeDirs
      Note that the default mount point of the above data set will be ‘/mypool/homeDirs’. If you wish to change the mount point to any other location,
      use the following commands –
      sudo mkdir [dir name for new mount point]
      sudo chmod -R 777 [dir name for new mount point]
      sudo zfs set mountpoint=[absolute path to the new mount point] [path to zfs data set]
      I recommend that you reboot the system at this point to verify that the ZFS pool is mounted upon reboot. After reboot run the following commands to verify the status –
      sudo zpool status
      sudo zfs list
      sudo zfs mount
      Now, to move the home directory of the existing user to ZFS, use the following command(better to make a separate backup of the home directories just in case the move operation fails for some unforeseen reasons) –
      sudo usermod -m -d [path to new home directory] [existing user name]
      (for e.g. sudo usermod -m -d /mypool/homeDirs ihaveapc)
      Now, in order that the home directories of the new users are created in ZFS data set, run the following commands (I am using gedit in the example, which should be easy to use, you can use nano or vi if you are familiar with those text editors) –
      sudo gedit /etc/default/useradd
      Now, look for the following line –
      # HOME=/home
      Change it to (remember to remove the hash)-
      HOME=/mypool/homeDirs
      Save and close the file.
      You can verify that the new home directories are created in the ZFS data set by running the following commands –
      sudo useradd dummyuser
      sudo passwd dummyuser
      sudo finger dummyuser
      The last command will show you the home directory path among other information about the user.

      Let us know if you need any more help with this.

      Regards,
      admin team

Comments are closed.