I would like to rsync some HTML files to a webserver that are in production form. To get them in production form I have to trivially insert a ".production" string in a script tag. I can do this with this sed command:

sed 's/steal\.js/steal\.production\.js/g' */*.html

I know I can sed -i inplace and rysync those files then sed -i them back when I'm done, but I'd like to be able to do something like rsync standard out to a destination file on the remote machine. This way I wouldn't ever need to worry about corrupting my html files by canceling the script in mid transfer.

Any recommendations on how to approach this?


If you've got a little spare disk space (it's cheap these days, right?), you could do a local rsync from your development tree to a second copy of the project -- a "staging" tree -- on your development box. Then perform whatever production modifications you need on the staging tree, and do the "real" rsync from the staging tree to the production server.

You can keep the staging tree around for extra deployment speed, or delete it afterwards to free up space; it's up to you.

Or, you could keep the staging tree on the production server instead. In this case, you can do just one rsync, make your changes, then do a few quick directory renames so that the staging tree is now the production tree, and the old production tree is now the staging tree. This way you never have a partially updated site in production.


I would suggest that having to access different file names on devel and production boxes is a hack you should consider removing.

  • You could use version control to keep a devel and a production branch of the same project. Keep merging the devel into your production branch but use your little script to keep the code in production state before commiting that branch. Use your server to checkout the production branch, or only rsync that one across.
  • You could have a bit of server side code decide which filename to use: if (hostname = productionserver) ...
  • You could use a server side redirect to serve up different files under the same request url based on hostname or some sort of tag file inside your project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.