Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

zfs snapshot and pruning

Rod Myers edited this page Mar 27, 2021 · 8 revisions

PLEASE NOTE: I am using trident as the zpool name, adjust as you need to for those wishing to take automatic snapshots of the ~/HOME directory.

First install zfs-prune-snapshots.

  • Either using octoxbps or

  • command line:

    sudo xbps-install -Sy zfs-prune-snapshots
    

This will clean out ONLY the ~/HOME snapshots.

Open a terminal and type the following;

mkdir  /usr/home/$USER/bin
touch /usr/home/$USER/bin/snapshot.sh
chmod 744 /usr/home/$USER/bin/snapshot.sh
lte /usr/home/$USER/bin/snapshot.sh

now copy and paste the following into the file;

#!/bin/sh
## working - all of /home
# /bin/zfs snapshot -r trident/home@`date +"%F"-"%H":"%M"`
## working -  /home/$USER
# replace john with your user name
/bin/zfs snapshot -r trident/home/<user>@`date +"%F"-"%H":"%M"`

Note there are two options. 1 for all of ~/HOME, the other for your users ~/HOME only. Save the file and close

now type;

sudo lte /var/spool/cron/root

Copy and paste the following (replace with your user name);

0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /usr/home/<user>/bin/snapshot.sh
0 3 * * * /bin/zfs-prune-snapshots -v  1w trident/home >> /var/log/snapshot.log

The top line takes a snapshot of your ~/HOME every two hours. And the bottom line will delete the snapshot(s) after a week.

Save and close the text editor.

This should start snapshotting your system every 2 hours.