generic zroot (sort of) + lockfile support
This commit is contained in:
parent
acff4503de
commit
e6cb9cfa3f
1 changed files with 28 additions and 8 deletions
36
zfsync.sh
36
zfsync.sh
|
@ -3,26 +3,42 @@
|
|||
# zfsync: sync zfs pool(s) between two servers
|
||||
|
||||
# in case of failure, unepexpected reboot while syncing, etc.:
|
||||
#
|
||||
# launch "zfsync.sh init"
|
||||
#
|
||||
# or manually:
|
||||
#
|
||||
# - destroy all snapshots on both local & ${bro}
|
||||
# - for i in ftp web mail; do zfs snapshot servers/$i/home@newsync ;done
|
||||
# - for i in ftp web mail; do zfs send servers/$i/home@newsync | ssh ${bro} zfs receive -vFd servers ;done
|
||||
# - for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done
|
||||
# - ssh ${bro} "for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done"
|
||||
# - ssh ${bro} 'for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done'
|
||||
|
||||
|
||||
bro="small"
|
||||
pools="ftp mail web"
|
||||
|
||||
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ <nagios_host>\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
|
||||
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ 192.168.3.3\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
|
||||
HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,1`
|
||||
SERVICENAME=zfsync
|
||||
LOGFILE=/tmp/zfsync.log
|
||||
LOCKFILE=/tmp/zfsync.lock
|
||||
ZROOT=zdata/servers
|
||||
sync_success=1
|
||||
|
||||
if [ -e $LOCKFILE ]
|
||||
then
|
||||
echo "ERROR: $0 is already running with pid `cat $LOCKFILE`, check $LOCKFILE"
|
||||
exit 1
|
||||
fi
|
||||
echo ${$}>$LOCKFILE
|
||||
|
||||
alert()
|
||||
{
|
||||
echo "${HOSTNAME};;${SERVICENAME};;2;CRITICAL - ZFS Sync failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
|
||||
exit $?
|
||||
}
|
||||
|
||||
if [ $1 ]
|
||||
then
|
||||
if [ $1 = "init" ]
|
||||
|
@ -32,12 +48,13 @@ echo "`date`: ZFSync INIT starting."
|
|||
for snapshot in `zfs list -t snapshot -o name | grep -e prevsync -e newsync`; do zfs destroy $snapshot ; done
|
||||
ssh -q ${bro} 'for snapshot in `zfs list -t snapshot -o name | grep -e prevsync -e newsync`; do zfs destroy $snapshot ; done'
|
||||
echo "making full snapshots"
|
||||
for jail in $pools; do zfs snapshot servers/$jail/home@newsync;done
|
||||
for jail in $pools; do zfs snapshot $ZROOT/$jail/home@newsync;done
|
||||
echo "sending full snapshots"
|
||||
for jail in $pools; do zfs send servers/$jail/home@newsync | ssh -q ${bro} 'zfs receive -vFd servers' ;done
|
||||
for jail in $pools; do zfs send $ZROOT/$jail/home@newsync | ssh -q ${bro} 'zfs receive -vFd zdata' ;done
|
||||
echo "renaming them to use them as a base for diff snapshots"
|
||||
for jail in $pools; do zfs rename servers/$jail/home@newsync servers/$jail/home@prevsync ;done
|
||||
ssh -q ${bro} 'for jail in ftp mail web; do zfs rename servers/$jail/home@newsync servers/$jail/home@prevsync ;done'
|
||||
for jail in $pools; do zfs rename $ZROOT/$jail/home@newsync $ZROOT/$jail/home@prevsync ;done
|
||||
ssh -q ${bro} 'for jail in ftp mail web; do zfs rename zdata/servers/$jail/home@newsync zdata/servers/$jail/home@prevsync ;done'
|
||||
echo "`date`: ZFSync INIT ending."
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
@ -45,16 +62,19 @@ fi
|
|||
echo "`date`: ZFSync starting."
|
||||
for pool in $pools
|
||||
do
|
||||
dataset="servers/${pool}/home"
|
||||
dataset="$ZROOT/${pool}/home"
|
||||
echo "making new snapshot for ${pool}"
|
||||
zfs snapshot ${dataset}@newsync || alert
|
||||
echo "sending snapshot"
|
||||
zfs send -i prevsync ${dataset}@newsync | ssh -q ${bro} "zfs receive -vFd servers" || alert
|
||||
zfs send -i prevsync ${dataset}@newsync | ssh -q ${bro} "zfs receive -vFd zdata" || alert
|
||||
echo "cleaning"
|
||||
zfs destroy ${dataset}@prevsync || alert
|
||||
zfs rename ${dataset}@newsync ${dataset}@prevsync || alert
|
||||
ssh -q ${bro} "zfs destroy ${dataset}@prevsync && zfs rename ${dataset}@newsync ${dataset}@prevsync" || alert
|
||||
done
|
||||
echo "`date`: ZFSync ending."
|
||||
|
||||
echo
|
||||
echo "${HOSTNAME};;${SERVICENAME};;0;OK - ZFS Sync succeeded at `date`" | ${SENDNSCA} >/dev/null
|
||||
|
||||
rm -f $LOCKFILE
|
||||
|
|
Loading…
Reference in a new issue