-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmysql-stripped-dump
executable file
·84 lines (63 loc) · 1.42 KB
/
mysql-stripped-dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/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