User Tools

Site Tools


freebsd:zfshealthscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
freebsd:zfshealthscript [2016/03/11 13:14]
tschulz [Checkpool]
freebsd:zfshealthscript [2017/01/09 14:12]
tschulz [ZFS Rep]
Line 30: Line 30:
  
 ===== ZFS Scrub ===== ===== ZFS Scrub =====
 +  * Check to see if it's the weekend then scrub main pool
 <file bash zfsScrubOnSat.sh>​ <file bash zfsScrubOnSat.sh>​
 #!/bin/sh #!/bin/sh
  
 WEEKDAY="​`date | cut -d " " -f1`" WEEKDAY="​`date | cut -d " " -f1`"
 +POOL="​tank"​
  
 if [ ${WEEKDAY} = "​Sat"​ ] if [ ${WEEKDAY} = "​Sat"​ ]
 then then
         echo "​It'​s Saturday Running Scrub"         echo "​It'​s Saturday Running Scrub"
-        zpool scrub tank+        zpool scrub ${POOL}
 else else
         echo "​It'​s not Saturday, exiting"​         echo "​It'​s not Saturday, exiting"​
Line 44: Line 46:
 </​file>​ </​file>​
  
 +===== ZFS Rep =====
 +<file bash zfs_rep.sh>​
 +#!/bin/sh
 + 
 +pool="​tank/​vol2"​
 +destination="​zroot"​
 +remote_pool="​zroot/​vol2"​
 +host="​10.1.0.61"​
 + 
 +today=`date +"​%Y-%m-%d"​`
 +#​yesterday=`date -v -1d +"​$type%Y-%m-%d"​`
 +yesterday="​2017-01-07"​
 + 
 +# create today snapshot
 +snapshot_today="​${pool}@${today}"​
 +# look for a snapshot with this name
 +if zfs list -H -o name -t snapshot | sort | grep "​${snapshot_today}"​ > /dev/null; then
 + echo " snapshot, ${snapshot_today},​ already exists"​
 +# exit 1
 +else
 + echo " taking todays snapshot, ${snapshot_today}"​
 + zfs snapshot -r ${snapshot_today}
 +fi
 + 
 +# look for yesterday snapshot
 +snapshot_yesterday="​$pool@$yesterday"​
 +snapshot_yesterday_r="​$remote_pool@$yesterday"​
 +snapshot_today_r="​$remote_pool@${today}"​
 +
 +#echo $snapshot_yesterday
 +if  ssh root@$host "zfs list -H -o name -t filesystem | sort | grep \"​${remote_pool}\""​ > /dev/null; then
 +    echo " Pool found on remote"​
 +else
 +    echo " Pool missing on remote, aborting"​
 +    exit 1;
 +fi
 +if zfs list -H -o name -t snapshot | sort | grep "​${snapshot_yesterday}"​ > /dev/null; then
 + echo " yesterday snapshot, ${snapshot_yesterday},​ exists locally"​
 + if ssh root@$host "zfs list -H -o name -t snapshot | sort | grep \"​${snapshot_yesterday_r}\""​ > /dev/null; then
 + echo " yesterday snapshot, ${snapshot_yesterday_r},​ exists on destination"​
 + if ssh root@$host "zfs list -H -o name -t snapshot | sort | grep \"​${snapshot_today_r}\""​ > /dev/null; then
 +            echo " Remote already has today'​s snapshot aborting sync"
 +            exit 2
 + else
 +            echo " proceeding with incremental sync"
 +            zfs send -R -i ${snapshot_yesterday} ${snapshot_today} | ssh root@$host "zfs receive -Fduv ${destination}"​
 +            echo " sync complete"​
 +            exit 0;
 +        fi
 + else
 + echo " yesterday snapshot, ${snapshot_yesterday_r},​ missing on destination"​
 + if ssh root@$host "zfs list -H -o name -t snapshot | sort | grep \"​${snapshot_today_r}\""​ > /dev/null; then
 +            echo " Remote already has today'​s snapshot aborting sync"
 +            exit 2
 + else
 +            echo " proceeding with full sync"
 +            zfs send ${snapshot_today} | ssh root@$host "zfs receive -Fduv ${destination}"​
 +            echo " sync complete"​
 +            exit 0;
 +        fi
 + fi
 +else
 + echo " missing yesterday snapshot aborting, ${snapshot_yesterday}"​
 + exit 1
 +fi
 +
 +</​file>​
freebsd/zfshealthscript.txt · Last modified: 2017/01/18 14:06 by tschulz