KB450089 – Setting up ZFS auto snapshots in Linux

Last modified: January 18, 2019
You are here:
Estimated reading time: 1 min

– After you have already created your zpool and want to setup zfs-auto-snapshot, below are the steps you need to take.

1. Install unzip and wget packages if not already installed.

   Centos --> yum install unzip wget 
   
   Ubuntu --> apt-get install unzip wget

2. Use wget to download the zfs-auto-snapshot zip file.

   wget https://github.com/zfsonlinux/zfs-auto-snapshot/archive/master.zip

3. Unzip the zfs-auto-snapshot zip file and install the package.

   unzip master.zip
   cd zfs-auto-snapshot-master
   make install

4. Enable the auto-snapshot on the zpool/dataset

   zfs set com.sun:auto-snapshot=true $pool
   example --> zfs set com.sun:auto-snapshot=true zpool

5. Verify that the value is now set to ‘true’ when running the get command

   zfs get com.sun:auto-snapshot

6. You have the option to set up the following snapshot types – frequent(every 15 minutes), hourly, daily, weekly or monthly

   zfs set com.sun:auto-snapshot:$type=true $pool
   example --> zfs set com.sun:auto-snapshot:daily=true zpool

7. Verify that you successfully setup the desired snapshot type

   zfs get com.sun:auto-snapshot:$type
   example --> zfs get com.sun:auto-snapshot:daily

8. Change maximum number of snapshots to keep and the pool/dataset name in the zfs-auto-snapshot file in each respective cron directory (i.e /etc/cron.daily/zfs-auto-snapshot). Below is an example of a daily snapshot of a zpool to setup to keep maximum of 14 snapshots.

 
   vim /etc/cron.daily/zfs-auto-snapshot
   #!/bin/sh
   # Only call zfs-auto-snapshot if it's available
   which zfs-auto-snapshot > /dev/null || exit 0
   exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=14 zpool

9. To test that everything is setup correctly, manually run the first snapshot and then list all snapshots to see if it worked.

   /etc/cron.daily/zfs-auto-snapshot
   zfs list -t snapshot
Was this article helpful?
Dislike 0
Views: 1638
Unboxing Racking Storage Drives Cable Setup Power UPS Sizing Remote Access