-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratePostImportFiles.sh
More file actions
executable file
·93 lines (85 loc) · 2.95 KB
/
generatePostImportFiles.sh
File metadata and controls
executable file
·93 lines (85 loc) · 2.95 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
mysql_config_file=mysql-client-target.cnf
function errcho() {
(echo >&2 "[ FAIL ] $@")
}
function errexit() {
errcho "$@"
exit 1
}
function echok() {
echo "[ OK ] $@"
}
function generate_post_import_script() {
[[ "$#" -lt 3 ]] && errexit "Not enough parameter provided."
local mysql_config_file=$1
shift
local db_name=$1
shift
local local_dump_dir=$1
if [[ ! -d "$local_dump_dir" ]]; then
mkdir "$local_dump_dir"
fi
if [[ ! -d "${local_dump_dir}/post" ]]; then
mkdir "${local_dump_dir}/post"
fi
rm -f ${local_dump_dir}/post/autogen_cms_domains.sql
mysql --defaults-extra-file=${mysql_config_file} ${db_name} -e "SELECT id, domain, larissa_lib, dir_publish FROM cms_domains;" | tail -n +2 | while read pk domain larissa_lib dir_publish; do
echo "UPDATE cms_domains
SET domain = '${domain}',
larissa_lib = '${larissa_lib}',
dir_publish = '${dir_publish}'
WHERE id = ${pk};" >>${local_dump_dir}/post/autogen_cms_domains.sql
echo "UPDATE cms_domains
INNER JOIN cms_community
ON cms_domains.id = cms_community.domain_id
SET cms_community.name = cms_domains.domain,
cms_community.url = CONCAT('https://', cms_domains.domain)
WHERE cms_domains.domain IS NOT NULL;" >>${local_dump_dir}/post/autogen_cms_domains.sql
done
if [[ "$?" -ne 0 ]]; then
errxit "generating of postimport script generated failed for autogen_cms_domains.sql"
fi
rm -f ${local_dump_dir}/post/autogen_application_portal.sql
mysql --defaults-extra-file=${mysql_config_file} ${db_name} -e "SELECT id, domain FROM application_portal;" | tail -n +2 | while read pk domain; do
echo "UPDATE application_portal
SET domain = '${domain}'
WHERE id = ${pk};" >>${local_dump_dir}/post/autogen_application_portal.sql
done
if [[ "$?" -ne 0 ]]; then
errxit "generating of postimport script generated failed for autogen_application_portal.sql"
fi
echok "Postimport script generated"
}
function print_usage_and_exit() {
echo "Usage: ${0} [-h] -d"
echo
echo "This script is part of the sync process,"
echo "it will create post import scripts from the destination 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 destination system"
echo "-l|--local_dump_dir the directory in which the dump from the source database lies"
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
generate_post_import_script ${mysql_config_file} ${database_name} ${local_dump_dir}