[Glibc-bsd-commits] r3936 - in trunk/zfsutils/debian: . local local/default

Robert Millan rmh at alioth.debian.org
Wed Dec 7 20:05:59 UTC 2011


Author: rmh
Date: 2011-12-07 20:05:59 +0000 (Wed, 07 Dec 2011)
New Revision: 3936

Added:
   trunk/zfsutils/debian/local/default/
   trunk/zfsutils/debian/local/default/zfs
   trunk/zfsutils/debian/zfsutils.cron.daily
Modified:
   trunk/zfsutils/debian/changelog
   trunk/zfsutils/debian/control
   trunk/zfsutils/debian/zfsutils.install
Log:
Add daily cron job for automated snapshots using a variation of Hanoi algorithm.

Modified: trunk/zfsutils/debian/changelog
===================================================================
--- trunk/zfsutils/debian/changelog	2011-12-07 14:58:56 UTC (rev 3935)
+++ trunk/zfsutils/debian/changelog	2011-12-07 20:05:59 UTC (rev 3936)
@@ -2,8 +2,10 @@
 
   * Require zfs-modules in zfsutils-udeb, but only versions that provide
     ZFS v28 or later.
+  * Add daily cron job for automated snapshots using a variation of
+    Hanoi algorithm.
 
- -- Robert Millan <rmh at debian.org>  Sat, 03 Dec 2011 17:15:57 +0100
+ -- Robert Millan <rmh at debian.org>  Wed, 07 Dec 2011 21:05:41 +0100
 
 zfsutils (8.3~svn226546-5) unstable; urgency=low
 

Modified: trunk/zfsutils/debian/control
===================================================================
--- trunk/zfsutils/debian/control	2011-12-07 14:58:56 UTC (rev 3935)
+++ trunk/zfsutils/debian/control	2011-12-07 20:05:59 UTC (rev 3936)
@@ -81,6 +81,7 @@
 Depends: ${shlibs:Depends}, ${misc:Depends},
  libuutil1 (= ${binary:Version}), libnvpair1 (= ${binary:Version}),
  libzfs1 (= ${binary:Version}), libumem1 (= ${binary:Version}), libzpool1 (= ${binary:Version})
+Recommends: cron
 Breaks:
 # Require GRUB with ZFS v28 support to ensure "zpool upgrade" doesn't render
 # system unbootable.

Added: trunk/zfsutils/debian/local/default/zfs
===================================================================
--- trunk/zfsutils/debian/local/default/zfs	                        (rev 0)
+++ trunk/zfsutils/debian/local/default/zfs	2011-12-07 20:05:59 UTC (rev 3936)
@@ -0,0 +1,9 @@
+# Space-separated list of filesystems you want automated snapshots for.
+#AUTOSNAP_FILESYSTEMS=""
+
+# Maximum number of automated snapshots that may be preserved at any
+# given time.  This variable is optional; if it isn't set, snapshots
+# will increase without limit.  However, 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).
+#AUTOSNAP_MAX_SNAPSHOTS="2"

Added: trunk/zfsutils/debian/zfsutils.cron.daily
===================================================================
--- trunk/zfsutils/debian/zfsutils.cron.daily	                        (rev 0)
+++ trunk/zfsutils/debian/zfsutils.cron.daily	2011-12-07 20:05:59 UTC (rev 3936)
@@ -0,0 +1,68 @@
+#!/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

Modified: trunk/zfsutils/debian/zfsutils.install
===================================================================
--- trunk/zfsutils/debian/zfsutils.install	2011-12-07 14:58:56 UTC (rev 3935)
+++ trunk/zfsutils/debian/zfsutils.install	2011-12-07 20:05:59 UTC (rev 3936)
@@ -4,3 +4,4 @@
 cddl/usr.bin/ztest/ztest			/usr/bin
 cddl/usr.sbin/zdb/zdb				/usr/sbin
 debian/local/bash_completion.d/zfsutils		/etc/bash_completion.d
+debian/local/default/zfs			/etc/default




More information about the Glibc-bsd-commits mailing list