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

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/usr/bin/ovbackup'
2--- scripts/usr/bin/ovbackup 2009-04-14 23:29:49 +0000
3+++ scripts/usr/bin/ovbackup 2009-04-15 17:31:43 +0000
4@@ -47,8 +47,6 @@
5 exit 2
6 fi
7
8-# FIXME: always clean up temp files, even on error
9-
10 # check permissions
11 in_groups || {
12 echo "ovbackup: permission denied" >&2
13@@ -84,6 +82,17 @@
14 exit 1
15 }
16
17+# the EXIT handler may or may not run if we're interrupted or killed depending
18+# on the shell used (from what I've read, it does run on bash, but not on
19+# dash); use $exit to exit with the correct status in both cases
20+trap '[ -z "$exit" ] && rm -rf $tempdir; exit ${exit:-0}' EXIT
21+
22+trap 'logger -p user.info -t "ovbackup[$$]" -- Caught SIGINT, exiting; rm -rf $tempdir; exit ${exit:=130}' INT
23+trap 'logger -p user.info -t "ovbackup[$$]" -- Caught SIGTERM, exiting; rm -rf $tempdir; exit ${exit:=143}' TERM
24+
25+# this signal is used to indicate failure of mupip backup, which is run in the background below
26+trap 'logger -p user.info -t "ovbackup[$$]" -- Backup of $instance failed: Unable to copy database files; echo "ovbackup: Unable to copy database files" >&2; rm -rf $tempdir; exit ${exit:=1}' USR1
27+
28 {
29 install -m 2750 -d "$tempdir/etc" &&
30 cp -a "$root/$instance/etc/"*.conf "$tempdir/etc/"
31@@ -118,36 +127,49 @@
32
33 # use mupip backup to take a consistent snapshot of the globals
34 #
35-# note: - the snapshot is consistent to the moment this command is executed,
36-# not to the moment the command finishes
37+# run mupip backup in the background and immediately check to see if the
38+# routines have changed. if they have, we can abort the backup. if they have
39+# not, we wait for the backup to finish before moving on. even if the routines
40+# change after the backup has started, we will still have a consistent backup,
41+# because the database backup is consistent to the moment when mupip backup
42+# *starts*, not when mupip backup *finishes*. if the backup fails, send
43+# SIGUSR1 to the parent process (this script), which is handled above.
44 (
45 umask 007
46 mupip backup DEFAULT "$tempdir/globals" 2>&1 \
47 | grep -v '^$' \
48 | logger -p user.info -t "ovbackup[$$]"
49 retval=${PIPESTATUS[0]}
50- [ $retval -eq 0 ] # hack to make subshell exit with exit code of mupip
51-) || {
52- logger -p user.info -t "ovbackup[$$]" -- Backup of $instance failed: Unable to copy database files
53- echo "ovbackup: Unable to copy database files" >&2
54- exit 1
55-}
56-
57-logger -p user.info -t "ovbackup[$$]" -- Checking backup integrity
58-
59-# FIXME: figure out a way to do this check while mupip backup is still running
60-# - this shortens the window where routines must stay static and also makes the
61-# backup process faster
62+ [ $retval -eq 0 ] || kill -USR1 $$ 2> /dev/null
63+) &
64+child_pid=$!
65+
66+# wait for DEFAULT*.tmp or default.dat file to appear, indicating that the backup has begun (or is already finished)
67+while [ 1 ]; do
68+ if ls "$tempdir/globals" | grep -i default > /dev/null; then
69+ break
70+ fi
71+ sleep 1
72+done
73+
74+# meanwhile, check to see if the routines have changed
75 #
76 # FIXME: if the routines did change, we should probably try again instead of
77 # just aborting - rsync the routines, then re-run the database backup
78 output=`rsync -ai --delete --dry-run "$root/$instance/routines/" "$tempdir/routines/"`
79 [ -z "$output" ] || {
80 logger -p user.info -t "ovbackup[$$]" -- Backup of $instance failed: Routines changed during backup
81- echo "ovbackup: Routines changed during backup"
82+ echo "ovbackup: Routines changed during backup" >&2
83 exit 1
84 }
85
86+# if we get here, that means that the routines haven't changed, and either the
87+# mupip backup is still running, or it completed successfully. make sure it's
88+# done before we move on.
89+wait $child_pid 2> /dev/null
90+
91+logger -p user.info -t "ovbackup[$$]" -- Checking backup integrity
92+
93 mupip integ -file "$tempdir/globals/default.dat" 2>&1 \
94 | grep -v '^$' \
95 | logger -p user.info -t "ovbackup[$$]"
96@@ -196,8 +218,6 @@
97
98 logger -p user.info -t "ovbackup[$$]" -- Backup of $instance written to "$root/$instance/backups/${instance}-$timestamp.tar.bz2"
99
100-rm -rf "$tempdir"
101-
102 # remove the oldest backup file until there are only $num_backups remaining
103 until [ `find "$root/$instance/backups" -type f -name "*.tar.bz2" | wc -l` -le $num_backups ]; do
104 delete=`find "$root/$instance/backups" -type f -name "*.tar.bz2" | sort | head -n 1`

Subscribers

People subscribed via source and target branches