-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmdz_alt.sh
More file actions
executable file
·36 lines (34 loc) · 1.29 KB
/
mdz_alt.sh
File metadata and controls
executable file
·36 lines (34 loc) · 1.29 KB
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
# +----+----+----+----+
# | | | | |
# Author: Mark David Scott Cunningham | M | D | S | C |
# +----+----+----+----+
# Created: 2014-02-01
# Updated: 2014-03-10
#
#
#!/bin/bash
source /etc/nexcess/bash_functions.sh
_mdz(){
test -z "$1" && echo -e "\nUsage: mdz database [-0..-9|--fast|--best]\n" && return;
dbsize=$(m -e"select SUM(Data_length) FROM information_schema.TABLES WHERE TABLE_SCHEMA = \"$1\";" | tail -n1);
echo; if [ -x /usr/bin/pigz ]; then GZIP='/usr/bin/pigz'; else GZIP='/bin/gzip'; fi;
case $2 in
-b|-9|--best) LEVEL='--best';;
-f|-0|--fast) LEVEL='--fast';;
-1|-2|-3|-4|-5|-6|-7|-8) LEVEL=$2;;
*) LEVEL='--best';;
esac
if [ -x /usr/bin/pv ]; then
mysqldump --opt --skip-lock-tables \
-u"$(grep ^rootdsn= /usr/local/interworx/iworx.ini | cut -d/ -f3 | cut -d: -f1)" \
-p"$(grep ^rootdsn= /home/interworx/iworx.ini | cut -d: -f3 | cut -d\@ -f1)" $1 \
| pv -s$dbsize -N $1 \
| $GZIP $LEVEL > "$1-$(date --iso-8601=minute).sql.gz"
else
mysqldump --opt --skip-lock-tables \
-u"$(grep ^rootdsn= /usr/local/interworx/iworx.ini | cut -d/ -f3 | cut -d: -f1)" \
-p"$(grep ^rootdsn= /home/interworx/iworx.ini | cut -d: -f3 | cut -d\@ -f1)" $1 \
| $GZIP $LEVEL > "$1-$(date --iso-8601=minute).sql.gz"
fi; echo
}
_mdz "$@"