Skip to content

Instantly share code, notes, and snippets.

@timmillwood
Forked from webbj74/drupal-quick-dump.sh
Last active October 28, 2019 07:49
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save timmillwood/3852923 to your computer and use it in GitHub Desktop.
Save timmillwood/3852923 to your computer and use it in GitHub Desktop.
Script to dump Drupal database structure, but exclude data from massive/unneeded tables.
#!/bin/bash
# usage: drupal-quick-dump user host database
USER="$1"
HOST="$2"
DB="$3"
DATE=`date +%Y%m%d`
# Get User Password
echo "Please provide the password for ${USER} on db ${DB} hosted at ${HOST}:"
read -se PASS
# Dump Structure
echo "Starting to dump the table structure."
TABLES=`mysql --skip-column-names -e 'show tables' -u ${USER} -p${PASS} -h ${HOST} ${DB}`
mysqldump --complete-insert --disable-keys --single-transaction --no-data -u ${USER} --password=${PASS} -h ${HOST} ${DB} ${TABLES} > ${DB}.${DATE}.sql
# Dump Data, Excluding Certain Tables
echo "Starting to dump the table data."
TABLES2=`echo "$TABLES" | grep -Ev "^(accesslog|cache.*|flood|search_.*|semaphore|sessions|watchdog)$"`
mysqldump --complete-insert --disable-keys --single-transaction --no-create-info -u ${USER} --password=${PASS} -h ${HOST} ${DB} ${TABLES2} >> ${DB}.${DATE}.sql
echo "Starting to gzip dump."
gzip -v ${DB}.${DATE}.sql
echo "Done!"
@webbj74
Copy link

webbj74 commented Jun 20, 2013

Need to put double quotes around ${PASS}, so that passwords with spaces can work.

I'm working on an update to handle passwords with spaces... just adding quotes didn't work.

@webbj74
Copy link

webbj74 commented Jun 21, 2013

Here's the fix for the problem with spaces:
https://gist.github.com/webbj74/3852713

You should be able to add my commits if you:

$ git clone https://gist.github.com/3852923.git drupal-quick-dump
$ cd drupal-quick-dump
$ git remote add webbj74 https://gist.github.com/3852713.git
$ git merge webbj74/master
# fix any conflicts & commit
$ git push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment