I am trying to sync a bunch of domains (a.com, b.com, and c.com) on a bunch of load balanced web nodes (w1, w2, w3).
I plan to build to node 1 (w1) and then rsync to the others with something like this:
rsync -arv /var/www/vhosts/a.com/ root@w1:/var/www/vhosts/a.com/
With a dynamic script like (assume I’m on w1 already) :
#!/bin/bash
DOMAINS="a.com b.com c.com"
NODES="w2 w3"
for DOMAIN in $DOMAINS; do
for NODE in $NODES; do
COMMAND="rsync -arv --exclude 'logs' --exclude '.git' /var/www/vhosts/$DOMAIN/ root@$NODE:/var/www/vhosts/$DOMAIN/"
echo "$COMMAND"
"$COMMAND"
done
done
The first, manual, rsync works just fine. But for some reason my batch rsync script is breaking.
Anyone care to help debug for me? Thanks.
You have some excessive quoting going on there. Change this line:
To this:
When you put quotes around the whole thing, the shell interprets it as a single “token”. Here’s a simple example: