-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDbDump.sh
More file actions
executable file
·75 lines (62 loc) · 1.92 KB
/
createDbDump.sh
File metadata and controls
executable file
·75 lines (62 loc) · 1.92 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
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
#!/usr/bin/env bash
mysql_config_file=mysql-client-source.cnf
excluded_tables=$(<./excludedTables.txt)
local_dump_dir=dumps
location=$( cd "$(dirname "$0")" ; pwd -P )
function print_usage_and_exit() {
echo "Usage: ${0} [-h] -d"
echo
echo "This script is part of the sync process,"
echo "it will create a dump of the source system"
echo
echo "Available options:"
echo
echo "-h|--help print this help text and exit"
echo "-d|--database_name the name of the database from the source system"
echo "-l|--local_dump_dir the directory in which the dump from the source database should be put"
echo
exit 0
}
[[ "$#" -lt 1 ]] && print_usage_and_exit
while [[ $# -ge 1 ]]; do
case "$1" in
-d | --database-name)
database_name="$2"
shift
;;
-l | --local-dump-dir)
local_dump_dir="$2"
shift
;;
-h | --help)
print_usage_and_exit
;;
esac
shift
done
function get_excluded_tables() {
echo ${excluded_tables}
}
function create_ignore_table_list() {
local database_name="$1"
for table in $( get_excluded_tables ) ; do
[ "${table}" == "" ] && continue
echo -n " --ignore-table=${database_name}.${table} "
done
}
echo "starting mysqldump"
ignore_table_list=$( create_ignore_table_list "${database_name}" )
columnStatistics="--column-statistics=0"
if mysqldump --version | grep MariaDB 1>/dev/null; then
columnStatistics=""
fi
mysqldump_command="mysqldump --defaults-extra-file=${mysql_config_file} ${columnStatistics} --no-tablespaces --single-transaction --default-character-set=utf8 --skip-set-charset"
set -o errexit
set -o pipefail
if [[ ! -d "$local_dump_dir" ]]; then
mkdir "$local_dump_dir"
fi
## one single dump-file, only usable for small databases
export LC_CTYPE=C
export LANG=C
${mysqldump_command} ${ignore_table_list} ${database_name} | sed -e 's/^\/\*\![0-9]* DEFINER=.*//' | sed "s/\`${database_name}\`\.//g" > ${local_dump_dir}/dump.sql