1

I've got a server where I do my web development and testing, and I have a bunch of frontend servers that sit behind a load balancer. I wrote a simple bash script to rsync a directory on my dev server to all of the production servers when I fix a bug, etc.

The rsync APPEARS to work, but when I actually go to the other servers, none of the files have been updated. What am I doing wrong?

#!/bin/bash

directory=$1

echo "$directory"

set -x
for host in "xxx.xxx.xxx.xxx"
do
    rsync -avz -e ssh ${directory} root@${host}:${directory}
done

At the moment I only have one ip address in the for loop, but I'll be adding more as time goes on. This is how I'm executing the script and the abbreviated output:

[root@admin vhosts]# ./rsync_to_frontend.sh /var/www/scripts
/var/www/scripts
+ for host in '"xxx.xxx.xxx.xxx"'
+ rsync -avz -e ssh /var/www/scripts [email protected]:/var/www/scripts
sending incremental file list
scripts/
scripts/fetchTweets.php
scripts/syncMediaFiles.log
scripts/syncMediaFiles.php
.....

sent 7395053 bytes  received 1252 bytes  2113230.00 bytes/sec
total size is 36718000  speedup is 4.96
[root@admin vhosts]#

If I run the command again, rsync appears to work appropriately and as expected does not show any files in the list, ostensibly because they've all been updated. However, when I go and look at the files on server xxx.xxx.xxx.xxx, they haven't been updated at all.

4
  • pick one file and find it in the destination, I think you are looking at (copying) to the wrong folder
    – perreal
    Jun 12, 2013 at 23:44
  • Hm, you're right. I wonder if this has to do with having a trailing slash on ${directory} Jun 13, 2013 at 0:03
  • these are equivalent: rsync -av /src/foo /dest, rsync -av /src/foo/ /dest/foo
    – perreal
    Jun 13, 2013 at 0:06
  • Right, my problem was occurring when I did rsync -av /src/foo user@host:/src/foo which was duplicating the directory as you suggested, creating /src/foo/foo Jun 13, 2013 at 0:08

1 Answer 1

1

Due to the strict requirements on trailing slashes when using rsync, I just needed to make sure to put a trailing slash when rsyncing a directory:

Bad:

# ./rsync_to_frontend.sh /var/www/scripts

vs Good:

# ./rsync_to_frontend.sh /var/www/scripts/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .