Browse code

kamdbctl: remove not working db migrate command

- remove db migrate implementation in kamdbctl, .base, .mysql and .db_berkley files
- it was not working for mysql anyway, and not implemented for berkleydb
- this state was already documtend some weeks ago in commit 52a8def8d2a3e831

Henning Westerholt authored on 03/03/2018 18:08:30
Showing 1 changed files
... ...
@@ -176,12 +176,6 @@ kamailio_berkeley()  # parms: <op> <arg1> <arg2>
176 176
 			exit $?
177 177
 			;;
178 178
 
179
-		migrate)
180
-			shift
181
-			kamailio_migrate $1 $DB_PATH
182
-			exit $?
183
-			;;
184
-
185 179
 		import)
186 180
 			shift
187 181
 			kamailio_import  $1 $DB_PATH
... ...
@@ -308,21 +302,6 @@ kamailio_export()  # parms: <DUMP_DIR> [DB_PATH]
308 302
 }
309 303
 
310 304
 
311
-##
312
-# MIGRATE (schema)
313
-# Examine each plain-txt file in DUMP_DIR
314
-#  (Assumes that kamailio_export was already invoked)
315
-#
316
-# Migrate converts data from schema-old to schema-new in place.
317
-#
318
-# After this step is complete the IMPORT should be executed.
319
-kamailio_migrate()  # parms: <DUMP_DIR> [DB_PATH]
320
-{
321
-	merr "db_berkeley migrate not implemented"
322
-	exit 1
323
-}
324
-
325
-
326 305
 ##
327 306
 # IMPORT existing plain-txt files from DUMP_DIR to DB_PATH
328 307
 # eg.  DUMP_DIR/version.txt  --> DB_PATH/version
Browse code

kamctl remove svn ID's and history

Olle E. Johansson authored on 03/06/2016 08:34:25
Showing 1 changed files
... ...
@@ -18,9 +18,6 @@
18 18
 # along with this program; if not, write to the Free Software 
19 19
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 20
 # 
21
-# History:
22
-# --------
23
-# 2007-09-19  genesis (wiquan)
24 21
 #
25 22
 
26 23
 #constants
Browse code

utils/kamctl: lookup new versions of dbutils tools in kamdbctl.db_berkeley

Daniel-Constantin Mierla authored on 05/10/2014 08:03:43
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 #
2
-# $Id$
3
-#
4 2
 # Script for maintaining Kamailio Berkeley DB tables
5 3
 # Copyright (C) 2007 Cisco Systems
6 4
 #
... ...
@@ -59,6 +57,19 @@ if [ $ret -eq 0 ] ; then
59 57
 fi ;
60 58
 
61 59
 
60
+which db5.0_dump > /dev/null
61
+ret=$?
62
+if [ $ret -eq 0 ] ; then
63
+	DUMP_CMD="db5.0_dump"
64
+fi ;
65
+
66
+which db5.1_dump > /dev/null
67
+ret=$?
68
+if [ $ret -eq 0 ] ; then
69
+	DUMP_CMD="db5.1_dump"
70
+fi ;
71
+
72
+
62 73
 #berkeley db utility program that imports data from plain text file
63 74
 #small hack to autodetect the db load command, debian prefix the version..
64 75
 
... ...
@@ -86,6 +97,19 @@ if [ $ret -eq 0 ] ; then
86 97
 	LOAD_CMD="db4.6_load"
87 98
 fi ;
88 99
 
100
+
101
+which db5.0_load > /dev/null
102
+ret=$?
103
+if [ $ret -eq 0 ] ; then
104
+	LOAD_CMD="db5.0_load"
105
+fi ;
106
+
107
+which db5.1_load > /dev/null
108
+ret=$?
109
+if [ $ret -eq 0 ] ; then
110
+	LOAD_CMD="db5.1_load"
111
+fi ;
112
+
89 113
 # path to the database schemas
90 114
 DATA_DIR="/usr/local/share/kamailio"
91 115
 if [ -d "$DATA_DIR/db_berkeley/kamailio" ] ; then
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -18,7 +18,7 @@
18 18
 #
19 19
 # You should have received a copy of the GNU General Public License 
20 20
 # along with this program; if not, write to the Free Software 
21
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 22
 # 
23 23
 # History:
24 24
 # --------
Browse code

kamctl: replaced openser with kamailio in variable and function names

Daniel-Constantin Mierla authored on 23/10/2012 14:49:29
Showing 1 changed files
... ...
@@ -118,7 +118,7 @@ EOF
118 118
 #
119 119
 # 
120 120
 #
