[PVE-User] can't make zfs-zsync working

Jean-Laurent Ivars jl.ivars at ipgenius.fr
Mon Sep 28 10:37:56 CEST 2015


I had no answer so I tough the mailing list wasn’t working for me…. I made a change in the wiki for other people not struggle like i have (completely insane the script can’t work with hostname…

If someone is interested i made cool script. What the script make is to keep in sync in both the hosts, create a new log file everyday to log all the sync and send you an email containing the log file if something bad happens. In fact it's a loop and the goal is to always have the most recent copies of the vm disk on both sides. Almost as interesting than DRBD but without the split-brain complications :)
In my case for exemple i have approximately 15 KVM VM witch are not to much solicited and the script need 1 minute to make a loop, I think during solicited period maybe 2 or 3 minutes, surely less than 5... It's all new so i have not experience with it, if someone use it i would be very happy if he let me know how it works for him. 

It's made to work almost "out of the box"" in a full ZFS Proxmox installation in a two hosts cluster only, if your configuration is different you will have to adapt it...

You just have to verify that you have following packages installed : pve-zsync and screen, you will have to put your mail address in the var monmail at the beginning of the script.

Sorry all the comments in the script are in french, hope you will understand :)

#!/bin/bash


monmail="admin at mydomain.com"


gosync() {
##On commence la boucle
while true;do
## Creation du log (on verifie que le dossier des logs est cree avant)
if [ ! -d "/var/log/syncro" ];then
mkdir -p /var/log/syncro
fi
logfic="/var/log/syncro/syncro-`date '+%d-%m-%Y'`.log"
##On detecte sur quelle machine on se trouve et quelle est la machine distante
loc=`hostname`
dist=`ls /etc/pve/nodes/ | grep -v $loc`
###On recupere les ID des VM qui utilisent zfs locales puis de VM distantes
vmloc=`grep rpool /etc/pve/nodes/$loc/qemu-server/*.conf | cut -d / -f 7 | cut -d . -f 1`
vmdist=`grep rpool /etc/pve/nodes/$dist/qemu-server/*.conf | cut -d / -f 7 | cut -d . -f 1`
###On recupere l'IP de l'hote distant
ipdist=$(ping -c 1 $dist | gawk -F'[()]' '/PING/{print $2}')
##On vérifie la présence du répertoire des hotes du cluster
if [ ! -d "/etc/pve/nodes/" ]; then
echo "PB avec le cluster a `date '+%d-%m-%Y_%Hh%Mm%Ss'`" >> $logfic
##On laisse une trace d'envoi de mail et on l'envoie
if [ $logfic != `cat /tmp/mail.tmp` ];then
echo $logfic > /tmp/mail.tmp
cat $logfic | mail -s "PB Syncro ZFS" $monmail;
fi
fi


echo "syncro des machines de $loc vers $dist" >> $logfic
for n in $vmloc
do
if test -f "/tmp/stopsync.req"
then
rm /tmp/stopsync.req
touch /tmp/stopsync.ok
exit 0
else
echo "debut syncro de la machine $n a `date '+%d-%m-%Y_%Hh%Mm%Ss'`" >> $logfic
pve-zsync sync --source $n --dest $ipdist:rpool/lastsync --maxsnap 1 --verbose >> $logfic
if test ${?} -eq 0 ; then
echo "syncro de la machine $n finie a `date '+%d-%m-%Y_%Hh%Mm%Ss'`" >> $logfic
else
##On laisse une trace d'envoi de mail et on l'envoie
if [ $logfic != `cat /tmp/mail.tmp` ];then
echo $logfic > /tmp/mail.tmp
cat $logfic | mail -s "PB Syncro ZFS" $monmail;
fi
fi
fi
done


echo "syncro des machines de $dist vers $loc" >> $logfic  
for n in $vmdist
do
if test -f "/tmp/stopsync.req"
then
rm /tmp/stopsync.req
touch /tmp/stopsync.ok
exit 0

else 
echo "debut syncro de la machine $n a `date '+%d-%m-%Y_%Hh%Mm%Ss'`" >> $logfic
pve-zsync sync --source $ipdist:$n --dest rpool/lastsync --maxsnap 1 --verbose >> $logfic
if test ${?} -eq 0 ; then
echo "syncro de la machine $n finie a `date '+%d-%m-%Y_%Hh%Mm%Ss'`" >> $logfic
else
##On laisse une trace d'envoi de mail et on l'envoie
if [ $logfic != `cat /tmp/mail.tmp` ];then
echo $logfic > /tmp/mail.tmp
cat $logfic | mail -s "PB Syncro ZFS" $monmail;
fi
fi
fi


done


done
}


stop() {
touch /tmp/stopsync.req
##On commence une nouvelle boucle pour attendre que la syncro en cours soit finie
while true;do
if test -f "/tmp/stopsync.ok"
then
echo "Arret de la syncro : OK"
##Et l'arret du script en lui meme
rm /tmp/stopsync.ok
kill $$
exit 0
else
echo "Arret en cours..."
echo "la syncronisation en cours se finit, cela peut durer un peu..."
sleep 3	
fi
done	
}


case "$1" in
gosync)
gosync
;;
start)
screen -d -m -S syncro-zfs bash -c '/root/scripts/syncro-zfs gosync'
echo "Lancement de la syncronisation : OK"
echo "taper la commande 'screen -r syncro-zfs' pour voir la sortie standard."
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}" >&2
exit 1
;;
esac


Hope you will like it, please let me know.

Best regards,



	
Jean-Laurent Ivars 
Responsable Technique | Technical Manager
22, rue Robert - 13007 Marseille 
Tel: 09 84 56 64 30 - Mobile: 06.52.60.86.47 
Linkedin <http://fr.linkedin.com/in/jlivars/>   |  Viadeo <http://www.viadeo.com/fr/profile/jean-laurent.ivars>   |  www.ipgenius.fr <https://www.ipgenius.fr/>
> Le 28 sept. 2015 à 08:18, Michael Rasmussen <mir at miras.org> a écrit :
> 
> On Mon, 28 Sep 2015 08:14:42 +0200 (CEST)
> Wolfgang Bumiller <w.bumiller at proxmox.com> wrote:
> 
>>> root at cyclone ~ # pve-zsync sync --source 106  --dest ouragan:rpool/BKP_24H
>>> --verbose   
>> 
>> I just checked the source - apparently we currently only allow ip(v4) addresses
>> there, no hostnames (this still needs changing...).
>> 
> And IPv6?
> 
> -- 
> Hilsen/Regards
> Michael Rasmussen
> 
> Get my public GnuPG keys:
> michael <at> rasmussen <dot> cc
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xD3C9A00E
> mir <at> datanom <dot> net
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE501F51C
> mir <at> miras <dot> org
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE3E80917
> --------------------------------------------------------------
> /usr/games/fortune -es says:
> Nature makes boys and girls lovely to look upon so they can be
> tolerated until they acquire some sense.
> 		-- William Phelps
> _______________________________________________
> pve-user mailing list
> pve-user at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.proxmox.com/pipermail/pve-user/attachments/20150928/e7633124/attachment.htm>


More information about the pve-user mailing list