Skip to content

Instantly share code, notes, and snippets.

@ferdnyc
Created May 22, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferdnyc/22d10303bb5df398434f to your computer and use it in GitHub Desktop.
Save ferdnyc/22d10303bb5df398434f to your computer and use it in GitHub Desktop.
Code snippets for a comment at dpedu.io
# I realize this post is a year old, and I'm not sure whether you even use this script anymore,
# but I thought I'd mention a couple of optimizations that might help out anyone else using it.
# Sed accepts multiple commands in a single invocation, so you can eliminate one tempfile by
# combining the two sed commands into one call:
sed -e '/^INSERT_INTO `drupal_cache/d;/^INSERT_INTO `drupal_watchdog`/d;' < dump_raw.sql > dump.sql
# However, thanks to the power of regular expressions, this could even be combined into a single regexp
# that matches both lines of interest:
sed -e '/^INSERT_INTO `drupal_\(cache\|watchdog`\)/d;' < dump_raw.sql > dump.sql
# Either of these forms will significantly speed up the processing on large dumps, because it will
# only have to scan through the entire file once. I'm not sure whether there's anything to argue one
# form over the other, my suspicion is that sed's regexp processing is optimized well enough to make
# the differences negligible.
# By the same token, here-docs let us use cat to replace all three of those echo statements:
cat >> dump.sql << '__EOF__'
UPDATE `drupal_variable` SET `value`='s:27:\"sites/dpedu.io/privatefiles\";' WHERE `name`='file_private_path';
UPDATE `drupal_variable` SET `value`='s:20:\"sites/dpedu.io/files\";' WHERE `name`='file_public_path';
UPDATE `drupal_variable` SET `value`='s:4:\"/tmp\";' WHERE `name`='file_temporary_path';
__EOF__
# (The single-quotes around the here-doc terminator ('__EOF__') cause the entire here-doc to be interpreted
# as if it's wrapped in single quotes, which eliminates the need for all of that tedious escaping.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment