forked from lobbywatch/lobbywatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_local_db_copy_to_test.sh
executable file
·60 lines (46 loc) · 2.06 KB
/
run_local_db_copy_to_test.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
56
57
58
59
60
#!/bin/bash
# run_local_db_copy_to_test.sh [dest]
# run_local_db_copy_to_test.sh source dest
# run_local_db_copy_to_test.sh → Copies lobbywatch to lobbywatchtest
# run_local_db_copy_to_test.sh lobbywatchtest2 → Copies lobbywatch to lobbywatchtest2
# run_local_db_copy_to_test.sh lobbywatchtest2 lobbywatchtest3 → Copies lobbywatch2 to lobbywatchtest3
# Abort on errors
set -e
if [[ $# = 0 ]]; then
db_src="lobbywatch"
db_dest="lobbywatchtest"
elif [[ $# = 1 ]]; then
db_src="lobbywatch"
db_dest="$1"
elif [[ $# = 2 ]]; then
db_src="$1"
db_dest="$2"
else
echo "ERROR: wrong options"
exit 1
fi
if [[ "$db_dest" == "lobbywatch" ]] && [[ "$HOSTNAME" =~ "abel" ]] ; then
echo "Full dump is not allowed to $db_dest DB on $HOSTNAME"
exit 1
fi
echo "Copy from '$db_src' to '$db_dest'..."
charset="utf8mb4"
# mysqldump of MariaDB dumps generated cols, see https://dba.stackexchange.com/questions/240882/how-to-take-mysqldump-with-generated-column
# mysqldump -u admin -p originaldb | mysql -u backup -p password duplicateddb;
MYSQL_CONTAINER=mysql57
docker exec -it $MYSQL_CONTAINER mysql --help >/dev/null 2>&1 && IS_DOCKER=true || IS_DOCKER=false
# IS_DOCKER=false
if $IS_DOCKER ; then
MYSQLDUMP="docker exec -it $MYSQL_CONTAINER mysqldump --default-character-set=$charset"
MYSQL="docker exec -i $MYSQL_CONTAINER mysql --default-character-set=$charset"
else
MYSQLDUMP=mysqldump
MYSQL=mysql
fi
user=root
# user=script
# $MYSQLDUMP -u $user --skip-extended-insert --dump-date --hex-blob --routines --databases lobbywatch --add-drop-database > /tmp/db_out.sql
$MYSQL -u $user -e "DROP DATABASE IF EXISTS $db_dest; CREATE DATABASE IF NOT EXISTS $db_dest DEFAULT CHARACTER SET $charset;"
# --skip-extended-insert
# echo "$MYSQLDUMP -u $user $db_src --dump-date --hex-blob --routines --skip-lock-tables --single-transaction --default-character-set=utf8mb4 --complete-insert"
$MYSQLDUMP -u $user $db_src --dump-date --hex-blob --routines --skip-lock-tables --default-character-set=utf8mb4 | $MYSQL -u $user $db_dest