Skip to content

Instantly share code, notes, and snippets.

@zerolab
Last active August 29, 2015 14:03
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 zerolab/bf24eec4e8e21faccc87 to your computer and use it in GitHub Desktop.
Save zerolab/bf24eec4e8e21faccc87 to your computer and use it in GitHub Desktop.
db_clean.sh
#!/bin/bash
#
# Remove INSERTs from tables you don't want in the database using a rather horrid grep hack.
# This probably assumes that the original mysqldump was performed with the --opt flag.
#
set -e
if [ -z "$1" ]; then
echo "You must specify an sql file"
exit 1
fi
echo "Copying: $1 to db.sql"
cp $1 db.sql
# Iterate over the tables we want to remove INSERTs for
j="";
for i in cache_ search_index search_dataset search_node_links search_total watchdog webform_submissions webform_submitted_data xmlsitemap apachesolr_search_node node_comment_statistics sessions; do echo "Removing: $i";
cat db$j.sql | grep -v 'INSERT INTO `'$i > db$i.sql;
rm db$j.sql
j=$i;
done;
echo "Moving: db$j.sql to db.sql"
mv db$j.sql db.sql
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment