Added an already running check
[zfs-nexenta/.git] / zfs-autosnap-wrapper
1 #!/bin/bash
2
3 # Author: Alan J. Pippin
4 # Description: This script is a wrapper script that calls zfs-autosnap
5 #              for each filesystem provided below.
6
7 # source our configuration
8 config="${0%/*}/zfs-scripts.conf"
9 [ -e "${config}.dist" ] && . ${config}.dist
10 [ -e "${config}" ] && . ${config}
11
12 # Setup some default values
13 logfile="$logdir/zfs-autosnap.log"
14 numsnapshots=20
15 maxagedays=365
16 date=`date`
17 mylockdir="/tmp/zfs-autosnap-all"
18 current_hour=`date +"%H"`
19 current_minute=`date +"%M"`
20 current_day=`date +"%u"`
21
22 # Make sure we aren't already running
23 if ! mkdir "$mylockdir" >/dev/null 2>&1; then
24   echo "$date Another $0 process is already running" >> $logfile
25   exit 1
26 fi
27
28 # Auto snapshot every zfs filesystem on the system specified below
29 date >> $logfile
30
31 # Special filesystems
32 # ex: zfs-autosnap storage /storage $numsnapshots 15
33 # ex: zfs-autosnap tank/usr/videos /usr/videos $numsnapshots 15
34
35 # Normal filesystems
36 # ex: zfs-autosnap tank / $numsnapshots $maxagedays 
37 # ex: zfs-autosnap tank/home /home $numsnapshots $maxagedays
38
39 # Daily filesystems (only perform these at midnight)
40 # midnight = true if (midnight < current time < midnight+5 min)
41 if [[ $current_hour == "00" && $current_minute -lt 5 ]]; then
42    echo "Performing Daily snapshots" >> $logfile
43 fi
44
45 # Weekly filesystems (only perform these on Sunday at midnight)
46 # midnight = true if (midnight < current time < midnight+5 min)
47 if [[ $current_day == "7" && $current_hour == "00" && $current_minute -lt 5 ]]; then
48   echo "Performing Weekly snapshots" >> $logfile
49 fi
50
51 rm -rf "$mylockdir"