Created
May 8, 2013 05:13
-
-
Save jacobbednarz/5538360 to your computer and use it in GitHub Desktop.
Dump MySQL tables excluding certain tables.
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 | |
# Take a MySQL DB dump excluding some tables. | |
# | |
# 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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment