Activate ZFS Snapshots

Solution 1:

Starting from Ubuntu 17.04 you can install zfs-auto-snapshot like this:

sudo apt install zfs-auto-snapshot

For Ubuntu versions prior 17.04 you could setup zfs-auto-snapshot to use automatic snapshots from repository

sudo add-apt-repository ppa:zfs-native/stable; sudo apt-get install zfs-auto-snapshot

or directly from github

curl -L https://github.com/zfsonlinux/zfs-auto-snapshot/archive/master.tar.gz | tar xz -C /tmp/
pushd /tmp/zfs-auto-snapshot-master && sudo make install && popd && rm -rf /tmp/zfs-auto-snapshot-master

By default it creates snapshots for each data set every 15 minutes and saves snapshot up to 1 year. However you could disable snapshots for specific dataset by setting com.sun:auto-snapshot dataset property to false

sudo zfs set com.sun:auto-snapshot=false tank/tmp

You could also use com.sun:auto-snapshot:... properties to tune auto snapshot behaviour. E.g. save snapshots daily for 31 days for tank/backup dataset:

sudo zfs set com.sun:auto-snapshot=true tank/backup
sudo zfs set com.sun:auto-snapshot:monthly=false tank/backup
sudo zfs set com.sun:auto-snapshot:weekly=false tank/backup
sudo zfs set com.sun:auto-snapshot:daily=true tank/backup
sudo zfs set com.sun:auto-snapshot:hourly=false tank/backup
sudo zfs set com.sun:auto-snapshot:frequent=false tank/backup

By default script saves:

  • frequent snapshots every 15 mins, keeping 4 snapshots
  • hourly snapshots every hour, keeping 24 snapshots
  • daily snapshots every day, keeping 31 snapshots
  • weekly snapshots every week, keeping 7 snapshots
  • monthly snapshots every month, keeping 12 snapshots

Solution 2:

If you have not taken any snapshots, you lost your data.

To take snapshot, use zfs snapshot command

http://docs.oracle.com/cd/E19253-01/819-5461/gbcya/index.html