Last active
August 29, 2015 14:03
-
-
Save zerolab/bf24eec4e8e21faccc87 to your computer and use it in GitHub Desktop.
db_clean.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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