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>
16 #ifdef HAVE_POSIX_REGEX /* use POSIX regexp library */
21 #include <afs/com_err.h>
22 #include <afs/afsutil.h>
24 #include <afs/budb_prototypes.h>
26 #include <afs/bubasics.h> /* PA */
27 #include <afs/afsint.h>
28 #include <afs/volser.h>
29 #include <afs/voldefs.h> /* PA */
30 #include <afs/vldbint.h> /* PA */
31 #include <afs/ktime.h> /* PA */
34 #include <afs/tcdata.h>
36 #include <afs/vsutils_prototypes.h>
39 #include "error_macros.h"
40 #include "bucoord_internal.h"
41 #include "bucoord_prototypes.h"
43 extern struct bc_config *bc_globalConfig;
44 extern struct bc_dumpTask bc_dumpTasks[BC_MAXSIMDUMPS];
45 extern struct ubik_client *cstruct;
49 extern afs_int32 lastTaskCode;
51 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
53 static int EvalVolumeSet1(struct bc_config *aconfig, struct bc_volumeSet *avs,
54 struct bc_volumeDump **avols,
55 struct ubik_client *uclient);
57 static int EvalVolumeSet2(struct bc_config *aconfig, struct bc_volumeSet *avs,
58 struct bc_volumeDump **avols,
59 struct ubik_client *uclient);
60 static int DBLookupByVolume(char *volumeName);
63 bc_EvalVolumeSet(struct bc_config *aconfig,
64 struct bc_volumeSet *avs,
65 struct bc_volumeDump **avols,
66 struct ubik_client *uclient)
67 { /*bc_EvalVolumeSet */
69 static afs_int32 use = 2;
71 if (use == 2) { /* Use EvalVolumeSet2() */
72 code = EvalVolumeSet2(aconfig, avs, avols, uclient);
73 if (code == RXGEN_OPCODE)
76 if (use == 1) { /* Use EvalVolumeSet1() */
77 code = EvalVolumeSet1(aconfig, avs, avols, uclient);
80 } /*bc_EvalVolumeSet */
82 struct partitionsort {
84 struct bc_volumeDump *vdlist;
85 struct bc_volumeDump *lastvdlist;
86 struct bc_volumeDump *dupvdlist;
87 struct bc_volumeEntry *vole;
88 struct partitionsort *next;
92 struct partitionsort *partitions;
93 struct serversort *next;
97 getSPEntries(afs_uint32 server, afs_int32 partition,
98 struct serversort **serverlist,
99 struct serversort **ss,
100 struct partitionsort **ps)
102 if (!(*ss) || ((*ss)->ipaddr != server)) {
104 for ((*ss) = *serverlist; (*ss); *ss = (*ss)->next) {
105 if ((*ss)->ipaddr == server)
109 /* No server entry added. Add one */
111 *ss = calloc(1, sizeof(struct serversort));
113 afs_com_err(whoami, BC_NOMEM, NULL);
117 (*ss)->ipaddr = server;
118 (*ss)->next = *serverlist;
123 if (!(*ps) || ((*ps)->part != partition)) {
124 for (*ps = (*ss)->partitions; *ps; *ps = (*ps)->next) {
125 if ((*ps)->part == partition)
129 /* No partition entry added. Add one */
131 *ps = calloc(1, sizeof(struct partitionsort));
133 afs_com_err(whoami, BC_NOMEM, NULL);
139 (*ps)->part = partition;
140 (*ps)->next = (*ss)->partitions;
141 (*ss)->partitions = *ps;
147 randSPEntries(struct serversort *serverlist,
148 struct bc_volumeDump **avols)
150 struct serversort *ss, **pss;
151 struct partitionsort *ps, **pps;
153 afs_int32 scount, pcount;
157 /* Seed random number generator */
158 r = time(0) + getpid();
161 /* Count number of servers, remove one at a time */
162 for (scount = 0, ss = serverlist; ss; ss = ss->next, scount++);
163 for (; scount; scount--) {
164 /* Pick a random server in list and remove it */
165 r = (rand() >> 4) % scount;
166 for (pss = &serverlist, ss = serverlist; r;
167 pss = &ss->next, ss = ss->next, r--);
170 /* Count number of partitions, remove one at a time */
171 for (pcount = 0, ps = ss->partitions; ps; ps = ps->next, pcount++);
172 for (; pcount; pcount--) {
173 /* Pick a random parition in list and remove it */
174 r = (rand() >> 4) % pcount;
175 for (pps = &ss->partitions, ps = ss->partitions; r;
176 pps = &ps->next, ps = ps->next, r--);
179 ps->lastvdlist->next = *avols;
189 EvalVolumeSet2(struct bc_config *aconfig,
190 struct bc_volumeSet *avs,
191 struct bc_volumeDump **avols,
192 struct ubik_client *uclient)
193 { /*EvalVolumeSet2 */
194 struct bc_volumeEntry *tve;
195 struct bc_volumeDump *tavols;
196 struct VldbListByAttributes attributes;
197 afs_int32 si, nsi; /* startIndex and nextStartIndex */
198 afs_int32 nentries, e, ei, et, add, l;
199 nbulkentries bulkentries;
200 struct nvldbentry *entries = 0;
201 struct bc_volumeDump *tvd;
202 afs_int32 code = 0, tcode;
204 struct serversort *servers = 0, *ss = 0;
205 struct partitionsort *ps = 0;
207 *avols = (struct bc_volumeDump *)0;
208 bulkentries.nbulkentries_len = 0;
209 bulkentries.nbulkentries_val = 0;
211 /* For each of the volume set entries - collect the volumes that match it */
212 for (tve = avs->ventries; tve; tve = tve->next) {
213 /* Put together a call to the vlserver for this vlentry. The
214 * performance gain is from letting the vlserver expand the
215 * volumeset and not this routine.
218 if (tve->server.sin_addr.s_addr) { /* The server */
219 attributes.Mask |= VLLIST_SERVER;
220 attributes.server = tve->server.sin_addr.s_addr;
222 if (tve->partition != -1) { /* The partition */
223 attributes.Mask |= VLLIST_PARTITION;
224 attributes.partition = tve->partition;
227 /* Now make the call to the vlserver */
228 for (si = 0; si != -1; si = nsi) {
230 bulkentries.nbulkentries_len = 0;
231 bulkentries.nbulkentries_val = 0;
234 ubik_VL_ListAttributesN2(uclient, 0, &attributes,
235 tve->name, si, &nentries, &bulkentries, &nsi);
239 /* The 3.4 vlserver has a VL_ListAttributesN2() RPC call, but
240 * it is not complete. The only way to tell if it is not complete
241 * is if et == 0 (which we check for below). Also, if the call didn't
242 * match any entries, then we don't know what version the vlserver
243 * is. In both cases, we return RXGEN_OPCODE and the calling routine
244 * will switch to the EvalVolumeSet1() call.
247 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
251 if (nentries > bulkentries.nbulkentries_len)
252 nentries = bulkentries.nbulkentries_len;
254 /* Step through each entry and add it to the list of volumes */
255 entries = bulkentries.nbulkentries_val;
256 for (e = 0; e < nentries; e++) {
257 ei = entries[e].matchindex & 0xffff;
258 et = (entries[e].matchindex >> 16) & 0xffff;
273 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
276 /* Find server and partiton structure to hang the entry off of */
278 getSPEntries(entries[e].serverNumber[ei],
279 entries[e].serverPartition[ei], &servers,
282 afs_com_err(whoami, tcode, NULL);
286 /* Detect if this entry should be added (not a duplicate).
287 * Use ps->dupvdlist and ps->vole to only search volumes from
288 * previous volume set entries.
291 if (tve != avs->ventries) {
292 l = strlen(entries[e].name);
293 if (ps->vole != tve) {
295 ps->dupvdlist = ps->vdlist;
297 for (tavols = ps->dupvdlist; add && tavols;
298 tavols = tavols->next) {
299 if (strncmp(tavols->name, entries[e].name, l) == 0) {
300 if ((strcmp(&entries[e].name[l], ".backup") == 0)
301 || (strcmp(&entries[e].name[l], ".readonly")
303 || (strcmp(&entries[e].name[l], "") == 0))
310 /* Allocate a volume dump structure and its name */
311 tvd = calloc(1, sizeof(struct bc_volumeDump));
313 afs_com_err(whoami, BC_NOMEM, NULL);
317 tvd->name = malloc(strlen(entries[e].name) + 10);
319 afs_com_err(whoami, BC_NOMEM, NULL);
324 /* Fill it in and thread onto avols list */
325 strcpy(tvd->name, entries[e].name);
327 strcat(tvd->name, ".backup");
328 else if (et == ROVOL)
329 strcat(tvd->name, ".readonly");
330 tvd->vid = entries[e].volumeId[et];
333 tvd->partition = entries[e].serverPartition[ei];
334 tvd->server.sin_addr.s_addr = entries[e].serverNumber[ei];
335 tvd->server.sin_port = 0; /* default FS port */
336 tvd->server.sin_family = AF_INET;
337 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
338 tvd->server.sin_len = sizeof(struct sockaddr_in);
341 /* String tvd off of partition struct */
342 tvd->next = ps->vdlist;
345 ps->lastvdlist = tvd;
351 /* Free memory allocated during VL call */
352 if (bulkentries.nbulkentries_val) {
353 free(bulkentries.nbulkentries_val);
354 bulkentries.nbulkentries_val = 0;
360 /* Randomly link the volumedump entries together */
361 randSPEntries(servers, avols);
362 fprintf(stderr, "Total number of volumes : %u\n", count);
365 if (bulkentries.nbulkentries_val) {
366 free(bulkentries.nbulkentries_val);
369 } /*EvalVolumeSet2 */
371 /*-----------------------------------------------------------------------------
375 * Takes the entries in a volumeset and expands them into a list of
376 * volumes. Every VLDB volume entry is looked at and compared to the
379 * When matching a VLDB volume entry to a volumeset entry,
380 * 1. If the RW volume entry matches, that RW volume is used.
381 * 2. Otherwise, if the BK volume entry matches, the BK volume is used.
382 * 3. Finally, if the RO volume entry matches, the RO volume is used.
383 * For instance: A volumeset entry of ".* .* user.t.*" will match volume
384 * "user.troy" and "user.troy.backup". The rules will use
385 * the RW volume "user.troy".
387 * When a VLDB volume entry matches a volumeset entry (be it RW, BK or RO),
388 * that volume is used and matches against any remaining volumeset entries
390 * For instance: A 1st volumeset entry ".* .* .*.backup" will match with
391 * "user.troy.backup". Its 2nd volumeset entry ".* .* .*"
392 * would have matched its RW volume "user.troy", but the first
393 * match is used and the second match isn't even done.
396 * aconfig : Global configuration info.
398 * avols : Ptr to linked list of entries describing volumes to dump.
399 * uclient : Ptr to Ubik client structure.
402 * 0 on successful volume set evaluation,
403 * Lower-level codes otherwise.
406 * Expand only the single volume set provided (avs); don't go down its chain.
410 *-----------------------------------------------------------------------------
413 EvalVolumeSet1(struct bc_config *aconfig,
414 struct bc_volumeSet *avs,
415 struct bc_volumeDump **avols,
416 struct ubik_client *uclient)
417 { /*EvalVolumeSet1 */
418 afs_int32 code; /*Result of various calls */
419 struct bc_volumeDump *tvd; /*Ptr to new dump instance */
420 struct bc_volumeEntry *tve, *ctve; /*Ptr to new volume entry instance */
421 char patt[256]; /*Composite regex; also, target string */
422 int volType = 0; /*Type of volume that worked */
423 afs_int32 index; /*Current VLDB entry index */
424 afs_int32 count; /*Needed by VL_ListEntry() */
425 afs_int32 next_index; /*Next index to list */
426 struct vldbentry entry; /*VLDB entry */
427 int srvpartpair; /*Loop counter: server/partition pair */
431 struct serversort *servers = 0, *ss = 0;
432 struct partitionsort *ps = 0;
433 #ifdef HAVE_POSIX_REGEX
435 int need_regfree = 0;
440 *avols = (struct bc_volumeDump *)0;
441 ctve = (struct bc_volumeEntry *)0; /* no compiled entry */
443 /* For each vldb entry.
444 * Variable next_index is set to the index of the next VLDB entry
445 * in the enumeration.
447 for (index = 0; 1; index = next_index) { /*w */
448 memset(&entry, 0, sizeof(entry));
449 code = ubik_VL_ListEntry(uclient, /*Ubik client structure */
451 index, /*Current index */
452 &count, /*Ptr to working variable */
453 &next_index, /*Ptr to next index value to list */
454 &entry); /*Ptr to entry to fill */
458 break; /* If the next index is invalid, bail out now. */
460 /* For each entry in the volume set */
461 found = 0; /* No match in volume set yet */
462 for (tve = avs->ventries; tve; tve = tve->next) { /*ve */
463 /* for each server in the vldb entry */
464 for (srvpartpair = 0; srvpartpair < entry.nServers; srvpartpair++) { /*s */
465 /* On the same server */
466 if (tve->server.sin_addr.s_addr
467 && !VLDB_IsSameAddrs(tve->server.sin_addr.s_addr,
468 entry.serverNumber[srvpartpair],
476 /* On the same partition */
477 if ((tve->partition != -1)
478 && (tve->partition != entry.serverPartition[srvpartpair]))
481 /* If the volume entry is not compiled, then compile it */
483 sprintf(patt, "^%s$", tve->name);
484 #ifdef HAVE_POSIX_REGEX
485 if (regcomp(&re, patt, REG_NOSUB) != 0) {
486 afs_com_err(whoami, 0, "Can't compile regular expression '%s'", patt);
491 errm = (char *)re_comp(patt);
493 afs_com_err(whoami, 0,
494 "Can't compile regular expression '%s': %s",
502 /* If the RW name matches the volume set entry, take
503 * it and exit. First choice is to use the RW volume.
505 if (entry.serverFlags[srvpartpair] & VLSF_RWVOL) {
506 if (entry.flags & VLF_RWEXISTS) {
507 sprintf(patt, "%s", entry.name);
508 #ifdef HAVE_POSIX_REGEX
509 code = regexec(&re, patt, 0, NULL, 0);
512 code = re_exec(patt);
516 foundentry = srvpartpair;
522 /* If the BK name matches the volume set entry, take
523 * it and exit. Second choice is to use the BK volume.
525 if (entry.flags & VLF_BACKEXISTS) {
526 sprintf(patt, "%s.backup", entry.name);
527 #ifdef HAVE_POSIX_REGEX
528 code = regexec(&re, patt, 0, NULL, 0);
531 code = re_exec(patt);
535 foundentry = srvpartpair;
542 /* If the RO name matches the volume set entry, remember
543 * it, but continue searching. Further entries may be
544 * RW or backup entries that will match.
546 else if (!found && (entry.serverFlags[srvpartpair] & VLSF_ROVOL)
547 && (entry.flags & VLF_ROEXISTS)) {
548 sprintf(patt, "%s.readonly", entry.name);
549 #ifdef HAVE_POSIX_REGEX
550 code = regexec(&re, patt, 0, NULL, 0);
553 code = re_exec(patt);
557 foundentry = srvpartpair;
563 afs_com_err(whoami, 0, "Internal error in regex package");
566 /* If found a match, then create a new volume dump entry */
568 /* Find server and partition structure to hang the entry off of */
570 getSPEntries(entry.serverNumber[foundentry],
571 entry.serverPartition[foundentry], &servers,
574 afs_com_err(whoami, code, NULL);
579 tvd = calloc(1, sizeof(struct bc_volumeDump));
581 afs_com_err(whoami, BC_NOMEM, NULL);
585 tvd->name = malloc(strlen(entry.name) + 10);
587 afs_com_err(whoami, BC_NOMEM, NULL);
592 strcpy(tvd->name, entry.name);
593 if (volType == BACKVOL)
594 strcat(tvd->name, ".backup");
595 else if (volType == ROVOL)
596 strcat(tvd->name, ".readonly");
597 tvd->vid = entry.volumeId[volType];
599 tvd->volType = volType;
600 tvd->partition = entry.serverPartition[foundentry];
601 tvd->server.sin_addr.s_addr = entry.serverNumber[foundentry];
602 tvd->server.sin_port = 0; /* default FS port */
603 tvd->server.sin_family = AF_INET;
605 /* String tvd off of partition struct */
606 tvd->next = ps->vdlist;
609 ps->lastvdlist = tvd;
615 #ifdef HAVE_POSIX_REGEX
620 /* Randomly link the volumedump entries together */
621 randSPEntries(servers, avols);
623 fprintf(stderr, "Total number of volumes : %u\n", total);
625 } /*EvalVolumeSet1 */
628 compactTimeString(time_t *date, char *string, afs_int32 size)
635 if (*date == NEVERDATE) {
636 sprintf(string, "NEVER");
638 ltime = localtime(date);
639 strftime(string, size, "%m/%d/%Y %H:%M", ltime);
645 * print out a date in compact format, 16 chars, format is
648 * date_long - ptr to a long containing the time
650 * ptr to a string containing a representation of the date
653 compactDateString(afs_uint32 *date_long, char *string, afs_int32 size)
655 time_t t = *date_long;
656 return compactTimeString(&t, string, size);
661 bc_SafeATOI(char *anum)
665 for (; *anum; anum++) {
666 if ((*anum < '0') || (*anum > '9'))
668 total = (10 * total) + (afs_int32) (*anum - '0');
674 * Take a string and parse it for a number (could be float) followed
675 * by a character representing the units (K,M,G,T). Default is 'K'.
676 * Return the size in KBytes.
679 bc_FloatATOI(char *anum)
683 afs_int32 fraction = 0; /* > 0 if past the decimal */
685 for (; *anum; anum++) {
686 if ((*anum == 't') || (*anum == 'T')) {
687 total *= 1024 * 1024 * 1024;
690 if ((*anum == 'g') || (*anum == 'G')) {
691 total *= 1024 * 1024;
694 if ((*anum == 'm') || (*anum == 'M')) {
698 if ((*anum == 'k') || (*anum == 'K')) {
705 if ((*anum < '0') || (*anum > '9'))
709 total = (10. * total) + (float)(*anum - '0');
711 total += ((float)(*anum - '0')) / (float)fraction;
716 total += 0.5; /* Round up */
717 if (total > 0x7fffffff) /* Don't go over 2G */
719 rtotal = (afs_int32) total;
723 /* make a copy of a string so that it can be freed later */
725 bc_CopyString(char *astring)
730 return (NULL); /* propagate null strings easily */
731 tp = strdup(astring);
733 afs_com_err(whoami, BC_NOMEM, NULL);
741 * Concatenates the parameters of an option and returns the string.
746 concatParams(struct cmd_item *itemPtr)
748 struct cmd_item *tempPtr;
749 afs_int32 length = 0;
752 /* compute the length of string required */
753 for (tempPtr = itemPtr; tempPtr; tempPtr = tempPtr->next) {
754 length += strlen(tempPtr->data);
755 length++; /* space or null terminator */
758 if (length == 0) { /* no string (0 length) */
759 afs_com_err(whoami, 0, "Can't have zero length date and time string");
763 string = malloc(length); /* allocate the string */
765 afs_com_err(whoami, BC_NOMEM, NULL);
770 tempPtr = itemPtr; /* now assemble the string */
772 strcat(string, tempPtr->data);
773 tempPtr = tempPtr->next;
778 return (string); /* return the string */
782 * print out an interface status node as received from butc
786 printIfStatus(struct tciStatusS *statusPtr)
788 printf("Task %d: %s: ", statusPtr->taskId, statusPtr->taskName);
789 if (statusPtr->nKBytes)
790 printf("%ld Kbytes transferred", (long unsigned int) statusPtr->nKBytes);
791 if (strlen(statusPtr->volumeName) != 0) {
792 if (statusPtr->nKBytes)
794 printf("volume %s", statusPtr->volumeName);
799 if (statusPtr->flags & ABORT_REQUEST)
800 printf(" [abort request rcvd]");
802 if (statusPtr->flags & ABORT_DONE)
803 printf(" [abort complete]");
805 if (statusPtr->flags & OPR_WAIT)
806 printf(" [operator wait]");
808 if (statusPtr->flags & CALL_WAIT)
809 printf(" [callout in progress]");
811 if (statusPtr->flags & DRIVE_WAIT)
812 printf(" [drive wait]");
814 if (statusPtr->flags & TASK_DONE)
820 getPortOffset(char *port)
822 afs_int32 portOffset;
824 portOffset = bc_SafeATOI(port);
826 if (portOffset < 0) {
827 afs_com_err(whoami, 0, "Can't decode port offset '%s'", port);
829 } else if (portOffset > BC_MAXPORTOFFSET) {
830 afs_com_err(whoami, 0, "%u exceeds max port offset %u", portOffset,
837 /* bc_GetTapeStatusCmd
838 * display status of all tasks on a particular tape coordinator
841 bc_GetTapeStatusCmd(struct cmd_syndesc *as, void *arock)
844 struct rx_connection *tconn;
845 afs_int32 portOffset = 0;
850 struct tciStatusS status;
852 code = bc_UpdateHosts();
854 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
858 if (as->parms[0].items) {
859 portOffset = getPortOffset(as->parms[0].items->data);
864 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
868 flags = TSK_STAT_FIRST;
872 while ((flags & TSK_STAT_END) == 0) {
873 code = TC_ScanStatus(tconn, &taskId, &status, &flags);
875 if (code == TC_NOTASKS)
877 afs_com_err(whoami, code, "; Can't get status from butc");
880 if ((flags & TSK_STAT_NOTFOUND))
881 break; /* Can't find the task id */
882 flags &= ~TSK_STAT_FIRST; /* turn off flag */
884 printIfStatus(&status);
889 printf("Tape coordinator is idle\n");
891 if (flags & TSK_STAT_ADSM)
892 printf("TSM Tape coordinator\n");
893 else if (flags & TSK_STAT_XBSA)
894 printf("XBSA Tape coordinator\n");
899 extern struct Lock dispatchLock;
902 * wait for all jobs to terminate
905 bc_WaitForNoJobs(void)
908 int usefulJobRunning = 1;
909 int printWaiting = 1;
911 extern dlqlinkT statusHead;
913 while (usefulJobRunning) {
914 usefulJobRunning = (dlqEmpty(&statusHead) ? 0 : 1);
915 if (dispatchLock.excl_locked)
916 usefulJobRunning = 1;
917 for (i = 0; (!usefulJobRunning && (i < BC_MAXSIMDUMPS)); i++) {
918 if (bc_dumpTasks[i].flags & BC_DI_INUSE)
919 usefulJobRunning = 1;
922 /* Wait 5 seconds and check again */
923 if (usefulJobRunning) {
925 afs_com_err(whoami, 0, "waiting for job termination");
931 return (lastTaskCode);
935 * print status on running jobs
937 * ignored - a null "as" prints only jobs.
940 bc_JobsCmd(struct cmd_syndesc *as, void *arock)
949 extern dlqlinkT statusHead;
951 dlqInit(&atJobsHead);
954 ptr = (&statusHead)->dlq_next;
955 while (ptr != &statusHead) {
956 statusPtr = (statusP) ptr;
959 if (statusPtr->scheduledDump) {
960 dlqUnlink((dlqlinkP) statusPtr);
961 dlqLinkb(&atJobsHead, (dlqlinkP) statusPtr);
963 printf("Job %d:", statusPtr->jobNumber);
965 printf(" %s", statusPtr->taskName);
967 if (statusPtr->dbDumpId)
968 printf(": DumpID %u", statusPtr->dbDumpId);
969 if (statusPtr->nKBytes)
970 printf(", %ld Kbytes", afs_printable_int32_ld(statusPtr->nKBytes));
971 if (strlen(statusPtr->volumeName) != 0)
972 printf(", volume %s", statusPtr->volumeName);
974 if (statusPtr->flags & CONTACT_LOST)
975 printf(" [butc contact lost]");
977 if (statusPtr->flags & ABORT_REQUEST)
978 printf(" [abort request]");
980 if (statusPtr->flags & ABORT_SENT)
981 printf(" [abort sent]");
983 if (statusPtr->flags & OPR_WAIT)
984 printf(" [operator wait]");
986 if (statusPtr->flags & CALL_WAIT)
987 printf(" [callout in progress]");
989 if (statusPtr->flags & DRIVE_WAIT)
990 printf(" [drive wait]");
996 * Now print the scheduled dumps.
998 if (!dlqEmpty(&statusHead) && as)
999 printf("\n"); /* blank line between running and scheduled dumps */
1002 while (!dlqEmpty(&atJobsHead)) {
1003 ptr = (&atJobsHead)->dlq_next;
1004 youngest = (statusP) ptr;
1006 ptr = ptr->dlq_next;
1007 while (ptr != &atJobsHead) { /* Find the dump that starts the earliest */
1008 statusPtr = (statusP) ptr;
1009 if (statusPtr->scheduledDump < youngest->scheduledDump)
1010 youngest = statusPtr;
1011 ptr = ptr->dlq_next;
1014 /* Print token expiration time */
1015 if ((tokenExpires > prevTime)
1016 && (tokenExpires <= youngest->scheduledDump) && as
1017 && (tokenExpires != NEVERDATE)) {
1018 if (tokenExpires > time(0)) {
1019 compactTimeString(&tokenExpires, ds, 50);
1020 printf(" %16s: TOKEN EXPIRATION\n", ds);
1022 printf(" TOKEN HAS EXPIRED\n");
1025 prevTime = youngest->scheduledDump;
1027 /* Print the info */
1028 compactDateString(&youngest->scheduledDump, ds, 50);
1029 printf("Job %d:", youngest->jobNumber);
1030 printf(" %16s: %s", ds, youngest->cmdLine);
1033 /* return to original list */
1034 dlqUnlink((dlqlinkP) youngest);
1035 dlqLinkb(&statusHead, (dlqlinkP) youngest);
1038 /* Print token expiration time if havn't already */
1039 if ((tokenExpires == NEVERDATE) && as)
1040 printf(" : TOKEN NEVER EXPIRES\n");
1041 else if ((tokenExpires > prevTime) && as) {
1042 if (tokenExpires > time(0)) {
1043 compactTimeString(&tokenExpires, ds, 50);
1044 printf(" %16s: TOKEN EXPIRATION\n", ds);
1046 printf(" : TOKEN HAS EXPIRED\n");
1055 bc_KillCmd(struct cmd_syndesc *as, void *arock)
1059 struct bc_dumpTask *td;
1066 extern dlqlinkT statusHead;
1068 tp = as->parms[0].items->data;
1069 if (strchr(tp, '.') == 0) {
1070 slot = bc_SafeATOI(tp);
1072 afs_com_err(whoami, 0, "Bad syntax for number '%s'", tp);
1077 ptr = (&statusHead)->dlq_next;
1078 while (ptr != &statusHead) {
1079 statusPtr = (statusP) ptr;
1080 if (statusPtr->jobNumber == slot) {
1081 statusPtr->flags |= ABORT_REQUEST;
1085 ptr = ptr->dlq_next;
1089 fprintf(stderr, "Job %d not found\n", slot);
1094 for (i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1095 if (td->flags & BC_DI_INUSE) {
1097 strcpy(tbuffer, td->volSetName);
1098 strcat(tbuffer, ".");
1099 strcat(tbuffer, tailCompPtr(td->dumpName));
1100 if (strcmp(tbuffer, tp) == 0)
1104 if (i >= BC_MAXSIMDUMPS) {
1105 afs_com_err(whoami, 0, "Can't find job %s", tp);
1110 statusPtr = findStatus(td->dumpID);
1112 if (statusPtr == 0) {
1113 afs_com_err(whoami, 0, "Can't locate status - internal error");
1117 statusPtr->flags |= ABORT_REQUEST;
1123 /* restore a volume or volumes */
1125 bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
1128 * parm 0 is the new server to restore to
1129 * parm 1 is the new partition to restore to
1130 * parm 2 is volume(s) to restore
1131 * parm 3 is the new extension, if any, for the volume name.
1132 * parm 4 gives the new volume # to restore this volume as (removed).
1133 * parm 4 date is a string representing the date
1135 * We handle four types of restores. If old is set, then we restore the
1136 * volume with the same name and ID. If old is not set, we allocate
1137 * a new volume ID for the restored volume. If a new extension is specified,
1138 * we add that extension to the volume name of the restored volume.
1140 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1141 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1142 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1143 struct bc_volumeDump *tvol; /* temp for same */
1144 struct sockaddr_in destServ; /* machine to which to restore volumes */
1145 afs_int32 destPartition; /* partition to which to restore volumes */
1147 struct cmd_item *ti;
1151 afs_int32 dumpID = 0;
1152 char *newExt, *timeString;
1154 afs_int32 *ports = NULL;
1155 afs_int32 portCount = 0;
1158 code = bc_UpdateHosts();
1160 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1164 /* specified other destination host */
1165 tp = as->parms[0].items->data;
1166 if (bc_ParseHost(tp, &destServ)) {
1167 afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
1171 /* specified other destination partition */
1172 tp = as->parms[1].items->data;
1173 if (bc_GetPartitionID(tp, &destPartition)) {
1174 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1178 for (ti = as->parms[2].items; ti; ti = ti->next) {
1179 /* build list of volume items */
1180 tvol = calloc(1, sizeof(struct bc_volumeDump));
1182 afs_com_err(whoami, BC_NOMEM, NULL);
1186 tvol->name = malloc(VOLSER_MAXVOLNAME + 1);
1188 afs_com_err(whoami, BC_NOMEM, NULL);
1191 strncpy(tvol->name, ti->data, VOLSER_OLDMAXVOLNAME);
1192 tvol->entry = &tvolumeEntry;
1195 lastVol->next = tvol; /* thread onto end of list */
1197 volsToRestore = tvol;
1201 if (as->parms[4].items) {
1202 timeString = concatParams(as->parms[4].items);
1206 code = ktime_DateToLong(timeString, &fromDate);
1209 afs_com_err(whoami, 0, "Can't parse restore date and time");
1210 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1214 fromDate = 0x7fffffff; /* latest one */
1217 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1220 /* Read all the port offsets into the ports array. The first element in the
1221 * array is for full restore and the rest are for incremental restores
1223 if (as->parms[5].items) {
1224 for (ti = as->parms[5].items; ti; ti = ti->next)
1226 ports = malloc(portCount * sizeof(afs_int32));
1228 afs_com_err(whoami, BC_NOMEM, NULL);
1232 for (ti = as->parms[5].items, i = 0; ti; ti = ti->next, i++) {
1233 ports[i] = getPortOffset(ti->data);
1239 dontExecute = (as->parms[6].items ? 1 : 0); /* -n */
1241 if (as->parms[7].items)
1243 dumpID = atoi(as->parms[7].items->data);
1249 * Perform the call to start the restore.
1252 bc_StartDmpRst(bc_globalConfig, "volume", "restore", volsToRestore,
1253 &destServ, destPartition, fromDate, newExt, oldFlag,
1254 /*parentDump */ dumpID, /*dumpLevel */ 0,
1255 bc_Restorer, ports, portCount,
1256 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1258 afs_com_err(whoami, code, "; Failed to queue restore");
1263 /* restore a whole partition or server */
1265 /* bc_DiskRestoreCmd
1266 * restore a whole partition
1268 * first, reqd - machine (server) to restore
1269 * second, reqd - partition to restore
1274 bc_DiskRestoreCmd(struct cmd_syndesc *as, void *arock)
1276 struct bc_volumeSet tvolumeSet; /* temporary volume set for EvalVolumeSet call */
1277 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1278 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1279 struct sockaddr_in destServ; /* machine to which to restore volumes */
1280 afs_int32 destPartition; /* partition to which to restore volumes */
1286 afs_int32 *ports = NULL;
1287 afs_int32 portCount = 0;
1289 struct bc_volumeDump *prev, *tvol, *nextvol;
1290 struct cmd_item *ti;
1293 /* parm 0 is the server to restore
1294 * parm 1 is the partition to restore
1296 * parm 8 and above as in VolRestoreCmd:
1297 * parm 8 is the new server to restore to
1298 * parm 9 is the new partition to restore to
1301 code = bc_UpdateVolumeSet();
1303 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1306 code = bc_UpdateHosts();
1308 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1312 /* create a volume set corresponding to the volume pattern we've been given */
1313 memset(&tvolumeSet, 0, sizeof(tvolumeSet));
1314 memset(&tvolumeEntry, 0, sizeof(tvolumeEntry));
1315 tvolumeSet.name = "TempVolumeSet";
1316 tvolumeSet.ventries = &tvolumeEntry;
1317 tvolumeEntry.serverName = as->parms[0].items->data;
1318 tvolumeEntry.partname = as->parms[1].items->data;
1320 if (bc_GetPartitionID(tvolumeEntry.partname, &tvolumeEntry.partition)) {
1321 afs_com_err(whoami, 0, "Can't parse partition '%s'",
1322 tvolumeEntry.partname);
1326 if (bc_ParseHost(tvolumeEntry.serverName, &tvolumeEntry.server)) {
1327 afs_com_err(whoami, 0, "Can't locate host '%s'", tvolumeEntry.serverName);
1331 /* specified other destination host */
1332 if (as->parms[8].items) {
1333 tp = as->parms[8].items->data;
1334 if (bc_ParseHost(tp, &destServ)) {
1335 afs_com_err(whoami, 0, "Can't locate destination host '%s'", tp);
1338 } else /* use destination host == original host */
1339 memcpy(&destServ, &tvolumeEntry.server, sizeof(destServ));
1341 /* specified other destination partition */
1342 if (as->parms[9].items) {
1343 tp = as->parms[9].items->data;
1344 if (bc_GetPartitionID(tp, &destPartition)) {
1345 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1348 } else /* use original partition */
1349 destPartition = tvolumeEntry.partition;
1351 tvolumeEntry.name = ".*"; /* match all volumes (this should be a parameter) */
1353 if (as->parms[2].items) {
1354 for (ti = as->parms[2].items; ti; ti = ti->next)
1356 ports = malloc(portCount * sizeof(afs_int32));
1358 afs_com_err(whoami, BC_NOMEM, NULL);
1362 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1363 ports[i] = getPortOffset(ti->data);
1369 newExt = (as->parms[10].items ? as->parms[10].items->data : NULL);
1370 dontExecute = (as->parms[11].items ? 1 : 0); /* -n */
1373 * Expand out the volume set into its component list of volumes, by calling VLDB server.
1376 bc_EvalVolumeSet(bc_globalConfig, &tvolumeSet, &volsToRestore,
1379 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1383 /* Since we want only RW volumes, remove any
1384 * BK or RO volumes from the list.
1386 for (prev = 0, tvol = volsToRestore; tvol; tvol = nextvol) {
1387 nextvol = tvol->next;
1388 if (BackupName(tvol->name)) {
1391 "Will not restore volume %s (its RW does not reside on the partition)\n",
1394 if (tvol == volsToRestore) {
1395 volsToRestore = nextvol;
1397 prev->next = nextvol;
1407 fromDate = 0x7fffffff; /* last one before this date */
1408 oldFlag = 1; /* do restore same volid (and name) */
1411 * Perform the call to start the dump.
1414 bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1415 &destServ, destPartition, fromDate, newExt, oldFlag,
1416 /*parentDump */ 0, /*dumpLevel */ 0,
1417 bc_Restorer, ports, portCount,
1418 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1420 afs_com_err(whoami, code, "; Failed to queue restore");
1425 /* bc_VolsetRestoreCmd
1426 * restore a volumeset or list of volumes.
1430 bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
1437 afs_int32 *ports = NULL;
1438 afs_int32 portCount = 0;
1441 struct bc_volumeSet *volsetPtr; /* Ptr to list of generated volume info */
1442 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1443 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1444 struct sockaddr_in destServer; /* machine to which to restore volume */
1445 afs_int32 destPartition; /* partition to which to restore volumes */
1446 struct cmd_item *ti;
1449 code = bc_UpdateVolumeSet();
1451 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1454 code = bc_UpdateHosts();
1456 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1460 if (as->parms[0].items) {
1461 if (as->parms[1].items) {
1462 afs_com_err(whoami, 0, "Can't have both -name and -file options");
1466 volsetName = as->parms[0].items->data;
1467 volsetPtr = bc_FindVolumeSet(bc_globalConfig, volsetName);
1469 afs_com_err(whoami, 0,
1470 "Can't find volume set '%s' in backup database",
1475 /* Expand out the volume set into its component list of volumes. */
1477 bc_EvalVolumeSet(bc_globalConfig, volsetPtr, &volsToRestore,
1480 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1483 } else if (as->parms[1].items) {
1486 char server[50], partition[50], volume[50], rest[256];
1488 struct bc_volumeDump *tvol;
1490 fd = fopen(as->parms[1].items->data, "r");
1492 afs_com_err(whoami, errno, "; Cannot open file '%s'",
1493 as->parms[1].items->data);
1497 while (fgets(line, 255, fd)) {
1499 sscanf(line, "%s %s %s %s", server, partition, volume, rest);
1505 "Invalid volumeset file format: Wrong number of arguments: Ignoring\n");
1506 fprintf(stderr, " %s", line);
1510 if (bc_ParseHost(server, &destServer)) {
1511 afs_com_err(whoami, 0, "Failed to locate host '%s'", server);
1515 if (bc_GetPartitionID(partition, &destPartition)) {
1516 afs_com_err(whoami, 0,
1517 "Failed to parse destination partition '%s'",
1522 /* Allocate a volumeDump structure and link it in */
1523 tvol = calloc(1, sizeof(struct bc_volumeDump));
1525 tvol->name = malloc(VOLSER_MAXVOLNAME + 1);
1527 afs_com_err(whoami, BC_NOMEM, NULL);
1530 strncpy(tvol->name, volume, VOLSER_OLDMAXVOLNAME);
1531 memcpy(&tvol->server, &destServer, sizeof(destServer));
1532 tvol->partition = destPartition;
1535 lastVol->next = tvol; /* thread onto end of list */
1537 volsToRestore = tvol;
1542 afs_com_err(whoami, 0, "-name or -file option required");
1547 /* Get the port offset for the restore */
1548 if (as->parms[2].items) {
1549 for (ti = as->parms[2].items; ti; ti = ti->next)
1551 ports = malloc(portCount * sizeof(afs_int32));
1553 afs_com_err(whoami, BC_NOMEM, NULL);
1557 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1558 ports[i] = getPortOffset(ti->data);
1564 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1565 dontExecute = (as->parms[4].items ? 1 : 0);
1567 fromDate = 0x7fffffff; /* last one before this date */
1568 oldFlag = 1; /* do restore same volid (and name) */
1570 /* Perform the call to start the restore */
1571 code = bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1572 /*destserver */ NULL, /*destpartition */ 0, fromDate,
1574 /*parentDump */ 0, /*dumpLevel */ 0,
1575 bc_Restorer, ports, portCount,
1576 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1578 afs_com_err(whoami, code, "; Failed to queue restore");
1583 /*-----------------------------------------------------------------------------
1587 * Perform a dump of the set of volumes provided.
1588 * user specifies: -volumeset .. -dump .. [-portoffset ..] [-n]
1591 * as : Parsed command line information.
1592 * arock : Ptr to misc stuff; not used.
1596 * The result of bc_StartDump() otherwise
1603 *---------------------------------------------------------------------------
1608 bc_DumpCmd(struct cmd_syndesc *as, void *arock)
1610 char *dumpPath = NULL;
1611 char *vsName = NULL; /*Ptrs to various names */
1612 struct bc_volumeSet *tvs = NULL; /*Ptr to list of generated volume info */
1613 struct bc_dumpSchedule *tds;
1614 struct bc_dumpSchedule *baseds = NULL; /*Ptr to dump schedule node */
1615 struct bc_volumeDump *tve, *volsToDump; /*Ptr to individual vols to be dumped */
1616 struct budb_dumpEntry dumpEntry, de, fde; /* dump entry */
1619 afs_int32 parent; /* parent dump */
1620 afs_int32 level; /* this dump's level # */
1621 afs_int32 problemFindingDump; /* can't find parent(s) */
1623 afs_int32 *portp = NULL;
1624 afs_int32 doAt, atTime; /* Time a timed-dump is to start at */
1627 int doAppend = 0; /* Append the dump to dump set */
1628 afs_int32 code; /* Return code */
1629 int loadfile; /* whether to load a file or not */
1633 extern struct bc_dumpTask bc_dumpTasks[];
1635 code = bc_UpdateDumpSchedule();
1637 afs_com_err(whoami, code, "; Can't retrieve dump schedule");
1640 code = bc_UpdateVolumeSet();
1642 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1645 code = bc_UpdateHosts();
1647 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1652 * Some parameters cannot be specified together
1653 * The "-file" option cannot exist with the "-volume", "-dump",
1654 * "-portoffset", or "-append" option
1656 if (as->parms[6].items) {
1658 if (as->parms[0].items || as->parms[1].items || as->parms[2].items
1659 || as->parms[4].items) {
1660 afs_com_err(whoami, 0, "Invalid option specified with -file option");
1665 if (!as->parms[0].items || !as->parms[1].items) {
1666 afs_com_err(whoami, 0,
1667 "Must specify volume set name and dump level name");
1673 * Get the time we are to perform this dump
1675 if (as->parms[3].items) {
1678 timeString = concatParams(as->parms[3].items);
1683 * Now parse this string for the time to start.
1685 code = ktime_DateToLong(timeString, &atTime);
1688 afs_com_err(whoami, 0, "Can't parse dump start date and time");
1689 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1695 dontExecute = (as->parms[5].items ? 1 : 0); /* -n */
1698 * If this dump is not a load file, then check the parameters.
1700 if (!loadfile) { /*6 */
1701 vsName = as->parms[0].items->data; /* get volume set name */
1702 dumpPath = as->parms[1].items->data; /* get dump path */
1704 /* get the port number, if one was specified */
1705 if (as->parms[2].items) {
1706 portp = malloc(sizeof(afs_int32));
1708 afs_com_err(whoami, BC_NOMEM, NULL);
1712 *portp = getPortOffset(as->parms[2].items->data);
1717 doAppend = (as->parms[4].items ? 1 : 0); /* -append */
1720 * Get a hold of the given volume set and dump set.
1722 tvs = bc_FindVolumeSet(bc_globalConfig, vsName);
1724 afs_com_err(whoami, 0,
1725 "Can't find volume set '%s' in backup database", vsName);
1728 baseds = bc_FindDumpSchedule(bc_globalConfig, dumpPath);
1730 afs_com_err(whoami, 0,
1731 "Can't find dump schedule '%s' in backup database",
1740 * If given the "-at" option, then add this to the jobs list and return
1743 * Create a status node for this timed dump.
1744 * Fill in the time to dump and the cmd line for the dump leaving off
1745 * the -at option. If the -n option is there, it is scheduled with
1746 * the Timed dump as opposed to not scheduling the time dump at all.
1749 if (atTime < time(0)) {
1750 afs_com_err(whoami, 0,
1751 "Time of dump is earlier then current time - not added");
1753 statusPtr = createStatusNode();
1755 statusPtr->scheduledDump = atTime;
1757 /* Determine length of the dump command */
1759 length += 4; /* "dump" */
1761 length += 6; /* " -file" */
1762 length += 1 + strlen(as->parms[6].items->data); /* " <file>" */
1764 /* length += 11; *//* " -volumeset" */
1765 length += 1 + strlen(as->parms[0].items->data); /* " <volset> */
1767 /* length += 6; *//* " -dump" */
1768 length += 1 + strlen(as->parms[1].items->data); /* " <dumpset> */
1770 if (as->parms[2].items) {
1771 /* length += 12; *//* " -portoffset" */
1772 length += 1 + strlen(as->parms[2].items->data); /* " <port>" */
1775 if (as->parms[4].items)
1776 length += 8; /* " -append" */
1780 length += 3; /* " -n" */
1781 length++; /* end-of-line */
1783 /* Allocate status block for this timed dump */
1784 sprintf(statusPtr->taskName, "Scheduled Dump");
1785 statusPtr->jobNumber = bc_jobNumber();
1786 statusPtr->scheduledDump = atTime;
1787 statusPtr->cmdLine = malloc(length);
1788 if (!statusPtr->cmdLine) {
1789 afs_com_err(whoami, BC_NOMEM, NULL);
1793 /* Now reconstruct the dump command */
1794 statusPtr->cmdLine[0] = 0;
1795 strcat(statusPtr->cmdLine, "dump");
1797 strcat(statusPtr->cmdLine, " -file");
1798 strcat(statusPtr->cmdLine, " ");
1799 strcat(statusPtr->cmdLine, as->parms[6].items->data);
1801 /* strcat(statusPtr->cmdLine, " -volumeset"); */
1802 strcat(statusPtr->cmdLine, " ");
1803 strcat(statusPtr->cmdLine, as->parms[0].items->data);
1805 /* strcat(statusPtr->cmdLine, " -dump"); */
1806 strcat(statusPtr->cmdLine, " ");
1807 strcat(statusPtr->cmdLine, as->parms[1].items->data);
1809 if (as->parms[2].items) {
1810 /* strcat(statusPtr->cmdLine, " -portoffset"); */
1811 strcat(statusPtr->cmdLine, " ");
1812 strcat(statusPtr->cmdLine, as->parms[2].items->data);
1815 if (as->parms[4].items)
1816 strcat(statusPtr->cmdLine, " -append");
1819 strcat(statusPtr->cmdLine, " -n");
1821 printf("Add scheduled dump as job %d\n", statusPtr->jobNumber);
1822 if ((atTime > tokenExpires) && (tokenExpires != NEVERDATE))
1823 afs_com_err(whoami, 0,
1824 "Warning: job %d starts after expiration of AFS token",
1825 statusPtr->jobNumber);
1834 * Read and execute the load file if specified. The work of reading is done
1835 * in the main routine prior the dispatch call. loadFile and dontExecute are
1836 * global variables so this can take place in main.
1839 loadFile = strdup(as->parms[6].items->data);
1841 afs_com_err(whoami, BC_NOMEM, NULL);
1848 * We are doing a real dump (no load file or timed dump).
1850 printf("Starting dump of volume set '%s' (dump level '%s')\n", vsName,
1853 /* For each dump-level above this one, see if the volumeset was dumped
1854 * at the level. We search all dump-levels since a higher dump-level
1855 * may have actually been done AFTER a lower dump level.
1857 parent = level = problemFindingDump = 0;
1858 for (tds = baseds->parent; tds; tds = tds->parent) {
1859 /* Find the most recent dump of the volume-set at this dump-level.
1860 * Raise problem flag if didn't find a dump and a parent not yet found.
1862 code = bcdb_FindLatestDump(vsName, tds->name, &dumpEntry);
1865 problemFindingDump = 1; /* skipping a dump level */
1869 /* We found the most recent dump at this level. Now check
1870 * if we should use it by seeing if its full dump hierarchy
1871 * exists. If it doesn't, we don't want to base our incremental
1874 if (!parent || (dumpEntry.id > parent)) {
1875 /* Follow the parent dumps to see if they are all there */
1876 for (d = dumpEntry.parent; d; d = de.parent) {
1877 code = bcdb_FindDumpByID(d, &de);
1882 /* If we found the entire level, remember it. Otherwise raise flag.
1883 * If we had already found a dump, raise the problem flag.
1887 problemFindingDump = 1;
1888 parent = dumpEntry.id;
1889 level = dumpEntry.level + 1;
1890 memcpy(&fde, &dumpEntry, sizeof(dumpEntry));
1892 /* Dump hierarchy not complete so can't base off the latest */
1893 problemFindingDump = 1;
1898 /* If the problemflag was raise, it means we are not doing the
1899 * dump at the level we requested it be done at.
1901 if (problemFindingDump) {
1902 afs_com_err(whoami, 0,
1903 "Warning: Doing level %d dump due to missing higher-level dumps",
1906 printf("Parent dump: dump %s (DumpID %u)\n", fde.name, parent);
1908 } else if (parent) {
1909 printf("Found parent: dump %s (DumpID %u)\n", fde.name, parent);
1912 /* Expand out the volume set into its component list of volumes. */
1913 code = bc_EvalVolumeSet(bc_globalConfig, tvs, &volsToDump, cstruct);
1915 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1919 printf("No volumes to dump\n");
1923 /* Determine what the clone time of the volume was when it was
1924 * last dumped (tve->date). This is the time from when an
1925 * incremental should be done (remains zero if a full dump).
1928 for (tve = volsToDump; tve; tve = tve->next) {
1929 code = bcdb_FindClone(parent, tve->name, &tve->date);
1933 /* Get the time the volume was last cloned and see if the volume has
1934 * changed since then. Only do this when the "-n" flag is specified
1935 * because butc will get the cloneDate at time of dump.
1939 volImageTime(tve->server.sin_addr.s_addr, tve->partition,
1940 tve->vid, tve->volType, &tve->cloneDate);
1944 if (tve->cloneDate && (tve->cloneDate == tve->date)) {
1945 afs_com_err(whoami, 0,
1946 "Warning: Timestamp on volume %s unchanged from previous dump",
1954 printf("Would have dumped the following volumes:\n");
1956 printf("Preparing to dump the following volumes:\n");
1957 for (tve = volsToDump; tve; tve = tve->next) {
1958 printf("\t%s (%u)\n", tve->name, tve->vid);
1963 code = bc_StartDmpRst(bc_globalConfig, dumpPath, vsName, volsToDump,
1964 /*destServer */ NULL, /*destPartition */ 0,
1966 /*newExt */ NULL, /*oldFlag */ 0,
1967 parent, level, bc_Dumper, portp, /*portCount */ 1,
1968 baseds, doAppend, dontExecute);
1970 afs_com_err(whoami, code, "; Failed to queue dump");
1977 * terminate the backup process. Insists that that all running backup
1978 * jobs be terminated before it will quit
1983 bc_QuitCmd(struct cmd_syndesc *as, void *arock)
1986 struct bc_dumpTask *td;
1987 extern dlqlinkT statusHead;
1991 /* Check the status list for outstanding jobs */
1993 for (ptr = (&statusHead)->dlq_next; ptr != &statusHead;
1994 ptr = ptr->dlq_next) {
1995 statusPtr = (statusP) ptr;
1996 if (!(statusPtr->flags & ABORT_REQUEST)) {
1998 afs_com_err(whoami, 0, "Job %d still running (and not aborted)",
1999 statusPtr->jobNumber);
2000 afs_com_err(whoami, 0,
2001 "You must at least 'kill' all running jobs before quitting");
2007 /* A job still being initialized (but no status structure or job number since it
2008 * has not been handed to a butc process yet)
2010 for (td = bc_dumpTasks, i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
2011 if (td->flags & BC_DI_INUSE) {
2012 afs_com_err(whoami, 0, "A job is still running");
2013 afs_com_err(whoami, 0,
2014 "You must at least 'kill' all running jobs before quitting");
2020 /* close the all temp text files before quitting */
2021 for (i = 0; i < TB_NUM; i++)
2022 bc_closeTextFile(&bc_globalConfig->configText[i],
2023 &bc_globalConfig->tmpTextFileNames[i][0]);
2029 * Labels a tape i.e. request the tape coordinator to perform this
2033 bc_LabelTapeCmd(struct cmd_syndesc *as, void *arock)
2035 char *tapename = 0, *pname = 0;
2040 code = bc_UpdateHosts();
2042 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2046 if (as->parms[0].items) { /* -name */
2047 tapename = as->parms[0].items->data;
2048 if (strlen(tapename) >= TC_MAXTAPELEN) {
2049 afs_com_err(whoami, 0, "AFS tape name '%s' is too long", tapename);
2054 if (as->parms[3].items) { /* -pname */
2056 afs_com_err(whoami, 0, "Can only specify -name or -pname");
2059 pname = as->parms[3].items->data;
2060 if (strlen(pname) >= TC_MAXTAPELEN) {
2061 afs_com_err(whoami, 0, "Permanent tape name '%s' is too long", pname);
2066 if (as->parms[1].items) {
2067 size = bc_FloatATOI(as->parms[1].items->data);
2069 afs_com_err(whoami, 0, "Bad syntax for tape size '%s'",
2070 as->parms[1].items->data);
2076 if (as->parms[2].items) {
2077 port = getPortOffset(as->parms[2].items->data);
2082 code = bc_LabelTape(tapename, pname, size, bc_globalConfig, port);
2089 * read the label on a tape
2091 * optional port number
2094 bc_ReadLabelCmd(struct cmd_syndesc *as, void *arock)
2099 code = bc_UpdateHosts();
2101 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2105 if (as->parms[0].items) {
2106 port = getPortOffset(as->parms[0].items->data);
2111 code = bc_ReadLabel(bc_globalConfig, port);
2118 * read content information from dump tapes, and if user desires,
2119 * add it to the database
2122 bc_ScanDumpsCmd(struct cmd_syndesc *as, void *arock)
2125 afs_int32 dbAddFlag = 0;
2128 code = bc_UpdateHosts();
2130 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2134 /* check for flag */
2135 if (as->parms[0].items != 0) { /* add scan to database */
2139 /* check for port */
2140 if (as->parms[1].items) {
2141 port = getPortOffset(as->parms[1].items->data);
2146 code = bc_ScanDumps(bc_globalConfig, dbAddFlag, port);
2150 /* bc_ParseExpiration
2153 * dates are specified as absolute or relative, the syntax is:
2154 * absolute: at %d/%d/%d [%d:%d] where [..] is optional
2155 * relative: in [%dy][%dm][%dd] where at least one component
2160 bc_ParseExpiration(struct cmd_parmdesc *paramPtr, afs_int32 *expType,
2163 struct cmd_item *itemPtr;
2164 struct ktime_date kt;
2165 char *dateString = 0;
2168 *expType = BC_NO_EXPDATE;
2171 if (!paramPtr->items)
2172 ERROR(0); /* no expiration specified */
2174 /* some form of expiration date specified. First validate the prefix */
2175 itemPtr = paramPtr->items;
2177 if (strcmp(itemPtr->data, "at") == 0) {
2178 *expType = BC_ABS_EXPDATE;
2180 dateString = concatParams(itemPtr->next);
2184 code = ktime_DateToLong(dateString, expDate);
2187 } else if (strcmp(itemPtr->data, "in") == 0) {
2188 *expType = BC_REL_EXPDATE;
2190 dateString = concatParams(itemPtr->next);
2194 code = ParseRelDate(dateString, &kt);
2197 *expDate = ktimeRelDate_ToLong(&kt);
2199 dateString = concatParams(itemPtr);
2203 if (ktime_DateToLong(dateString, expDate) == 0) {
2204 *expType = BC_ABS_EXPDATE;
2205 code = ktime_DateToLong(dateString, expDate);
2208 } else if (ParseRelDate(dateString, &kt) == 0) {
2209 *expType = BC_REL_EXPDATE;
2210 *expDate = ktimeRelDate_ToLong(&kt);
2222 /* database lookup command and routines */
2225 * Currently a single option, volumename to search for. Reports
2226 * all dumps containing the specified volume
2229 bc_dblookupCmd(struct cmd_syndesc *as, void *arock)
2231 struct cmd_item *ciptr;
2234 ciptr = as->parms[0].items;
2235 if (ciptr == 0) /* no argument specified */
2238 code = DBLookupByVolume(ciptr->data);
2244 /* for ubik version */
2246 bc_dbVerifyCmd(struct cmd_syndesc *as, void *arock)
2252 struct hostent *hostPtr;
2256 extern struct udbHandleS udbHandle;
2258 detail = (as->parms[0].items ? 1 : 0); /* print more details */
2261 ubik_BUDB_DbVerify(udbHandle.uh_client, 0, &status, &orphans,
2265 afs_com_err(whoami, code, "; Unable to verify database");
2269 /* verification call succeeded */
2272 printf("Database OK\n");
2274 afs_com_err(whoami, status, "; Database is NOT_OK");
2277 printf("Orphan blocks %d\n", orphans);
2280 printf("Unable to lookup host id\n");
2282 hostPtr = gethostbyaddr((char *)&host, sizeof(host), AF_INET);
2284 printf("Database checker was %d.%d.%d.%d\n",
2285 ((host & 0xFF000000) >> 24), ((host & 0xFF0000) >> 16),
2286 ((host & 0xFF00) >> 8), (host & 0xFF));
2288 printf("Database checker was %s\n", hostPtr->h_name);
2291 return ((status ? -1 : 0));
2295 * Delete a dump. If port is >= 0, it means try to delete from XBSA server
2298 deleteDump(afs_uint32 dumpid, /* The dumpid to delete */
2299 afs_int32 port, /* port==-1 means don't go to butc */
2302 afs_int32 code = 0, tcode;
2303 struct budb_dumpEntry dumpEntry;
2304 struct rx_connection *tconn = 0;
2305 afs_int32 i, taskflag, xbsadump;
2306 statusP statusPtr = 0;
2307 budb_dumpsList dumps;
2310 /* If the port is set, we will try to send a delete request to the butc */
2312 tcode = bc_UpdateHosts();
2314 afs_com_err(whoami, tcode, "; Can't retrieve tape hosts");
2318 /* Find the dump in the backup database */
2319 tcode = bcdb_FindDumpByID(dumpid, &dumpEntry);
2321 afs_com_err(whoami, tcode, "; Unable to locate dumpID %u in database",
2325 xbsadump = (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA));
2327 /* If dump is to an XBSA server, connect to butc and send it
2328 * the dump to delete. Butc will contact the XBSA server.
2329 * The dump will not be an appended dump because XBSA butc
2330 * does not support the append option.
2332 if (xbsadump && dumpEntry.nVolumes) {
2333 tcode = ConnectButc(bc_globalConfig, port, &tconn);
2337 tcode = TC_DeleteDump(tconn, dumpid, &taskId);
2339 if (tcode == RXGEN_OPCODE)
2340 tcode = BC_VERSIONFAIL;
2341 afs_com_err(whoami, tcode,
2342 "; Unable to delete dumpID %u via butc", dumpid);
2346 statusPtr = createStatusNode();
2348 statusPtr->taskId = taskId;
2349 statusPtr->port = port;
2350 statusPtr->jobNumber = bc_jobNumber();
2351 statusPtr->flags |= (SILENT | NOREMOVE); /* No msg & keep statusPtr */
2352 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2353 sprintf(statusPtr->taskName, "DeleteDump");
2356 /* Wait for task to finish */
2357 taskflag = waitForTask(taskId);
2358 if (taskflag & (TASK_ERROR | ABORT_DONE)) {
2359 afs_com_err(whoami, BUTX_DELETEOBJFAIL,
2360 "; Unable to delete dumpID %u via butc", dumpid);
2361 ERROR(BUTX_DELETEOBJFAIL); /* the task failed */
2368 deleteStatusNode(statusPtr); /* Clean up statusPtr - because NOREMOVE */
2370 rx_DestroyConnection(tconn); /* Destroy the connection */
2372 /* Remove the dump from the backup database */
2373 if (!code || force) {
2374 dumps.budb_dumpsList_len = 0;
2375 dumps.budb_dumpsList_val = 0;
2377 tcode = bcdb_deleteDump(dumpid, 0, 0, &dumps);
2379 afs_com_err(whoami, tcode,
2380 "; Unable to delete dumpID %u from database", dumpid);
2381 dumps.budb_dumpsList_len = 0;
2386 /* Display the dumps that were deleted - includes appended dumps */
2387 for (i = 0; i < dumps.budb_dumpsList_len; i++)
2388 printf(" %u%s\n", dumps.budb_dumpsList_val[i],
2389 (i > 0) ? " Appended Dump" : NULL);
2390 if (dumps.budb_dumpsList_val)
2391 free(dumps.budb_dumpsList_val);
2398 * Delete a specified dump from the database
2400 * dump id - single required arg as param 0.
2403 bc_deleteDumpCmd(struct cmd_syndesc *as, void *arock)
2407 afs_int32 rcode = 0;
2408 afs_int32 groupId = 0, havegroupid, sflags, noexecute;
2409 struct cmd_item *ti;
2410 afs_int32 fromTime = 0, toTime = 0, havetime = 0;
2412 budb_dumpsList dumps, flags;
2414 afs_int32 port = -1, force;
2416 /* Must specify at least one of -dumpid, -from, or -to */
2417 if (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items
2418 && !as->parms[4].items) {
2419 afs_com_err(whoami, 0, "Must specify at least one field");
2423 /* Must have -to option with -from option */
2424 if (as->parms[1].items && !as->parms[2].items) {
2425 afs_com_err(whoami, 0, "Must specify '-to' field with '-from' field");
2429 /* Get the time to delete from */
2430 if (as->parms[1].items) { /* -from */
2431 timeString = concatParams(as->parms[1].items);
2436 * Now parse this string for the time to start.
2438 code = ktime_DateToLong(timeString, &fromTime);
2441 afs_com_err(whoami, 0, "Can't parse 'from' date and time");
2442 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2448 port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -portoffset */
2449 if (as->parms[5].items) /* -dbonly */
2452 force = (as->parms[6].items ? 1 : 0);
2454 havegroupid = (as->parms[4].items ? 1 : 0);
2456 groupId = atoi(as->parms[4].items->data);
2458 if (as->parms[7].items || as->parms[8].items) {
2459 /* -noexecute (hidden) or -dryrun used */
2465 /* Get the time to delete to */
2466 if (as->parms[2].items) { /* -to */
2467 timeString = concatParams(as->parms[2].items);
2472 * Now parse this string for the time to start. Simce
2473 * times are at minute granularity, add 59 seconds.
2475 code = ktime_DateToLong(timeString, &toTime);
2478 afs_com_err(whoami, 0, "Can't parse 'to' date and time");
2479 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2486 if (fromTime > toTime) {
2487 afs_com_err(whoami, 0,
2488 "'-from' date/time cannot be later than '-to' date/time");
2492 /* Remove speicific dump ids - if any */
2493 printf("The following dumps %s deleted:\n",
2494 (noexecute ? "would have been" : "were"));
2495 for (ti = as->parms[0].items; ti != 0; ti = ti->next) { /* -dumpid */
2496 dumpid = atoi(ti->data);
2498 code = deleteDump(dumpid, port, force);
2500 printf(" %u\n", dumpid);
2505 * Now remove dumps between to and from dates.
2507 if (havegroupid || havetime) {
2508 dumps.budb_dumpsList_len = 0;
2509 dumps.budb_dumpsList_val = 0;
2510 flags.budb_dumpsList_len = 0;
2511 flags.budb_dumpsList_val = 0;
2514 sflags |= BUDB_OP_GROUPID;
2516 sflags |= BUDB_OP_DATES;
2519 bcdb_listDumps(sflags, groupId, fromTime, toTime, &dumps, &flags);
2521 afs_com_err(whoami, code,
2522 "; Error while deleting dumps from %u to %u", fromTime,
2527 for (i = 0; i < dumps.budb_dumpsList_len; i++) {
2528 if (flags.budb_dumpsList_val[i] & BUDB_OP_DBDUMP)
2532 if (flags.budb_dumpsList_val[i] & BUDB_OP_APPDUMP)
2534 code = deleteDump(dumps.budb_dumpsList_val[i], port, force);
2535 /* Ignore code and continue */
2537 printf(" %u%s%s\n", dumps.budb_dumpsList_val[i],
2539 budb_dumpsList_val[i] & BUDB_OP_APPDUMP) ?
2540 " Appended Dump" : "",
2542 budb_dumpsList_val[i] & BUDB_OP_DBDUMP) ?
2543 " Database Dump" : "");
2548 if (dumps.budb_dumpsList_val)
2549 free(dumps.budb_dumpsList_val);
2550 dumps.budb_dumpsList_len = 0;
2551 dumps.budb_dumpsList_val = 0;
2552 if (flags.budb_dumpsList_val)
2553 free(flags.budb_dumpsList_val);
2554 flags.budb_dumpsList_len = 0;
2555 flags.budb_dumpsList_val = 0;
2562 bc_saveDbCmd(struct cmd_syndesc *as, void *arock)
2564 struct rx_connection *tconn;
2565 afs_int32 portOffset = 0;
2572 code = bc_UpdateHosts();
2574 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2578 if (as->parms[0].items) {
2579 portOffset = getPortOffset(as->parms[0].items->data);
2584 /* Get the time to delete to */
2585 if (as->parms[1].items) {
2586 timeString = concatParams(as->parms[1].items);
2591 * Now parse this string for the time. Since
2592 * times are at minute granularity, add 59 seconds.
2594 code = ktime_DateToLong(timeString, &toTime);
2597 afs_com_err(whoami, 0, "Can't parse '-archive' date and time");
2598 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2605 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2609 code = TC_SaveDb(tconn, toTime, &taskId);
2611 afs_com_err(whoami, code, "; Failed to save database");
2615 /* create status monitor block */
2616 statusPtr = createStatusNode();
2618 statusPtr->taskId = taskId;
2619 statusPtr->port = portOffset;
2620 statusPtr->jobNumber = bc_jobNumber();
2621 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2622 sprintf(statusPtr->taskName, "SaveDb");
2626 rx_DestroyConnection(tconn);
2631 bc_restoreDbCmd(struct cmd_syndesc *as, void *arock)
2633 struct rx_connection *tconn;
2634 afs_int32 portOffset = 0;
2639 code = bc_UpdateHosts();
2641 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2645 if (as->parms[0].items) {
2646 portOffset = getPortOffset(as->parms[0].items->data);
2651 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2655 code = TC_RestoreDb(tconn, &taskId);
2657 afs_com_err(whoami, code, "; Failed to restore database");
2661 /* create status monitor block */
2662 statusPtr = createStatusNode();
2664 statusPtr->taskId = taskId;
2665 statusPtr->port = portOffset;
2666 statusPtr->jobNumber = bc_jobNumber();
2667 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2668 sprintf(statusPtr->taskName, "RestoreDb");
2672 rx_DestroyConnection(tconn);
2676 /* ----------------------------------
2677 * supporting routines for database examination
2678 * ----------------------------------
2681 /* structures and defines for DBLookupByVolume */
2683 #define DBL_MAX_VOLUMES 20 /* max. for each dump */
2685 /* dumpedVol - saves interesting information so that we can print it out
2690 struct dumpedVol *next;
2692 afs_int32 initialDumpID;
2693 char tapeName[BU_MAXTAPELEN];
2696 afs_int32 createTime;
2697 afs_int32 incTime; /* actually the clone time */
2700 /* -----------------------------------------
2701 * routines for examining the database
2702 * -----------------------------------------
2706 * Lookup the volumename in the backup database and print the results
2708 * volumeName - volume to lookup
2712 DBLookupByVolume(char *volumeName)
2714 struct budb_dumpEntry dumpEntry;
2715 struct budb_volumeEntry volumeEntry[DBL_MAX_VOLUMES];
2716 afs_int32 numEntries;
2717 afs_int32 tapedumpid;
2718 afs_int32 last, next;
2720 struct dumpedVol *dvptr = 0;
2721 struct dumpedVol *tempPtr = 0;
2724 char vname[BU_MAXNAMELEN];
2727 for (pass = 0; pass < 2; pass++) {
2729 /* On second pass, search for backup volume */
2731 if (!BackupName(volumeName)) {
2732 strcpy(vname, volumeName);
2733 strcat(vname, ".backup");
2741 while (next != -1) { /*w */
2743 bcdb_LookupVolume(volumeName, &volumeEntry[0], last, &next,
2744 DBL_MAX_VOLUMES, &numEntries);
2748 /* add the volumes to the list */
2749 for (i = 0; i < numEntries; i++) { /*f */
2750 struct dumpedVol *insPtr, **prevPtr;
2752 tempPtr = calloc(1, sizeof(struct dumpedVol));
2756 tempPtr->incTime = volumeEntry[i].clone;
2757 tempPtr->dumpID = volumeEntry[i].dump;
2758 strncpy(tempPtr->tapeName, volumeEntry[i].tape,
2761 /* check if we need to null terminate it - just for safety */
2762 if (strlen(volumeEntry[i].tape) >= BU_MAXTAPELEN)
2763 tempPtr->tapeName[BU_MAXTAPELEN - 1] = 0;
2765 code = bcdb_FindDumpByID(tempPtr->dumpID, &dumpEntry);
2771 tempPtr->initialDumpID = dumpEntry.initialDumpID;
2772 tempPtr->parent = dumpEntry.parent;
2773 tempPtr->level = dumpEntry.level;
2774 tempPtr->createTime = dumpEntry.created;
2776 /* add volume to list in reverse chronological order */
2780 while ((insPtr != 0)
2781 && (insPtr->createTime > tempPtr->createTime)
2783 prevPtr = &insPtr->next;
2784 insPtr = insPtr->next;
2787 /* now at the right place - insert the block */
2788 tempPtr->next = *prevPtr;
2798 ("DumpID lvl parentID creation date clone date tape name\n");
2799 for (tempPtr = dvptr; tempPtr; tempPtr = tempPtr->next) {
2800 /* For the user, the tape name is its name and initial dump id */
2802 (tempPtr->initialDumpID ? tempPtr->initialDumpID : tempPtr->
2805 /* beware the static items in compactDateString */
2806 compactDateString(&tempPtr->createTime, ds, 50);
2807 printf("%-9d %-2d %-9d %16s", tempPtr->dumpID, tempPtr->level,
2808 tempPtr->parent, ds);
2809 compactDateString(&tempPtr->incTime, ds, 50);
2810 printf(" %16s %s (%u)\n", ds, tempPtr->tapeName, tapedumpid);
2816 for (tempPtr = dvptr; tempPtr; tempPtr = dvptr) {
2817 dvptr = dvptr->next;
2822 afs_com_err(whoami, code, NULL);
2826 /* structures for dumpInfo */
2829 struct volumeLink *nextVolume;
2830 struct budb_volumeEntry volumeEntry;
2834 struct tapeLink *nextTape;
2835 struct budb_tapeEntry tapeEntry;
2836 struct volumeLink *firstVolume;
2841 * print information about a dump and all its tapes and volumes.
2845 dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
2847 struct budb_dumpEntry dumpEntry;
2848 struct tapeLink *head = 0;
2849 struct tapeLink *tapeLinkPtr, *lastTapeLinkPtr;
2850 struct volumeLink **link, *volumeLinkPtr, *lastVolumeLinkPtr;
2853 afs_int32 last, next, dbTime;
2854 afs_int32 tapedumpid;
2862 extern struct udbHandleS udbHandle;
2865 lastTapeLinkPtr = 0;
2867 lastVolumeLinkPtr = 0;
2869 /* first get information about the dump */
2871 code = bcdb_FindDumpByID(dumpid, &dumpEntry);
2875 /* For the user, the tape name is its name and initial dump id */
2876 tapedumpid = (dumpEntry.initialDumpID ? dumpEntry.initialDumpID : dumpid);
2878 /* Is this a database dump id or not */
2879 if (strcmp(dumpEntry.name, DUMP_TAPE_NAME) == 0)
2884 /* print out the information about the dump */
2888 printDumpEntry(&dumpEntry);
2890 time_t t = dumpEntry.created;
2892 printf("Dump: id %u, created: %s\n", dumpEntry.id,
2895 printf("Dump: id %u, level %d, volumes %d, created: %s\n",
2896 dumpEntry.id, dumpEntry.level, dumpEntry.nVolumes,
2900 if (!detailFlag && (strlen(dumpEntry.tapes.tapeServer) > 0)
2901 && (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA))) {
2902 printf("Backup Service: TSM: Server: %s\n",
2903 dumpEntry.tapes.tapeServer);
2906 /* now get the list of tapes */
2907 for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) { /*f */
2908 tapeLinkPtr = calloc(1, sizeof(struct tapeLink));
2910 afs_com_err(whoami, BC_NOMEM, NULL);
2914 code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
2921 /* add this tape to previous chain */
2922 if (lastTapeLinkPtr) {
2923 lastTapeLinkPtr->nextTape = tapeLinkPtr;
2924 lastTapeLinkPtr = tapeLinkPtr;
2929 lastTapeLinkPtr = head;
2933 while (next != -1) { /*wn */
2934 vl.budb_volumeList_len = 0;
2935 vl.budb_volumeList_val = 0;
2938 /* now get all the volumes in this dump. */
2939 code = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client, UF_SINGLESERVER, BUDB_MAJORVERSION, BUDB_OP_DUMPID | BUDB_OP_TAPENAME, tapeLinkPtr->tapeEntry.name, /* tape name */
2940 dumpid, /* dumpid (not initial dumpid) */
2943 &next, /* nextindex */
2944 &dbTime, /* update time */
2948 if (code == BUDB_ENDOFLIST) { /* 0 volumes on tape */
2955 for (i = 0; i < vl.budb_volumeList_len; i++) {
2956 link = &tapeLinkPtr->firstVolume;
2958 volumeLinkPtr = calloc(1, sizeof(struct volumeLink));
2959 if (!volumeLinkPtr) {
2960 afs_com_err(whoami, BC_NOMEM, NULL);
2964 memcpy(&volumeLinkPtr->volumeEntry,
2965 &vl.budb_volumeList_val[i],
2966 sizeof(struct budb_volumeEntry));
2968 /* now insert it onto the right place */
2970 && (volumeLinkPtr->volumeEntry.position >
2971 (*link)->volumeEntry.position)) {
2972 link = &((*link)->nextVolume);
2975 /* now link it in */
2976 volumeLinkPtr->nextVolume = *link;
2977 *link = volumeLinkPtr;
2980 if (vl.budb_volumeList_val)
2981 free(vl.budb_volumeList_val);
2985 for (tapeLinkPtr = head; tapeLinkPtr; tapeLinkPtr = tapeLinkPtr->nextTape) {
2989 printTapeEntry(&tapeLinkPtr->tapeEntry);
2991 printf("Tape: name %s (%u)\n", tapeLinkPtr->tapeEntry.name,
2993 printf("nVolumes %d, ", tapeLinkPtr->tapeEntry.nVolumes);
2994 compactDateString(&tapeLinkPtr->tapeEntry.written, ds, 50);
2995 printf("created %16s", ds);
2996 if (tapeLinkPtr->tapeEntry.expires != 0) {
2997 compactDateString(&tapeLinkPtr->tapeEntry.expires, ds, 50);
2998 printf(", expires %16s", ds);
3003 /* print out all the volumes */
3005 /* print header for volume listing - db dumps have no volumes */
3006 if ((detailFlag == 0) && !dbDump)
3007 printf("%4s %16s %9s %-s\n", "Pos", "Clone time", "Nbytes",
3010 for (volumeLinkPtr = tapeLinkPtr->firstVolume; volumeLinkPtr;
3011 volumeLinkPtr = volumeLinkPtr->nextVolume) {
3013 printf("\nVolume\n");
3015 printVolumeEntry(&volumeLinkPtr->volumeEntry);
3017 compactDateString(&volumeLinkPtr->volumeEntry.clone, ds, 50),
3018 printf("%4d %s %10u %16s\n",
3019 volumeLinkPtr->volumeEntry.position, ds,
3020 volumeLinkPtr->volumeEntry.nBytes,
3021 volumeLinkPtr->volumeEntry.name);
3028 afs_com_err("dumpInfo", code, "; Can't get dump information");
3030 /* free all allocated structures */
3032 while (tapeLinkPtr) {
3033 volumeLinkPtr = tapeLinkPtr->firstVolume;
3034 while (volumeLinkPtr) {
3035 lastVolumeLinkPtr = volumeLinkPtr;
3036 volumeLinkPtr = volumeLinkPtr->nextVolume;
3037 free(lastVolumeLinkPtr);
3040 lastTapeLinkPtr = tapeLinkPtr;
3041 tapeLinkPtr = tapeLinkPtr->nextTape;
3042 free(lastTapeLinkPtr);
3048 compareDump(struct budb_dumpEntry *ptr1, struct budb_dumpEntry *ptr2)
3050 if (ptr1->created < ptr2->created)
3052 else if (ptr1->created > ptr2->created)
3058 printRecentDumps(int ndumps)
3061 afs_int32 nextindex, index = 0;
3064 struct budb_dumpEntry *dumpPtr;
3068 extern struct udbHandleS udbHandle;
3070 do { /* while (nextindex != -1) */
3071 /* initialize the dump list */
3072 dl.budb_dumpList_len = 0;
3073 dl.budb_dumpList_val = 0;
3075 /* outline algorithm */
3076 code = ubik_BUDB_GetDumps(udbHandle.uh_client, 0, BUDB_MAJORVERSION, BUDB_OP_NPREVIOUS, "", /* no name */
3080 &nextindex, &dbTime, &dl);
3082 if (code == BUDB_ENDOFLIST)
3084 afs_com_err("dumpInfo", code, "; Can't get dump information");
3088 /* No need to sort, it's already sorted */
3090 if (dl.budb_dumpList_len && (index == 0))
3091 printf("%10s %10s %2s %-16s %2s %5s dump name\n", "dumpid",
3092 "parentid", "lv", "created", "nt", "nvols");
3094 dumpPtr = dl.budb_dumpList_val;
3095 for (i = 1; i <= dl.budb_dumpList_len; i++) {
3096 compactDateString(&dumpPtr->created, ds, 50),
3097 printf("%10u %10u %-2d %16s %2d %5d %s", dumpPtr->id,
3098 dumpPtr->parent, dumpPtr->level, ds,
3099 dumpPtr->tapes.maxTapes - dumpPtr->tapes.b + 1,
3100 dumpPtr->nVolumes, dumpPtr->name);
3101 if (dumpPtr->initialDumpID) /* an appended dump */
3102 printf(" (%u)", dumpPtr->initialDumpID);
3103 else if (dumpPtr->appendedDumpID) /* has appended dumps */
3104 printf(" (%u)", dumpPtr->id);
3110 if (dl.budb_dumpList_val)
3111 free(dl.budb_dumpList_val);
3113 } while (nextindex != -1);
3119 * list the dumps and contens of the dumps.
3125 bc_dumpInfoCmd(struct cmd_syndesc *as, void *arock)
3128 afs_int32 detailFlag;
3132 if (as->parms[0].items) {
3133 if (as->parms[1].items) {
3134 afs_com_err(whoami, 0,
3135 "These options are exclusive - select only one");
3138 ndumps = atoi(as->parms[0].items->data);
3140 afs_com_err(whoami, 0, "Must provide a positive number");
3144 code = printRecentDumps(ndumps);
3145 } else if (as->parms[1].items) {
3146 detailFlag = (as->parms[2].items ? 1 : 0); /* 1 = detailed listing */
3147 dumpid = atoi(as->parms[1].items->data);
3148 code = dumpInfo(dumpid, detailFlag);
3150 code = printRecentDumps(10);