3 # Author: Alan J. Pippin
4 # Description: This script calls zfs-replicate for each filesystem needing
5 # to be backed up, or replicated, to another ZFS pool.
7 # Setup some default values
8 replicate="/usr/local/etc/bin/zfs-replicate"
9 logfile_parser="/usr/local/etc/bin/zfs-log-parser"
10 logfile="/var/log/zfs-replicate.log"
11 lockdir="/tmp/zfs-admin-lock"
16 # Setup our cleanup and exit trap
19 if [ $released_lock_date == 0 ]; then
20 echo `date` ZFS admin lock released >> $logfile
25 # Auto snapshot every zfs filesystem on the system specified below
27 echo "$date Polling for ZFS admin lock" >> $logfile
29 # Poll for a lock on the zfs subsystem, and make the lock once we can do so
31 if ! mkdir "$lockdir" >/dev/null 2>&1; then
32 # Another zfs admin tool is running.
33 # Wait a random amount of time and try again
34 ransleep=$(($RANDOM % $maxsleeptime))
37 # No other zfs admin tool is running, we can now.
42 echo "$date ZFS admin lock obtained" >> $logfile
44 # Poweron the destpool and import it
45 /usr/local/bin/br -x /dev/ttyd0 A3 ON
47 zpool import $destpool
49 # List the filesystems to replicate
50 # The parent filesystems MUST be listed ahead
51 # of the children filesystems.
52 # Pool root filesystems must end with a slash.
53 $replicate tank/ $destpool
54 $replicate tank/var $destpool
55 $replicate tank/usr $destpool
56 $replicate tank/usr/home $destpool
57 $replicate tank/usr/videos $destpool
58 $replicate tank/usr/local $destpool
59 $replicate tank/usr/local/etc $destpool
60 $replicate tank/usr/local/var $destpool
61 $replicate tank/backup $destpool
63 # Export the destpool and power it down
64 zpool export $destpool
65 /usr/local/bin/br -x /dev/ttyd0 A3 OFF
69 echo `date` ZFS admin lock released >> $logfile
71 # Parse the log file and extract our backup stats
72 $logfile_parser "$logfile" "$date" >> $logfile