#!/bin/bash clear ONLYPULL=1 echo "Start Sync" if [ $ONLYPULL -eq 0 ]; then #Dump local database echo "Exporting the local Database" mysqldump -h 192.168.0.41 -u root chocolatdemariage > chocolatdemariage.sql printf "Export complete => file chocolatdemariage.sql has been created\n" printf "Replacing shop names\n" sed -i -e 's/chocolatdemariage.local/chocolatdemariage.preprod.antadis.fr/g' chocolatdemariage.sql printf "Sending the Database dump to the preprod server" PORT="4096" rsync -e "ssh -p$PORT" -az ./chocolatdemariage.sql root@chocolatdemariage.preprod.antadis.fr:/home/www/chocolatdemariage.preprod.antadis.fr printf "Sending complete\n" #printf "importing the Database on the preprod server\n" ssh root@chocolatdemariage.preprod.antadis.fr -p4096 "cd /home/www/chocolatdemariage.preprod.antadis.fr \\ && git pull origin master \\ && mysql -u chocolatdemariage -pantadis78 chocolatdemariage < chocolatdemariage.sql \\ && if [ -f /home/www/chocolatdemariage.preprod.antadis.fr/www/cache/class_index.php ] ; then rm /home/www/chocolatdemariage.preprod.antadis.fr/www/cache/class_index.php ; fi \\ && mkdir -p /home/www/chocolatdemariage.preprod.antadis.fr/www/{log,upload} \\ && chown -R www-data:www-data www/* \\ " else ssh root@chocolatdemariage.preprod.antadis.fr -p4096 "cd /home/www/chocolatdemariage.preprod.antadis.fr \\ && git pull origin master \\ && if [ -f /home/www/chocolatdemariage.preprod.antadis.fr/www/cache/class_index.php ] ; then rm /home/www/chocolatdemariage.preprod.antadis.fr/www/cache/class_index.php ; fi \\ && mkdir -p /home/www/chocolatdemariage.preprod.antadis.fr/www/{log,upload} \\ && chown -R www-data:www-data www/* \\ " fi echo "Sync complete !!"