121
-openser_berkeley()  # parms: <op> <arg1> <arg2>
121
+kamailio_berkeley()  # parms: <op> <arg1> <arg2>
122 122
 {
123 123
 	case $1 in
124 124
 		list|ls)
... ...
@@ -127,43 +127,43 @@ openser_berkeley()  # parms: <op> <arg1> <arg2>
127 127
 			;;
128 128
 		cat)
129 129
 			shift
130
-			openser_cat $1 $DB_PATH
130
+			kamailio_cat $1 $DB_PATH
131 131
 			exit $?
132 132
 			;;
133 133
 
134 134
 		swap)
135 135
 			shift
136
-			openser_swap $1 $DB_PATH
136
+			kamailio_swap $1 $DB_PATH
137 137
 			exit $?
138 138
 			;;
139 139
 
140 140
 		append)
141 141
 			shift
142
-			openser_append  $1 $2 $DB_PATH
142
+			kamailio_append  $1 $2 $DB_PATH
143 143
 			exit $?
144 144
 			;;
145 145
 
146 146
 		newappend)
147 147
 			shift
148
-			openser_newappend  $1 $2 $DB_PATH
148
+			kamailio_newappend  $1 $2 $DB_PATH
149 149
 			exit $?
150 150
 			;;
151 151
 
152 152
 		export)
153 153
 			shift
154
-			openser_export  $1 $DB_PATH
154
+			kamailio_export  $1 $DB_PATH
155 155
 			exit $?
156 156
 			;;
157 157
 
158 158
 		migrate)
159 159
 			shift
160
-			openser_migrate $1 $DB_PATH
160
+			kamailio_migrate $1 $DB_PATH
161 161
 			exit $?
162 162
 			;;
163 163
 
164 164
 		import)
165 165
 			shift
166
-			openser_import  $1 $DB_PATH
166
+			kamailio_import  $1 $DB_PATH
167 167
 			exit $?
168 168
 			;;
169 169
 
... ...
@@ -182,10 +182,10 @@ esac
182 182
 #
183 183
 # Export is used as part of a DB migration process to another 
184 184
 # major version of berkeley db.
