Last active
December 18, 2015 02:39
-
-
Save hariadi/5712380 to your computer and use it in GitHub Desktop.
Push site updates from master server to front end web servers via rsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#sync.sh - Push site updates from master server to front end web servers via rsync | |
# USAGE: | |
# ./sync.sh (rsync all node) | |
# ./sync.sh portal2 portal4 (rsync for node portal2 and portal4) | |
# | |
# Original script: http://www.stephenlang.net/2012/09/keeping-multiple-web-servers-in-sync-with-rsync/ | |
WEBSERVERS=(${@-portal1 portal2 portal3 portal4 portal5}) | |
STATUS="/srv/www/htdocs/sync.status" | |
HTDOCS="/srv/www/htdocs" | |
if [ -d /tmp/.rsync.lock ]; then | |
echo "FAILURE : rsync lock exists : Perhaps there is a lot of new data to push to front end web servers. Will retry soon." > $STATUS | |
exit 1 | |
fi | |
/bin/mkdir /tmp/.rsync.lock | |
if [ $? = "1" ]; then | |
echo "FAILURE : can not create lock" > $STATUS | |
exit 1 | |
else | |
echo "SUCCESS : created lock" > $STATUS | |
fi | |
for i in ${WEBSERVERS[@]}; do | |
echo "===== BEGINNING RSYNC OF $i =====" | |
nice -n 20 /usr/bin/rsync -avzx --delete -e ssh $HTDOCS root@$i:$HTDOCS | |
if [ $? = "1" ]; then | |
echo "FAILURE : rsync failed. Please refer to the solution documentation " > $STATUS | |
exit 1 | |
fi | |
echo "===== COMPLETED RSYNC OF $i ====="; | |
done | |
/bin/rm -rf /tmp/.rsync.lock | |
echo "SUCCESS : RSYNC COMPLETED SUCCESSFULLY" > $STATUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment