Unhugeifying drupal database dumps

If you are moving a drupal 6 production database back to development, you really don't need to be hauling around years of logs and old sessions in your database.

Your first option is to use the Backup and Migrate module to leave these tables out of the export file in the first place.

However if someone helpfully delivers you a 700MB .sql file with all of the unnecessary tables still in it, you can trim it down to size with the following commands.

First make a backup. Note you will need the disk space for this.

cp databasedump.sql databasedump.sql.backup

Now, these commands destroy the insert statements for the uneeded data. The table creation statements are on separate lines, and so should be fine.

sed -i '/INSERT INTO `accesslog`/d' databasedump.sql
sed -i '/INSERT INTO `sessions`/d' databasedump.sql

Then import and see if everything works. Keep your backup file around just in case until development is finished, and everything is peachy.