+# This function obtains the date a given snapshot was created in epoch seconds
+snapshot_age() {
+ snapshot=${local_pool}/${1}${previous_backup_marker}
+ $zfs list -t snapshot ${snapshot} > /dev/null 2>&1
+ if [ $? == 0 ]; then
+ $zfs get creation ${snapshot} > /dev/null 2>&1
+ if [ $? == 0 ]; then
+ snap_creation=`$zfs get creation ${snapshot} | grep $1 | awk '{ print $3" "$4" "$5" "$6" "$7 }'`
+ snap_age=`date -d "$snap_creation" +%s`
+ echo "$snap_age"
+ else
+ echo "0"
+ fi
+ else
+ echo "0"
+ fi
+}
+
+# Obtain the zpool guid for the local pool
+local_pool_guid=`zpool get guid $local_pool 2>&1 | grep $local_pool | awk '{ print $3 }'`
+zpool get guid $local_pool > /dev/null 2>&1
+if [ $? != 0 ]; then
+ echo >&2 "-E- Unable to extract the guid for the local pool: $local_pool"
+ exit 1
+fi
+
+# Setup our backup marker names
+current_backup_marker=@current-backup-${local_pool_guid}
+previous_backup_marker=@previous-backup-${local_pool_guid}
+
+# Auto snapshot every zfs filesystem on the system specified below
+echo "$date ZFS replicate started" >> $logfile
+echo "$date ZFS replicate started" | tee -a $mylogfile