-
Notifications
You must be signed in to change notification settings - Fork 12
/
mysqlrestorep.sh
executable file
·55 lines (45 loc) · 1.11 KB
/
mysqlrestorep.sh
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
#!/usr/bin/env bash
USER=$1
DATABASE=$2
DIRECTORY=$3
HOST=$4
PORT=$5
# Validate our arugments and ensure that GNU parallel is available.
if [[ -z $DIRECTORY ]]
then
echo "Usage: mysqlrestorep.sh <user> <database> <directory> [host] [port]"
exit 1
fi
if [[ -z $HOST ]]
then
HOST='localhost'
fi
if [[ -z $PORT ]]
then
PORT=3306
fi
PARALLEL=`type -P parallel`
if [[ -z $PARALLEL ]]
then
echo "GNU Parallel is required. Install it from your package manager or from"
echo "https://savannah.gnu.org/projects/parallel/."
exit 1
fi
BZIP2=`type -P lbzip2`
if [[ -z $BZIP2 ]]
then
echo "lbzip2 was not found. Falling back to bzip2. Consider installing lbzip2 for improved"
echo "performance."
BZIP2=`type -P bzip2`
fi
cd $DIRECTORY
echo -n "Please enter your mysql password for $USER: "
read -s PASS
echo ""
if [ -z "$PASS" ]
then
time ls -S *.sql.bz2 | $PARALLEL -I, echo "Importing table ,." \&\& $BZIP2 -kcd , \| mysql -u $USER -h$HOST -P$PORT $DATABASE
else
time ls -S *.sql.bz2 | $PARALLEL -I, echo "Importing table ,." \&\& $BZIP2 -kcd , \| mysql -u $USER -h$HOST -P$PORT -p"'$PASS'" $DATABASE
fi
cd -