1 /* $Id: main.c,v 1.106 2003-09-16 13:58:25 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
35 #include <sys/times.h>
47 int main (int argc, char **argv)
54 int disableCommit = 0;
59 struct tms tms1, tms2;
60 struct timeval start_time, end_time;
66 struct recordGroup rGroupDef;
74 sprintf(nbuf, "%.40s(%d)", *argv, getpid());
75 yaz_log_init_prefix (nbuf);
79 gettimeofday(&start_time, 0);
82 rGroupDef.groupName = NULL;
83 rGroupDef.databaseName = NULL;
84 rGroupDef.path = NULL;
85 rGroupDef.recordId = NULL;
86 rGroupDef.recordType = NULL;
87 rGroupDef.flagStoreData = -1;
88 rGroupDef.flagStoreKeys = -1;
90 rGroupDef.databaseNamePath = 0;
91 rGroupDef.explainDatabase = 0;
92 rGroupDef.fileVerboseLimit = 100000;
93 rGroupDef.followLinks = -1;
98 fprintf (stderr, "%s [options] command <dir> ...\n"
100 " update <dir> Update index with files below <dir>.\n"
101 " If <dir> is empty filenames are read from stdin.\n"
102 " delete <dir> Delete index with files below <dir>.\n"
103 " create <db> Create database <db>\n"
104 " drop <db> Drop database <db>\n"
105 " commit Commit changes\n"
106 " clean Clean shadow files\n"
108 " -t <type> Index files as <type> (grs or text).\n"
109 " -c <config> Read configuration file <config>.\n"
110 " -g <group> Index files according to group settings.\n"
111 " -d <database> Records belong to Z39.50 database <database>.\n"
112 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
113 " -n Don't use shadow system.\n"
114 " -s Show analysis on stdout, but do no work.\n"
115 " -v <level> Set logging to <level>.\n"
116 " -l <file> Write log to <file>.\n"
117 " -L Don't follow symbolic links.\n"
118 " -f <n> Display information for the first <n> records.\n"
119 " -V Show version.\n", *argv
123 while ((ret = options ("sVt:c:g:d:m:v:nf:l:L"
124 , argv, argc, &arg)) != -2)
128 if(cmd == 0) /* command */
132 const char *config = configName ? configName : "zebra.cfg";
133 logf (LOG_LOG, "Zebra version %s %s",
134 ZEBRAVER, ZEBRADATE);
135 zs = zebra_start (config);
138 yaz_log (LOG_FATAL, "Cannot read config %s", config);
141 zh = zebra_open (zs);
143 zebra_shadow_enable (zh, 0);
146 if (rGroupDef.databaseName)
148 if (zebra_select_database (zh, rGroupDef.databaseName))
150 logf(LOG_FATAL, "Could not select database %s errCode=%d",
151 rGroupDef.databaseName, zebra_errCode(zh) );
157 if (zebra_select_database (zh, "Default"))
159 logf(LOG_FATAL, "Could not select database Default errCode=%d",
165 zebra_set_resource(zh, "memmax",mem_max);
167 if (!strcmp (arg, "update"))
169 else if (!strcmp (arg, "update1"))
171 else if (!strcmp (arg, "update2"))
173 else if (!strcmp (arg, "dump"))
175 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
177 else if (!strcmp (arg, "init"))
181 else if (!strcmp(arg, "drop"))
185 else if (!strcmp(arg, "create"))
189 else if (!strcmp (arg, "commit"))
193 else if (!strcmp (arg, "clean"))
197 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
199 zebra_register_statistics (zh,0);
201 else if (!strcmp (arg, "dumpdict"))
203 zebra_register_statistics (zh,1);
205 else if (!strcmp (arg, "compact"))
211 logf (LOG_FATAL, "unknown command: %s", arg);
217 rGroupDef.path = arg;
218 zebra_set_group (zh, &rGroupDef);
222 if (zebra_begin_trans (zh, 1))
228 zebra_repository_update (zh);
231 zebra_repository_delete (zh);
234 logf (LOG_LOG, "dumping %s", rGroupDef.path);
235 zebra_repository_show (zh);
239 zebra_create_database(zh, rGroupDef.path);
242 zebra_drop_database(zh, rGroupDef.path);
247 log_event_end (NULL, NULL);
252 printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
253 printf(" (C) 1994-2003, Index Data ApS\n");
256 printf(" WIN32 Debug\n");
258 printf(" WIN32 Release\n");
262 printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n");
265 printf("Using: Tcl %s\n", TCL_VERSION);
269 yaz_log_init_level (yaz_log_mask_str(arg));
271 yaz_log_init_file (arg);
275 rGroupDef.databaseName = arg;
277 rGroupDef.flagRw = 0;
279 rGroupDef.groupName = arg;
281 rGroupDef.fileVerboseLimit = atoi(arg);
285 rGroupDef.recordType = arg;
289 rGroupDef.followLinks = 0;
291 logf (LOG_WARN, "unknown option '-%s'", arg);
295 zebra_end_trans (zh);
302 gettimeofday(&end_time, 0);
303 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000L +
304 end_time.tv_usec - start_time.tv_usec;
306 yaz_log (LOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f",
307 (double) usec / 1000000.0,
308 (double) (tms2.tms_utime - tms1.tms_utime)/100,
309 (double) (tms2.tms_stime - tms1.tms_stime)/100);