185
-openser_export()  # parms: <DUMP_DIR> [DB_PATH]
185
+kamailio_export()  # parms: <DUMP_DIR> [DB_PATH]
186 186
 {
187 187
 	if [ $# -lt 2  ]; then
188
-		echo  "openser_dump parms: <DUMP_DIR> [DB_PATH]"
188
+		echo  "kamailio_dump parms: <DUMP_DIR> [DB_PATH]"
189 189
 		exit 1
190 190
 	fi
191 191
 	
... ...
@@ -290,12 +290,12 @@ openser_export()  # parms: <DUMP_DIR> [DB_PATH]
290 290
 ##
291 291
 # MIGRATE (schema)
292 292
 # Examine each plain-txt file in DUMP_DIR
293
-#  (Assumes that openser_export was already invoked)
293
+#  (Assumes that kamailio_export was already invoked)
294 294
 #
295 295
 # Migrate converts data from schema-old to schema-new in place.
296 296
 #
297 297
 # After this step is complete the IMPORT should be executed.
298
-openser_migrate()  # parms: <DUMP_DIR> [DB_PATH]
298
+kamailio_migrate()  # parms: <DUMP_DIR> [DB_PATH]
299 299
 {
300 300
 	merr "db_berkeley migrate not implemented"
301 301
 	exit 1
... ...
@@ -308,10 +308,10 @@ openser_migrate()  # parms: <DUMP_DIR> [DB_PATH]
308 308
 #
309 309
 # import is used as part of DB migrate to another major version of berkeley db.
310 310
 # this will over-write anything in DB_PATH
311
-openser_import()  # parms: <DUMP_DIR> [DB_PATH]
311
+kamailio_import()  # parms: <DUMP_DIR> [DB_PATH]
312 312
 {
313 313
 	if [ $# -lt 2  ]; then
314
-		echo  "openser_dump parms: <DUMP_DIR> [DB_PATH]"
314
+		echo  "kamailio_dump parms: <DUMP_DIR> [DB_PATH]"
315 315
 		exit 1
316 316
 	fi
317 317
 	
... ...
@@ -393,10 +393,10 @@ openser_import()  # parms: <DUMP_DIR> [DB_PATH]
393 393
 }
394 394
 
395 395
 
396
-openser_swap()  # parms: <db> [DB_PATH]
396
+kamailio_swap()  # parms: <db> [DB_PATH]
397 397
 {
398 398
 	if [ $# -lt 2  ]; then
399
-		echo  "openser_swap parms: <db> [DB_PATH]"
399
+		echo  "kamailio_swap parms: <db> [DB_PATH]"
400 400
 		exit 1
401 401
 	fi
402 402
 	
... ...
@@ -412,10 +412,10 @@ openser_swap()  # parms: <db> [DB_PATH]
412 412
 # 1. copy DB_PATH/db to DB_PATH/db.new
413 413
 # 2. appends contents of newdata to DB_PATH/db.new
414 414
 #
415
-openser_append()  # parms: <db> <newdata> [DB_PATH]
415
+kamailio_append()  # parms: <db> <newdata> [DB_PATH]
416 416
 {
417 417
 	if [ $# -lt 3  ]; then
418
-		echo  "openser_append parms: <db> <newdata> [DB_PATH]"
418
+		echo  "kamailio_append parms: <db> <newdata> [DB_PATH]"
419 419
 		exit 1
420 420
 	fi
421 421
 	
... ...
@@ -441,10 +441,10 @@ openser_append()  # parms: <db> <newdata> [DB_PATH]
441 441
 # 3. move /tmp/sc-<processID>/db over to DB_PATH/db.new
442 442
 # 4. delete temp DBENV dir /tmp/sc-<processID>
443 443
 #
444
-openser_newappend()  # parms: <db> <newdata> [DB_PATH]
444
+kamailio_newappend()  # parms: <db> <newdata> [DB_PATH]
445 445
 {
446 446
 	if [ $# -lt 3  ]; then
447
-		echo  "openser_append parms: <db> <newdata> [DB_PATH]"
447
+		echo  "kamailio_append parms: <db> <newdata> [DB_PATH]"
448 448
 		exit 1
449 449
 	fi
450 450
 	
... ...
@@ -454,7 +454,7 @@ openser_newappend()  # parms: <db> <newdata> [DB_PATH]
454 454
 		rm $DBNEW
455 455
 	fi
456 456
 	TMPENV=/tmp/sc-$$
457
-	openser_create $TMPENV
457
+	kamailio_create $TMPENV
458 458
 	cd $OLDPWD
459 459
 	$LOAD_CMD -T -t hash -f $2 -h $TMPENV $1
460 460
 	mv $TMPENV/$1 $DBNEW
... ...
@@ -463,20 +463,20 @@ openser_newappend()  # parms: <db> <newdata> [DB_PATH]
463 463
 
464 464
 
465 465
 # cat all rows to STDOUT
466
-openser_cat()  # pars: <database name> <DB_PATH>
466
+kamailio_cat()  # pars: <database name> <DB_PATH>
467 467
 {
468 468
 	if [ $# -ne 2 ] ; then
469
-		echo  "openser_cat params <db> [DB_PATH]"
469
+		echo  "kamailio_cat params <db> [DB_PATH]"
470 470
 		exit 1
471 471
 	fi
472 472
 	
473 473
 	$DUMP_CMD -p -h $2 $1
474 474
 }
475 475
 
476
-openser_drop()  # pars:  <DB_PATH>
476
+kamailio_drop()  # pars:  <DB_PATH>
477 477
 {
478 478
 	if [ $# -ne 1 ] ; then
479
-		echo "openser_drop function takes one param"
479
+		echo "kamailio_drop function takes one param"
480 480
 		exit 1
481 481
 	fi
482 482
 	
... ...
@@ -519,10 +519,10 @@ openser_drop()  # pars:  <DB_PATH>
519 519
 }
520 520
 
521 521
 
522
-openser_create() # pars: <DB_PATH>
522
+kamailio_create() # pars: <DB_PATH>
523 523
 {
524 524
 	if [ $# -ne 1 ] ; then
525
-		echo "openser_create param [DB_PATH]"
525
+		echo "kamailio_create param [DB_PATH]"
526 526
 		exit 1
527 527
 	fi
528 528
 	
... ...
@@ -551,7 +551,7 @@ openser_create() # pars: <DB_PATH>
551 551
 		extra_create $1
552 552
 	fi
553 553
 
554
-} # openser_create
554
+} # kamailio_create
555 555
 
556 556
 
557 557
 presence_create() # pars: <DB_PATH>
Browse code

kamctl: moved from tools/ to utils/

- mv tools/kamctl utils/kamctl
- updated srdb1 Makefile and test/unit/include/common with the new
kamctl path

Andrei Pelinescu-Onciul authored on 09/10/2009 12:05:15
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,619 @@
1
+#
2
+# $Id$
3
+#
4
+# Script for maintaining Kamailio Berkeley DB tables
5
+# Copyright (C) 2007 Cisco Systems
6
+#
7
+# This file is part of Kamailio, a free SIP server.
8
+#
9
+# Kamailio is free software; you can redistribute it and/or modify
10
+# it under the terms of the GNU General Public License as published by
11
+# the Free Software Foundation; either version 2 of the License, or
12
+# (at your option) any later version
13
+#
14
+# Kamailio is distributed in the hope that it will be useful,
15
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+# GNU General Public License for more details.
18
+#
19
+# You should have received a copy of the GNU General Public License 
20
+# along with this program; if not, write to the Free Software 
21
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+# 
23
+# History:
24
+# --------
25
+# 2007-09-19  genesis (wiquan)
26
+#
27
+
28
+#constants
29
+PATH=$PATH:/usr/local/BerkeleyDB.4.6/bin
30
+DELIM="|"
31
+BACKUP_CMD="tar czvf "
32
+RESTORE_CMD="tar xzvf "
33
+
34
+#berkeley db utility program that writes out db to plain text
35
+#small hack to autodetect the db dump command, debian prefix the version..
36
+
37
+which db_dump > /dev/null
38
+ret=$?
39
+if [ $ret -eq 0 ] ; then
40
+	DUMP_CMD="db_dump"
41
+fi ;
42
+
43
+which db4.4_dump > /dev/null
44
+ret=$?
45
+if [ $ret -eq 0 ] ; then
46
+	DUMP_CMD="db4.4_dump"
47
+fi ;
48
+
49
+which db4.5_dump > /dev/null
50
+ret=$?
51
+if [ $ret -eq 0 ] ; then
52
+	DUMP_CMD="db4.5_dump"
53
+fi ;
54
+
55
+which db4.6_dump > /dev/null
56
+ret=$?
57
+if [ $ret -eq 0 ] ; then
58
+	DUMP_CMD="db4.6_dump"
59
+fi ;
60
+
61
+
62
+#berkeley db utility program that imports data from plain text file
63
+#small hack to autodetect the db load command, debian prefix the version..
64
+
65
+which db_load > /dev/null
66
+ret=$?
67
+if [ $ret -eq 0 ] ; then
68
+	LOAD_CMD="db_load"
69
+fi ;
70
+
71
+which db4.4_load > /dev/null
72
+ret=$?
73
+if [ $ret -eq 0 ] ; then
74
+	LOAD_CMD="db4.4_load"
75
+fi ;
76
+
77
+which db4.5_load > /dev/null
78
+ret=$?
79
+if [ $ret -eq 0 ] ; then
80
+	LOAD_CMD="db4.5_load"
81
+fi ;
82
+
83
+which db4.6_load > /dev/null
84
+ret=$?
85
+if [ $ret -eq 0 ] ; then
86
+	LOAD_CMD="db4.6_load"
87
+fi ;
88
+
89
+# path to the database schemas
90
+DATA_DIR="/usr/local/share/kamailio"
91
+if [ -d "$DATA_DIR/db_berkeley/kamailio" ] ; then
92
+	DB_SCHEMA="$DATA_DIR/db_berkeley/kamailio"
93
+else
94
+	DB_SCHEMA="./db_berkeley/kamailio"
95
+fi
96
+
97
+# path to the db_berkeley database
98
+if [ -z "$DB_PATH" ]; then
99
+	DB_PATH="/usr/local/etc/kamailio/db_berkeley"
100
+fi
101
+
102
+berkeley_usage() 
103
+{
104
+COMMAND=`basename $0`
105
+cat <<EOF
106
+Script for maintaining Kamailio Berkeley DB tables
107
+       $COMMAND list      (lists the underlying db files in DB_PATH)
108
+       $COMMAND cat       <db>  (db_dump the underlying db file to STDOUT)
109
+       $COMMAND swap      <db>  (installs db.new by db -> db.old; db.new -> db)
110
+       $COMMAND append    <db> <datafile> (appends data to an existing db;output DB_PATH/db.new)
111
+       $COMMAND newappend <db> <datafile> (appends data to a new instance of db; output DB_PATH/db.new)
112
+       $COMMAND export  <dump_dir> (exports table data to plain-txt files in dump_dir)
113
+       $COMMAND import  <dump_dir> (imports plain-txt table data and creates new db tables in db_path)
114
+EOF
115
+} #usage
116
+
117
+
118
+#
119
+# 
120
+#
121
+openser_berkeley()  # parms: <op> <arg1> <arg2>
122
+{
123
+	case $1 in
124
+		list|ls)
125
+			ls -l $DB_PATH
126
+			exit $?
127
+			;;
128
+		cat)
129
+			shift
130
+			openser_cat $1 $DB_PATH
131
+			exit $?
132
+			;;
133
+
134
+		swap)
135
+			shift
136
+			openser_swap $1 $DB_PATH
137
+			exit $?
138
+			;;
139
+
140
+		append)
141
+			shift
142
+			openser_append  $1 $2 $DB_PATH
143
+			exit $?
144
+			;;
145
+
146
+		newappend)
147
+			shift
148
+			openser_newappend  $1 $2 $DB_PATH
149
+			exit $?
150
+			;;
151
+
152
+		export)
153
+			shift
154
+			openser_export  $1 $DB_PATH
155
+			exit $?
156
+			;;
157
+
158
+		migrate)
159
+			shift
160
+			openser_migrate $1 $DB_PATH
161
+			exit $?
162
+			;;
163
+
164
+		import)
165
+			shift
166
+			openser_import  $1 $DB_PATH
167
+			exit $?
168
+			;;
169
+
170
+		*)
171
+			berkeley_usage
172
+			exit 1;
173
+			;;
174
+esac
175
+}
176
+
177
+
178
+
179
+##
180
+# EXPORT existing data to plain-txt files in DUMP_DIR
181
+# eg.  DB_PATH/version ---> DUMP_DIR/version.txt
182
+#
183
+# Export is used as part of a DB migration process to another 
184
+# major version of berkeley db.
185
+openser_export()  # parms: <DUMP_DIR> [DB_PATH]
186
+{
187
+	if [ $# -lt 2  ]; then
188
+		echo  "openser_dump parms: <DUMP_DIR> [DB_PATH]"
189
+		exit 1
190
+	fi
191
+	
192
+	# Assert: the DB_PATH directory should already exist
193
+	if [ ! -d $2 ] ; then
194
+		merr "BerkeleyDB directory does not exist at: [$2]"
195
+		exit 1
196
+	fi
197
+	
198
+	# Assert: DB_PATH directory should already contain table 'version'
199
+	if [ ! -f $2/version ] ; then
200
+		merr "BerkeleyDB directory does not have VERSION table at: [$2]"
201
+		exit 1
202
+	fi
203
+	
204
+	# Create dir at <DUMP_DIR> to store the exported data
205
+	if [ ! -d $1 ] ; then
206
+		minfo "creating DUMP_DIR at: [$1]"
207
+		mkdir -p $1
208
+	else
209
+		mdbg "Cleaning out DUMP_DIR to get ready for new data"
210
+		rm -rf $1/*
211
+	fi
212
+	
213
+	# DUMP_CMD will result in something like this:
214
+	#
215
+	#	VERSION=3
216
+	#	format=print
217
+	#	type=hash
218
+	#	h_nelem=2
219
+	#	db_pagesize=4096
220
+	#	HEADER=END
221
+	#	 METADATA_COLUMNS
222
+	#	 callid(str) method(str) from_tag(str) to_tag(str) sip_code(str) sip_reason(str) time(datetime)
223
+	#	 METADATA_KEY
224
+	#	 0
225
+	#	DATA=END
226
+	#
227
+	# However, we are only interested in the indented stuff between 
228
+	#  'HEADER=END' and 'DATA=END',
229
+	#  as everything else is DB instance specific. That is, we are interested in this part:
230
+	#
231
+	# METADATA_COLUMNS
232
+	# callid(str) method(str) from_tag(str) to_tag(str) sip_code(str) sip_reason(str) time(datetime)
233
+	# METADATA_KEY
234
+	# 0
235
+	#
236
+	# The following PERL filter will do this processing.
237
+	#
238
+	# perl -pe 's/^\w.*// ; s/^\s(.*)/$1/'
239
+
240
+	# Dump the STANDARD tables to plain-text files in DUMP_DIR
241
+	for TABLE in $STANDARD_TABLES; do
242
+	    if [ -f $2/$TABLE ] ; then
243
+		    mdbg "Exporting standard table: $TABLE"
244
+		    $DUMP_CMD -p -h $2 $TABLE  | perl -pe 's/^\w.*// ; s/^\s(.*)/$1/' > $1/$TABLE.txt
245
+		    
246
+		    # Check return code to make sure the export worked ok
247
+		    if [ $? -ne 0 ] ; then
248
+			merr "Export of standard table failed [$TABLE]"
249
+			# there was a problem, but it is not something
250
+			# we can handle here; We can deal with this at import
251
+			# time.
252
+		    fi
253
+	    else
254
+	    	    mwarn "Table not found: [$TABLE]"
255
+	    fi
256
+	done
257
+	
258
+	# Dump the PRESENCE tables to plain-text files in DUMP_DIR
259
+	for TABLE in $PRESENCE_TABLES; do
260
+	    if [ -f $2/$TABLE ] ; then
261
+		    mdbg "Exporting presence table: $TABLE"
262
+		    $DUMP_CMD -p -h $2 $TABLE  | perl -pe 's/^\w.*// ; s/^\s(.*)/$1/' > $1/$TABLE.txt
263
+		    if [ $? -ne 0 ] ; then
264
+			merr "Export of presence table failed [$TABLE]"
265
+		    fi
266
+	    else
267
+	    	    mwarn "Table not found: [$TABLE]"
268
+	    fi
269
+	done
270
+	
271
+	# Dump the EXTRA tables to plain-text files in DUMP_DIR
272
+	for TABLE in $EXTRA_TABLES; do
273
+	    if [ -f $2/$TABLE ] ; then
274
+		    mdbg "Exporting extra table: $TABLE"
275
+		    $DUMP_CMD -p -h $2 $TABLE  | perl -pe 's/^\w.*// ; s/^\s(.*)/$1/' > $1/$TABLE.txt
276
+		    if [ $? -ne 0 ] ; then
277
+			merr "Export of extra table failed [$TABLE]"
278
+		    fi
279
+	    else
280
+	    	    mwarn "Table not found: [$TABLE]"
281
+	    fi
282
+	done
283
+	
284
+	mdbg "All tables are now exported to DUMP_DIR: [$1]"
285
+	return 0
286
+
287
+}
288
+
289
+
290
+##
291
+# MIGRATE (schema)
292
+# Examine each plain-txt file in DUMP_DIR
293
+#  (Assumes that openser_export was already invoked)
294
+#
295
+# Migrate converts data from schema-old to schema-new in place.
296
+#
297
+# After this step is complete the IMPORT should be executed.
298
+openser_migrate()  # parms: <DUMP_DIR> [DB_PATH]
299
+{
300
+	merr "db_berkeley migrate not implemented"
301
+	exit 1
302
+}
303
+
304
+
305
+##
306
+# IMPORT existing plain-txt files from DUMP_DIR to DB_PATH
307
+# eg.  DUMP_DIR/version.txt  --> DB_PATH/version
308
+#
309
+# import is used as part of DB migrate to another major version of berkeley db.
310
+# this will over-write anything in DB_PATH
311
+openser_import()  # parms: <DUMP_DIR> [DB_PATH]
312
+{
313
+	if [ $# -lt 2  ]; then
314
+		echo  "openser_dump parms: <DUMP_DIR> [DB_PATH]"
315
+		exit 1
316
+	fi
317
+	
318
+	# Assert: DUMP_DIR (source dir) already exists
319
+	if [ ! -d $1 ] ; then
320
+		merr "Berkeley DUMP_DIR directory does not exist: [$1]"
321
+		exit 1;
322
+	fi
323
+	
324
+	# Assert: DUMP_DIR directory should already contain table 'version.txt'
325
+	if [ ! -f $1/version.txt ] ; then
326
+		merr "DUMP_DIR directory does not have VERSION.txt data at: [$1]"
327
+		exit 1
328
+	fi
329
+	
330
+	# Assert: destination dir exists [DB_PATH]
331
+	if [ ! -d $2 ] ; then
332
+		mdbg "Berkeley DB_PATH directory is being created: [$2]"
333
+		mkdir -p $2
334
+	else
335
+		# Wipe out the destination dir to make room for new data
336
+		mwarn "Berkeley DB_PATH directory is being purged at: [$2]"
337
+		rm -rf $2/*
338
+	fi
339
+	
340
+	# Creates STANDARD tables from plain-text files in DUMP_DIR
341
+	for TABLE in $STANDARD_TABLES; do
342
+	    if [ -s $1/$TABLE.txt ] ; then
343
+		    mdbg "Importing standard table: $TABLE"
344
+		    $LOAD_CMD -T -t hash -f $1/$TABLE.txt -h $2 $TABLE
345
+		    
346
+		    # Check return code to make sure the export worked ok
347
+		    if [ $? -ne 0 ] ; then
348
+			merr "Import of standard table failed [$TABLE.txt]"
349
+			merr "Create this missing table with kambdb_recover."
350
+		    fi
351
+	    else
352
+	    	    merr "Import data not found for table: [$TABLE.txt]" 
353
+		    merr "Create this missing table with kambdb_recover."
354
+	    fi
355
+	done
356
+	
357
+
358
+	# Creates PRESENCE tables from plain-text files in DUMP_DIR
359
+	for TABLE in $PRESENCE_TABLES; do
360
+	    if [ -s $1/$TABLE.txt ] ; then
361
+		    mdbg "Importing presence table: $TABLE"
362
+		    $LOAD_CMD -T -t hash -f $1/$TABLE.txt -h $2 $TABLE
363
+		    
364
+		    # Check return code to make sure the export worked ok
365
+		    if [ $? -ne 0 ] ; then
366
+			merr "Import of presence table failed [$TABLE.txt]"
367
+			merr "Create this missing table with kambdb_recover."
368
+		    fi
369
+	    else
370
+		    mwarn "Import data not found for table: [$TABLE.txt]"
371
+	    fi
372
+	done
373
+
374
+	# Creates EXTRA tables from plain-text files in DUMP_DIR
375
+	for TABLE in $EXTRA_TABLES; do
376
+	    if [ -s $1/$TABLE.txt ] ; then
377
+		    mdbg "Importing extra table: $TABLE"
378
+		    $LOAD_CMD -T -t hash -f $1/$TABLE.txt -h $2 $TABLE
379
+		    
380
+		    # Check return code to make sure the export worked ok
381
+		    if [ $? -ne 0 ] ; then
382
+			merr "Import of extra table failed [$TABLE.txt]"
383
+			merr "Create this missing table with kambdb_recover."
384
+		    fi
385
+	    else
386
+		    mwarn "Import data not found for table: [$TABLE.txt]"
387
+	    fi
388
+	done
389
+	
390
+	mdbg "All tables are now imported to DB_PATH: [$2]"
391
+	return 0
392
+
393
+}
394
+
395
+
396
+openser_swap()  # parms: <db> [DB_PATH]
397
+{
398
+	if [ $# -lt 2  ]; then
399
+		echo  "openser_swap parms: <db> [DB_PATH]"
400
+		exit 1
401
+	fi
402
+	
403
+	DB=$2/$1
404
+	DBNEW=$DB.new
405
+	DBOLD=$DB.old
406
+	cp $DB $DBOLD
407
+	mv $DBNEW $DB
408
+}
409
+
410
+#####
411
+# append process is:
412
+# 1. copy DB_PATH/db to DB_PATH/db.new
413
+# 2. appends contents of newdata to DB_PATH/db.new
414
+#
415
+openser_append()  # parms: <db> <newdata> [DB_PATH]
416
+{
417
+	if [ $# -lt 3  ]; then
418
+		echo  "openser_append parms: <db> <newdata> [DB_PATH]"
419
+		exit 1
420
+	fi
421
+	
422
+	DB=$3/$1
423
+	DBNEW=$DB.new
424
+	if [ -f $DB.new ] ; then
425
+		rm $DB.new
426
+	fi
427
+	
428
+	cp $DB $DBNEW
429
+# echo "$LOAD_CMD -T -t hash -f $2 -h $3 $1.new"
430
+	$LOAD_CMD -T -t hash -f $2 -h $3 $1.new
431
+	
432
+# echo "$LOAD_CMD -r fileid -h $3 $1.new"
433
+  	$LOAD_CMD -r fileid -h $3 $1.new
434
+}
435
+
436
+
437
+#####
438
+# newappend process is:
439
+# 1. create a new temp DBENV in /tmp/sc-<processID>
440
+# 2. appends contents of newdata to /tmp/sc-<processID>/db
441
+# 3. move /tmp/sc-<processID>/db over to DB_PATH/db.new
442
+# 4. delete temp DBENV dir /tmp/sc-<processID>
443
+#
444
+openser_newappend()  # parms: <db> <newdata> [DB_PATH]
445
+{
446
+	if [ $# -lt 3  ]; then
447
+		echo  "openser_append parms: <db> <newdata> [DB_PATH]"
448
+		exit 1
449
+	fi
450
+	
451
+	DB=$3/$1
452
+	DBNEW=$DB.new
453
+	if [ -f $DBNEW ] ; then
454
+		rm $DBNEW
455
+	fi
456
+	TMPENV=/tmp/sc-$$
457
+	openser_create $TMPENV
458
+	cd $OLDPWD
459
+	$LOAD_CMD -T -t hash -f $2 -h $TMPENV $1
460
+	mv $TMPENV/$1 $DBNEW
461
+	rm -rf $TMPENV
462
+}
463
+
464
+
465
+# cat all rows to STDOUT
466
+openser_cat()  # pars: <database name> <DB_PATH>
467
+{
468
+	if [ $# -ne 2 ] ; then
469
+		echo  "openser_cat params <db> [DB_PATH]"
470
+		exit 1
471
+	fi
472
+	
473
+	$DUMP_CMD -p -h $2 $1
474
+}
475
+
476
+openser_drop()  # pars:  <DB_PATH>
477
+{
478
+	if [ $# -ne 1 ] ; then
479
+		echo "openser_drop function takes one param"
480
+		exit 1
481
+	fi
482
+	
483
+	if [ ! -d $1 ] ; then
484
+		echo "Directory does not exist:  $1"
485
+	fi
486
+	
487
+	minfo "Dropping Berkeley DB database at: $1 ..."
488
+	
489
+	# core
490
+	if [ -f $1/version ] ; then
491
+		for TABLE in $STANDARD_TABLES; do
492
+		    mdbg "Dropping core table: $TABLE"
493
+		    rm -f $1/$TABLE
494
+		done
495
+	fi
496
+	
497
+	# presence
498
+	if [ -f $1/presentity ] ; then
499
+		for TABLE in $PRESENCE_TABLES; do
500
+		    mdbg "Dropping presence table: $TABLE"
501
+		    rm -f $1/$TABLE
502
+		done
503
+	fi
504
+	
505
+	# extra tables
506
+	if [ -f $1/cpl ] ; then
507
+		for TABLE in $EXTRA_TABLES; do
508
+		    mdbg "Dropping extra table: $TABLE"
509
+		    rm -f $1/$TABLE
510
+		done
511
+	fi
512
+
513
+	# delete db files and directory
514
+	rm -rf $1/__db.001
515
+	rm -rf $1/__db.002
516
+	rm -rf $1/__db.003
517
+	rm -rf $1/__db.004
518
+	rmdir $1
519
+}
520
+
521
+
522
+openser_create() # pars: <DB_PATH>
523
+{
524
+	if [ $# -ne 1 ] ; then
525
+		echo "openser_create param [DB_PATH]"
526
+		exit 1
527
+	fi
528
+	
529
+	DB_PATH=$1
530
+	if [ ! -d $1 ] ; then
531
+		minfo "creating Berkeley DB database at: [$1]"
532
+		mkdir -p $DB_PATH
533
+	fi
534
+	
535
+	for TABLE in $STANDARD_TABLES; do
536
+	    mdbg "Creating standard table: $TABLE"
537
+	    $LOAD_CMD -T -t hash -f $DB_SCHEMA/$TABLE -h $1 $TABLE
538
+	    if [ $? -ne 0 ] ; then
539
+		merr "Creating standard tables failed!"
540
+		exit 1
541
+	    fi
542
+	done
543
+
544
+	get_answer $INSTALL_PRESENCE_TABLES "Install presence related tables? (y/n): "
545
+	if [ "$ANSWER" = "y" ]; then
546
+		presence_create $1
547
+	fi
548
+
549
+	get_answer $INSTALL_EXTRA_TABLES "Install tables for $EXTRA_MODULES? (y/n): "
550
+	if [ "$ANSWER" = "y" ]; then
551
+		extra_create $1
552
+	fi
553
+
554
+} # openser_create
555
+
556
+
557
+presence_create() # pars: <DB_PATH>
558
+{
559
+	if [ $# -ne 1 ] ; then
560
+		merr "presence_create param [DB_PATH]"
561
+		exit 1
562
+	fi
563
+	
564
+	DB_PATH=$1
565
+	if [ ! -d $1 ] ; then
566
+		# Assert: the directory should already exist
567
+		merr "BerkeleyDB directory does not exist at: [$1]"
568
+		exit 1
569
+	fi
570
+
571
+	if [ ! -f $1/version ] ; then
572
+		# Assert: directory should already contain table 'version'
573
+		merr "BerkeleyDB directory does not have VERSION table at: [$1]"
574
+		exit 1
575
+	fi
576
+	
577
+	for TABLE in $PRESENCE_TABLES; do
578
+	    mdbg "Creating presence table: $TABLE"
579
+	    $LOAD_CMD -T -t hash -f $DB_SCHEMA/$TABLE -h $1 $TABLE
580
+	    if [ $? -ne 0 ] ; then
581
+		merr "Creating presence tables failed!"
582
+		exit 1
583
+	    fi
584
+	done
585
+	
586
+}  # end presence_create
587
+
588
+
589
+extra_create() # pars: <DB_PATH>
590
+{
591
+
592
+	if [ $# -ne 1 ] ; then
593
+		merr "extra_create function takes one param (DB_PATH)"
594
+		exit 1
595
+	fi
596
+	
597
+	DB_PATH=$1
598
+	if [ ! -d $1 ] ; then
599
+		# Assert: the directory should already exist
600
+		merr "BerkeleyDB directory does not exist at: [$1]"
601
+		exit 1
602
+	fi
603
+
604
+	if [ ! -f $1/version ] ; then
605
+		# Assert: directory should already contain table 'version'
606
+		merr "BerkeleyDB directory does not have VERSION table at: [$1]"
607
+		exit 1
608
+	fi
609
+	
610
+	for TABLE in $EXTRA_TABLES; do