Merge lp:~jontai/openvista-gtm-integration/bug363080 into lp:openvista-gtm-integration

Proposed by Jon Tai
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jontai/openvista-gtm-integration/bug363080
Merge into: lp:openvista-gtm-integration
Diff against target: None lines
To merge this branch: bzr merge lp:~jontai/openvista-gtm-integration/bug363080
Reviewer Review Type Date Requested Status
jeff.apple Approve
Review via email: mp+5706@code.launchpad.net
To post a comment you must log in.
Revision history for this message
jeff.apple (jeff-apple) wrote :

Looks good.
The only corner case would be if the newline conversion converts within a string for a global value. I'm guessing that never happens with this data, the underlying tools may not support it anyway, it isn't a bad thing anyway, etc.

review: Approve
Revision history for this message
Jon Tai (jontai) wrote :

> Looks good.
> The only corner case would be if the newline conversion converts within a
> string for a global value. I'm guessing that never happens with this data, the
> underlying tools may not support it anyway, it isn't a bad thing anyway, etc.

In ZWR format, a newline within a global is escaped with $C(...). I'm not sure what the other formats do, but if a newline shows up unescaped, it's going to confuse %RI/%GI anyway. So I don't think we're doing anything wrong here.

I'm going to commit.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'packages/rpm/openvista-utils.spec'
--- packages/rpm/openvista-utils.spec 2009-04-18 01:54:22 +0000
+++ packages/rpm/openvista-utils.spec 2009-04-20 08:35:31 +0000
@@ -51,6 +51,7 @@
51install scripts/usr/bin/ovtied %{buildroot}%{_bindir}/51install scripts/usr/bin/ovtied %{buildroot}%{_bindir}/
52install scripts/usr/bin/ovbackup %{buildroot}%{_bindir}/52install scripts/usr/bin/ovbackup %{buildroot}%{_bindir}/
53install scripts/usr/bin/ovpurgejournals %{buildroot}%{_bindir}/53install scripts/usr/bin/ovpurgejournals %{buildroot}%{_bindir}/
54install scripts/usr/bin/ovimport %{buildroot}%{_bindir}/
5455
55install -d %{buildroot}%{_sysconfdir}/rc.d/init.d/56install -d %{buildroot}%{_sysconfdir}/rc.d/init.d/
56install scripts/etc/init.d/openvista-databases %{buildroot}%{_sysconfdir}/rc.d/init.d/57install scripts/etc/init.d/openvista-databases %{buildroot}%{_sysconfdir}/rc.d/init.d/
@@ -81,6 +82,7 @@
81%{_bindir}/ovtied82%{_bindir}/ovtied
82%{_bindir}/ovbackup83%{_bindir}/ovbackup
83%{_bindir}/ovpurgejournals84%{_bindir}/ovpurgejournals
85%{_bindir}/ovimport
84%{_sysconfdir}/rc.d/init.d/openvista-databases86%{_sysconfdir}/rc.d/init.d/openvista-databases
85%{_sysconfdir}/rc.d/init.d/openvista87%{_sysconfdir}/rc.d/init.d/openvista
86%{_sysconfdir}/bash_completion.d/openvista88%{_sysconfdir}/bash_completion.d/openvista
8789
=== added file 'scripts/usr/bin/ovimport'
--- scripts/usr/bin/ovimport 1970-01-01 00:00:00 +0000
+++ scripts/usr/bin/ovimport 2009-04-20 08:35:23 +0000
@@ -0,0 +1,274 @@
1#!/bin/bash
2
3# This script imports routines and globals into a new OpenVista instance.
4
5
6# Copyright (C) 2009 Medsphere Systems Corporation
7#
8# This program is free software; you can redistribute it and/or modify it solely
9# under the terms of the GNU Affero General Public License version 3 as published
10# by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15# for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses>.
19#
20# You can contact Medsphere Systems Corporation headquarters at 1917 Palomar
21# Oaks Way, Suite 200, Carlsbad, CA 92008 or at legal@medsphere.com.
22
23
24# common functions
25. /usr/lib/openvista/functions
26
27# parse arguments
28while getopts hqfr:g: option; do
29 case $option in
30 h)
31 echo "Usage: ovimport [-q] [-f] [-r ROUTINES] [-g GLOBALS] INSTANCE_NAME"
32 echo " or ovimport -h"
33 echo
34 echo " -q quiet; suppress status messages"
35 echo " -f force; import routines and globals even if target instance is not empty"
36 echo " -r path to routine export file, archive, or directory"
37 echo " -g path to global export file or archive"
38 echo " -h display this help text"
39 exit 0
40 ;;
41 q)
42 skip_status=true
43 ;;
44 f)
45 force=true
46 ;;
47 r)
48 routines=$OPTARG
49 ;;
50 g)
51 globals=$OPTARG
52 ;;
53 esac
54done
55shift `expr $OPTIND - 1`
56
57: ${skip_status:=false}
58: ${force:=false}
59real_routines=$routines
60real_globals=$globals
61
62# check command syntax
63if [ -z "$1" ]; then
64 echo "ovimport: missing operand" >&2
65 echo "Try 'ovimport -h' for more information" >&2
66 exit 2
67fi
68
69# check permissions
70in_groups || {
71 echo "ovimport: permission denied" >&2
72 exit 1
73}
74
75# check for for valid arguments (requires correct permissions to do; must happen after permission checks)
76set_gtm_env "$1" || {
77 echo "ovimport: $instance: Not an OpenVista instance" >&2
78 exit 3
79}
80
81if [ -z "$routines" ] && [ -z "$globals" ]; then
82 echo "ovimport: No routines or globals specified; please use -r ROUTINES, -g GLOBALS, or both" >&2
83 exit 3
84fi
85
86if [ "0x0000000000000001" != `dse dump -fileheader 2>&1 | grep -F 'Current transaction' | awk '{ print $3 }'` ]; then
87 $force || {
88 echo "ovimport: $instance: OpenVista instance is not new; use -f to force"
89 exit 1
90 }
91fi
92
93if [ `find "$root/$instance/routines" -type f -name '*.m' | wc -l` -ne 0 ]; then
94 $force || {
95 echo "ovimport: $instance: OpenVista instance is not new; use -f to force"
96 exit 1
97 }
98fi
99
100# we can't use a subshell to isolate the umask call because $tempdir wouldn't
101# survive, so save/restore the umask instead
102old_umask=`umask`
103umask 077
104tempdir=`mktemp -d -p "$root/$instance/tmp" .ovimport.XXXXXXXXXX` ||
105exit_with_error "ovimport" "Unable to create temporary directory"
106umask "$old_umask"
107
108# the EXIT handler may or may not run if we're interrupted or killed depending
109# on the shell used (from what I've read, it does run on bash, but not on
110# dash); use $exit to exit with the correct status in both cases
111trap '[ -z "$exit" ] && rm -rf "$tempdir"; exit ${exit:-0}' EXIT
112
113trap 'print_status "ovimport" "Caught SIGINT, exiting" "$skip_status"; rm -rf "$tempdir"; exit ${exit:=130}' INT
114trap 'print_status "ovimport" "Caught SIGTERM, exiting" "$skip_status"; rm -rf "$tempdir"; exit ${exit:=143}' TERM
115
116if [ -n "$routines" ]; then
117 if [ -f "$routines" ]; then
118 # FIXME: handle compressed files
119
120 routines_format="RO"
121
122 if grep -E $'\r$' "$routines" > /dev/null; then
123 routines_convert_newlines=true
124 fi
125 elif [ -d "$routines" ]; then
126 if [ `find "$routines" -type f -name '*.m' | wc -l` -ne 0 ]; then
127 routines_format="M"
128 else
129 echo "ovimport: $routines: Directory does not contain .m files" >&2
130 exit 1
131 fi
132 else
133 echo "ovimport: $routines: No such file or directory" >&2
134 exit 3
135 fi
136fi
137
138if [ -n "$globals" ]; then
139 if [ -f "$globals" ]; then
140 # FIXME: handle compressed files
141
142 if awk '{ if (NR == 3) { print $0; exit 0 } }' "$globals" | grep -F '=' > /dev/null; then
143 globals_format=ZWR
144 else
145 globals_format=GO
146 fi
147
148 if grep -E $'\r$' "$globals" > /dev/null; then
149 globals_convert_newlines=true
150 fi
151 else
152 echo "ovimport: $globals: No such file" >&2
153 exit 3
154 fi
155fi
156
157if [ -n "$routines" ]; then
158 print_status "ovimport" "Starting load of $routines into $instance" "$skip_status"
159
160 print_status "ovimport" "Routines are in $routines_format format" "$skip_status"
161
162 if ${routines_convert_newlines:-false}; then
163 print_status "ovimport" "Converting file to UNIX-style line endings" "$skip_status"
164
165 real_routines=$tempdir/ovimport.ro
166
167 {
168 cp "$routines" "$real_routines" &&
169 perl -pi -we 's/\r\n/\n/' "$real_routines"
170 } || exit_with_error "ovimport" "Unable to convert file to UNIX-style line endings"
171 fi
172
173 case $routines_format in
174 RO)
175 print_status "ovimport" "Loading routines using ^%RI" "$skip_status"
176
177 # convert $real_routines into an absolute path, since %RI may run
178 # with a different cwd than this script
179 dirname=`dirname "$real_routines"`
180 basename=`basename "$real_routines"`
181 real_routines=`cd "$dirname"; pwd`/"$basename"
182
183 # redirect output to a temporary file because we need to both log
184 # the output and inspect it to determine success
185 (
186 umask 007
187 mumps -run ^%RI > "$tempdir/ovimport.ri" 2>&1 <<EOF
188N
189$real_routines
190$root/$instance/routines/
191EOF
192 )
193
194 cat "$tempdir/ovimport.ri" \
195 | grep -v '^$' \
196 | logger -p user.info -t "ovimport[$$]"
197
198 grep '^Restored [0-9]\{1,\} lines in [0-9]\{1,\} routines' "$tempdir/ovimport.ri" > /dev/null ||
199 exit_with_error "ovimport" "Unable to import routines"
200 ;;
201 M)
202 print_status "ovimport" "Copying routines" "$skip_status"
203
204 # use install to copy routines instead of cp because install allows
205 # setting the permissions at the same time
206 find "$real_routines" -type f -name '*.m' -exec install -m 660 {} "$root/$instance/routines/" \; ||
207 exit_with_error "ovimport" "Unable to import routines"
208 ;;
209 esac
210
211 print_status "ovimport" "Compiling routines" "$skip_status"
212
213 (
214 umask 007
215 cd "$root/$instance/objects" &&
216 find "$root/$instance/routines" -type f -name '*.m' -exec mumps {} \; 2> /dev/null
217 ) || exit_with_error "ovimport" "Unable to compile routines"
218
219 print_status "ovimport" "Finished loading $routines into $instance" "$skip_status"
220fi
221
222if [ -n "$globals" ]; then
223 print_status "ovimport" "Starting load of $globals into $instance" "$skip_status"
224
225 print_status "ovimport" "Globals are in $globals_format format" "$skip_status"
226
227 if ${globals_convert_newlines:-false}; then
228 print_status "ovimport" "Converting file to UNIX-style line endings" "$skip_status"
229
230 real_globals=$tempdir/ovimport.go
231
232 {
233 cp "$globals" "$real_globals" &&
234 perl -pi -we 's/\r\n/\n/' "$real_globals"
235 } || exit_with_error "ovimport" "Unable to convert file to UNIX-style line endings"
236 fi
237
238 # disabling journaling while "mupip load" runs saves about a minute. this
239 # is pretty safe to do, since we check that the database is empty before we
240 # load, so even if the system crashes and the database is destroyed, we can
241 # just create a new one and run ovimport again. if -f was given, do not
242 # disable journaling because the database may have other data in it worth
243 # protecting
244 $force || {
245 print_status "ovimport" "Temporarily disabling journaling" "$skip_status"
246 mupip set -journal="OFF" -region DEFAULT 2>&1 \
247 | grep -v '^$' \
248 | logger -p user.info -t "ovimport[$$]"
249 }
250
251 print_status "ovimport" "Loading globals using 'mupip load'" "$skip_status"
252
253 mupip load -format="$globals_format" "$real_globals" 2>&1 \
254 | grep -v '^$' \
255 | logger -p user.info -t "ovimport[$$]"
256 retval=${PIPESTATUS[0]}
257 [ $retval -eq 0 ] || {
258 exit_with_error "ovimport" "Unable to import globals"
259 }
260
261 $force || {
262 print_status "ovimport" "Re-enabling journaling" "$skip_status"
263 mupip set -journal="ON,BEFORE_IMAGES" -region DEFAULT 2>&1 \
264 | grep -v '^$' \
265 | logger -p user.info -t "ovimport[$$]"
266 retval=${PIPESTATUS[0]}
267 [ $retval -eq 0 ] || {
268 exit_with_error "ovimport" "Unable to re-enable journaling"
269 }
270 }
271
272 print_status "ovimport" "Finished loading $globals into $instance" "$skip_status"
273fi
274
0275
=== modified file 'scripts/usr/sbin/ovinstanceadd'
--- scripts/usr/sbin/ovinstanceadd 2009-04-18 04:42:59 +0000
+++ scripts/usr/sbin/ovinstanceadd 2009-04-20 05:53:54 +0000
@@ -239,7 +239,7 @@
239 | logger -p user.info -t "ovinstanceadd[$$]"239 | logger -p user.info -t "ovinstanceadd[$$]"
240retval=${PIPESTATUS[0]}240retval=${PIPESTATUS[0]}
241[ $retval -eq 0 ] || {241[ $retval -eq 0 ] || {
242 echo "ovinstanceadd: Unable to enable journaling for region DEFAULT" >&2242 echo "ovinstanceadd: Unable to enable journaling" >&2
243 exit 1243 exit 1
244}244}
245245
246246
=== modified file 'scripts/usr/sbin/ovrestore'
--- scripts/usr/sbin/ovrestore 2009-04-18 04:42:59 +0000
+++ scripts/usr/sbin/ovrestore 2009-04-20 08:35:23 +0000
@@ -188,12 +188,14 @@
188 rsync -a --delete --exclude 'lost+found' "$tempdir/routines/" "$root/$instance/routines/"188 rsync -a --delete --exclude 'lost+found' "$tempdir/routines/" "$root/$instance/routines/"
189} || exit_with_error "ovrestore" "Unable to restore routines"189} || exit_with_error "ovrestore" "Unable to restore routines"
190190
191print_status "ovrestore" "Compiling routines" "$skip_status"
192
191(193(
192 umask 007194 umask 007
193 find "$root/$instance/objects" -type f -name '*.o' -exec rm -f {} \; &&195 find "$root/$instance/objects" -type f -name '*.o' -exec rm -f {} \; &&
194 cd "$root/$instance/objects" &&196 cd "$root/$instance/objects" &&
195 find "$root/$instance/routines" -type f -name '*.m' -exec mumps {} \; 2> /dev/null197 find "$root/$instance/routines" -type f -name '*.m' -exec mumps {} \; 2> /dev/null
196) || exit_with_error "ovrestore" "Unable to recompile routines"198) || exit_with_error "ovrestore" "Unable to compile routines"
197199
198# if we're not applying journals, shut off journaling on the old database so200# if we're not applying journals, shut off journaling on the old database so
199# that there's a clean break, then move the journal file out of the way201# that there's a clean break, then move the journal file out of the way

Subscribers

People subscribed via source and target branches