Another iWeb + Apache tidbit: using rsync
Posted by: tygerbox in Mac, Tech, tags: Apache, How-To, iWeb, OS X, rsyncSeems like most of the “external” hits to my blog are being generated by Google searches hitting my second blog entry. In the aforementioned entry, that arises when using iWeb to “publish to a folder” when you don’t wish to host your site on the Mac hosting service. So, since people seem to be finding this blog by Google searches like “using iWeb with Apache” I thought I would toss out another thing I do when using iWeb to publish to other hosting platforms.
If you’re using iWeb you’re obviously using some flavor of OS X which means you have a UNIX shell utility on your system called rsync. It’s a file transfer utility that is far more flexible and interesting than FTP, and since you can do it over SSH, you have more options when transferring your files to some sort of shell-based hosting environment since many places allow SSH use since it’s far more secure than things like FTP. Moreover, rsync is smart enough to figure out which files have changed since you last used it so it will only transfer the new files rather than: 1) having to copy over your entire site every time; or 2) figure out what the new files are and copy them manually. Finally, if you remove pages locally, it will remove them from the remote server as well. This does involve using the terminal program. so if that freaks you out, then I can’t help you – but I will address how you can streamline the process somewhat.
The basic command you want to issue (from the terminal) will look something like this:
rsync -vrca –delete –rsh=ssh /Users/username/Sites/sitename/ username@www.example.com:/www/docroot
The first file path is the pathname to where iWeb stores your published site when you publish it to a folder. The default place is in the “Sites” subdirectory of your home directory and the “sitename” defaults to what you named your site at the top level. Note the trailing ‘/’ on the path name – it tells rsync to push out the entire contents of that folder. The hostname “www.example.com” should be replaced with the name of the machine your site is hosted on and the “username@” is your username on that machine. Finally, the path after the ‘:’ (no spaces between hostname and that) is the document root of where your website files go on the hosting server. Note the lack of a trailing slash on that.
If you run that command, it will take all your “publish(ed) to a folder” iWeb files and transfer them to the proper spot after prompting you for your passphrase. And when you update your site, it will only push out the new files, or ones that have been changed rather than transferring everything. And entries/files/images that have been deleted, will also be removed at the remote end. Play with this until it’s putting the files from the right place, to the right place (will involve tweeking your file paths to taste).
For the non-UNIX-savvy, here is an easy way to automate this process rather than having to deal with this rather cumbersome command (requires administrative access on your Mac):
1) Edit the file /etc/bashrc to include the following line: source ~/.bashrc (admin access needed).
2) In the root of your home directory create a file called .bashrc if it does not already exist (note leading ‘.’ character) and add the following line to it:
alias publish=”your long tailor-made rsync command” (quotation marks included)
3) If you want to execute the command immediately, execute the command: source .bashrc (optional).
Now, all you need to do whenever you are ready to push out new changes to your iWeb publish(ed) to a folder website, just open the terminal program and type publish (or whatever you named the alias). There are probably other Mac-oriented ways to alias this command, but this is the UNIX way and that’s all I know.
Cheers.
Entries (RSS)