Added code to fallback to lists of snapshots to find common point
[zfs-nexenta/.git] / zfs-autosnap-wrapper
index 2e500e1196b284796dd349712aba697d1e138579..813d9fe6140edbe2188df8bc057da490b37616af 100755 (executable)
@@ -6,9 +6,17 @@
 
 # Setup some default values
 autosnap="/usr/local/etc/bin/zfs-autosnap"
-logfile="/var/log/zfs-autosnap.log"
+logfile="/var/log/zfs/zfs-autosnap.log"
+lockdir="/tmp/zfs-autosnap-all"
 numsnapshots=20
 maxagedays=365
+date=`date`
+
+# Make sure we aren't already running
+if ! mkdir "$lockdir" >/dev/null 2>&1; then
+  echo "$date Another $0 process is already running" >> $logfile
+  exit 1
+fi
 
 # Auto snapshot every zfs filesystem on the system specified below
 date >> $logfile
@@ -27,7 +35,14 @@ $autosnap tank/usr/local/etc /usr/local/etc $numsnapshots $maxagedays
 
 # Daily filesystems (only perform these at midnight)
 if [ `date +"%H:%M"` == "00:00" ]; then 
-  $autosnap tank/var /var $numsnapshots $maxagedays
-  $autosnap tank/usr/local/var /usr/local/var $numsnapshots $maxagedays
+   echo "Performing Daily snapshots" >> $logfile
+fi
+
+# Weekly filesystems (only perform these on Sunday at midnight)
+if [ `date +"%H:%M:%u"` == "00:00:7" ]; then
+  echo "Performing Weekly snapshots" >> $logfile
+  $autosnap tank/var /var $numsnapshots 60
+  $autosnap tank/usr/local/var /usr/local/var $numsnapshots 60
 fi
 
+rm -rf "$lockdir"