Some doc path fixes from Anders
[pkg-k5-afs_openafs.git] / src / bucoord / main.c
blob34a3a7926c1faabb1a6074dc05babf2042eb42c7
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
14 #include <roken.h>
17 #include <afs/cmd.h>
18 #include <rx/rx.h>
19 #include <rx/rx_globals.h>
20 #include <lwp.h>
21 #include <afs/bubasics.h>
22 #include <afs/afsutil.h>
23 #include <afs/auth.h>
24 #include <afs/cellconfig.h>
25 #include <afs/keys.h>
26 #include <ubik.h>
27 #include <afs/cmd.h>
28 #include <rx/rxkad.h>
29 #include <afs/afsint.h>
30 #include <afs/volser.h> /*VLDB_MAXSERVERS */
31 #include <afs/com_err.h>
32 #include <lock.h>
33 #include <afs/budb.h>
34 #include <afs/kautils.h>
35 #include <afs/vlserver.h>
36 #include <afs/butm.h>
37 #include <afs/butx.h>
38 #include <afs/tcdata.h>
40 #include "bc.h" /*Backup Coordinator structs and defs */
41 #include "bucoord_internal.h"
42 #include "bucoord_prototypes.h"
44 int localauth, interact;
45 char tcell[64];
48 * Global configuration information for the Backup Coordinator.
50 struct bc_config *bc_globalConfig; /*Ptr to global BC configuration info */
52 struct ubik_client *cstruct; /* Ptr to Ubik client structure */
53 time_t tokenExpires; /* The token's expiration time */
55 static const char *DefaultConfDir; /*Default backup config directory */
56 static int bcInit = 0; /* backupInit called yet ? */
57 char *whoami = "backup";
59 /* dummy routine for the audit work. It should do nothing since audits */
60 /* occur at the server level and bos is not a server. */
61 int
62 osi_audit(void)
64 return 0;
68 * Initialize all the error tables that may be used by com_err
69 * in this module.
71 void
72 InitErrTabs(void)
74 initialize_ACFG_error_table();
75 initialize_KA_error_table();
76 initialize_RXK_error_table();
77 initialize_CMD_error_table();
78 initialize_VL_error_table();
79 initialize_BUTM_error_table();
80 initialize_VOLS_error_table();
81 initialize_BUTC_error_table();
82 initialize_BUTX_error_table();
83 initialize_BUDB_error_table();
84 initialize_BUCD_error_table();
85 initialize_KTC_error_table();
89 * got to account for the errors which are volume related but
90 * not dealt with by standard errno and com_err stuff.
92 void
93 bc_HandleMisc(afs_int32 code)
95 if (((code <= VMOVED) && (code >= VSALVAGE)) || (code < 0)) {
96 switch (code) {
97 case -1:
98 fprintf(STDERR, "Possible communication failure\n");
99 break;
100 case VSALVAGE:
101 fprintf(STDERR, "Volume needs salvage\n");
102 break;
103 case VNOVNODE:
104 fprintf(STDERR, "Bad vnode number quoted\n");
105 break;
106 case VNOVOL:
107 fprintf(STDERR,
108 "Volume not attached, does not exist, or not on line\n");
109 break;
110 case VVOLEXISTS:
111 fprintf(STDERR, "Volume already exists\n");
112 break;
113 case VNOSERVICE:
114 fprintf(STDERR, "Volume is not in service\n");
115 break;
116 case VOFFLINE:
117 fprintf(STDERR, "Volume is off line\n");
118 break;
119 case VONLINE:
120 fprintf(STDERR, "Volume is already on line\n");
121 break;
122 case VDISKFULL:
123 fprintf(STDERR, "Partition is full\n");
124 break;
125 case VOVERQUOTA:
126 fprintf(STDERR, "Volume max quota exceeded\n");
127 break;
128 case VBUSY:
129 fprintf(STDERR, "Volume temporarily unavailable\n");
130 break;
131 case VMOVED:
132 fprintf(STDERR, "Volume has moved to another server\n");
133 break;
134 default:
135 break;
138 return;
141 /* Return true if line is all whitespace */
142 static int
143 LineIsBlank(char *aline)
145 int tc;
147 while ((tc = *aline++))
148 if ((tc != ' ') && (tc != '\t') && (tc != '\n'))
149 return (0);
151 return (1);
155 /* bc_InitTextConfig
156 * initialize configuration information that is stored as text blocks
159 afs_int32
160 bc_InitTextConfig(void)
162 udbClientTextP ctPtr;
163 int i;
165 extern struct bc_config *bc_globalConfig;
167 mkdir(DefaultConfDir, 777); /* temporary */
169 /* initialize the client text structures */
170 ctPtr = &bc_globalConfig->configText[0];
172 for (i = 0; i < TB_NUM; i++) {
173 memset(ctPtr, 0, sizeof(*ctPtr));
174 ctPtr->textType = i;
175 ctPtr->textVersion = -1;
176 ctPtr++;
179 return (0);
182 /*----------------------------------------------------------------------------
183 * backupInit
185 * Description:
186 * Routine that is called when the backup coordinator is invoked, responsible for
187 * basic initialization and some command line parsing.
189 * Returns:
190 * Zero (but may exit the entire program on error!)
192 * Environment:
193 * Nothing interesting.
195 * Side Effects:
196 * Initializes this program.
197 *----------------------------------------------------------------------------
200 static int
201 backupInit(void)
203 afs_int32 code;
204 static int initd = 0; /* ever called? */
205 PROCESS watcherPid;
206 PROCESS pid; /* LWP process ID */
208 /* Initialization */
209 initialize_CMD_error_table();
211 /* don't run more than once */
212 if (initd) {
213 afs_com_err(whoami, 0, "Backup already initialized.");
214 return 0;
216 initd = 1;
218 code = bc_InitConfig((char *)DefaultConfDir);
219 if (code) {
220 afs_com_err(whoami, code,
221 "Can't initialize from config files in directory '%s'",
222 DefaultConfDir);
223 return (code);
227 * Set up Rx.
229 code = LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &pid);
230 if (code) {
231 afs_com_err(whoami, code, "; Can't initialize LWP");
232 return (code);
235 code = rx_Init(htons(0));
236 if (code) {
237 afs_com_err(whoami, code, "; Can't initialize Rx");
238 return (code);
241 rx_SetRxDeadTime(60);
243 /* VLDB initialization */
244 code = vldbClientInit(0, localauth, tcell, &cstruct, &tokenExpires);
245 if (code)
246 return (code);
248 /* Backup database initialization */
249 code = udbClientInit(0, localauth, tcell);
250 if (code)
251 return (code);
253 /* setup status monitoring thread */
254 initStatus();
255 code =
256 LWP_CreateProcess(statusWatcher, 20480, LWP_NORMAL_PRIORITY,
257 (void *)2, "statusWatcher", &watcherPid);
258 if (code) {
259 afs_com_err(whoami, code, "; Can't create status monitor task");
260 return (code);
263 return (0);
266 /*----------------------------------------------------------------------------
267 * MyBeforeProc
269 * Description:
270 * Make sure we mark down when we need to exit the Backup Coordinator.
271 * Specifically, we don't want to continue when our help and apropos
272 * routines are called from the command line.
274 * Arguments:
275 * as : Ptr to the command syntax descriptor.
277 * Returns:
278 * 0.
280 * Environment:
281 * This routine is called right before each of the Backup Coordinator
282 * opcode routines are invoked.
284 *----------------------------------------------------------------------------
287 static int
288 MyBeforeProc(struct cmd_syndesc *as, void *arock)
290 afs_int32 code;
292 /* Handling the command line opcode */
293 if (!bcInit) {
294 localauth = ((as && as->parms[14].items) ? 1 : 0);
295 if (as && as->parms[15].items)
296 strcpy(tcell, as->parms[15].items->data);
297 else
298 tcell[0] = '\0';
300 code = backupInit();
301 if (code) {
302 afs_com_err(whoami, code, "; Can't initialize backup");
303 exit(1);
306 /* Get initial information from the database */
307 code = bc_InitTextConfig();
308 if (code) {
309 afs_com_err(whoami, code,
310 "; Can't obtain configuration text from backup database");
311 exit(1);
314 bcInit = 1;
316 return 0;
320 #define MAXV 100
322 #include "AFS_component_version_number.c"
324 #define MAXRECURSION 20
325 extern int dontExecute; /* declared in commands.c */
326 extern char *loadFile; /* declared in commands.c */
327 char lineBuffer[1024]; /* Line typed in by user or read from load file */
330 * This will dispatch a command. It holds a recursive loop for the
331 * "dump -file" option. This option reads backup commands from a file.
333 * Cannot put this code on other side of cmd_Dispatch call (in
334 * commands.c) because when make a dispatch call when in a dispatch
335 * call, environment is mucked up.
337 * To avoid multiple processes stepping on each other in the dispatch code,
338 * put a lock around it so only 1 process gets in at a time.
341 struct Lock dispatchLock; /* lock on the Dispatch call */
342 #define lock_Dispatch() ObtainWriteLock(&dispatchLock)
343 #define unlock_Dispatch() ReleaseWriteLock(&dispatchLock)
345 afs_int32
346 doDispatch(afs_int32 targc,
347 char *targv[MAXV],
348 afs_int32 dispatchCount) /* to prevent infinite recursion */
350 char *sargv[MAXV];
351 afs_int32 sargc;
352 afs_int32 code, c;
353 FILE *fd;
354 int i;
355 int lineNumber;
356 int noExecute; /* local capy of global variable */
357 char *internalLoadFile;
359 lock_Dispatch();
361 loadFile = NULL;
362 code = cmd_Dispatch(targc, targv);
363 internalLoadFile = loadFile;
365 unlock_Dispatch();
367 if (internalLoadFile) { /* Load a file in */
368 if (dispatchCount > MAXRECURSION) { /* Beware recursive loops. */
369 afs_com_err(whoami, 0, "Potential recursion: will not load file %s",
370 internalLoadFile);
371 code = -1;
372 goto done;
375 fd = fopen(internalLoadFile, "r"); /* Open the load file */
376 if (!fd) {
377 afs_com_err(whoami, errno, "; Cannot open file %s", internalLoadFile);
378 code = -1;
379 goto done;
382 noExecute = dontExecute;
383 if (noExecute)
384 printf("Would have executed the following commands:\n");
386 lineNumber = 0;
387 while (fgets(lineBuffer, sizeof(lineBuffer) - 1, fd)) { /* Get commands from file */
388 lineNumber++;
390 i = strlen(lineBuffer) - 1;
391 if (lineBuffer[i] == '\n') /* Drop return at end of line */
392 lineBuffer[i] = '\0';
394 if (noExecute)
395 printf(" %s\n", lineBuffer); /* echo */
396 else
397 printf("------> %s\n", lineBuffer); /* echo */
399 if (!LineIsBlank(lineBuffer) && /* Skip if blank line */
400 (lineBuffer[0] != '#') && /* or comment */
401 (!noExecute)) { /* or no execute */
402 c = cmd_ParseLine(lineBuffer, sargv, &sargc, MAXV);
403 if (c) {
404 afs_com_err(whoami, c, "; Can't parse line");
405 } else {
406 doDispatch(sargc, sargv, dispatchCount + 1); /* Recursive - ignore error */
407 cmd_FreeArgv(sargv); /* Free up arguments */
412 fclose(fd);
415 done:
416 if (internalLoadFile)
417 free(internalLoadFile);
418 return (code);
422 bc_interactCmd(struct cmd_syndesc *as, void *arock)
424 interact = 1;
425 return 0;
428 static void
429 add_std_args(struct cmd_syndesc *ts)
431 cmd_Seek(ts, 14);
432 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
433 "local authentication");
434 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
438 main(int argc, char **argv)
439 { /*main */
440 char *targv[MAXV]; /*Ptr to parsed argv stuff */
441 afs_int32 targc; /*Num parsed arguments */
442 afs_int32 code; /*Return code */
443 struct cmd_syndesc *ts; /*Ptr to parsed command line */
444 int i;
447 #ifdef AFS_AIX32_ENV
449 * The following signal action for AIX is necessary so that in case of a
450 * crash (i.e. core is generated) we can include the user's data section
451 * in the core dump. Unfortunately, by default, only a partial core is
452 * generated which, in many cases, isn't too useful.
454 struct sigaction nsa;
456 sigemptyset(&nsa.sa_mask);
457 nsa.sa_handler = SIG_DFL;
458 nsa.sa_flags = SA_FULLDUMP;
459 sigaction(SIGSEGV, &nsa, NULL);
460 #endif
461 Lock_Init(&dispatchLock);
462 InitErrTabs(); /* init all the error tables which may be used */
464 /* setup the default backup dir */
465 DefaultConfDir = AFSDIR_SERVER_BACKUP_DIRPATH;
466 /* Get early warning if the command is interacive mode or not */
467 if (argc < 2) {
468 interact = 1;
469 } else {
470 interact = 0;
471 if (argv[1][0] == '-') {
472 interact = 1;
473 if (strcmp(argv[1], "-help") == 0) {
474 interact = 0;
479 cmd_SetBeforeProc(MyBeforeProc, NULL);
481 ts = cmd_CreateSyntax("dump", bc_DumpCmd, NULL, 0, "start dump");
482 cmd_AddParm(ts, "-volumeset", CMD_SINGLE, CMD_OPTIONAL,
483 "volume set name");
484 cmd_AddParm(ts, "-dump", CMD_SINGLE, CMD_OPTIONAL, "dump level name");
485 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
486 "TC port offset");
487 cmd_AddParm(ts, "-at", CMD_LIST, CMD_OPTIONAL, "Date/time to start dump");
488 cmd_AddParm(ts, "-append", CMD_FLAG, CMD_OPTIONAL,
489 "append to existing dump set");
490 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
491 "list what would be done, don't do it");
492 cmd_AddParmAlias(ts, 5, "-n");
493 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "load file");
494 if (!interact)
495 add_std_args(ts);
497 ts = cmd_CreateSyntax("volrestore", bc_VolRestoreCmd, NULL, 0,
498 "restore volume");
499 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED,
500 "destination machine");
501 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED,
502 "destination partition");
503 cmd_AddParm(ts, "-volume", CMD_LIST, CMD_REQUIRED,
504 "volume(s) to restore");
505 cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL,
506 "new volume name extension");
507 cmd_AddParm(ts, "-date", CMD_LIST, CMD_OPTIONAL,
508 "date from which to restore");
509 cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offsets");
510 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
511 "list what would be done, don't do it");
512 cmd_AddParmAlias(ts, 6, "-n");
513 cmd_AddParm(ts, "-usedump", CMD_SINGLE, CMD_OPTIONAL,
514 "specify the dumpID to restore from");
515 if (!interact)
516 add_std_args(ts);
518 ts = cmd_CreateSyntax("diskrestore", bc_DiskRestoreCmd, NULL, 0,
519 "restore partition");
520 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED,
521 "machine to restore");
522 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED,
523 "partition to restore");
524 cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offset");
525 cmd_Seek(ts, 8);
526 cmd_AddParm(ts, "-newserver", CMD_SINGLE, CMD_OPTIONAL,
527 "destination machine");
528 cmd_AddParm(ts, "-newpartition", CMD_SINGLE, CMD_OPTIONAL,
529 "destination partition");
530 cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL,
531 "new volume name extension");
532 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
533 "list what would be done, don't do it");
534 cmd_AddParmAlias(ts, 11, "-n");
535 if (!interact)
536 add_std_args(ts);
538 cmd_CreateSyntax("quit", bc_QuitCmd, NULL, 0, "leave the program");
540 ts = cmd_CreateSyntax("volsetrestore", bc_VolsetRestoreCmd, NULL, 0,
541 "restore a set of volumes");
542 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume set name");
543 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "file name");
544 cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offset");
545 cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL,
546 "new volume name extension");
547 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
548 "list what would be done, don't do it");
549 cmd_AddParmAlias(ts, 4, "-n");
550 if (!interact)
551 add_std_args(ts);
553 ts = cmd_CreateSyntax("addhost", bc_AddHostCmd, NULL, 0, "add host to config");
554 cmd_AddParm(ts, "-tapehost", CMD_SINGLE, CMD_REQUIRED,
555 "tape machine name");
556 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
557 "TC port offset");
558 if (!interact)
559 add_std_args(ts);
561 ts = cmd_CreateSyntax("delhost", bc_DeleteHostCmd, NULL, 0,
562 "delete host to config");
563 cmd_AddParm(ts, "-tapehost", CMD_SINGLE, CMD_REQUIRED,
564 "tape machine name");
565 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
566 "TC port offset");
567 if (!interact)
568 add_std_args(ts);
570 ts = cmd_CreateSyntax("listhosts", bc_ListHostsCmd, NULL, 0,
571 "list config hosts");
572 if (!interact)
573 add_std_args(ts);
575 cmd_CreateSyntax("jobs", bc_JobsCmd, NULL, 0, "list running jobs");
577 ts = cmd_CreateSyntax("kill", bc_KillCmd, NULL, 0, "kill running job");
578 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_REQUIRED,
579 "job ID or dump set name");
581 ts = cmd_CreateSyntax("listvolsets", bc_ListVolSetCmd, NULL, 0,
582 "list volume sets");
583 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume set name");
584 if (!interact)
585 add_std_args(ts);
587 ts = cmd_CreateSyntax("listdumps", bc_ListDumpScheduleCmd, NULL, 0,
588 "list dump schedules");
589 if (!interact)
590 add_std_args(ts);
592 ts = cmd_CreateSyntax("addvolset", bc_AddVolSetCmd, NULL, 0,
593 "create a new volume set");
594 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_REQUIRED, "volume set name");
595 cmd_AddParm(ts, "-temporary", CMD_FLAG, CMD_OPTIONAL,
596 "temporary volume set");
597 if (!interact)
598 add_std_args(ts);
600 ts = cmd_CreateSyntax("status", bc_GetTapeStatusCmd, NULL, 0,
601 "get tape coordinator status");
602 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
603 "TC port offset");
604 if (!interact)
605 add_std_args(ts);
607 ts = cmd_CreateSyntax("delvolset", bc_DeleteVolSetCmd, NULL, 0,
608 "delete a volume set");
609 cmd_AddParm(ts, "-name", CMD_LIST, CMD_REQUIRED, "volume set name");
610 if (!interact)
611 add_std_args(ts);
613 ts = cmd_CreateSyntax("addvolentry", bc_AddVolEntryCmd, NULL, 0,
614 "add a new volume entry");
615 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_REQUIRED, "volume set name");
616 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
617 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
618 cmd_AddParm(ts, "-volumes", CMD_SINGLE, CMD_REQUIRED,
619 "volume name (regular expression)");
620 if (!interact)
621 add_std_args(ts);
623 ts = cmd_CreateSyntax("delvolentry", bc_DeleteVolEntryCmd, NULL, 0,
624 "delete a volume set sub-entry");
625 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_REQUIRED, "volume set name");
626 cmd_AddParm(ts, "-entry", CMD_SINGLE, CMD_REQUIRED, "volume set index");
627 if (!interact)
628 add_std_args(ts);
630 ts = cmd_CreateSyntax("adddump", bc_AddDumpCmd, NULL, 0, "add dump schedule");
631 cmd_AddParm(ts, "-dump", CMD_LIST, CMD_REQUIRED, "dump level name");
632 cmd_AddParm(ts, "-expires", CMD_LIST, CMD_OPTIONAL, "expiration date");
633 if (!interact)
634 add_std_args(ts);
636 ts = cmd_CreateSyntax("deldump", bc_DeleteDumpCmd, NULL, 0,
637 "delete dump schedule");
638 cmd_AddParm(ts, "-dump", CMD_SINGLE, CMD_REQUIRED, "dump level name");
639 if (!interact)
640 add_std_args(ts);
642 ts = cmd_CreateSyntax("labeltape", bc_LabelTapeCmd, NULL, 0, "label a tape");
643 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL,
644 "AFS tape name, defaults to NULL");
645 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL,
646 "tape size in Kbytes, defaults to size in tapeconfig");
647 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
648 "TC port offset");
649 cmd_AddParm(ts, "-pname", CMD_SINGLE, CMD_OPTIONAL,
650 "permanent tape name");
651 if (!interact)
652 add_std_args(ts);
654 ts = cmd_CreateSyntax("readlabel", bc_ReadLabelCmd, NULL, 0,
655 "read the label on tape");
656 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
657 "TC port offset");
658 if (!interact)
659 add_std_args(ts);
661 ts = cmd_CreateSyntax("scantape", bc_ScanDumpsCmd, NULL, 0,
662 "dump information recovery from tape");
663 cmd_AddParm(ts, "-dbadd", CMD_FLAG, CMD_OPTIONAL,
664 "add information to the database");
665 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
666 "TC port offset");
667 if (!interact)
668 add_std_args(ts);
670 ts = cmd_CreateSyntax("volinfo", bc_dblookupCmd, NULL, 0,
671 "query the backup database");
672 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_REQUIRED, "volume name");
673 if (!interact)
674 add_std_args(ts);
676 ts = cmd_CreateSyntax("setexp", bc_SetExpCmd, NULL, 0,
677 "set/clear dump expiration dates");
678 cmd_AddParm(ts, "-dump", CMD_LIST, CMD_REQUIRED, "dump level name");
679 cmd_AddParm(ts, "-expires", CMD_LIST, CMD_OPTIONAL, "expiration date");
680 if (!interact)
681 add_std_args(ts);
683 ts = cmd_CreateSyntax("savedb", bc_saveDbCmd, NULL, 0, "save backup database");
684 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
685 "TC port offset");
686 cmd_AddParm(ts, "-archive", CMD_LIST, CMD_OPTIONAL, "date time");
687 if (!interact)
688 add_std_args(ts);
690 ts = cmd_CreateSyntax("restoredb", bc_restoreDbCmd, NULL, 0,
691 "restore backup database");
692 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL,
693 "TC port offset");
694 if (!interact)
695 add_std_args(ts);
697 ts = cmd_CreateSyntax("dumpinfo", bc_dumpInfoCmd, NULL, 0,
698 "provide information about a dump in the database");
699 cmd_AddParm(ts, "-ndumps", CMD_SINGLE, CMD_OPTIONAL, "no. of dumps");
700 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "dump id");
701 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL,
702 "detailed description");
703 if (!interact)
704 add_std_args(ts);
706 ts = cmd_CreateSyntax("dbverify", bc_dbVerifyCmd, NULL, 0,
707 "check ubik database integrity");
708 cmd_AddParm(ts, "-detail", CMD_FLAG, CMD_OPTIONAL, "additional details");
709 if (!interact)
710 add_std_args(ts);
712 ts = cmd_CreateSyntax("deletedump", bc_deleteDumpCmd, NULL, 0,
713 "delete dumps from the database");
714 cmd_AddParm(ts, "-dumpid", CMD_LIST, CMD_OPTIONAL, "dump id");
715 cmd_AddParm(ts, "-from", CMD_LIST, CMD_OPTIONAL, "date time");
716 cmd_AddParm(ts, "-to", CMD_LIST, CMD_OPTIONAL, "date time");
717 cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset");
718 cmd_AddParmAlias(ts, 3, "-port");
719 cmd_AddParm(ts, "-groupid", CMD_SINGLE, CMD_OPTIONAL, "group ID");
720 cmd_AddParm(ts, "-dbonly", CMD_FLAG, CMD_OPTIONAL,
721 "delete the dump from the backup database only");
722 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
723 "always delete from backup database");
724 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
725 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
726 "list the dumps, don't delete anything");
727 cmd_AddParmAlias(ts, 8, "-n");
729 if (!interact)
730 add_std_args(ts);
732 ts = cmd_CreateSyntax("interactive", bc_interactCmd, NULL, 0,
733 "enter interactive mode");
734 add_std_args(ts);
737 * Now execute the command.
740 targc = 0;
741 targv[targc++] = argv[0];
742 if (interact)
743 targv[targc++] = "interactive";
744 for (i = 1; i < argc; i++)
745 targv[targc++] = argv[i];
747 code = doDispatch(targc, targv, 1);
749 if (!interact || !bcInit) { /* Non-interactive mode */
750 if (code)
751 exit(-1);
752 if (bcInit)
753 code = bc_WaitForNoJobs(); /* wait for any jobs to finish */
754 exit(code); /* and exit */
757 /* Iterate on command lines, interpreting user commands (interactive mode) */
758 while (1) {
759 int ret;
761 printf("backup> ");
762 fflush(stdout);
765 while ((ret = LWP_GetLine(lineBuffer, sizeof(lineBuffer))) == 0)
766 printf("%s: Command line too long\n", whoami); /* line too long */
768 if (ret == -1)
769 return 0; /* Got EOF */
771 if (!LineIsBlank(lineBuffer)) {
772 code = cmd_ParseLine(lineBuffer, targv, &targc, MAXV);
773 if (code)
774 afs_com_err(whoami, code, "; Can't parse line: '%s'",
775 afs_error_message(code));
776 else {
777 doDispatch(targc, targv, 1);
778 cmd_FreeArgv(targv);
782 } /*main */