Rsync to Update a Drupal Website
I saw a recent post by Brandon Tate about using rsync and I wanted to share that...
a) I'm a big fan of rsync, and
b) I've used rsync for some time to keep Drupal websites up-to-date
Typically, I create a staging directory on a local machine. I check the website files out, from a source code control system, into the staging directory.
Then, I run a script that uses rsync to keep the files up-to-date on the live server. The script calls rsync twice. The first invocation syncs files that should be overwritten on the web server. This includes say modules files that have been updated in my source code control. The second invocation of rsync sends files that should not be overwritten. This includes files like settings.php and .htaccess which, if I have modified on the live server, I want to keep the live server copy unchanged.
The script looks like this, notice the arguments passed to rsync determine whether it will overwrite files on the server or not. I exclude directories named 'localbase' and 'localwork' because they are aliases for 'localhost' and I often have sites/localbase and/or sites/localwork checked into my source code control. The 'htdocs/' refers to where drupal files are found. For example if I am syncing file for www.drupalforfacebook.org, I run this script from ~/stage/drupalforfacebook, and the files are found in ~/stage/drupalforfacebook/htdocs/.
#!/bin/bash<p># This determines where on the live server the files will be sent to.<br>destination=username@www.example.com:/path/to/drupal/htdocs</p><p>#First excluding files that should not be overritten<br>command="rsync $@ -rptgoDvzL --del --exclude=*~ --exclude=.htaccess --exclude=localbase --exclude=localwork --exclude=default --exclude=.svn --exclude=CVS --exclude=files --exclude=*rsync.sh htdocs/ "<br>echo $command $destination<br>$command $destination</p><p>#Next with files that may not already be there (really needed first time only)<br>command="rsync $@ -rptgoDvzL --ignore-existing --exclude=localbase --exclude=localwork --exclude=.svn --exclude=CVS htdocs/.htaccess htdocs/sites htdocs/files"<br>echo $command $destination<br>$command $destination</p>
Tags: