Skip to content
Find file
bd163fb Jul 23, 2012
Alexander Menk Fix
executable file 85 lines (63 sloc) 1.42 KB
#!/bin/bash
# Exports a database while stripping the data of some tables
# Useful for setting up a development system that does not need log-data and so on
#
# Alexander Menk, 13. Apr 2012
# License: https://github.com/amenk/SelfScripts/blob/master/LICENSE.md
### Configuration
DB=
USER=
PASS=
HOST=localhost
usage()
{
cat << EOF
usage: $0 options table1 table2 table3 ...
Exports a mysql database, stripping the data from table1, table2, ...
Example for a magento database:
$0 -h localhost -d magento_db-u myuser -p mypass report_event
OPTIONS:
-h Host (default: localhost)
-d Database
-u User
-p Password
EOF
}
OPTIND=1
while getopts “h:d:u:p:” OPTION
do
case $OPTION in
h)
HOST=$OPTARG
;;
d)
DB=$OPTARG
;;
u)
USER=$OPTARG
;;
p)
PASS=$OPTARG
;;
?)
usage
exit
;;
esac
done
if [[ -z $DB ]] || [[ -z $USER ]] || [[ -z $PASS ]]
then
usage
exit 1
fi
shift $(($OPTIND - 1))
# Tables to strip (export only structure)
STRIP=$*
### Main Program
ignore_tables=""
for I in $STRIP
do
ignore_tables="${ignore_tables} --ignore-table=$DB.$I"
done
mysqldump --no-data --single-transaction -h$HOST -u$USER -p$PASS $DB $STRIP
mysqldump --single-transaction $ignore_tables -h$HOST -u$USER -p$PASS $DB
Something went wrong with that request. Please try again.