Script to sync files between web severs having plesk
I got a little assignment where there are two webservers are there behind a load balancer and both needs to have identical files. Both server has plesk control panel. As we know, plesk store website files in /var/www/vhosts/domain/httpdocs directory, here domain is the name of website. Though this script can be used in any other case, just you may need to update it little bit.
I wrote a wrapper script for rsync and deployed there. Here is the script:
#!/bin/bash ############### websync.sh by Jagbir Singh ################# # # This script acts as wrapper for rsync. It checks every domain listed in /var/www/vshots # for existence in other server, if found there, then sync domain's 'httpdocs' only directory. # # ver 1.0 Mar 8, 2009: Initial version. # ############################################################# cd /var/www/vhosts webserver2="192.168.30.2" ## get directory list ls --file-type | grep "\/" | sed 's/\///' | grep -Ev "^chroot|^default" > /tmp/dir.list exec 10</tmp/dir.list let count=0 ## check domains in other server and update them. while read LINE <&10; do ## update second webserver if domain exist there (just in case) if `ssh $webserver2 "ls /var/www/vhosts/$LINE/httpdocs/ > /dev/null 2>&1"` ; then `rsync -az --delete -e ssh /var/www/vhosts/$LINE/httpdocs/ $webserver2:/var/www/vhosts/$LINE/httpdocs/` fi ((count++)) done exec 10>&-