2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #if defined(AFS_LINUX24_ENV)
16 #define _REGEX_RE_COMP
18 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
28 #include <afs/com_err.h>
29 #include <afs/afsutil.h>
31 #include <afs/budb_prototypes.h>
33 #include <afs/bubasics.h> /* PA */
34 #include <afs/volser.h>
35 #include <afs/voldefs.h> /* PA */
36 #include <afs/vldbint.h> /* PA */
37 #include <afs/ktime.h> /* PA */
42 #include <afs/tcdata.h>
44 #include <afs/vsutils_prototypes.h>
45 #ifdef HAVE_POSIX_REGEX /* use POSIX regexp library */
49 #include "error_macros.h"
50 #include "bucoord_internal.h"
51 #include "bucoord_prototypes.h"
53 extern struct bc_config *bc_globalConfig;
54 extern struct bc_dumpTask bc_dumpTasks[BC_MAXSIMDUMPS];
55 extern struct ubik_client *cstruct;
59 extern afs_int32 lastTaskCode;
61 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
63 static int EvalVolumeSet1(struct bc_config *aconfig, struct bc_volumeSet *avs,
64 struct bc_volumeDump **avols,
65 struct ubik_client *uclient);
67 static int EvalVolumeSet2(struct bc_config *aconfig, struct bc_volumeSet *avs,
68 struct bc_volumeDump **avols,
69 struct ubik_client *uclient);
70 static int DBLookupByVolume(char *volumeName);
73 bc_EvalVolumeSet(struct bc_config *aconfig,
74 struct bc_volumeSet *avs,
75 struct bc_volumeDump **avols,
76 struct ubik_client *uclient)
77 { /*bc_EvalVolumeSet */
79 static afs_int32 use = 2;
81 if (use == 2) { /* Use EvalVolumeSet2() */
82 code = EvalVolumeSet2(aconfig, avs, avols, uclient);
83 if (code == RXGEN_OPCODE)
86 if (use == 1) { /* Use EvalVolumeSet1() */
87 code = EvalVolumeSet1(aconfig, avs, avols, uclient);
90 } /*bc_EvalVolumeSet */
92 struct partitionsort {
94 struct bc_volumeDump *vdlist;
95 struct bc_volumeDump *lastvdlist;
96 struct bc_volumeDump *dupvdlist;
97 struct bc_volumeEntry *vole;
98 struct partitionsort *next;
102 struct partitionsort *partitions;
103 struct serversort *next;
107 getSPEntries(afs_uint32 server, afs_int32 partition,
108 struct serversort **serverlist,
109 struct serversort **ss,
110 struct partitionsort **ps)
112 if (!(*ss) || ((*ss)->ipaddr != server)) {
114 for ((*ss) = *serverlist; (*ss); *ss = (*ss)->next) {
115 if ((*ss)->ipaddr == server)
119 /* No server entry added. Add one */
121 *ss = (struct serversort *)malloc(sizeof(struct serversort));
123 afs_com_err(whoami, BC_NOMEM, NULL);
127 memset(*ss, 0, sizeof(struct serversort));
128 (*ss)->ipaddr = server;
129 (*ss)->next = *serverlist;
134 if (!(*ps) || ((*ps)->part != partition)) {
135 for (*ps = (*ss)->partitions; *ps; *ps = (*ps)->next) {
136 if ((*ps)->part == partition)
140 /* No partition entry added. Add one */
142 *ps = (struct partitionsort *)malloc(sizeof(struct partitionsort));
144 afs_com_err(whoami, BC_NOMEM, NULL);
150 memset(*ps, 0, sizeof(struct partitionsort));
151 (*ps)->part = partition;
152 (*ps)->next = (*ss)->partitions;
153 (*ss)->partitions = *ps;
159 randSPEntries(struct serversort *serverlist,
160 struct bc_volumeDump **avols)
162 struct serversort *ss, **pss;
163 struct partitionsort *ps, **pps;
165 afs_int32 scount, pcount;
169 /* Seed random number generator */
170 r = time(0) + getpid();
173 /* Count number of servers, remove one at a time */
174 for (scount = 0, ss = serverlist; ss; ss = ss->next, scount++);
175 for (; scount; scount--) {
176 /* Pick a random server in list and remove it */
177 r = (rand() >> 4) % scount;
178 for (pss = &serverlist, ss = serverlist; r;
179 pss = &ss->next, ss = ss->next, r--);
182 /* Count number of partitions, remove one at a time */
183 for (pcount = 0, ps = ss->partitions; ps; ps = ps->next, pcount++);
184 for (; pcount; pcount--) {
185 /* Pick a random parition in list and remove it */
186 r = (rand() >> 4) % pcount;
187 for (pps = &ss->partitions, ps = ss->partitions; r;
188 pps = &ps->next, ps = ps->next, r--);
191 ps->lastvdlist->next = *avols;
201 EvalVolumeSet2(struct bc_config *aconfig,
202 struct bc_volumeSet *avs,
203 struct bc_volumeDump **avols,
204 struct ubik_client *uclient)
205 { /*EvalVolumeSet2 */
206 struct bc_volumeEntry *tve;
207 struct bc_volumeDump *tavols;
208 struct VldbListByAttributes attributes;
209 afs_int32 si, nsi; /* startIndex and nextStartIndex */
210 afs_int32 nentries, e, ei, et, add, l;
211 nbulkentries bulkentries;
212 struct nvldbentry *entries = 0;
213 struct bc_volumeDump *tvd;
214 afs_int32 code = 0, tcode;
216 struct serversort *servers = 0, *ss = 0;
217 struct partitionsort *ps = 0;
219 *avols = (struct bc_volumeDump *)0;
220 bulkentries.nbulkentries_len = 0;
221 bulkentries.nbulkentries_val = 0;
223 /* For each of the volume set entries - collect the volumes that match it */
224 for (tve = avs->ventries; tve; tve = tve->next) {
225 /* Put together a call to the vlserver for this vlentry. The
226 * performance gain is from letting the vlserver expand the
227 * volumeset and not this routine.
230 if (tve->server.sin_addr.s_addr) { /* The server */
231 attributes.Mask |= VLLIST_SERVER;
232 attributes.server = tve->server.sin_addr.s_addr;
234 if (tve->partition != -1) { /* The partition */
235 attributes.Mask |= VLLIST_PARTITION;
236 attributes.partition = tve->partition;
239 /* Now make the call to the vlserver */
240 for (si = 0; si != -1; si = nsi) {
242 bulkentries.nbulkentries_len = 0;
243 bulkentries.nbulkentries_val = 0;
246 ubik_Call(VL_ListAttributesN2, uclient, 0, &attributes,
247 tve->name, si, &nentries, &bulkentries, &nsi);
251 /* The 3.4 vlserver has a VL_ListAttributesN2() RPC call, but
252 * it is not complete. The only way to tell if it is not complete
253 * is if et == 0 (which we check for below). Also, if the call didn't
254 * match any entries, then we don't know what version the vlserver
255 * is. In both cases, we return RXGEN_OPCODE and the calling routine
256 * will switch to the EvalVolumeSet1() call.
259 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
261 /* Step through each entry and add it to the list of volumes */
262 entries = bulkentries.nbulkentries_val;
263 for (e = 0; e < nentries; e++) {
264 ei = entries[e].matchindex & 0xffff;
265 et = (entries[e].matchindex >> 16) & 0xffff;
280 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
283 /* Find server and partiton structure to hang the entry off of */
285 getSPEntries(entries[e].serverNumber[ei],
286 entries[e].serverPartition[ei], &servers,
289 afs_com_err(whoami, tcode, NULL);
293 /* Detect if this entry should be added (not a duplicate).
294 * Use ps->dupvdlist and ps->vole to only search volumes from
295 * previous volume set entries.
298 if (tve != avs->ventries) {
299 l = strlen(entries[e].name);
300 if (ps->vole != tve) {
302 ps->dupvdlist = ps->vdlist;
304 for (tavols = ps->dupvdlist; add && tavols;
305 tavols = tavols->next) {
306 if (strncmp(tavols->name, entries[e].name, l) == 0) {
307 if ((strcmp(&entries[e].name[l], ".backup") == 0)
308 || (strcmp(&entries[e].name[l], ".readonly")
310 || (strcmp(&entries[e].name[l], NULL) == 0))
317 /* Allocate a volume dump structure and its name */
318 tvd = (struct bc_volumeDump *)
319 malloc(sizeof(struct bc_volumeDump));
321 afs_com_err(whoami, BC_NOMEM, NULL);
324 memset(tvd, 0, sizeof(*tvd));
326 tvd->name = (char *)malloc(strlen(entries[e].name) + 10);
328 afs_com_err(whoami, BC_NOMEM, NULL);
333 /* Fill it in and thread onto avols list */
334 strcpy(tvd->name, entries[e].name);
336 strcat(tvd->name, ".backup");
337 else if (et == ROVOL)
338 strcat(tvd->name, ".readonly");
339 tvd->vid = entries[e].volumeId[et];
342 tvd->partition = entries[e].serverPartition[ei];
343 tvd->server.sin_addr.s_addr = entries[e].serverNumber[ei];
344 tvd->server.sin_port = 0; /* default FS port */
345 tvd->server.sin_family = AF_INET;
346 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
347 tvd->server.sin_len = sizeof(struct sockaddr_in);
350 /* String tvd off of partition struct */
351 tvd->next = ps->vdlist;
354 ps->lastvdlist = tvd;
360 /* Free memory allocated during VL call */
361 if (bulkentries.nbulkentries_val) {
362 free((char *)bulkentries.nbulkentries_val);
363 bulkentries.nbulkentries_val = 0;
369 /* Randomly link the volumedump entries together */
370 randSPEntries(servers, avols);
371 fprintf(stderr, "Total number of volumes : %u\n", count);
374 if (bulkentries.nbulkentries_val) {
375 free((char *)bulkentries.nbulkentries_val);
378 } /*EvalVolumeSet2 */
380 /*-----------------------------------------------------------------------------
384 * Takes the entries in a volumeset and expands them into a list of
385 * volumes. Every VLDB volume entry is looked at and compared to the
388 * When matching a VLDB volume entry to a volumeset entry,
389 * 1. If the RW volume entry matches, that RW volume is used.
390 * 2. Otherwise, if the BK volume entry matches, the BK volume is used.
391 * 3. Finally, if the RO volume entry matches, the RO volume is used.
392 * For instance: A volumeset entry of ".* .* user.t.*" will match volume
393 * "user.troy" and "user.troy.backup". The rules will use
394 * the RW volume "user.troy".
396 * When a VLDB volume entry matches a volumeset entry (be it RW, BK or RO),
397 * that volume is used and matches against any remaining volumeset entries
399 * For instance: A 1st volumeset entry ".* .* .*.backup" will match with
400 * "user.troy.backup". Its 2nd volumeset entry ".* .* .*"
401 * would have matched its RW volume "user.troy", but the first
402 * match is used and the second match isn't even done.
405 * aconfig : Global configuration info.
407 * avols : Ptr to linked list of entries describing volumes to dump.
408 * uclient : Ptr to Ubik client structure.
411 * 0 on successful volume set evaluation,
412 * Lower-level codes otherwise.
415 * Expand only the single volume set provided (avs); don't go down its chain.
419 *-----------------------------------------------------------------------------
422 EvalVolumeSet1(struct bc_config *aconfig,
423 struct bc_volumeSet *avs,
424 struct bc_volumeDump **avols,
425 struct ubik_client *uclient)
426 { /*EvalVolumeSet1 */
427 afs_int32 code; /*Result of various calls */
428 struct bc_volumeDump *tvd; /*Ptr to new dump instance */
429 struct bc_volumeEntry *tve, *ctve; /*Ptr to new volume entry instance */
430 char patt[256]; /*Composite regex; also, target string */
431 int volType = 0; /*Type of volume that worked */
432 afs_int32 index; /*Current VLDB entry index */
433 afs_int32 count; /*Needed by VL_ListEntry() */
434 afs_int32 next_index; /*Next index to list */
435 struct vldbentry entry; /*VLDB entry */
436 int srvpartpair; /*Loop counter: server/partition pair */
440 struct serversort *servers = 0, *ss = 0;
441 struct partitionsort *ps = 0;
442 #ifdef HAVE_POSIX_REGEX
444 int need_regfree = 0;
449 *avols = (struct bc_volumeDump *)0;
450 ctve = (struct bc_volumeEntry *)0; /* no compiled entry */
452 /* For each vldb entry.
453 * Variable next_index is set to the index of the next VLDB entry
454 * in the enumeration.
456 for (index = 0; 1; index = next_index) { /*w */
457 memset(&entry, 0, sizeof(entry));
458 code = ubik_Call(VL_ListEntry, /*Routine to invoke */
459 uclient, /*Ubik client structure */
461 index, /*Current index */
462 &count, /*Ptr to working variable */
463 &next_index, /*Ptr to next index value to list */
464 &entry); /*Ptr to entry to fill */
468 break; /* If the next index is invalid, bail out now. */
470 /* For each entry in the volume set */
471 found = 0; /* No match in volume set yet */
472 for (tve = avs->ventries; tve; tve = tve->next) { /*ve */
473 /* for each server in the vldb entry */
474 for (srvpartpair = 0; srvpartpair < entry.nServers; srvpartpair++) { /*s */
475 /* On the same server */
476 if (tve->server.sin_addr.s_addr
477 && !VLDB_IsSameAddrs(tve->server.sin_addr.s_addr,
478 entry.serverNumber[srvpartpair],
486 /* On the same partition */
487 if ((tve->partition != -1)
488 && (tve->partition != entry.serverPartition[srvpartpair]))
491 /* If the volume entry is not compiled, then compile it */
493 sprintf(patt, "^%s$", tve->name);
494 #ifdef HAVE_POSIX_REGEX
495 if (regcomp(&re, patt, REG_NOSUB) != 0) {
496 afs_com_err(whoami, 0, "Can't compile regular expression '%s'", patt);
501 errm = (char *)re_comp(patt);
503 afs_com_err(whoami, 0,
504 "Can't compile regular expression '%s': %s",
512 /* If the RW name matches the volume set entry, take
513 * it and exit. First choice is to use the RW volume.
515 if (entry.serverFlags[srvpartpair] & ITSRWVOL) {
516 if (entry.flags & RW_EXISTS) {
517 sprintf(patt, "%s", entry.name);
518 #ifdef HAVE_POSIX_REGEX
519 code = regexec(&re, patt, 0, NULL, 0);
522 code = re_exec(patt);
526 foundentry = srvpartpair;
532 /* If the BK name matches the volume set entry, take
533 * it and exit. Second choice is to use the BK volume.
535 if (entry.flags & BACK_EXISTS) {
536 sprintf(patt, "%s.backup", entry.name);
537 #ifdef HAVE_POSIX_REGEX
538 code = regexec(&re, patt, 0, NULL, 0);
541 code = re_exec(patt);
545 foundentry = srvpartpair;
552 /* If the RO name matches the volume set entry, remember
553 * it, but continue searching. Further entries may be
554 * RW or backup entries that will match.
556 else if (!found && (entry.serverFlags[srvpartpair] & ITSROVOL)
557 && (entry.flags & RO_EXISTS)) {
558 sprintf(patt, "%s.readonly", entry.name);
559 #ifdef HAVE_POSIX_REGEX
560 code = regexec(&re, patt, 0, NULL, 0);
563 code = re_exec(patt);
567 foundentry = srvpartpair;
573 afs_com_err(whoami, 0, "Internal error in regex package");
576 /* If found a match, then create a new volume dump entry */
578 /* Find server and partition structure to hang the entry off of */
580 getSPEntries(entry.serverNumber[foundentry],
581 entry.serverPartition[foundentry], &servers,
584 afs_com_err(whoami, code, NULL);
589 tvd = (struct bc_volumeDump *)
590 malloc(sizeof(struct bc_volumeDump));
592 afs_com_err(whoami, BC_NOMEM, NULL);
595 memset(tvd, 0, sizeof(*tvd));
597 tvd->name = (char *)malloc(strlen(entry.name) + 10);
599 afs_com_err(whoami, BC_NOMEM, NULL);
604 strcpy(tvd->name, entry.name);
605 if (volType == BACKVOL)
606 strcat(tvd->name, ".backup");
607 else if (volType == ROVOL)
608 strcat(tvd->name, ".readonly");
609 tvd->vid = entry.volumeId[volType];
611 tvd->volType = volType;
612 tvd->partition = entry.serverPartition[foundentry];
613 tvd->server.sin_addr.s_addr = entry.serverNumber[foundentry];
614 tvd->server.sin_port = 0; /* default FS port */
615 tvd->server.sin_family = AF_INET;
617 /* String tvd off of partition struct */
618 tvd->next = ps->vdlist;
621 ps->lastvdlist = tvd;
627 #ifdef HAVE_POSIX_REGEX
632 /* Randomly link the volumedump entries together */
633 randSPEntries(servers, avols);
635 fprintf(stderr, "Total number of volumes : %u\n", total);
637 } /*EvalVolumeSet1 */
640 compactTimeString(time_t *date, char *string, afs_int32 size)
647 if (*date == NEVERDATE) {
648 sprintf(string, "NEVER");
650 ltime = localtime(date);
651 strftime(string, size, "%m/%d/%Y %H:%M", ltime);
657 * print out a date in compact format, 16 chars, format is
660 * date_long - ptr to a long containing the time
662 * ptr to a string containing a representation of the date
665 compactDateString(afs_uint32 *date_long, char *string, afs_int32 size)
667 time_t t = *date_long;
668 return compactTimeString(&t, string, size);
673 bc_SafeATOI(char *anum)
677 for (; *anum; anum++) {
678 if ((*anum < '0') || (*anum > '9'))
680 total = (10 * total) + (afs_int32) (*anum - '0');
686 * Take a string and parse it for a number (could be float) followed
687 * by a character representing the units (K,M,G,T). Default is 'K'.
688 * Return the size in KBytes.
691 bc_FloatATOI(char *anum)
695 afs_int32 fraction = 0; /* > 0 if past the decimal */
697 for (; *anum; anum++) {
698 if ((*anum == 't') || (*anum == 'T')) {
699 total *= 1024 * 1024 * 1024;
702 if ((*anum == 'g') || (*anum == 'G')) {
703 total *= 1024 * 1024;
706 if ((*anum == 'm') || (*anum == 'M')) {
710 if ((*anum == 'k') || (*anum == 'K')) {
717 if ((*anum < '0') || (*anum > '9'))
721 total = (10. * total) + (float)(*anum - '0');
723 total += ((float)(*anum - '0')) / (float)fraction;
728 total += 0.5; /* Round up */
729 if (total > 0x7fffffff) /* Don't go over 2G */
731 rtotal = (afs_int32) total;
735 /* make a copy of a string so that it can be freed later */
737 bc_CopyString(char *astring)
743 return (NULL); /* propagate null strings easily */
744 tlen = strlen(astring);
745 tp = (char *)malloc(tlen + 1); /* don't forget the terminating null */
747 afs_com_err(whoami, BC_NOMEM, NULL);
756 * Concatenates the parameters of an option and returns the string.
761 concatParams(struct cmd_item *itemPtr)
763 struct cmd_item *tempPtr;
764 afs_int32 length = 0;
767 /* compute the length of string required */
768 for (tempPtr = itemPtr; tempPtr; tempPtr = tempPtr->next) {
769 length += strlen(tempPtr->data);
770 length++; /* space or null terminator */
773 if (length == 0) { /* no string (0 length) */
774 afs_com_err(whoami, 0, "Can't have zero length date and time string");
778 string = (char *)malloc(length); /* allocate the string */
780 afs_com_err(whoami, BC_NOMEM, NULL);
785 tempPtr = itemPtr; /* now assemble the string */
787 strcat(string, tempPtr->data);
788 tempPtr = tempPtr->next;
793 return (string); /* return the string */
797 * print out an interface status node as received from butc
801 printIfStatus(struct tciStatusS *statusPtr)
803 printf("Task %d: %s: ", statusPtr->taskId, statusPtr->taskName);
804 if (statusPtr->nKBytes)
805 printf("%ld Kbytes transferred", (long unsigned int) statusPtr->nKBytes);
806 if (strlen(statusPtr->volumeName) != 0) {
807 if (statusPtr->nKBytes)
809 printf("volume %s", statusPtr->volumeName);
814 if (statusPtr->flags & ABORT_REQUEST)
815 printf(" [abort request rcvd]");
817 if (statusPtr->flags & ABORT_DONE)
818 printf(" [abort complete]");
820 if (statusPtr->flags & OPR_WAIT)
821 printf(" [operator wait]");
823 if (statusPtr->flags & CALL_WAIT)
824 printf(" [callout in progress]");
826 if (statusPtr->flags & DRIVE_WAIT)
827 printf(" [drive wait]");
829 if (statusPtr->flags & TASK_DONE)
835 getPortOffset(char *port)
837 afs_int32 portOffset;
839 portOffset = bc_SafeATOI(port);
841 if (portOffset < 0) {
842 afs_com_err(whoami, 0, "Can't decode port offset '%s'", port);
844 } else if (portOffset > BC_MAXPORTOFFSET) {
845 afs_com_err(whoami, 0, "%u exceeds max port offset %u", portOffset,
852 /* bc_GetTapeStatusCmd
853 * display status of all tasks on a particular tape coordinator
856 bc_GetTapeStatusCmd(struct cmd_syndesc *as, void *arock)
859 struct rx_connection *tconn;
860 afs_int32 portOffset = 0;
865 struct tciStatusS status;
867 code = bc_UpdateHosts();
869 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
873 if (as->parms[0].items) {
874 portOffset = getPortOffset(as->parms[0].items->data);
879 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
883 flags = TSK_STAT_FIRST;
887 while ((flags & TSK_STAT_END) == 0) {
888 code = TC_ScanStatus(tconn, &taskId, &status, &flags);
890 if (code == TC_NOTASKS)
892 afs_com_err(whoami, code, "; Can't get status from butc");
895 if ((flags & TSK_STAT_NOTFOUND))
896 break; /* Can't find the task id */
897 flags &= ~TSK_STAT_FIRST; /* turn off flag */
899 printIfStatus(&status);
904 printf("Tape coordinator is idle\n");
906 if (flags & TSK_STAT_ADSM)
907 printf("TSM Tape coordinator\n");
908 else if (flags & TSK_STAT_XBSA)
909 printf("XBSA Tape coordinator\n");
914 extern struct Lock dispatchLock;
917 * wait for all jobs to terminate
920 bc_WaitForNoJobs(void)
923 int usefulJobRunning = 1;
925 extern dlqlinkT statusHead;
927 afs_com_err(whoami, 0, "waiting for job termination");
929 while (usefulJobRunning) {
930 usefulJobRunning = (dlqEmpty(&statusHead) ? 0 : 1);
931 if (dispatchLock.excl_locked)
932 usefulJobRunning = 1;
933 for (i = 0; (!usefulJobRunning && (i < BC_MAXSIMDUMPS)); i++) {
934 if (bc_dumpTasks[i].flags & BC_DI_INUSE)
935 usefulJobRunning = 1;
938 /* Wait 5 seconds and check again */
939 if (usefulJobRunning)
942 return (lastTaskCode);
946 * print status on running jobs
948 * ignored - a null "as" prints only jobs.
951 bc_JobsCmd(struct cmd_syndesc *as, void *arock)
960 extern dlqlinkT statusHead;
962 dlqInit(&atJobsHead);
965 ptr = (&statusHead)->dlq_next;
966 while (ptr != &statusHead) {
967 statusPtr = (statusP) ptr;
970 if (statusPtr->scheduledDump) {
971 dlqUnlink((dlqlinkP) statusPtr);
972 dlqLinkb(&atJobsHead, (dlqlinkP) statusPtr);
974 printf("Job %d:", statusPtr->jobNumber);
976 printf(" %s", statusPtr->taskName);
978 if (statusPtr->dbDumpId)
979 printf(": DumpID %u", statusPtr->dbDumpId);
980 if (statusPtr->nKBytes)
981 printf(", %ld Kbytes", afs_printable_int32_ld(statusPtr->nKBytes));
982 if (strlen(statusPtr->volumeName) != 0)
983 printf(", volume %s", statusPtr->volumeName);
985 if (statusPtr->flags & CONTACT_LOST)
986 printf(" [butc contact lost]");
988 if (statusPtr->flags & ABORT_REQUEST)
989 printf(" [abort request]");
991 if (statusPtr->flags & ABORT_SENT)
992 printf(" [abort sent]");
994 if (statusPtr->flags & OPR_WAIT)
995 printf(" [operator wait]");
997 if (statusPtr->flags & CALL_WAIT)
998 printf(" [callout in progress]");
1000 if (statusPtr->flags & DRIVE_WAIT)
1001 printf(" [drive wait]");
1007 * Now print the scheduled dumps.
1009 if (!dlqEmpty(&statusHead) && as)
1010 printf("\n"); /* blank line between running and scheduled dumps */
1013 while (!dlqEmpty(&atJobsHead)) {
1014 ptr = (&atJobsHead)->dlq_next;
1015 youngest = (statusP) ptr;
1017 ptr = ptr->dlq_next;
1018 while (ptr != &atJobsHead) { /* Find the dump that starts the earliest */
1019 statusPtr = (statusP) ptr;
1020 if (statusPtr->scheduledDump < youngest->scheduledDump)
1021 youngest = statusPtr;
1022 ptr = ptr->dlq_next;
1025 /* Print token expiration time */
1026 if ((tokenExpires > prevTime)
1027 && (tokenExpires <= youngest->scheduledDump) && as
1028 && (tokenExpires != NEVERDATE)) {
1029 if (tokenExpires > time(0)) {
1030 compactTimeString(&tokenExpires, ds, 50);
1031 printf(" %16s: TOKEN EXPIRATION\n", ds);
1033 printf(" TOKEN HAS EXPIRED\n");
1036 prevTime = youngest->scheduledDump;
1038 /* Print the info */
1039 compactDateString(&youngest->scheduledDump, ds, 50);
1040 printf("Job %d:", youngest->jobNumber);
1041 printf(" %16s: %s", ds, youngest->cmdLine);
1044 /* return to original list */
1045 dlqUnlink((dlqlinkP) youngest);
1046 dlqLinkb(&statusHead, (dlqlinkP) youngest);
1049 /* Print token expiration time if havn't already */
1050 if ((tokenExpires == NEVERDATE) && as)
1051 printf(" : TOKEN NEVER EXPIRES\n");
1052 else if ((tokenExpires > prevTime) && as) {
1053 if (tokenExpires > time(0)) {
1054 compactTimeString(&tokenExpires, ds, 50);
1055 printf(" %16s: TOKEN EXPIRATION\n", ds);
1057 printf(" : TOKEN HAS EXPIRED\n");
1066 bc_KillCmd(struct cmd_syndesc *as, void *arock)
1070 struct bc_dumpTask *td;
1077 extern dlqlinkT statusHead;
1079 tp = as->parms[0].items->data;
1080 if (strchr(tp, '.') == 0) {
1081 slot = bc_SafeATOI(tp);
1083 afs_com_err(whoami, 0, "Bad syntax for number '%s'", tp);
1088 ptr = (&statusHead)->dlq_next;
1089 while (ptr != &statusHead) {
1090 statusPtr = (statusP) ptr;
1091 if (statusPtr->jobNumber == slot) {
1092 statusPtr->flags |= ABORT_REQUEST;
1096 ptr = ptr->dlq_next;
1100 fprintf(stderr, "Job %d not found\n", slot);
1105 for (i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1106 if (td->flags & BC_DI_INUSE) {
1108 strcpy(tbuffer, td->volSetName);
1109 strcat(tbuffer, ".");
1110 strcat(tbuffer, tailCompPtr(td->dumpName));
1111 if (strcmp(tbuffer, tp) == 0)
1115 if (i >= BC_MAXSIMDUMPS) {
1116 afs_com_err(whoami, 0, "Can't find job %s", tp);
1121 statusPtr = findStatus(td->dumpID);
1123 if (statusPtr == 0) {
1124 afs_com_err(whoami, 0, "Can't locate status - internal error");
1128 statusPtr->flags |= ABORT_REQUEST;
1135 /* restore a volume or volumes */
1137 bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
1140 * parm 0 is the new server to restore to
1141 * parm 1 is the new partition to restore to
1142 * parm 2 is volume(s) to restore
1143 * parm 3 is the new extension, if any, for the volume name.
1144 * parm 4 gives the new volume # to restore this volume as (removed).
1145 * parm 4 date is a string representing the date
1147 * We handle four types of restores. If old is set, then we restore the
1148 * volume with the same name and ID. If old is not set, we allocate
1149 * a new volume ID for the restored volume. If a new extension is specified,
1150 * we add that extension to the volume name of the restored volume.
1152 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1153 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1154 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1155 struct bc_volumeDump *tvol; /* temp for same */
1156 struct sockaddr_in destServ; /* machine to which to restore volumes */
1157 afs_int32 destPartition; /* partition to which to restore volumes */
1159 struct cmd_item *ti;
1163 afs_int32 dumpID = 0;
1164 char *newExt, *timeString;
1166 afs_int32 *ports = NULL;
1167 afs_int32 portCount = 0;
1170 code = bc_UpdateHosts();
1172 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1176 /* specified other destination host */
1177 if (as->parms[0].items) {
1178 tp = as->parms[0].items->data;
1179 if (bc_ParseHost(tp, &destServ)) {
1180 afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
1185 /* specified other destination partition */
1186 if (as->parms[1].items) {
1187 tp = as->parms[1].items->data;
1188 if (bc_GetPartitionID(tp, &destPartition)) {
1189 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1194 for (ti = as->parms[2].items; ti; ti = ti->next) {
1195 /* build list of volume items */
1196 tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1198 afs_com_err(whoami, BC_NOMEM, NULL);
1201 memset(tvol, 0, sizeof(struct bc_volumeDump));
1203 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1205 afs_com_err(whoami, BC_NOMEM, NULL);
1208 strncpy(tvol->name, ti->data, VOLSER_OLDMAXVOLNAME);
1209 tvol->entry = &tvolumeEntry;
1212 lastVol->next = tvol; /* thread onto end of list */
1214 volsToRestore = tvol;
1218 if (as->parms[4].items) {
1219 timeString = concatParams(as->parms[4].items);
1223 code = ktime_DateToLong(timeString, &fromDate);
1226 afs_com_err(whoami, 0, "Can't parse restore date and time");
1227 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1231 fromDate = 0x7fffffff; /* latest one */
1234 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1237 /* Read all the port offsets into the ports array. The first element in the
1238 * array is for full restore and the rest are for incremental restores
1240 if (as->parms[5].items) {
1241 for (ti = as->parms[5].items; ti; ti = ti->next)
1243 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1245 afs_com_err(whoami, BC_NOMEM, NULL);
1249 for (ti = as->parms[5].items, i = 0; ti; ti = ti->next, i++) {
1250 ports[i] = getPortOffset(ti->data);
1256 dontExecute = (as->parms[6].items ? 1 : 0); /* -n */
1258 if (as->parms[7].items)
1260 dumpID = atoi(as->parms[7].items->data);
1266 * Perform the call to start the restore.
1269 bc_StartDmpRst(bc_globalConfig, "volume", "restore", volsToRestore,
1270 &destServ, destPartition, fromDate, newExt, oldFlag,
1271 /*parentDump */ dumpID, /*dumpLevel */ 0,
1272 bc_Restorer, ports, portCount,
1273 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1275 afs_com_err(whoami, code, "; Failed to queue restore");
1280 /* restore a whole partition or server */
1282 /* bc_DiskRestoreCmd
1283 * restore a whole partition
1285 * first, reqd - machine (server) to restore
1286 * second, reqd - partition to restore
1291 bc_DiskRestoreCmd(struct cmd_syndesc *as, void *arock)
1293 struct bc_volumeSet tvolumeSet; /* temporary volume set for EvalVolumeSet call */
1294 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1295 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1296 struct sockaddr_in destServ; /* machine to which to restore volumes */
1297 afs_int32 destPartition; /* partition to which to restore volumes */
1303 afs_int32 *ports = NULL;
1304 afs_int32 portCount = 0;
1306 struct bc_volumeDump *prev, *tvol, *nextvol;
1307 struct cmd_item *ti;
1310 /* parm 0 is the server to restore
1311 * parm 1 is the partition to restore
1313 * parm 8 and above as in VolRestoreCmd:
1314 * parm 8 is the new server to restore to
1315 * parm 9 is the new partition to restore to
1318 code = bc_UpdateVolumeSet();
1320 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1323 code = bc_UpdateHosts();
1325 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1329 /* create a volume set corresponding to the volume pattern we've been given */
1330 memset(&tvolumeSet, 0, sizeof(tvolumeSet));
1331 memset(&tvolumeEntry, 0, sizeof(tvolumeEntry));
1332 tvolumeSet.name = "TempVolumeSet";
1333 tvolumeSet.ventries = &tvolumeEntry;
1334 tvolumeEntry.serverName = as->parms[0].items->data;
1335 tvolumeEntry.partname = as->parms[1].items->data;
1337 if (bc_GetPartitionID(tvolumeEntry.partname, &tvolumeEntry.partition)) {
1338 afs_com_err(whoami, 0, "Can't parse partition '%s'",
1339 tvolumeEntry.partname);
1343 if (bc_ParseHost(tvolumeEntry.serverName, &tvolumeEntry.server)) {
1344 afs_com_err(whoami, 0, "Can't locate host '%s'", tvolumeEntry.serverName);
1348 /* specified other destination host */
1349 if (as->parms[8].items) {
1350 tp = as->parms[8].items->data;
1351 if (bc_ParseHost(tp, &destServ)) {
1352 afs_com_err(whoami, 0, "Can't locate destination host '%s'", tp);
1355 } else /* use destination host == original host */
1356 memcpy(&destServ, &tvolumeEntry.server, sizeof(destServ));
1358 /* specified other destination partition */
1359 if (as->parms[9].items) {
1360 tp = as->parms[9].items->data;
1361 if (bc_GetPartitionID(tp, &destPartition)) {
1362 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1365 } else /* use original partition */
1366 destPartition = tvolumeEntry.partition;
1368 tvolumeEntry.name = ".*"; /* match all volumes (this should be a parameter) */
1370 if (as->parms[2].items) {
1371 for (ti = as->parms[2].items; ti; ti = ti->next)
1373 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1375 afs_com_err(whoami, BC_NOMEM, NULL);
1379 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1380 ports[i] = getPortOffset(ti->data);
1386 newExt = (as->parms[10].items ? as->parms[10].items->data : NULL);
1387 dontExecute = (as->parms[11].items ? 1 : 0); /* -n */
1390 * Expand out the volume set into its component list of volumes, by calling VLDB server.
1393 bc_EvalVolumeSet(bc_globalConfig, &tvolumeSet, &volsToRestore,
1396 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1400 /* Since we want only RW volumes, remove any
1401 * BK or RO volumes from the list.
1403 for (prev = 0, tvol = volsToRestore; tvol; tvol = nextvol) {
1404 nextvol = tvol->next;
1405 if (BackupName(tvol->name)) {
1408 "Will not restore volume %s (its RW does not reside on the partition)\n",
1411 if (tvol == volsToRestore) {
1412 volsToRestore = nextvol;
1414 prev->next = nextvol;
1424 fromDate = 0x7fffffff; /* last one before this date */
1425 oldFlag = 1; /* do restore same volid (and name) */
1428 * Perform the call to start the dump.
1431 bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1432 &destServ, destPartition, fromDate, newExt, oldFlag,
1433 /*parentDump */ 0, /*dumpLevel */ 0,
1434 bc_Restorer, ports, portCount,
1435 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1437 afs_com_err(whoami, code, "; Failed to queue restore");
1442 /* bc_VolsetRestoreCmd
1443 * restore a volumeset or list of volumes.
1447 bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
1454 afs_int32 *ports = NULL;
1455 afs_int32 portCount = 0;
1458 struct bc_volumeSet *volsetPtr; /* Ptr to list of generated volume info */
1459 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1460 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1461 struct sockaddr_in destServer; /* machine to which to restore volume */
1462 afs_int32 destPartition; /* partition to which to restore volumes */
1463 struct cmd_item *ti;
1466 code = bc_UpdateVolumeSet();
1468 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1471 code = bc_UpdateHosts();
1473 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1477 if (as->parms[0].items) {
1478 if (as->parms[1].items) {
1479 afs_com_err(whoami, 0, "Can't have both -name and -file options");
1483 volsetName = as->parms[0].items->data;
1484 volsetPtr = bc_FindVolumeSet(bc_globalConfig, volsetName);
1486 afs_com_err(whoami, 0,
1487 "Can't find volume set '%s' in backup database",
1492 /* Expand out the volume set into its component list of volumes. */
1494 bc_EvalVolumeSet(bc_globalConfig, volsetPtr, &volsToRestore,
1497 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1500 } else if (as->parms[1].items) {
1503 char server[50], partition[50], volume[50], rest[256];
1505 struct bc_volumeDump *tvol;
1507 fd = fopen(as->parms[1].items->data, "r");
1509 afs_com_err(whoami, errno, "; Cannot open file '%s'",
1510 as->parms[1].items->data);
1514 while (fgets(line, 255, fd)) {
1516 sscanf(line, "%s %s %s %s", server, partition, volume, rest);
1522 "Invalid volumeset file format: Wrong number of arguments: Ignoring\n");
1523 fprintf(stderr, " %s", line);
1527 if (bc_ParseHost(server, &destServer)) {
1528 afs_com_err(whoami, 0, "Failed to locate host '%s'", server);
1532 if (bc_GetPartitionID(partition, &destPartition)) {
1533 afs_com_err(whoami, 0,
1534 "Failed to parse destination partition '%s'",
1539 /* Allocate a volumeDump structure and link it in */
1541 (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1542 memset(tvol, 0, sizeof(struct bc_volumeDump));
1544 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1546 afs_com_err(whoami, BC_NOMEM, NULL);
1549 strncpy(tvol->name, volume, VOLSER_OLDMAXVOLNAME);
1550 memcpy(&tvol->server, &destServer, sizeof(destServer));
1551 tvol->partition = destPartition;
1554 lastVol->next = tvol; /* thread onto end of list */
1556 volsToRestore = tvol;
1561 afs_com_err(whoami, 0, "-name or -file option required");
1566 /* Get the port offset for the restore */
1567 if (as->parms[2].items) {
1568 for (ti = as->parms[2].items; ti; ti = ti->next)
1570 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1572 afs_com_err(whoami, BC_NOMEM, NULL);
1576 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1577 ports[i] = getPortOffset(ti->data);
1583 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1584 dontExecute = (as->parms[4].items ? 1 : 0);
1586 fromDate = 0x7fffffff; /* last one before this date */
1587 oldFlag = 1; /* do restore same volid (and name) */
1589 /* Perform the call to start the restore */
1590 code = bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1591 /*destserver */ NULL, /*destpartition */ 0, fromDate,
1593 /*parentDump */ 0, /*dumpLevel */ 0,
1594 bc_Restorer, ports, portCount,
1595 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1597 afs_com_err(whoami, code, "; Failed to queue restore");
1602 /*-----------------------------------------------------------------------------
1606 * Perform a dump of the set of volumes provided.
1607 * user specifies: -volumeset .. -dump .. [-portoffset ..] [-n]
1610 * as : Parsed command line information.
1611 * arock : Ptr to misc stuff; not used.
1615 * The result of bc_StartDump() otherwise
1622 *---------------------------------------------------------------------------
1627 bc_DumpCmd(struct cmd_syndesc *as, void *arock)
1629 char *dumpPath = NULL;
1630 char *vsName = NULL; /*Ptrs to various names */
1631 struct bc_volumeSet *tvs = NULL; /*Ptr to list of generated volume info */
1632 struct bc_dumpSchedule *tds;
1633 struct bc_dumpSchedule *baseds = NULL; /*Ptr to dump schedule node */
1634 struct bc_volumeDump *tve, *volsToDump; /*Ptr to individual vols to be dumped */
1635 struct budb_dumpEntry dumpEntry, de, fde; /* dump entry */
1638 afs_int32 parent; /* parent dump */
1639 afs_int32 level; /* this dump's level # */
1640 afs_int32 problemFindingDump; /* can't find parent(s) */
1642 afs_int32 *portp = NULL;
1643 afs_int32 portCount = 0;
1644 afs_int32 doAt, atTime; /* Time a timed-dump is to start at */
1647 int doAppend = 0; /* Append the dump to dump set */
1648 afs_int32 code; /* Return code */
1649 int loadfile; /* whether to load a file or not */
1653 extern struct bc_dumpTask bc_dumpTasks[];
1655 code = bc_UpdateDumpSchedule();
1657 afs_com_err(whoami, code, "; Can't retrieve dump schedule");
1660 code = bc_UpdateVolumeSet();
1662 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1665 code = bc_UpdateHosts();
1667 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1672 * Some parameters cannot be specified together
1673 * The "-file" option cannot exist with the "-volume", "-dump",
1674 * "-portoffset", or "-append" option
1676 if (as->parms[6].items) {
1678 if (as->parms[0].items || as->parms[1].items || as->parms[2].items
1679 || as->parms[4].items) {
1680 afs_com_err(whoami, 0, "Invalid option specified with -file option");
1685 if (!as->parms[0].items || !as->parms[1].items) {
1686 afs_com_err(whoami, 0,
1687 "Must specify volume set name and dump level name");
1693 * Get the time we are to perform this dump
1695 if (as->parms[3].items) {
1698 timeString = concatParams(as->parms[3].items);
1703 * Now parse this string for the time to start.
1705 code = ktime_DateToLong(timeString, &atTime);
1708 afs_com_err(whoami, 0, "Can't parse dump start date and time");
1709 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1715 dontExecute = (as->parms[5].items ? 1 : 0); /* -n */
1718 * If this dump is not a load file, then check the parameters.
1720 if (!loadfile) { /*6 */
1721 vsName = as->parms[0].items->data; /* get volume set name */
1722 dumpPath = as->parms[1].items->data; /* get dump path */
1724 /* get the port number, if one was specified */
1725 if (as->parms[2].items) {
1727 portp = (afs_int32 *) malloc(sizeof(afs_int32));
1729 afs_com_err(whoami, BC_NOMEM, NULL);
1733 *portp = getPortOffset(as->parms[2].items->data);
1738 doAppend = (as->parms[4].items ? 1 : 0); /* -append */
1741 * Get a hold of the given volume set and dump set.
1743 tvs = bc_FindVolumeSet(bc_globalConfig, vsName);
1745 afs_com_err(whoami, 0,
1746 "Can't find volume set '%s' in backup database", vsName);
1749 baseds = bc_FindDumpSchedule(bc_globalConfig, dumpPath);
1751 afs_com_err(whoami, 0,
1752 "Can't find dump schedule '%s' in backup database",
1761 * If given the "-at" option, then add this to the jobs list and return
1764 * Create a status node for this timed dump.
1765 * Fill in the time to dump and the cmd line for the dump leaving off
1766 * the -at option. If the -n option is there, it is scheduled with
1767 * the Timed dump as opposed to not scheduling the time dump at all.
1770 if (atTime < time(0)) {
1771 afs_com_err(whoami, 0,
1772 "Time of dump is earlier then current time - not added");
1774 statusPtr = createStatusNode();
1776 statusPtr->scheduledDump = atTime;
1778 /* Determine length of the dump command */
1780 length += 4; /* "dump" */
1782 length += 6; /* " -file" */
1783 length += 1 + strlen(as->parms[6].items->data); /* " <file>" */
1785 /* length += 11; *//* " -volumeset" */
1786 length += 1 + strlen(as->parms[0].items->data); /* " <volset> */
1788 /* length += 6; *//* " -dump" */
1789 length += 1 + strlen(as->parms[1].items->data); /* " <dumpset> */
1791 if (as->parms[2].items) {
1792 /* length += 12; *//* " -portoffset" */
1793 length += 1 + strlen(as->parms[2].items->data); /* " <port>" */
1796 if (as->parms[4].items)
1797 length += 8; /* " -append" */
1801 length += 3; /* " -n" */
1802 length++; /* end-of-line */
1804 /* Allocate status block for this timed dump */
1805 sprintf(statusPtr->taskName, "Scheduled Dump");
1806 statusPtr->jobNumber = bc_jobNumber();
1807 statusPtr->scheduledDump = atTime;
1808 statusPtr->cmdLine = (char *)malloc(length);
1809 if (!statusPtr->cmdLine) {
1810 afs_com_err(whoami, BC_NOMEM, NULL);
1814 /* Now reconstruct the dump command */
1815 statusPtr->cmdLine[0] = 0;
1816 strcat(statusPtr->cmdLine, "dump");
1818 strcat(statusPtr->cmdLine, " -file");
1819 strcat(statusPtr->cmdLine, " ");
1820 strcat(statusPtr->cmdLine, as->parms[6].items->data);
1822 /* strcat(statusPtr->cmdLine, " -volumeset"); */
1823 strcat(statusPtr->cmdLine, " ");
1824 strcat(statusPtr->cmdLine, as->parms[0].items->data);
1826 /* strcat(statusPtr->cmdLine, " -dump"); */
1827 strcat(statusPtr->cmdLine, " ");
1828 strcat(statusPtr->cmdLine, as->parms[1].items->data);
1830 if (as->parms[2].items) {
1831 /* strcat(statusPtr->cmdLine, " -portoffset"); */
1832 strcat(statusPtr->cmdLine, " ");
1833 strcat(statusPtr->cmdLine, as->parms[2].items->data);
1836 if (as->parms[4].items)
1837 strcat(statusPtr->cmdLine, " -append");
1840 strcat(statusPtr->cmdLine, " -n");
1842 printf("Add scheduled dump as job %d\n", statusPtr->jobNumber);
1843 if ((atTime > tokenExpires) && (tokenExpires != NEVERDATE))
1844 afs_com_err(whoami, 0,
1845 "Warning: job %d starts after expiration of AFS token",
1846 statusPtr->jobNumber);
1855 * Read and execute the load file if specified. The work of reading is done
1856 * in the main routine prior the dispatch call. loadFile and dontExecute are
1857 * global variables so this can take place in main.
1860 loadFile = (char *)malloc(strlen(as->parms[6].items->data) + 1);
1862 afs_com_err(whoami, BC_NOMEM, NULL);
1865 strcpy(loadFile, as->parms[6].items->data);
1870 * We are doing a real dump (no load file or timed dump).
1872 printf("Starting dump of volume set '%s' (dump level '%s')\n", vsName,
1875 /* For each dump-level above this one, see if the volumeset was dumped
1876 * at the level. We search all dump-levels since a higher dump-level
1877 * may have actually been done AFTER a lower dump level.
1879 parent = level = problemFindingDump = 0;
1880 for (tds = baseds->parent; tds; tds = tds->parent) {
1881 /* Find the most recent dump of the volume-set at this dump-level.
1882 * Raise problem flag if didn't find a dump and a parent not yet found.
1884 code = bcdb_FindLatestDump(vsName, tds->name, &dumpEntry);
1887 problemFindingDump = 1; /* skipping a dump level */
1891 /* We found the most recent dump at this level. Now check
1892 * if we should use it by seeing if its full dump hierarchy
1893 * exists. If it doesn't, we don't want to base our incremental
1896 if (!parent || (dumpEntry.id > parent)) {
1897 /* Follow the parent dumps to see if they are all there */
1898 for (d = dumpEntry.parent; d; d = de.parent) {
1899 code = bcdb_FindDumpByID(d, &de);
1904 /* If we found the entire level, remember it. Otherwise raise flag.
1905 * If we had already found a dump, raise the problem flag.
1909 problemFindingDump = 1;
1910 parent = dumpEntry.id;
1911 level = dumpEntry.level + 1;
1912 memcpy(&fde, &dumpEntry, sizeof(dumpEntry));
1914 /* Dump hierarchy not complete so can't base off the latest */
1915 problemFindingDump = 1;
1920 /* If the problemflag was raise, it means we are not doing the
1921 * dump at the level we requested it be done at.
1923 if (problemFindingDump) {
1924 afs_com_err(whoami, 0,
1925 "Warning: Doing level %d dump due to missing higher-level dumps",
1928 printf("Parent dump: dump %s (DumpID %u)\n", fde.name, parent);
1930 } else if (parent) {
1931 printf("Found parent: dump %s (DumpID %u)\n", fde.name, parent);
1934 /* Expand out the volume set into its component list of volumes. */
1935 code = bc_EvalVolumeSet(bc_globalConfig, tvs, &volsToDump, cstruct);
1937 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1941 printf("No volumes to dump\n");
1945 /* Determine what the clone time of the volume was when it was
1946 * last dumped (tve->date). This is the time from when an
1947 * incremental should be done (remains zero if a full dump).
1950 for (tve = volsToDump; tve; tve = tve->next) {
1951 code = bcdb_FindClone(parent, tve->name, &tve->date);
1955 /* Get the time the volume was last cloned and see if the volume has
1956 * changed since then. Only do this when the "-n" flag is specified
1957 * because butc will get the cloneDate at time of dump.
1961 volImageTime(tve->server.sin_addr.s_addr, tve->partition,
1962 tve->vid, tve->volType, &tve->cloneDate);
1966 if (tve->cloneDate && (tve->cloneDate == tve->date)) {
1967 afs_com_err(whoami, 0,
1968 "Warning: Timestamp on volume %s unchanged from previous dump",
1976 printf("Would have dumped the following volumes:\n");
1978 printf("Preparing to dump the following volumes:\n");
1979 for (tve = volsToDump; tve; tve = tve->next) {
1980 printf("\t%s (%u)\n", tve->name, tve->vid);
1985 code = bc_StartDmpRst(bc_globalConfig, dumpPath, vsName, volsToDump,
1986 /*destServer */ NULL, /*destPartition */ 0,
1988 /*newExt */ NULL, /*oldFlag */ 0,
1989 parent, level, bc_Dumper, portp, /*portCount */ 1,
1990 baseds, doAppend, dontExecute);
1992 afs_com_err(whoami, code, "; Failed to queue dump");
1999 * terminate the backup process. Insists that that all running backup
2000 * jobs be terminated before it will quit
2005 bc_QuitCmd(struct cmd_syndesc *as, void *arock)
2008 struct bc_dumpTask *td;
2009 extern dlqlinkT statusHead;
2013 /* Check the status list for outstanding jobs */
2015 for (ptr = (&statusHead)->dlq_next; ptr != &statusHead;
2016 ptr = ptr->dlq_next) {
2017 statusPtr = (statusP) ptr;
2018 if (!(statusPtr->flags & ABORT_REQUEST)) {
2020 afs_com_err(whoami, 0, "Job %d still running (and not aborted)",
2021 statusPtr->jobNumber);
2022 afs_com_err(whoami, 0,
2023 "You must at least 'kill' all running jobs before quitting");
2029 /* A job still being initialized (but no status structure or job number since it
2030 * has not been handed to a butc process yet)
2032 for (td = bc_dumpTasks, i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
2033 if (td->flags & BC_DI_INUSE) {
2034 afs_com_err(whoami, 0, "A job is still running");
2035 afs_com_err(whoami, 0,
2036 "You must at least 'kill' all running jobs before quitting");
2042 /* close the all temp text files before quitting */
2043 for (i = 0; i < TB_NUM; i++)
2044 bc_closeTextFile(&bc_globalConfig->configText[i],
2045 &bc_globalConfig->tmpTextFileNames[i][0]);
2051 * Labels a tape i.e. request the tape coordinator to perform this
2055 bc_LabelTapeCmd(struct cmd_syndesc *as, void *arock)
2057 char *tapename = 0, *pname = 0;
2062 code = bc_UpdateHosts();
2064 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2068 if (as->parms[0].items) { /* -name */
2069 tapename = as->parms[0].items->data;
2070 if (strlen(tapename) >= TC_MAXTAPELEN) {
2071 afs_com_err(whoami, 0, "AFS tape name '%s' is too long", tapename);
2076 if (as->parms[3].items) { /* -pname */
2078 afs_com_err(whoami, 0, "Can only specify -name or -pname");
2081 pname = as->parms[3].items->data;
2082 if (strlen(pname) >= TC_MAXTAPELEN) {
2083 afs_com_err(whoami, 0, "Permanent tape name '%s' is too long", pname);
2088 if (as->parms[1].items) {
2089 size = bc_FloatATOI(as->parms[1].items->data);
2091 afs_com_err(whoami, 0, "Bad syntax for tape size '%s'",
2092 as->parms[1].items->data);
2098 if (as->parms[2].items) {
2099 port = getPortOffset(as->parms[2].items->data);
2104 code = bc_LabelTape(tapename, pname, size, bc_globalConfig, port);
2111 * read the label on a tape
2113 * optional port number
2116 bc_ReadLabelCmd(struct cmd_syndesc *as, void *arock)
2121 code = bc_UpdateHosts();
2123 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2127 if (as->parms[0].items) {
2128 port = getPortOffset(as->parms[0].items->data);
2133 code = bc_ReadLabel(bc_globalConfig, port);
2140 * read content information from dump tapes, and if user desires,
2141 * add it to the database
2144 bc_ScanDumpsCmd(struct cmd_syndesc *as, void *arock)
2147 afs_int32 dbAddFlag = 0;
2150 code = bc_UpdateHosts();
2152 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2156 /* check for flag */
2157 if (as->parms[0].items != 0) { /* add scan to database */
2161 /* check for port */
2162 if (as->parms[1].items) {
2163 port = getPortOffset(as->parms[1].items->data);
2168 code = bc_ScanDumps(bc_globalConfig, dbAddFlag, port);
2172 /* bc_ParseExpiration
2175 * dates are specified as absolute or relative, the syntax is:
2176 * absolute: at %d/%d/%d [%d:%d] where [..] is optional
2177 * relative: in [%dy][%dm][%dd] where at least one component
2182 bc_ParseExpiration(struct cmd_parmdesc *paramPtr, afs_int32 *expType,
2185 struct cmd_item *itemPtr;
2186 struct ktime_date kt;
2187 char *dateString = 0;
2190 *expType = BC_NO_EXPDATE;
2193 if (!paramPtr->items)
2194 ERROR(0); /* no expiration specified */
2196 /* some form of expiration date specified. First validate the prefix */
2197 itemPtr = paramPtr->items;
2199 if (strcmp(itemPtr->data, "at") == 0) {
2200 *expType = BC_ABS_EXPDATE;
2202 dateString = concatParams(itemPtr->next);
2206 code = ktime_DateToLong(dateString, expDate);
2209 } else if (strcmp(itemPtr->data, "in") == 0) {
2210 *expType = BC_REL_EXPDATE;
2212 dateString = concatParams(itemPtr->next);
2216 code = ParseRelDate(dateString, &kt);
2219 *expDate = ktimeRelDate_ToLong(&kt);
2221 dateString = concatParams(itemPtr);
2225 if (ktime_DateToLong(dateString, expDate) == 0) {
2226 *expType = BC_ABS_EXPDATE;
2227 code = ktime_DateToLong(dateString, expDate);
2230 } else if (ParseRelDate(dateString, &kt) == 0) {
2231 *expType = BC_REL_EXPDATE;
2232 *expDate = ktimeRelDate_ToLong(&kt);
2244 /* database lookup command and routines */
2247 * Currently a single option, volumename to search for. Reports
2248 * all dumps containing the specified volume
2251 bc_dblookupCmd(struct cmd_syndesc *as, void *arock)
2253 struct cmd_item *ciptr;
2256 ciptr = as->parms[0].items;
2257 if (ciptr == 0) /* no argument specified */
2260 code = DBLookupByVolume(ciptr->data);
2266 /* for ubik version */
2268 bc_dbVerifyCmd(struct cmd_syndesc *as, void *arock)
2274 struct hostent *hostPtr;
2278 extern struct udbHandleS udbHandle;
2280 detail = (as->parms[0].items ? 1 : 0); /* print more details */
2283 ubik_Call(BUDB_DbVerify, udbHandle.uh_client, 0, &status, &orphans,
2287 afs_com_err(whoami, code, "; Unable to verify database");
2291 /* verification call succeeded */
2294 printf("Database OK\n");
2296 afs_com_err(whoami, status, "; Database is NOT_OK");
2299 printf("Orphan blocks %d\n", orphans);
2302 printf("Unable to lookup host id\n");
2304 hostPtr = gethostbyaddr((char *)&host, sizeof(host), AF_INET);
2306 printf("Database checker was %d.%d.%d.%d\n",
2307 ((host & 0xFF000000) >> 24), ((host & 0xFF0000) >> 16),
2308 ((host & 0xFF00) >> 8), (host & 0xFF));
2310 printf("Database checker was %s\n", hostPtr->h_name);
2313 return ((status ? -1 : 0));
2317 * Delete a dump. If port is >= 0, it means try to delete from XBSA server
2320 deleteDump(afs_uint32 dumpid, /* The dumpid to delete */
2321 afs_int32 port, /* port==-1 means don't go to butc */
2324 afs_int32 code = 0, tcode;
2325 struct budb_dumpEntry dumpEntry;
2326 struct rx_connection *tconn = 0;
2327 afs_int32 i, taskflag, xbsadump;
2328 statusP statusPtr = 0;
2329 budb_dumpsList dumps;
2332 /* If the port is set, we will try to send a delete request to the butc */
2334 tcode = bc_UpdateHosts();
2336 afs_com_err(whoami, tcode, "; Can't retrieve tape hosts");
2340 /* Find the dump in the backup database */
2341 tcode = bcdb_FindDumpByID(dumpid, &dumpEntry);
2343 afs_com_err(whoami, tcode, "; Unable to locate dumpID %u in database",
2347 xbsadump = (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA));
2349 /* If dump is to an XBSA server, connect to butc and send it
2350 * the dump to delete. Butc will contact the XBSA server.
2351 * The dump will not be an appended dump because XBSA butc
2352 * does not support the append option.
2354 if (xbsadump && dumpEntry.nVolumes) {
2355 tcode = ConnectButc(bc_globalConfig, port, &tconn);
2359 tcode = TC_DeleteDump(tconn, dumpid, &taskId);
2361 if (tcode == RXGEN_OPCODE)
2362 tcode = BC_VERSIONFAIL;
2363 afs_com_err(whoami, tcode,
2364 "; Unable to delete dumpID %u via butc", dumpid);
2368 statusPtr = createStatusNode();
2370 statusPtr->taskId = taskId;
2371 statusPtr->port = port;
2372 statusPtr->jobNumber = bc_jobNumber();
2373 statusPtr->flags |= (SILENT | NOREMOVE); /* No msg & keep statusPtr */
2374 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2375 sprintf(statusPtr->taskName, "DeleteDump");
2378 /* Wait for task to finish */
2379 taskflag = waitForTask(taskId);
2380 if (taskflag & (TASK_ERROR | ABORT_DONE)) {
2381 afs_com_err(whoami, BUTX_DELETEOBJFAIL,
2382 "; Unable to delete dumpID %u via butc", dumpid);
2383 ERROR(BUTX_DELETEOBJFAIL); /* the task failed */
2390 deleteStatusNode(statusPtr); /* Clean up statusPtr - because NOREMOVE */
2392 rx_DestroyConnection(tconn); /* Destroy the connection */
2394 /* Remove the dump from the backup database */
2395 if (!code || force) {
2396 dumps.budb_dumpsList_len = 0;
2397 dumps.budb_dumpsList_val = 0;
2399 tcode = bcdb_deleteDump(dumpid, 0, 0, &dumps);
2401 afs_com_err(whoami, tcode,
2402 "; Unable to delete dumpID %u from database", dumpid);
2403 dumps.budb_dumpsList_len = 0;
2408 /* Display the dumps that were deleted - includes appended dumps */
2409 for (i = 0; i < dumps.budb_dumpsList_len; i++)
2410 printf(" %u%s\n", dumps.budb_dumpsList_val[i],
2411 (i > 0) ? " Appended Dump" : NULL);
2412 if (dumps.budb_dumpsList_val)
2413 free(dumps.budb_dumpsList_val);
2420 * Delete a specified dump from the database
2422 * dump id - single required arg as param 0.
2425 bc_deleteDumpCmd(struct cmd_syndesc *as, void *arock)
2429 afs_int32 rcode = 0;
2430 afs_int32 groupId = 0, havegroupid, sflags, noexecute;
2431 struct cmd_item *ti;
2432 afs_int32 fromTime = 0, toTime = 0, havetime = 0;
2434 budb_dumpsList dumps, flags;
2436 afs_int32 port = -1, force;
2438 /* Must specify at least one of -dumpid, -from, or -to */
2439 if (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items
2440 && !as->parms[4].items) {
2441 afs_com_err(whoami, 0, "Must specify at least one field");
2445 /* Must have -to option with -from option */
2446 if (as->parms[1].items && !as->parms[2].items) {
2447 afs_com_err(whoami, 0, "Must specify '-to' field with '-from' field");
2451 /* Get the time to delete from */
2452 if (as->parms[1].items) { /* -from */
2453 timeString = concatParams(as->parms[1].items);
2458 * Now parse this string for the time to start.
2460 code = ktime_DateToLong(timeString, &fromTime);
2463 afs_com_err(whoami, 0, "Can't parse 'from' date and time");
2464 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2470 port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -port */
2471 if (as->parms[5].items) /* -dbonly */
2474 force = (as->parms[6].items ? 1 : 0);
2476 havegroupid = (as->parms[4].items ? 1 : 0);
2478 groupId = atoi(as->parms[4].items->data);
2480 noexecute = (as->parms[7].items ? 1 : 0);
2482 /* Get the time to delete to */
2483 if (as->parms[2].items) { /* -to */
2484 timeString = concatParams(as->parms[2].items);
2489 * Now parse this string for the time to start. Simce
2490 * times are at minute granularity, add 59 seconds.
2492 code = ktime_DateToLong(timeString, &toTime);
2495 afs_com_err(whoami, 0, "Can't parse 'to' date and time");
2496 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2503 if (fromTime > toTime) {
2504 afs_com_err(whoami, 0,
2505 "'-from' date/time cannot be later than '-to' date/time");
2509 /* Remove speicific dump ids - if any */
2510 printf("The following dumps %s deleted:\n",
2511 (noexecute ? "would have been" : "were"));
2512 for (ti = as->parms[0].items; ti != 0; ti = ti->next) { /* -dumpid */
2513 dumpid = atoi(ti->data);
2515 code = deleteDump(dumpid, port, force);
2517 printf(" %u\n", dumpid);
2522 * Now remove dumps between to and from dates.
2524 if (havegroupid || havetime) {
2525 dumps.budb_dumpsList_len = 0;
2526 dumps.budb_dumpsList_val = 0;
2527 flags.budb_dumpsList_len = 0;
2528 flags.budb_dumpsList_val = 0;
2531 sflags |= BUDB_OP_GROUPID;
2533 sflags |= BUDB_OP_DATES;
2536 bcdb_listDumps(sflags, groupId, fromTime, toTime, &dumps, &flags);
2538 afs_com_err(whoami, code,
2539 "; Error while deleting dumps from %u to %u", fromTime,
2544 for (i = 0; i < dumps.budb_dumpsList_len; i++) {
2545 if (flags.budb_dumpsList_val[i] & BUDB_OP_DBDUMP)
2549 if (flags.budb_dumpsList_val[i] & BUDB_OP_APPDUMP)
2551 code = deleteDump(dumps.budb_dumpsList_val[i], port, force);
2552 /* Ignore code and continue */
2554 printf(" %u%s%s\n", dumps.budb_dumpsList_val[i],
2556 budb_dumpsList_val[i] & BUDB_OP_APPDUMP) ?
2557 " Appended Dump" : "",
2559 budb_dumpsList_val[i] & BUDB_OP_DBDUMP) ?
2560 " Database Dump" : "");
2565 if (dumps.budb_dumpsList_val)
2566 free(dumps.budb_dumpsList_val);
2567 dumps.budb_dumpsList_len = 0;
2568 dumps.budb_dumpsList_val = 0;
2569 if (flags.budb_dumpsList_val)
2570 free(flags.budb_dumpsList_val);
2571 flags.budb_dumpsList_len = 0;
2572 flags.budb_dumpsList_val = 0;
2579 bc_saveDbCmd(struct cmd_syndesc *as, void *arock)
2581 struct rx_connection *tconn;
2582 afs_int32 portOffset = 0;
2589 code = bc_UpdateHosts();
2591 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2595 if (as->parms[0].items) {
2596 portOffset = getPortOffset(as->parms[0].items->data);
2601 /* Get the time to delete to */
2602 if (as->parms[1].items) {
2603 timeString = concatParams(as->parms[1].items);
2608 * Now parse this string for the time. Since
2609 * times are at minute granularity, add 59 seconds.
2611 code = ktime_DateToLong(timeString, &toTime);
2614 afs_com_err(whoami, 0, "Can't parse '-archive' date and time");
2615 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2622 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2626 code = TC_SaveDb(tconn, toTime, &taskId);
2628 afs_com_err(whoami, code, "; Failed to save database");
2632 /* create status monitor block */
2633 statusPtr = createStatusNode();
2635 statusPtr->taskId = taskId;
2636 statusPtr->port = portOffset;
2637 statusPtr->jobNumber = bc_jobNumber();
2638 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2639 sprintf(statusPtr->taskName, "SaveDb");
2643 rx_DestroyConnection(tconn);
2648 bc_restoreDbCmd(struct cmd_syndesc *as, void *arock)
2650 struct rx_connection *tconn;
2651 afs_int32 portOffset = 0;
2656 code = bc_UpdateHosts();
2658 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2662 if (as->parms[0].items) {
2663 portOffset = getPortOffset(as->parms[0].items->data);
2668 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2672 code = TC_RestoreDb(tconn, &taskId);
2674 afs_com_err(whoami, code, "; Failed to restore database");
2678 /* create status monitor block */
2679 statusPtr = createStatusNode();
2681 statusPtr->taskId = taskId;
2682 statusPtr->port = portOffset;
2683 statusPtr->jobNumber = bc_jobNumber();
2684 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2685 sprintf(statusPtr->taskName, "RestoreDb");
2689 rx_DestroyConnection(tconn);
2693 /* ----------------------------------
2694 * supporting routines for database examination
2695 * ----------------------------------
2698 /* structures and defines for DBLookupByVolume */
2700 #define DBL_MAX_VOLUMES 20 /* max. for each dump */
2702 /* dumpedVol - saves interesting information so that we can print it out
2707 struct dumpedVol *next;
2709 afs_int32 initialDumpID;
2710 char tapeName[BU_MAXTAPELEN];
2713 afs_int32 createTime;
2714 afs_int32 incTime; /* actually the clone time */
2717 /* -----------------------------------------
2718 * routines for examining the database
2719 * -----------------------------------------
2723 * Lookup the volumename in the backup database and print the results
2725 * volumeName - volume to lookup
2729 DBLookupByVolume(char *volumeName)
2731 struct budb_dumpEntry dumpEntry;
2732 struct budb_volumeEntry volumeEntry[DBL_MAX_VOLUMES];
2733 afs_int32 numEntries;
2734 afs_int32 tapedumpid;
2735 afs_int32 last, next;
2737 struct dumpedVol *dvptr = 0;
2738 struct dumpedVol *tempPtr = 0;
2741 char vname[BU_MAXNAMELEN];
2744 for (pass = 0; pass < 2; pass++) {
2746 /* On second pass, search for backup volume */
2748 if (!BackupName(volumeName)) {
2749 strcpy(vname, volumeName);
2750 strcat(vname, ".backup");
2758 while (next != -1) { /*w */
2760 bcdb_LookupVolume(volumeName, &volumeEntry[0], last, &next,
2761 DBL_MAX_VOLUMES, &numEntries);
2765 /* add the volumes to the list */
2766 for (i = 0; i < numEntries; i++) { /*f */
2767 struct dumpedVol *insPtr, **prevPtr;
2770 (struct dumpedVol *)malloc(sizeof(struct dumpedVol));
2774 memset(tempPtr, 0, sizeof(*tempPtr));
2775 tempPtr->incTime = volumeEntry[i].clone;
2776 tempPtr->dumpID = volumeEntry[i].dump;
2777 strncpy(tempPtr->tapeName, volumeEntry[i].tape,
2780 /* check if we need to null terminate it - just for safety */
2781 if (strlen(volumeEntry[i].tape) >= BU_MAXTAPELEN)
2782 tempPtr->tapeName[BU_MAXTAPELEN - 1] = 0;
2784 code = bcdb_FindDumpByID(tempPtr->dumpID, &dumpEntry);
2790 tempPtr->initialDumpID = dumpEntry.initialDumpID;
2791 tempPtr->parent = dumpEntry.parent;
2792 tempPtr->level = dumpEntry.level;
2793 tempPtr->createTime = dumpEntry.created;
2795 /* add volume to list in reverse chronological order */
2799 while ((insPtr != 0)
2800 && (insPtr->createTime > tempPtr->createTime)
2802 prevPtr = &insPtr->next;
2803 insPtr = insPtr->next;
2806 /* now at the right place - insert the block */
2807 tempPtr->next = *prevPtr;
2817 ("DumpID lvl parentID creation date clone date tape name\n");
2818 for (tempPtr = dvptr; tempPtr; tempPtr = tempPtr->next) {
2819 /* For the user, the tape name is its name and initial dump id */
2821 (tempPtr->initialDumpID ? tempPtr->initialDumpID : tempPtr->
2824 /* beware the static items in compactDateString */
2825 compactDateString(&tempPtr->createTime, ds, 50);
2826 printf("%-9d %-2d %-9d %16s", tempPtr->dumpID, tempPtr->level,
2827 tempPtr->parent, ds);
2828 compactDateString(&tempPtr->incTime, ds, 50);
2829 printf(" %16s %s (%u)\n", ds, tempPtr->tapeName, tapedumpid);
2835 for (tempPtr = dvptr; tempPtr; tempPtr = dvptr) {
2836 dvptr = dvptr->next;
2841 afs_com_err(whoami, code, NULL);
2845 /* structures for dumpInfo */
2848 struct volumeLink *nextVolume;
2849 struct budb_volumeEntry volumeEntry;
2853 struct tapeLink *nextTape;
2854 struct budb_tapeEntry tapeEntry;
2855 struct volumeLink *firstVolume;
2860 * print information about a dump and all its tapes and volumes.
2864 dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
2866 struct budb_dumpEntry dumpEntry;
2867 struct tapeLink *head = 0;
2868 struct tapeLink *tapeLinkPtr, *lastTapeLinkPtr;
2869 struct volumeLink **link, *volumeLinkPtr, *lastVolumeLinkPtr;
2872 afs_int32 last, next, dbTime;
2873 afs_int32 tapedumpid;
2881 extern struct udbHandleS udbHandle;
2884 lastTapeLinkPtr = 0;
2886 lastVolumeLinkPtr = 0;
2888 /* first get information about the dump */
2890 code = bcdb_FindDumpByID(dumpid, &dumpEntry);
2894 /* For the user, the tape name is its name and initial dump id */
2895 tapedumpid = (dumpEntry.initialDumpID ? dumpEntry.initialDumpID : dumpid);
2897 /* Is this a database dump id or not */
2898 if (strcmp(dumpEntry.name, DUMP_TAPE_NAME) == 0)
2903 /* print out the information about the dump */
2907 printDumpEntry(&dumpEntry);
2909 time_t t = dumpEntry.created;
2911 printf("Dump: id %u, created: %s\n", dumpEntry.id,
2914 printf("Dump: id %u, level %d, volumes %d, created: %s\n",
2915 dumpEntry.id, dumpEntry.level, dumpEntry.nVolumes,
2919 if (!detailFlag && (strlen(dumpEntry.tapes.tapeServer) > 0)
2920 && (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA))) {
2921 printf("Backup Service: TSM: Server: %s\n",
2922 dumpEntry.tapes.tapeServer);
2925 /* now get the list of tapes */
2926 for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) { /*f */
2927 tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
2929 afs_com_err(whoami, BC_NOMEM, NULL);
2933 memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
2934 code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
2941 /* add this tape to previous chain */
2942 if (lastTapeLinkPtr) {
2943 lastTapeLinkPtr->nextTape = tapeLinkPtr;
2944 lastTapeLinkPtr = tapeLinkPtr;
2949 lastTapeLinkPtr = head;
2953 while (next != -1) { /*wn */
2954 vl.budb_volumeList_len = 0;
2955 vl.budb_volumeList_val = 0;
2958 /* now get all the volumes in this dump. */
2959 code = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client, UF_SINGLESERVER, BUDB_MAJORVERSION, BUDB_OP_DUMPID | BUDB_OP_TAPENAME, tapeLinkPtr->tapeEntry.name, /* tape name */
2960 dumpid, /* dumpid (not initial dumpid) */
2963 &next, /* nextindex */
2964 &dbTime, /* update time */
2968 if (code == BUDB_ENDOFLIST) { /* 0 volumes on tape */
2975 for (i = 0; i < vl.budb_volumeList_len; i++) {
2976 link = &tapeLinkPtr->firstVolume;
2979 (struct volumeLink *)malloc(sizeof(struct volumeLink));
2980 if (!volumeLinkPtr) {
2981 afs_com_err(whoami, BC_NOMEM, NULL);
2984 memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
2986 memcpy(&volumeLinkPtr->volumeEntry,
2987 &vl.budb_volumeList_val[i],
2988 sizeof(struct budb_volumeEntry));
2990 /* now insert it onto the right place */
2992 && (volumeLinkPtr->volumeEntry.position >
2993 (*link)->volumeEntry.position)) {
2994 link = &((*link)->nextVolume);
2997 /* now link it in */
2998 volumeLinkPtr->nextVolume = *link;
2999 *link = volumeLinkPtr;
3002 if (vl.budb_volumeList_val)
3003 free(vl.budb_volumeList_val);
3007 for (tapeLinkPtr = head; tapeLinkPtr; tapeLinkPtr = tapeLinkPtr->nextTape) {
3011 printTapeEntry(&tapeLinkPtr->tapeEntry);
3013 printf("Tape: name %s (%u)\n", tapeLinkPtr->tapeEntry.name,
3015 printf("nVolumes %d, ", tapeLinkPtr->tapeEntry.nVolumes);
3016 compactDateString(&tapeLinkPtr->tapeEntry.written, ds, 50);
3017 printf("created %16s", ds);
3018 if (tapeLinkPtr->tapeEntry.expires != 0) {
3019 compactDateString(&tapeLinkPtr->tapeEntry.expires, ds, 50);
3020 printf(", expires %16s", ds);
3025 /* print out all the volumes */
3027 /* print header for volume listing - db dumps have no volumes */
3028 if ((detailFlag == 0) && !dbDump)
3029 printf("%4s %16s %9s %-s\n", "Pos", "Clone time", "Nbytes",
3032 for (volumeLinkPtr = tapeLinkPtr->firstVolume; volumeLinkPtr;
3033 volumeLinkPtr = volumeLinkPtr->nextVolume) {
3035 printf("\nVolume\n");
3037 printVolumeEntry(&volumeLinkPtr->volumeEntry);
3039 compactDateString(&volumeLinkPtr->volumeEntry.clone, ds, 50),
3040 printf("%4d %s %10u %16s\n",
3041 volumeLinkPtr->volumeEntry.position, ds,
3042 volumeLinkPtr->volumeEntry.nBytes,
3043 volumeLinkPtr->volumeEntry.name);
3050 afs_com_err("dumpInfo", code, "; Can't get dump information");
3052 /* free all allocated structures */
3054 while (tapeLinkPtr) {
3055 volumeLinkPtr = tapeLinkPtr->firstVolume;
3056 while (volumeLinkPtr) {
3057 lastVolumeLinkPtr = volumeLinkPtr;
3058 volumeLinkPtr = volumeLinkPtr->nextVolume;
3059 free(lastVolumeLinkPtr);
3062 lastTapeLinkPtr = tapeLinkPtr;
3063 tapeLinkPtr = tapeLinkPtr->nextTape;
3064 free(lastTapeLinkPtr);
3070 compareDump(struct budb_dumpEntry *ptr1, struct budb_dumpEntry *ptr2)
3072 if (ptr1->created < ptr2->created)
3074 else if (ptr1->created > ptr2->created)
3080 printRecentDumps(int ndumps)
3083 afs_int32 nextindex, index = 0;
3086 struct budb_dumpEntry *dumpPtr;
3090 extern struct udbHandleS udbHandle;
3092 do { /* while (nextindex != -1) */
3093 /* initialize the dump list */
3094 dl.budb_dumpList_len = 0;
3095 dl.budb_dumpList_val = 0;
3097 /* outline algorithm */
3098 code = ubik_Call(BUDB_GetDumps, udbHandle.uh_client, 0, BUDB_MAJORVERSION, BUDB_OP_NPREVIOUS, "", /* no name */
3102 &nextindex, &dbTime, &dl);
3104 if (code == BUDB_ENDOFLIST)
3106 afs_com_err("dumpInfo", code, "; Can't get dump information");
3110 /* No need to sort, it's already sorted */
3112 if (dl.budb_dumpList_len && (index == 0))
3113 printf("%10s %10s %2s %-16s %2s %5s dump name\n", "dumpid",
3114 "parentid", "lv", "created", "nt", "nvols");
3116 dumpPtr = dl.budb_dumpList_val;
3117 for (i = 1; i <= dl.budb_dumpList_len; i++) {
3118 compactDateString(&dumpPtr->created, ds, 50),
3119 printf("%10u %10u %-2d %16s %2d %5d %s", dumpPtr->id,
3120 dumpPtr->parent, dumpPtr->level, ds,
3121 dumpPtr->tapes.maxTapes - dumpPtr->tapes.b + 1,
3122 dumpPtr->nVolumes, dumpPtr->name);
3123 if (dumpPtr->initialDumpID) /* an appended dump */
3124 printf(" (%u)", dumpPtr->initialDumpID);
3125 else if (dumpPtr->appendedDumpID) /* has appended dumps */
3126 printf(" (%u)", dumpPtr->id);
3132 if (dl.budb_dumpList_val)
3133 free(dl.budb_dumpList_val);
3135 } while (nextindex != -1);
3141 * list the dumps and contens of the dumps.
3147 bc_dumpInfoCmd(struct cmd_syndesc *as, void *arock)
3150 afs_int32 detailFlag;
3154 if (as->parms[0].items) {
3155 if (as->parms[1].items) {
3156 afs_com_err(whoami, 0,
3157 "These options are exclusive - select only one");
3160 ndumps = atoi(as->parms[0].items->data);
3162 afs_com_err(whoami, 0, "Must provide a positive number");
3166 code = printRecentDumps(ndumps);
3167 } else if (as->parms[1].items) {
3168 detailFlag = (as->parms[2].items ? 1 : 0); /* 1 = detailed listing */
3169 dumpid = atoi(as->parms[1].items->data);
3170 code = dumpInfo(dumpid, detailFlag);
3172 code = printRecentDumps(10);