Module Monday: Drush Search & Replace

A very powerful Drush extension

Have you needed to change all occurrences of a domain, filepath, or text string within your site? Normally this would involve a lot of planning and custom queries. Drush Search & Replace fixes that problem.

Warning! This is a very powerful drush extension. If used incorrectly it can actually destroy data integrity or cause data loss which can not be reverted. Please test on development environment, backup your site, and use at your own risk.

This module will iterate through all text fields, text areas and blocks you have on your site, look for a specific string and replace it with one you provide. It will also update all revisions of those fields and blocks as well. This is great if you had previously used absolute paths in text fields or text areas of existing content, but then changed the domain of your site or the path to your site's files directory. A simple drush command will fix all occurrences.

Examples
changing domains

  
~ drush sar old.com new.com
  

changing filepath

  
~ drush sar sites/default/files sites/new.com/files
  

 

You will be warned that this change is non-revertible. Upon confirming that you have in fact created a database backup and want to execute this command, the extension will report back as to how many occurrences for each field it has updated.

A few things I would have liked to see in this module are:

I stumbled across this module a couple weeks ago and have used it more than once since than. The fact that these changes are permanent and affects many tables, I would only suggest using it at times when I know it's the right tool for the job.

If you use drush to download this "module" you'll notice it gets installed into your drush directory, not in the sites module directory. Because of this it can be used on any site you have setup. Drush Search & Replace one of a few modules that ships with a risk disclaimer.

Published in:

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!