Package: zfs-fuse Severity: wishlist Tags: patch I've recently added this to zfsutils. I figured that you might find it useful for zfs-fuse.
Btw, maybe it'd be a good idea to set up a "zfs-common" package for things like this (and bash completion script, etc). Let me know if you're interested. # This algorithm implements a variation of the Towers of Hanoi rotation method # (see http://en.wikipedia.org/wiki/Backup_rotation_scheme#Towers_of_Hanoi). # # Unlike traditional ToH rotation, which uses a finite set of physical tapes, # we operate on a set of snapshots whose size doesn't necessarily have to be # bounded. Note that the number of snapshots only grows logarithmically with # time, which makes it very hard to fill your hard disk (even when running # unbounded). # # The result is that once we've run this for long enough, we'll find that for # recent dates (e.g. last few days) almost all snapshots are available, and the # older the date we're searching the more spread available snapshots will be. -- System Information: Debian Release: 6.0.3 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: kfreebsd-amd64 (x86_64) Kernel: kFreeBSD 8.1-1-amd64 Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash
#!/bin/bash # This algorithm implements a variation of the Towers of Hanoi rotation method # (see http://en.wikipedia.org/wiki/Backup_rotation_scheme#Towers_of_Hanoi). # # Unlike traditional ToH rotation, which uses a finite set of physical tapes, # we operate on a set of snapshots whose size doesn't necessarily have to be # bounded. Note that the number of snapshots only grows logarithmically with # time, which makes it very hard to fill your hard disk (even when running # unbounded). # # The result is that once we've run this for long enough, we'll find that for # recent dates (e.g. last few days) almost all snapshots are available, and the # older the date we're searching the more spread available snapshots will be. set -e . /etc/default/zfs # Does $1 belong to class $2 ? isclass () { if [ "$2" == "$AUTOSNAP_MAX_SNAPSHOTS" ] ; then # Special-case. Treat all snapshots as if they belong to # this class (in addition to their real class). return 0 fi local remainder=$((2 ** ($2 - 1))) local divisor=$((${remainder} * 2)) [ $(($1 % ${divisor})) == ${remainder} ] } classify () { local creation="$1" local creation_in_days="$(($(LANG=C date +%s -d "@${creation}") / 86400))" local class="1" # Find the class ${creation_in_days} belongs to. while ! isclass "${creation_in_days}" "${class}" ; do class=$((${class}+1)) done echo "${class}" } for fs in $AUTOSNAP_FILESYSTEMS ; do # Create today's snapshot. echo zfs snapshot ${fs}@autosnap-$(date +%F) zfs snapshot ${fs}@autosnap-$(date +%F) # Remove any snapshots in the same class as today's addition. LANG=C zfs list -r ${fs} -t snapshot -H -o name,creation \ | grep @autosnap- \ | while read name creation_human ; do creation="$(LANG=C date +%s -d "${creation_human}")" echo "$(classify "${creation}") ${creation} ${name}" done \ | sort -nr \ | while read class creation name ; do echo ${class} ${name} if [ ${class} == "${previous_class}" ] ; then echo zfs destroy "${name}" zfs destroy "${name}" fi previous_class="${class}" done done exit 0

