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;
57 extern struct ktc_token ttoken;
60 extern afs_int32 lastTaskCode;
62 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
64 static int EvalVolumeSet1(struct bc_config *aconfig, struct bc_volumeSet *avs,
65 struct bc_volumeDump **avols,
66 struct ubik_client *uclient);
68 static int EvalVolumeSet2(struct bc_config *aconfig, struct bc_volumeSet *avs,
69 struct bc_volumeDump **avols,
70 struct ubik_client *uclient);
71 static int DBLookupByVolume(char *volumeName);
74 bc_EvalVolumeSet(struct bc_config *aconfig,
75 struct bc_volumeSet *avs,
76 struct bc_volumeDump **avols,
77 struct ubik_client *uclient)
78 { /*bc_EvalVolumeSet */
80 static afs_int32 use = 2;
82 if (use == 2) { /* Use EvalVolumeSet2() */
83 code = EvalVolumeSet2(aconfig, avs, avols, uclient);
84 if (code == RXGEN_OPCODE)
87 if (use == 1) { /* Use EvalVolumeSet1() */
88 code = EvalVolumeSet1(aconfig, avs, avols, uclient);
91 } /*bc_EvalVolumeSet */
93 struct partitionsort {
95 struct bc_volumeDump *vdlist;
96 struct bc_volumeDump *lastvdlist;
97 struct bc_volumeDump *dupvdlist;
98 struct bc_volumeEntry *vole;
99 struct partitionsort *next;
103 struct partitionsort *partitions;
104 struct serversort *next;
108 getSPEntries(afs_uint32 server, afs_int32 partition,
109 struct serversort **serverlist,
110 struct serversort **ss,
111 struct partitionsort **ps)
113 if (!(*ss) || ((*ss)->ipaddr != server)) {
115 for ((*ss) = *serverlist; (*ss); *ss = (*ss)->next) {
116 if ((*ss)->ipaddr == server)
120 /* No server entry added. Add one */
122 *ss = (struct serversort *)malloc(sizeof(struct serversort));
124 afs_com_err(whoami, BC_NOMEM, "");
128 memset(*ss, 0, sizeof(struct serversort));
129 (*ss)->ipaddr = server;
130 (*ss)->next = *serverlist;
135 if (!(*ps) || ((*ps)->part != partition)) {
136 for (*ps = (*ss)->partitions; *ps; *ps = (*ps)->next) {
137 if ((*ps)->part == partition)
141 /* No partition entry added. Add one */
143 *ps = (struct partitionsort *)malloc(sizeof(struct partitionsort));
145 afs_com_err(whoami, BC_NOMEM, "");
151 memset(*ps, 0, sizeof(struct partitionsort));
152 (*ps)->part = partition;
153 (*ps)->next = (*ss)->partitions;
154 (*ss)->partitions = *ps;
160 randSPEntries(struct serversort *serverlist,
161 struct bc_volumeDump **avols)
163 struct serversort *ss, **pss;
164 struct partitionsort *ps, **pps;
166 afs_int32 scount, pcount;
170 /* Seed random number generator */
171 r = time(0) + getpid();
174 /* Count number of servers, remove one at a time */
175 for (scount = 0, ss = serverlist; ss; ss = ss->next, scount++);
176 for (; scount; scount--) {
177 /* Pick a random server in list and remove it */
178 r = (rand() >> 4) % scount;
179 for (pss = &serverlist, ss = serverlist; r;
180 pss = &ss->next, ss = ss->next, r--);
183 /* Count number of partitions, remove one at a time */
184 for (pcount = 0, ps = ss->partitions; ps; ps = ps->next, pcount++);
185 for (; pcount; pcount--) {
186 /* Pick a random parition in list and remove it */
187 r = (rand() >> 4) % pcount;
188 for (pps = &ss->partitions, ps = ss->partitions; r;
189 pps = &ps->next, ps = ps->next, r--);
192 ps->lastvdlist->next = *avols;
202 EvalVolumeSet2(struct bc_config *aconfig,
203 struct bc_volumeSet *avs,
204 struct bc_volumeDump **avols,
205 struct ubik_client *uclient)
206 { /*EvalVolumeSet2 */
207 struct bc_volumeEntry *tve;
208 struct bc_volumeDump *tavols;
209 struct VldbListByAttributes attributes;
210 afs_int32 si, nsi; /* startIndex and nextStartIndex */
211 afs_int32 nentries, e, ei, et, add, l;
212 nbulkentries bulkentries;
213 struct nvldbentry *entries = 0;
214 struct bc_volumeDump *tvd;
215 afs_int32 code = 0, tcode;
217 struct serversort *servers = 0, *ss = 0;
218 struct partitionsort *ps = 0;
220 *avols = (struct bc_volumeDump *)0;
221 bulkentries.nbulkentries_len = 0;
222 bulkentries.nbulkentries_val = 0;
224 /* For each of the volume set entries - collect the volumes that match it */
225 for (tve = avs->ventries; tve; tve = tve->next) {
226 /* Put together a call to the vlserver for this vlentry. The
227 * performance gain is from letting the vlserver expand the
228 * volumeset and not this routine.
231 if (tve->server.sin_addr.s_addr) { /* The server */
232 attributes.Mask |= VLLIST_SERVER;
233 attributes.server = tve->server.sin_addr.s_addr;
235 if (tve->partition != -1) { /* The partition */
236 attributes.Mask |= VLLIST_PARTITION;
237 attributes.partition = tve->partition;
240 /* Now make the call to the vlserver */
241 for (si = 0; si != -1; si = nsi) {
243 bulkentries.nbulkentries_len = 0;
244 bulkentries.nbulkentries_val = 0;
247 ubik_Call(VL_ListAttributesN2, uclient, 0, &attributes,
248 tve->name, si, &nentries, &bulkentries, &nsi);
252 /* The 3.4 vlserver has a VL_ListAttributesN2() RPC call, but
253 * it is not complete. The only way to tell if it is not complete
254 * is if et == 0 (which we check for below). Also, if the call didn't
255 * match any entries, then we don't know what version the vlserver
256 * is. In both cases, we return RXGEN_OPCODE and the calling routine
257 * will switch to the EvalVolumeSet1() call.
260 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
262 /* Step through each entry and add it to the list of volumes */
263 entries = bulkentries.nbulkentries_val;
264 for (e = 0; e < nentries; e++) {
265 ei = entries[e].matchindex & 0xffff;
266 et = (entries[e].matchindex >> 16) & 0xffff;
281 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
284 /* Find server and partiton structure to hang the entry off of */
286 getSPEntries(entries[e].serverNumber[ei],
287 entries[e].serverPartition[ei], &servers,
290 afs_com_err(whoami, tcode, "");
294 /* Detect if this entry should be added (not a duplicate).
295 * Use ps->dupvdlist and ps->vole to only search volumes from
296 * previous volume set entries.
299 if (tve != avs->ventries) {
300 l = strlen(entries[e].name);
301 if (ps->vole != tve) {
303 ps->dupvdlist = ps->vdlist;
305 for (tavols = ps->dupvdlist; add && tavols;
306 tavols = tavols->next) {
307 if (strncmp(tavols->name, entries[e].name, l) == 0) {
308 if ((strcmp(&entries[e].name[l], ".backup") == 0)
309 || (strcmp(&entries[e].name[l], ".readonly")
311 || (strcmp(&entries[e].name[l], "") == 0))
318 /* Allocate a volume dump structure and its name */
319 tvd = (struct bc_volumeDump *)
320 malloc(sizeof(struct bc_volumeDump));
322 afs_com_err(whoami, BC_NOMEM, "");
325 memset(tvd, 0, sizeof(*tvd));
327 tvd->name = (char *)malloc(strlen(entries[e].name) + 10);
329 afs_com_err(whoami, BC_NOMEM, "");
334 /* Fill it in and thread onto avols list */
335 strcpy(tvd->name, entries[e].name);
337 strcat(tvd->name, ".backup");
338 else if (et == ROVOL)
339 strcat(tvd->name, ".readonly");
340 tvd->vid = entries[e].volumeId[et];
343 tvd->partition = entries[e].serverPartition[ei];
344 tvd->server.sin_addr.s_addr = entries[e].serverNumber[ei];
345 tvd->server.sin_port = 0; /* default FS port */
346 tvd->server.sin_family = AF_INET;
347 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
348 tvd->server.sin_len = sizeof(struct sockaddr_in);
351 /* String tvd off of partition struct */
352 tvd->next = ps->vdlist;
355 ps->lastvdlist = tvd;
361 /* Free memory allocated during VL call */
362 if (bulkentries.nbulkentries_val) {
363 free((char *)bulkentries.nbulkentries_val);
364 bulkentries.nbulkentries_val = 0;
370 /* Randomly link the volumedump entries together */
371 randSPEntries(servers, avols);
372 fprintf(stderr, "Total number of volumes : %u\n", count);
375 if (bulkentries.nbulkentries_val) {
376 free((char *)bulkentries.nbulkentries_val);
379 } /*EvalVolumeSet2 */
381 /*-----------------------------------------------------------------------------
385 * Takes the entries in a volumeset and expands them into a list of
386 * volumes. Every VLDB volume entry is looked at and compared to the
389 * When matching a VLDB volume entry to a volumeset entry,
390 * 1. If the RW volume entry matches, that RW volume is used.
391 * 2. Otherwise, if the BK volume entry matches, the BK volume is used.
392 * 3. Finally, if the RO volume entry matches, the RO volume is used.
393 * For instance: A volumeset entry of ".* .* user.t.*" will match volume
394 * "user.troy" and "user.troy.backup". The rules will use
395 * the RW volume "user.troy".
397 * When a VLDB volume entry matches a volumeset entry (be it RW, BK or RO),
398 * that volume is used and matches against any remaining volumeset entries
400 * For instance: A 1st volumeset entry ".* .* .*.backup" will match with
401 * "user.troy.backup". Its 2nd volumeset entry ".* .* .*"
402 * would have matched its RW volume "user.troy", but the first
403 * match is used and the second match isn't even done.
406 * aconfig : Global configuration info.
408 * avols : Ptr to linked list of entries describing volumes to dump.
409 * uclient : Ptr to Ubik client structure.
412 * 0 on successful volume set evaluation,
413 * Lower-level codes otherwise.
416 * Expand only the single volume set provided (avs); don't go down its chain.
420 *-----------------------------------------------------------------------------
423 EvalVolumeSet1(struct bc_config *aconfig,
424 struct bc_volumeSet *avs,
425 struct bc_volumeDump **avols,
426 struct ubik_client *uclient)
427 { /*EvalVolumeSet1 */
428 afs_int32 code; /*Result of various calls */
429 struct bc_volumeDump *tvd; /*Ptr to new dump instance */
430 struct bc_volumeEntry *tve, *ctve; /*Ptr to new volume entry instance */
431 char patt[256]; /*Composite regex; also, target string */
432 int volType = 0; /*Type of volume that worked */
433 afs_int32 index; /*Current VLDB entry index */
434 afs_int32 count; /*Needed by VL_ListEntry() */
435 afs_int32 next_index; /*Next index to list */
436 struct vldbentry entry; /*VLDB entry */
437 int srvpartpair; /*Loop counter: server/partition pair */
441 struct serversort *servers = 0, *ss = 0;
442 struct partitionsort *ps = 0;
443 #ifdef HAVE_POSIX_REGEX
445 int need_regfree = 0;
450 *avols = (struct bc_volumeDump *)0;
451 ctve = (struct bc_volumeEntry *)0; /* no compiled entry */
453 /* For each vldb entry.
454 * Variable next_index is set to the index of the next VLDB entry
455 * in the enumeration.
457 for (index = 0; 1; index = next_index) { /*w */
458 memset(&entry, 0, sizeof(entry));
459 code = ubik_Call(VL_ListEntry, /*Routine to invoke */
460 uclient, /*Ubik client structure */
462 index, /*Current index */
463 &count, /*Ptr to working variable */
464 &next_index, /*Ptr to next index value to list */
465 &entry); /*Ptr to entry to fill */
469 break; /* If the next index is invalid, bail out now. */
471 /* For each entry in the volume set */
472 found = 0; /* No match in volume set yet */
473 for (tve = avs->ventries; tve; tve = tve->next) { /*ve */
474 /* for each server in the vldb entry */
475 for (srvpartpair = 0; srvpartpair < entry.nServers; srvpartpair++) { /*s */
476 /* On the same server */
477 if (tve->server.sin_addr.s_addr
478 && !VLDB_IsSameAddrs(tve->server.sin_addr.s_addr,
479 entry.serverNumber[srvpartpair],
487 /* On the same partition */
488 if ((tve->partition != -1)
489 && (tve->partition != entry.serverPartition[srvpartpair]))
492 /* If the volume entry is not compiled, then compile it */
494 sprintf(patt, "^%s$", tve->name);
495 #ifdef HAVE_POSIX_REGEX
496 if (regcomp(&re, patt, REG_NOSUB) != 0) {
497 afs_com_err(whoami, 0, "Can't compile regular expression '%s'", patt);
502 errm = (char *)re_comp(patt);
504 afs_com_err(whoami, 0,
505 "Can't compile regular expression '%s': %s",
513 /* If the RW name matches the volume set entry, take
514 * it and exit. First choice is to use the RW volume.
516 if (entry.serverFlags[srvpartpair] & ITSRWVOL) {
517 if (entry.flags & RW_EXISTS) {
518 sprintf(patt, "%s", entry.name);
519 #ifdef HAVE_POSIX_REGEX
520 code = regexec(&re, patt, 0, NULL, 0);
523 code = re_exec(patt);
527 foundentry = srvpartpair;
533 /* If the BK name matches the volume set entry, take
534 * it and exit. Second choice is to use the BK volume.
536 if (entry.flags & BACK_EXISTS) {
537 sprintf(patt, "%s.backup", entry.name);
538 #ifdef HAVE_POSIX_REGEX
539 code = regexec(&re, patt, 0, NULL, 0);
542 code = re_exec(patt);
546 foundentry = srvpartpair;
553 /* If the RO name matches the volume set entry, remember
554 * it, but continue searching. Further entries may be
555 * RW or backup entries that will match.
557 else if (!found && (entry.serverFlags[srvpartpair] & ITSROVOL)
558 && (entry.flags & RO_EXISTS)) {
559 sprintf(patt, "%s.readonly", entry.name);
560 #ifdef HAVE_POSIX_REGEX
561 code = regexec(&re, patt, 0, NULL, 0);
564 code = re_exec(patt);
568 foundentry = srvpartpair;
574 afs_com_err(whoami, 0, "Internal error in regex package");
577 /* If found a match, then create a new volume dump entry */
579 /* Find server and partition structure to hang the entry off of */
581 getSPEntries(entry.serverNumber[foundentry],
582 entry.serverPartition[foundentry], &servers,
585 afs_com_err(whoami, code, "");
590 tvd = (struct bc_volumeDump *)
591 malloc(sizeof(struct bc_volumeDump));
593 afs_com_err(whoami, BC_NOMEM, "");
596 memset(tvd, 0, sizeof(*tvd));
598 tvd->name = (char *)malloc(strlen(entry.name) + 10);
600 afs_com_err(whoami, BC_NOMEM, "");
605 strcpy(tvd->name, entry.name);
606 if (volType == BACKVOL)
607 strcat(tvd->name, ".backup");
608 else if (volType == ROVOL)
609 strcat(tvd->name, ".readonly");
610 tvd->vid = entry.volumeId[volType];
612 tvd->volType = volType;
613 tvd->partition = entry.serverPartition[foundentry];
614 tvd->server.sin_addr.s_addr = entry.serverNumber[foundentry];
615 tvd->server.sin_port = 0; /* default FS port */
616 tvd->server.sin_family = AF_INET;
618 /* String tvd off of partition struct */
619 tvd->next = ps->vdlist;
622 ps->lastvdlist = tvd;
628 #ifdef HAVE_POSIX_REGEX
633 /* Randomly link the volumedump entries together */
634 randSPEntries(servers, avols);
636 fprintf(stderr, "Total number of volumes : %u\n", total);
638 } /*EvalVolumeSet1 */
641 * print out a date in compact format, 16 chars, format is
644 * date_long - ptr to a long containing the time
646 * ptr to a string containing a representation of the date
649 compactDateString(afs_uint32 *date_long, char *string, afs_int32 size)
656 if (*date_long == NEVERDATE) {
657 sprintf(string, "NEVER");
659 time_t t = *date_long;
660 ltime = localtime(&t);
661 /* prints date in U.S. format of mm/dd/yyyy */
662 strftime(string, size, "%m/%d/%Y %H:%M", ltime);
668 bc_SafeATOI(char *anum)
672 for (; *anum; anum++) {
673 if ((*anum < '0') || (*anum > '9'))
675 total = (10 * total) + (afs_int32) (*anum - '0');
681 * Take a string and parse it for a number (could be float) followed
682 * by a character representing the units (K,M,G,T). Default is 'K'.
683 * Return the size in KBytes.
686 bc_FloatATOI(char *anum)
690 afs_int32 fraction = 0; /* > 0 if past the decimal */
692 for (; *anum; anum++) {
693 if ((*anum == 't') || (*anum == 'T')) {
694 total *= 1024 * 1024 * 1024;
697 if ((*anum == 'g') || (*anum == 'G')) {
698 total *= 1024 * 1024;
701 if ((*anum == 'm') || (*anum == 'M')) {
705 if ((*anum == 'k') || (*anum == 'K')) {
712 if ((*anum < '0') || (*anum > '9'))
716 total = (10. * total) + (float)(*anum - '0');
718 total += ((float)(*anum - '0')) / (float)fraction;
723 total += 0.5; /* Round up */
724 if (total > 0x7fffffff) /* Don't go over 2G */
726 rtotal = (afs_int32) total;
730 /* make a copy of a string so that it can be freed later */
732 bc_CopyString(char *astring)
738 return (NULL); /* propagate null strings easily */
739 tlen = strlen(astring);
740 tp = (char *)malloc(tlen + 1); /* don't forget the terminating null */
742 afs_com_err(whoami, BC_NOMEM, "");
751 * Concatenates the parameters of an option and returns the string.
756 concatParams(struct cmd_item *itemPtr)
758 struct cmd_item *tempPtr;
759 afs_int32 length = 0;
762 /* compute the length of string required */
763 for (tempPtr = itemPtr; tempPtr; tempPtr = tempPtr->next) {
764 length += strlen(tempPtr->data);
765 length++; /* space or null terminator */
768 if (length == 0) { /* no string (0 length) */
769 afs_com_err(whoami, 0, "Can't have zero length date and time string");
773 string = (char *)malloc(length); /* allocate the string */
775 afs_com_err(whoami, BC_NOMEM, "");
780 tempPtr = itemPtr; /* now assemble the string */
782 strcat(string, tempPtr->data);
783 tempPtr = tempPtr->next;
788 return (string); /* return the string */
792 * print out an interface status node as received from butc
796 printIfStatus(struct tciStatusS *statusPtr)
798 printf("Task %d: %s: ", statusPtr->taskId, statusPtr->taskName);
799 if (statusPtr->nKBytes)
800 printf("%ld Kbytes transferred", (long unsigned int) statusPtr->nKBytes);
801 if (strlen(statusPtr->volumeName) != 0) {
802 if (statusPtr->nKBytes)
804 printf("volume %s", statusPtr->volumeName);
809 if (statusPtr->flags & ABORT_REQUEST)
810 printf(" [abort request rcvd]");
812 if (statusPtr->flags & ABORT_DONE)
813 printf(" [abort complete]");
815 if (statusPtr->flags & OPR_WAIT)
816 printf(" [operator wait]");
818 if (statusPtr->flags & CALL_WAIT)
819 printf(" [callout in progress]");
821 if (statusPtr->flags & DRIVE_WAIT)
822 printf(" [drive wait]");
824 if (statusPtr->flags & TASK_DONE)
830 getPortOffset(char *port)
832 afs_int32 portOffset;
834 portOffset = bc_SafeATOI(port);
836 if (portOffset < 0) {
837 afs_com_err(whoami, 0, "Can't decode port offset '%s'", port);
839 } else if (portOffset > BC_MAXPORTOFFSET) {
840 afs_com_err(whoami, 0, "%u exceeds max port offset %u", portOffset,
847 /* bc_GetTapeStatusCmd
848 * display status of all tasks on a particular tape coordinator
851 bc_GetTapeStatusCmd(struct cmd_syndesc *as, void *arock)
854 struct rx_connection *tconn;
855 afs_int32 portOffset = 0;
860 struct tciStatusS status;
862 code = bc_UpdateHosts();
864 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
868 if (as->parms[0].items) {
869 portOffset = getPortOffset(as->parms[0].items->data);
874 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
878 flags = TSK_STAT_FIRST;
882 while ((flags & TSK_STAT_END) == 0) {
883 code = TC_ScanStatus(tconn, &taskId, &status, &flags);
885 if (code == TC_NOTASKS)
887 afs_com_err(whoami, code, "; Can't get status from butc");
890 if ((flags & TSK_STAT_NOTFOUND))
891 break; /* Can't find the task id */
892 flags &= ~TSK_STAT_FIRST; /* turn off flag */
894 printIfStatus(&status);
899 printf("Tape coordinator is idle\n");
901 if (flags & TSK_STAT_ADSM)
902 printf("TSM Tape coordinator\n");
903 else if (flags & TSK_STAT_XBSA)
904 printf("XBSA Tape coordinator\n");
909 extern struct Lock dispatchLock;
912 * wait for all jobs to terminate
915 bc_WaitForNoJobs(void)
918 int usefulJobRunning = 1;
920 extern dlqlinkT statusHead;
922 afs_com_err(whoami, 0, "waiting for job termination");
924 while (usefulJobRunning) {
925 usefulJobRunning = (dlqEmpty(&statusHead) ? 0 : 1);
926 if (dispatchLock.excl_locked)
927 usefulJobRunning = 1;
928 for (i = 0; (!usefulJobRunning && (i < BC_MAXSIMDUMPS)); i++) {
929 if (bc_dumpTasks[i].flags & BC_DI_INUSE)
930 usefulJobRunning = 1;
933 /* Wait 5 seconds and check again */
934 if (usefulJobRunning)
937 return (lastTaskCode);
941 * print status on running jobs
943 * ignored - a null "as" prints only jobs.
946 bc_JobsCmd(struct cmd_syndesc *as, void *arock)
955 extern dlqlinkT statusHead;
957 dlqInit(&atJobsHead);
960 ptr = (&statusHead)->dlq_next;
961 while (ptr != &statusHead) {
962 statusPtr = (statusP) ptr;
965 if (statusPtr->scheduledDump) {
966 dlqUnlink((dlqlinkP) statusPtr);
967 dlqLinkb(&atJobsHead, (dlqlinkP) statusPtr);
969 printf("Job %d:", statusPtr->jobNumber);
971 printf(" %s", statusPtr->taskName);
973 if (statusPtr->dbDumpId)
974 printf(": DumpID %u", statusPtr->dbDumpId);
975 if (statusPtr->nKBytes)
976 printf(", %ld Kbytes", afs_printable_int32_ld(statusPtr->nKBytes));
977 if (strlen(statusPtr->volumeName) != 0)
978 printf(", volume %s", statusPtr->volumeName);
980 if (statusPtr->flags & CONTACT_LOST)
981 printf(" [butc contact lost]");
983 if (statusPtr->flags & ABORT_REQUEST)
984 printf(" [abort request]");
986 if (statusPtr->flags & ABORT_SENT)
987 printf(" [abort sent]");
989 if (statusPtr->flags & OPR_WAIT)
990 printf(" [operator wait]");
992 if (statusPtr->flags & CALL_WAIT)
993 printf(" [callout in progress]");
995 if (statusPtr->flags & DRIVE_WAIT)
996 printf(" [drive wait]");
1002 * Now print the scheduled dumps.
1004 if (!dlqEmpty(&statusHead) && as)
1005 printf("\n"); /* blank line between running and scheduled dumps */
1008 while (!dlqEmpty(&atJobsHead)) {
1009 ptr = (&atJobsHead)->dlq_next;
1010 youngest = (statusP) ptr;
1012 ptr = ptr->dlq_next;
1013 while (ptr != &atJobsHead) { /* Find the dump that starts the earliest */
1014 statusPtr = (statusP) ptr;
1015 if (statusPtr->scheduledDump < youngest->scheduledDump)
1016 youngest = statusPtr;
1017 ptr = ptr->dlq_next;
1020 /* Print token expiration time */
1021 if ((ttoken.endTime > prevTime)
1022 && (ttoken.endTime <= youngest->scheduledDump) && as
1023 && (ttoken.endTime != NEVERDATE)) {
1024 if (ttoken.endTime > time(0)) {
1025 compactDateString(&ttoken.endTime, ds, 50);
1026 printf(" %16s: TOKEN EXPIRATION\n", ds);
1028 printf(" TOKEN HAS EXPIRED\n");
1031 prevTime = youngest->scheduledDump;
1033 /* Print the info */
1034 compactDateString(&youngest->scheduledDump, ds, 50);
1035 printf("Job %d:", youngest->jobNumber);
1036 printf(" %16s: %s", ds, youngest->cmdLine);
1039 /* return to original list */
1040 dlqUnlink((dlqlinkP) youngest);
1041 dlqLinkb(&statusHead, (dlqlinkP) youngest);
1044 /* Print token expiration time if havn't already */
1045 if ((ttoken.endTime == NEVERDATE) && as)
1046 printf(" : TOKEN NEVER EXPIRES\n");
1047 else if ((ttoken.endTime > prevTime) && as) {
1048 if (ttoken.endTime > time(0)) {
1049 compactDateString(&ttoken.endTime, ds, 50);
1050 printf(" %16s: TOKEN EXPIRATION\n", ds);
1052 printf(" : TOKEN HAS EXPIRED\n");
1061 bc_KillCmd(struct cmd_syndesc *as, void *arock)
1065 struct bc_dumpTask *td;
1072 extern dlqlinkT statusHead;
1074 tp = as->parms[0].items->data;
1075 if (strchr(tp, '.') == 0) {
1076 slot = bc_SafeATOI(tp);
1078 afs_com_err(whoami, 0, "Bad syntax for number '%s'", tp);
1083 ptr = (&statusHead)->dlq_next;
1084 while (ptr != &statusHead) {
1085 statusPtr = (statusP) ptr;
1086 if (statusPtr->jobNumber == slot) {
1087 statusPtr->flags |= ABORT_REQUEST;
1091 ptr = ptr->dlq_next;
1095 fprintf(stderr, "Job %d not found\n", slot);
1100 for (i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1101 if (td->flags & BC_DI_INUSE) {
1103 strcpy(tbuffer, td->volSetName);
1104 strcat(tbuffer, ".");
1105 strcat(tbuffer, tailCompPtr(td->dumpName));
1106 if (strcmp(tbuffer, tp) == 0)
1110 if (i >= BC_MAXSIMDUMPS) {
1111 afs_com_err(whoami, 0, "Can't find job %s", tp);
1116 statusPtr = findStatus(td->dumpID);
1118 if (statusPtr == 0) {
1119 afs_com_err(whoami, 0, "Can't locate status - internal error");
1123 statusPtr->flags |= ABORT_REQUEST;
1130 /* restore a volume or volumes */
1132 bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
1135 * parm 0 is the new server to restore to
1136 * parm 1 is the new partition to restore to
1137 * parm 2 is volume(s) to restore
1138 * parm 3 is the new extension, if any, for the volume name.
1139 * parm 4 gives the new volume # to restore this volume as (removed).
1140 * parm 4 date is a string representing the date
1142 * We handle four types of restores. If old is set, then we restore the
1143 * volume with the same name and ID. If old is not set, we allocate
1144 * a new volume ID for the restored volume. If a new extension is specified,
1145 * we add that extension to the volume name of the restored volume.
1147 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1148 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1149 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1150 struct bc_volumeDump *tvol; /* temp for same */
1151 struct sockaddr_in destServ; /* machine to which to restore volumes */
1152 afs_int32 destPartition; /* partition to which to restore volumes */
1154 struct cmd_item *ti;
1158 afs_int32 dumpID = 0;
1159 char *newExt, *timeString;
1161 afs_int32 *ports = NULL;
1162 afs_int32 portCount = 0;
1165 code = bc_UpdateHosts();
1167 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1171 /* specified other destination host */
1172 if (as->parms[0].items) {
1173 tp = as->parms[0].items->data;
1174 if (bc_ParseHost(tp, &destServ)) {
1175 afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
1180 /* specified other destination partition */
1181 if (as->parms[1].items) {
1182 tp = as->parms[1].items->data;
1183 if (bc_GetPartitionID(tp, &destPartition)) {
1184 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1189 for (ti = as->parms[2].items; ti; ti = ti->next) {
1190 /* build list of volume items */
1191 tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1193 afs_com_err(whoami, BC_NOMEM, "");
1196 memset(tvol, 0, sizeof(struct bc_volumeDump));
1198 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1200 afs_com_err(whoami, BC_NOMEM, "");
1203 strncpy(tvol->name, ti->data, VOLSER_OLDMAXVOLNAME);
1204 tvol->entry = &tvolumeEntry;
1207 lastVol->next = tvol; /* thread onto end of list */
1209 volsToRestore = tvol;
1213 if (as->parms[4].items) {
1214 timeString = concatParams(as->parms[4].items);
1218 code = ktime_DateToLong(timeString, &fromDate);
1221 afs_com_err(whoami, 0, "Can't parse restore date and time");
1222 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1226 fromDate = 0x7fffffff; /* latest one */
1229 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1232 /* Read all the port offsets into the ports array. The first element in the
1233 * array is for full restore and the rest are for incremental restores
1235 if (as->parms[5].items) {
1236 for (ti = as->parms[5].items; ti; ti = ti->next)
1238 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1240 afs_com_err(whoami, BC_NOMEM, "");
1244 for (ti = as->parms[5].items, i = 0; ti; ti = ti->next, i++) {
1245 ports[i] = getPortOffset(ti->data);
1251 dontExecute = (as->parms[6].items ? 1 : 0); /* -n */
1253 if (as->parms[7].items)
1255 dumpID = atoi(as->parms[7].items->data);
1261 * Perform the call to start the restore.
1264 bc_StartDmpRst(bc_globalConfig, "volume", "restore", volsToRestore,
1265 &destServ, destPartition, fromDate, newExt, oldFlag,
1266 /*parentDump */ dumpID, /*dumpLevel */ 0,
1267 bc_Restorer, ports, portCount,
1268 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1270 afs_com_err(whoami, code, "; Failed to queue restore");
1275 /* restore a whole partition or server */
1277 /* bc_DiskRestoreCmd
1278 * restore a whole partition
1280 * first, reqd - machine (server) to restore
1281 * second, reqd - partition to restore
1286 bc_DiskRestoreCmd(struct cmd_syndesc *as, void *arock)
1288 struct bc_volumeSet tvolumeSet; /* temporary volume set for EvalVolumeSet call */
1289 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1290 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1291 struct sockaddr_in destServ; /* machine to which to restore volumes */
1292 afs_int32 destPartition; /* partition to which to restore volumes */
1298 afs_int32 *ports = NULL;
1299 afs_int32 portCount = 0;
1301 struct bc_volumeDump *prev, *tvol, *nextvol;
1302 struct cmd_item *ti;
1305 /* parm 0 is the server to restore
1306 * parm 1 is the partition to restore
1308 * parm 8 and above as in VolRestoreCmd:
1309 * parm 8 is the new server to restore to
1310 * parm 9 is the new partition to restore to
1313 code = bc_UpdateVolumeSet();
1315 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1318 code = bc_UpdateHosts();
1320 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1324 /* create a volume set corresponding to the volume pattern we've been given */
1325 memset(&tvolumeSet, 0, sizeof(tvolumeSet));
1326 memset(&tvolumeEntry, 0, sizeof(tvolumeEntry));
1327 tvolumeSet.name = "TempVolumeSet";
1328 tvolumeSet.ventries = &tvolumeEntry;
1329 tvolumeEntry.serverName = as->parms[0].items->data;
1330 tvolumeEntry.partname = as->parms[1].items->data;
1332 if (bc_GetPartitionID(tvolumeEntry.partname, &tvolumeEntry.partition)) {
1333 afs_com_err(whoami, 0, "Can't parse partition '%s'",
1334 tvolumeEntry.partname);
1338 if (bc_ParseHost(tvolumeEntry.serverName, &tvolumeEntry.server)) {
1339 afs_com_err(whoami, 0, "Can't locate host '%s'", tvolumeEntry.serverName);
1343 /* specified other destination host */
1344 if (as->parms[8].items) {
1345 tp = as->parms[8].items->data;
1346 if (bc_ParseHost(tp, &destServ)) {
1347 afs_com_err(whoami, 0, "Can't locate destination host '%s'", tp);
1350 } else /* use destination host == original host */
1351 memcpy(&destServ, &tvolumeEntry.server, sizeof(destServ));
1353 /* specified other destination partition */
1354 if (as->parms[9].items) {
1355 tp = as->parms[9].items->data;
1356 if (bc_GetPartitionID(tp, &destPartition)) {
1357 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1360 } else /* use original partition */
1361 destPartition = tvolumeEntry.partition;
1363 tvolumeEntry.name = ".*"; /* match all volumes (this should be a parameter) */
1365 if (as->parms[2].items) {
1366 for (ti = as->parms[2].items; ti; ti = ti->next)
1368 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1370 afs_com_err(whoami, BC_NOMEM, "");
1374 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1375 ports[i] = getPortOffset(ti->data);
1381 newExt = (as->parms[10].items ? as->parms[10].items->data : NULL);
1382 dontExecute = (as->parms[11].items ? 1 : 0); /* -n */
1385 * Expand out the volume set into its component list of volumes, by calling VLDB server.
1388 bc_EvalVolumeSet(bc_globalConfig, &tvolumeSet, &volsToRestore,
1391 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1395 /* Since we want only RW volumes, remove any
1396 * BK or RO volumes from the list.
1398 for (prev = 0, tvol = volsToRestore; tvol; tvol = nextvol) {
1399 nextvol = tvol->next;
1400 if (BackupName(tvol->name)) {
1403 "Will not restore volume %s (its RW does not reside on the partition)\n",
1406 if (tvol == volsToRestore) {
1407 volsToRestore = nextvol;
1409 prev->next = nextvol;
1419 fromDate = 0x7fffffff; /* last one before this date */
1420 oldFlag = 1; /* do restore same volid (and name) */
1423 * Perform the call to start the dump.
1426 bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1427 &destServ, destPartition, fromDate, newExt, oldFlag,
1428 /*parentDump */ 0, /*dumpLevel */ 0,
1429 bc_Restorer, ports, portCount,
1430 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1432 afs_com_err(whoami, code, "; Failed to queue restore");
1437 /* bc_VolsetRestoreCmd
1438 * restore a volumeset or list of volumes.
1442 bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
1449 afs_int32 *ports = NULL;
1450 afs_int32 portCount = 0;
1453 struct bc_volumeSet *volsetPtr; /* Ptr to list of generated volume info */
1454 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1455 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1456 struct sockaddr_in destServer; /* machine to which to restore volume */
1457 afs_int32 destPartition; /* partition to which to restore volumes */
1458 struct cmd_item *ti;
1461 code = bc_UpdateVolumeSet();
1463 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1466 code = bc_UpdateHosts();
1468 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1472 if (as->parms[0].items) {
1473 if (as->parms[1].items) {
1474 afs_com_err(whoami, 0, "Can't have both -name and -file options");
1478 volsetName = as->parms[0].items->data;
1479 volsetPtr = bc_FindVolumeSet(bc_globalConfig, volsetName);
1481 afs_com_err(whoami, 0,
1482 "Can't find volume set '%s' in backup database",
1487 /* Expand out the volume set into its component list of volumes. */
1489 bc_EvalVolumeSet(bc_globalConfig, volsetPtr, &volsToRestore,
1492 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1495 } else if (as->parms[1].items) {
1498 char server[50], partition[50], volume[50], rest[256];
1500 struct bc_volumeDump *tvol;
1502 fd = fopen(as->parms[1].items->data, "r");
1504 afs_com_err(whoami, errno, "; Cannot open file '%s'",
1505 as->parms[1].items->data);
1509 while (fgets(line, 255, fd)) {
1511 sscanf(line, "%s %s %s %s", server, partition, volume, rest);
1517 "Invalid volumeset file format: Wrong number of arguments: Ignoring\n");
1518 fprintf(stderr, " %s", line);
1522 if (bc_ParseHost(server, &destServer)) {
1523 afs_com_err(whoami, 0, "Failed to locate host '%s'", server);
1527 if (bc_GetPartitionID(partition, &destPartition)) {
1528 afs_com_err(whoami, 0,
1529 "Failed to parse destination partition '%s'",
1534 /* Allocate a volumeDump structure and link it in */
1536 (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1537 memset(tvol, 0, sizeof(struct bc_volumeDump));
1539 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1541 afs_com_err(whoami, BC_NOMEM, "");
1544 strncpy(tvol->name, volume, VOLSER_OLDMAXVOLNAME);
1545 memcpy(&tvol->server, &destServer, sizeof(destServer));
1546 tvol->partition = destPartition;
1549 lastVol->next = tvol; /* thread onto end of list */
1551 volsToRestore = tvol;
1556 afs_com_err(whoami, 0, "-name or -file option required");
1561 /* Get the port offset for the restore */
1562 if (as->parms[2].items) {
1563 for (ti = as->parms[2].items; ti; ti = ti->next)
1565 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1567 afs_com_err(whoami, BC_NOMEM, "");
1571 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1572 ports[i] = getPortOffset(ti->data);
1578 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1579 dontExecute = (as->parms[4].items ? 1 : 0);
1581 fromDate = 0x7fffffff; /* last one before this date */
1582 oldFlag = 1; /* do restore same volid (and name) */
1584 /* Perform the call to start the restore */
1585 code = bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1586 /*destserver */ NULL, /*destpartition */ 0, fromDate,
1588 /*parentDump */ 0, /*dumpLevel */ 0,
1589 bc_Restorer, ports, portCount,
1590 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1592 afs_com_err(whoami, code, "; Failed to queue restore");
1597 /*-----------------------------------------------------------------------------
1601 * Perform a dump of the set of volumes provided.
1602 * user specifies: -volumeset .. -dump .. [-portoffset ..] [-n]
1605 * as : Parsed command line information.
1606 * arock : Ptr to misc stuff; not used.
1610 * The result of bc_StartDump() otherwise
1617 *---------------------------------------------------------------------------
1622 bc_DumpCmd(struct cmd_syndesc *as, void *arock)
1624 char *dumpPath = NULL;
1625 char *vsName = NULL; /*Ptrs to various names */
1626 struct bc_volumeSet *tvs = NULL; /*Ptr to list of generated volume info */
1627 struct bc_dumpSchedule *tds;
1628 struct bc_dumpSchedule *baseds = NULL; /*Ptr to dump schedule node */
1629 struct bc_volumeDump *tve, *volsToDump; /*Ptr to individual vols to be dumped */
1630 struct budb_dumpEntry dumpEntry, de, fde; /* dump entry */
1633 afs_int32 parent; /* parent dump */
1634 afs_int32 level; /* this dump's level # */
1635 afs_int32 problemFindingDump; /* can't find parent(s) */
1637 afs_int32 *portp = NULL;
1638 afs_int32 portCount = 0;
1639 afs_int32 doAt, atTime; /* Time a timed-dump is to start at */
1642 int doAppend = 0; /* Append the dump to dump set */
1643 afs_int32 code; /* Return code */
1644 int loadfile; /* whether to load a file or not */
1648 extern struct bc_dumpTask bc_dumpTasks[];
1650 code = bc_UpdateDumpSchedule();
1652 afs_com_err(whoami, code, "; Can't retrieve dump schedule");
1655 code = bc_UpdateVolumeSet();
1657 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1660 code = bc_UpdateHosts();
1662 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1667 * Some parameters cannot be specified together
1668 * The "-file" option cannot exist with the "-volume", "-dump",
1669 * "-portoffset", or "-append" option
1671 if (as->parms[6].items) {
1673 if (as->parms[0].items || as->parms[1].items || as->parms[2].items
1674 || as->parms[4].items) {
1675 afs_com_err(whoami, 0, "Invalid option specified with -file option");
1680 if (!as->parms[0].items || !as->parms[1].items) {
1681 afs_com_err(whoami, 0,
1682 "Must specify volume set name and dump level name");
1688 * Get the time we are to perform this dump
1690 if (as->parms[3].items) {
1693 timeString = concatParams(as->parms[3].items);
1698 * Now parse this string for the time to start.
1700 code = ktime_DateToLong(timeString, &atTime);
1703 afs_com_err(whoami, 0, "Can't parse dump start date and time");
1704 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1710 dontExecute = (as->parms[5].items ? 1 : 0); /* -n */
1713 * If this dump is not a load file, then check the parameters.
1715 if (!loadfile) { /*6 */
1716 vsName = as->parms[0].items->data; /* get volume set name */
1717 dumpPath = as->parms[1].items->data; /* get dump path */
1719 /* get the port number, if one was specified */
1720 if (as->parms[2].items) {
1722 portp = (afs_int32 *) malloc(sizeof(afs_int32));
1724 afs_com_err(whoami, BC_NOMEM, "");
1728 *portp = getPortOffset(as->parms[2].items->data);
1733 doAppend = (as->parms[4].items ? 1 : 0); /* -append */
1736 * Get a hold of the given volume set and dump set.
1738 tvs = bc_FindVolumeSet(bc_globalConfig, vsName);
1740 afs_com_err(whoami, 0,
1741 "Can't find volume set '%s' in backup database", vsName);
1744 baseds = bc_FindDumpSchedule(bc_globalConfig, dumpPath);
1746 afs_com_err(whoami, 0,
1747 "Can't find dump schedule '%s' in backup database",
1756 * If given the "-at" option, then add this to the jobs list and return
1759 * Create a status node for this timed dump.
1760 * Fill in the time to dump and the cmd line for the dump leaving off
1761 * the -at option. If the -n option is there, it is scheduled with
1762 * the Timed dump as opposed to not scheduling the time dump at all.
1765 if (atTime < time(0)) {
1766 afs_com_err(whoami, 0,
1767 "Time of dump is earlier then current time - not added");
1769 statusPtr = createStatusNode();
1771 statusPtr->scheduledDump = atTime;
1773 /* Determine length of the dump command */
1775 length += 4; /* "dump" */
1777 length += 6; /* " -file" */
1778 length += 1 + strlen(as->parms[6].items->data); /* " <file>" */
1780 /* length += 11; *//* " -volumeset" */
1781 length += 1 + strlen(as->parms[0].items->data); /* " <volset> */
1783 /* length += 6; *//* " -dump" */
1784 length += 1 + strlen(as->parms[1].items->data); /* " <dumpset> */
1786 if (as->parms[2].items) {
1787 /* length += 12; *//* " -portoffset" */
1788 length += 1 + strlen(as->parms[2].items->data); /* " <port>" */
1791 if (as->parms[4].items)
1792 length += 8; /* " -append" */
1796 length += 3; /* " -n" */
1797 length++; /* end-of-line */
1799 /* Allocate status block for this timed dump */
1800 sprintf(statusPtr->taskName, "Scheduled Dump");
1801 statusPtr->jobNumber = bc_jobNumber();
1802 statusPtr->scheduledDump = atTime;
1803 statusPtr->cmdLine = (char *)malloc(length);
1804 if (!statusPtr->cmdLine) {
1805 afs_com_err(whoami, BC_NOMEM, "");
1809 /* Now reconstruct the dump command */
1810 statusPtr->cmdLine[0] = 0;
1811 strcat(statusPtr->cmdLine, "dump");
1813 strcat(statusPtr->cmdLine, " -file");
1814 strcat(statusPtr->cmdLine, " ");
1815 strcat(statusPtr->cmdLine, as->parms[6].items->data);
1817 /* strcat(statusPtr->cmdLine, " -volumeset"); */
1818 strcat(statusPtr->cmdLine, " ");
1819 strcat(statusPtr->cmdLine, as->parms[0].items->data);
1821 /* strcat(statusPtr->cmdLine, " -dump"); */
1822 strcat(statusPtr->cmdLine, " ");
1823 strcat(statusPtr->cmdLine, as->parms[1].items->data);
1825 if (as->parms[2].items) {
1826 /* strcat(statusPtr->cmdLine, " -portoffset"); */
1827 strcat(statusPtr->cmdLine, " ");
1828 strcat(statusPtr->cmdLine, as->parms[2].items->data);
1831 if (as->parms[4].items)
1832 strcat(statusPtr->cmdLine, " -append");
1835 strcat(statusPtr->cmdLine, " -n");
1837 printf("Add scheduled dump as job %d\n", statusPtr->jobNumber);
1838 if ((atTime > ttoken.endTime) && (ttoken.endTime != NEVERDATE))
1839 afs_com_err(whoami, 0,
1840 "Warning: job %d starts after expiration of AFS token",
1841 statusPtr->jobNumber);
1850 * Read and execute the load file if specified. The work of reading is done
1851 * in the main routine prior the dispatch call. loadFile and dontExecute are
1852 * global variables so this can take place in main.
1855 loadFile = (char *)malloc(strlen(as->parms[6].items->data) + 1);
1857 afs_com_err(whoami, BC_NOMEM, "");
1860 strcpy(loadFile, as->parms[6].items->data);
1865 * We are doing a real dump (no load file or timed dump).
1867 printf("Starting dump of volume set '%s' (dump level '%s')\n", vsName,
1870 /* For each dump-level above this one, see if the volumeset was dumped
1871 * at the level. We search all dump-levels since a higher dump-level
1872 * may have actually been done AFTER a lower dump level.
1874 parent = level = problemFindingDump = 0;
1875 for (tds = baseds->parent; tds; tds = tds->parent) {
1876 /* Find the most recent dump of the volume-set at this dump-level.
1877 * Raise problem flag if didn't find a dump and a parent not yet found.
1879 code = bcdb_FindLatestDump(vsName, tds->name, &dumpEntry);
1882 problemFindingDump = 1; /* skipping a dump level */
1886 /* We found the most recent dump at this level. Now check
1887 * if we should use it by seeing if its full dump hierarchy
1888 * exists. If it doesn't, we don't want to base our incremental
1891 if (!parent || (dumpEntry.id > parent)) {
1892 /* Follow the parent dumps to see if they are all there */
1893 for (d = dumpEntry.parent; d; d = de.parent) {
1894 code = bcdb_FindDumpByID(d, &de);
1899 /* If we found the entire level, remember it. Otherwise raise flag.
1900 * If we had already found a dump, raise the problem flag.
1904 problemFindingDump = 1;
1905 parent = dumpEntry.id;
1906 level = dumpEntry.level + 1;
1907 memcpy(&fde, &dumpEntry, sizeof(dumpEntry));
1909 /* Dump hierarchy not complete so can't base off the latest */
1910 problemFindingDump = 1;
1915 /* If the problemflag was raise, it means we are not doing the
1916 * dump at the level we requested it be done at.
1918 if (problemFindingDump) {
1919 afs_com_err(whoami, 0,
1920 "Warning: Doing level %d dump due to missing higher-level dumps",
1923 printf("Parent dump: dump %s (DumpID %u)\n", fde.name, parent);
1925 } else if (parent) {
1926 printf("Found parent: dump %s (DumpID %u)\n", fde.name, parent);
1929 /* Expand out the volume set into its component list of volumes. */
1930 code = bc_EvalVolumeSet(bc_globalConfig, tvs, &volsToDump, cstruct);
1932 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1936 printf("No volumes to dump\n");
1940 /* Determine what the clone time of the volume was when it was
1941 * last dumped (tve->date). This is the time from when an
1942 * incremental should be done (remains zero if a full dump).
1945 for (tve = volsToDump; tve; tve = tve->next) {
1946 code = bcdb_FindClone(parent, tve->name, &tve->date);
1950 /* Get the time the volume was last cloned and see if the volume has
1951 * changed since then. Only do this when the "-n" flag is specified
1952 * because butc will get the cloneDate at time of dump.
1956 volImageTime(tve->server.sin_addr.s_addr, tve->partition,
1957 tve->vid, tve->volType, &tve->cloneDate);
1961 if (tve->cloneDate && (tve->cloneDate == tve->date)) {
1962 afs_com_err(whoami, 0,
1963 "Warning: Timestamp on volume %s unchanged from previous dump",
1971 printf("Would have dumped the following volumes:\n");
1973 printf("Preparing to dump the following volumes:\n");
1974 for (tve = volsToDump; tve; tve = tve->next) {
1975 printf("\t%s (%u)\n", tve->name, tve->vid);
1980 code = bc_StartDmpRst(bc_globalConfig, dumpPath, vsName, volsToDump,
1981 /*destServer */ NULL, /*destPartition */ 0,
1983 /*newExt */ NULL, /*oldFlag */ 0,
1984 parent, level, bc_Dumper, portp, /*portCount */ 1,
1985 baseds, doAppend, dontExecute);
1987 afs_com_err(whoami, code, "; Failed to queue dump");
1994 * terminate the backup process. Insists that that all running backup
1995 * jobs be terminated before it will quit
2000 bc_QuitCmd(struct cmd_syndesc *as, void *arock)
2003 struct bc_dumpTask *td;
2004 extern dlqlinkT statusHead;
2008 /* Check the status list for outstanding jobs */
2010 for (ptr = (&statusHead)->dlq_next; ptr != &statusHead;
2011 ptr = ptr->dlq_next) {
2012 statusPtr = (statusP) ptr;
2013 if (!(statusPtr->flags & ABORT_REQUEST)) {
2015 afs_com_err(whoami, 0, "Job %d still running (and not aborted)",
2016 statusPtr->jobNumber);
2017 afs_com_err(whoami, 0,
2018 "You must at least 'kill' all running jobs before quitting");
2024 /* A job still being initialized (but no status structure or job number since it
2025 * has not been handed to a butc process yet)
2027 for (td = bc_dumpTasks, i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
2028 if (td->flags & BC_DI_INUSE) {
2029 afs_com_err(whoami, 0, "A job is still running");
2030 afs_com_err(whoami, 0,
2031 "You must at least 'kill' all running jobs before quitting");
2037 /* close the all temp text files before quitting */
2038 for (i = 0; i < TB_NUM; i++)
2039 bc_closeTextFile(&bc_globalConfig->configText[i],
2040 &bc_globalConfig->tmpTextFileNames[i][0]);
2046 * Labels a tape i.e. request the tape coordinator to perform this
2050 bc_LabelTapeCmd(struct cmd_syndesc *as, void *arock)
2052 char *tapename = 0, *pname = 0;
2057 code = bc_UpdateHosts();
2059 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2063 if (as->parms[0].items) { /* -name */
2064 tapename = as->parms[0].items->data;
2065 if (strlen(tapename) >= TC_MAXTAPELEN) {
2066 afs_com_err(whoami, 0, "AFS tape name '%s' is too long", tapename);
2071 if (as->parms[3].items) { /* -pname */
2073 afs_com_err(whoami, 0, "Can only specify -name or -pname");
2076 pname = as->parms[3].items->data;
2077 if (strlen(pname) >= TC_MAXTAPELEN) {
2078 afs_com_err(whoami, 0, "Permanent tape name '%s' is too long", pname);
2083 if (as->parms[1].items) {
2084 size = bc_FloatATOI(as->parms[1].items->data);
2086 afs_com_err(whoami, 0, "Bad syntax for tape size '%s'",
2087 as->parms[1].items->data);
2093 if (as->parms[2].items) {
2094 port = getPortOffset(as->parms[2].items->data);
2099 code = bc_LabelTape(tapename, pname, size, bc_globalConfig, port);
2106 * read the label on a tape
2108 * optional port number
2111 bc_ReadLabelCmd(struct cmd_syndesc *as, void *arock)
2116 code = bc_UpdateHosts();
2118 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2122 if (as->parms[0].items) {
2123 port = getPortOffset(as->parms[0].items->data);
2128 code = bc_ReadLabel(bc_globalConfig, port);
2135 * read content information from dump tapes, and if user desires,
2136 * add it to the database
2139 bc_ScanDumpsCmd(struct cmd_syndesc *as, void *arock)
2142 afs_int32 dbAddFlag = 0;
2145 code = bc_UpdateHosts();
2147 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2151 /* check for flag */
2152 if (as->parms[0].items != 0) { /* add scan to database */
2156 /* check for port */
2157 if (as->parms[1].items) {
2158 port = getPortOffset(as->parms[1].items->data);
2163 code = bc_ScanDumps(bc_globalConfig, dbAddFlag, port);
2167 /* bc_ParseExpiration
2170 * dates are specified as absolute or relative, the syntax is:
2171 * absolute: at %d/%d/%d [%d:%d] where [..] is optional
2172 * relative: in [%dy][%dm][%dd] where at least one component
2177 bc_ParseExpiration(struct cmd_parmdesc *paramPtr, afs_int32 *expType,
2180 struct cmd_item *itemPtr;
2181 struct ktime_date kt;
2182 char *dateString = 0;
2185 *expType = BC_NO_EXPDATE;
2188 if (!paramPtr->items)
2189 ERROR(0); /* no expiration specified */
2191 /* some form of expiration date specified. First validate the prefix */
2192 itemPtr = paramPtr->items;
2194 if (strcmp(itemPtr->data, "at") == 0) {
2195 *expType = BC_ABS_EXPDATE;
2197 dateString = concatParams(itemPtr->next);
2201 code = ktime_DateToLong(dateString, expDate);
2204 } else if (strcmp(itemPtr->data, "in") == 0) {
2205 *expType = BC_REL_EXPDATE;
2207 dateString = concatParams(itemPtr->next);
2211 code = ParseRelDate(dateString, &kt);
2214 *expDate = ktimeRelDate_ToLong(&kt);
2216 dateString = concatParams(itemPtr);
2220 if (ktime_DateToLong(dateString, expDate) == 0) {
2221 *expType = BC_ABS_EXPDATE;
2222 code = ktime_DateToLong(dateString, expDate);
2225 } else if (ParseRelDate(dateString, &kt) == 0) {
2226 *expType = BC_REL_EXPDATE;
2227 *expDate = ktimeRelDate_ToLong(&kt);
2239 /* database lookup command and routines */
2242 * Currently a single option, volumename to search for. Reports
2243 * all dumps containing the specified volume
2246 bc_dblookupCmd(struct cmd_syndesc *as, void *arock)
2248 struct cmd_item *ciptr;
2251 ciptr = as->parms[0].items;
2252 if (ciptr == 0) /* no argument specified */
2255 code = DBLookupByVolume(ciptr->data);
2261 /* for ubik version */
2263 bc_dbVerifyCmd(struct cmd_syndesc *as, void *arock)
2269 struct hostent *hostPtr;
2273 extern struct udbHandleS udbHandle;
2275 detail = (as->parms[0].items ? 1 : 0); /* print more details */
2278 ubik_Call(BUDB_DbVerify, udbHandle.uh_client, 0, &status, &orphans,
2282 afs_com_err(whoami, code, "; Unable to verify database");
2286 /* verification call succeeded */
2289 printf("Database OK\n");
2291 afs_com_err(whoami, status, "; Database is NOT_OK");
2294 printf("Orphan blocks %d\n", orphans);
2297 printf("Unable to lookup host id\n");
2299 hostPtr = gethostbyaddr((char *)&host, sizeof(host), AF_INET);
2301 printf("Database checker was %d.%d.%d.%d\n",
2302 ((host & 0xFF000000) >> 24), ((host & 0xFF0000) >> 16),
2303 ((host & 0xFF00) >> 8), (host & 0xFF));
2305 printf("Database checker was %s\n", hostPtr->h_name);
2308 return ((status ? -1 : 0));
2312 * Delete a dump. If port is >= 0, it means try to delete from XBSA server
2315 deleteDump(afs_uint32 dumpid, /* The dumpid to delete */
2316 afs_int32 port, /* port==-1 means don't go to butc */
2319 afs_int32 code = 0, tcode;
2320 struct budb_dumpEntry dumpEntry;
2321 struct rx_connection *tconn = 0;
2322 afs_int32 i, taskflag, xbsadump;
2323 statusP statusPtr = 0;
2324 budb_dumpsList dumps;
2327 /* If the port is set, we will try to send a delete request to the butc */
2329 tcode = bc_UpdateHosts();
2331 afs_com_err(whoami, tcode, "; Can't retrieve tape hosts");
2335 /* Find the dump in the backup database */
2336 tcode = bcdb_FindDumpByID(dumpid, &dumpEntry);
2338 afs_com_err(whoami, tcode, "; Unable to locate dumpID %u in database",
2342 xbsadump = (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA));
2344 /* If dump is to an XBSA server, connect to butc and send it
2345 * the dump to delete. Butc will contact the XBSA server.
2346 * The dump will not be an appended dump because XBSA butc
2347 * does not support the append option.
2349 if (xbsadump && dumpEntry.nVolumes) {
2350 tcode = ConnectButc(bc_globalConfig, port, &tconn);
2354 tcode = TC_DeleteDump(tconn, dumpid, &taskId);
2356 if (tcode == RXGEN_OPCODE)
2357 tcode = BC_VERSIONFAIL;
2358 afs_com_err(whoami, tcode,
2359 "; Unable to delete dumpID %u via butc", dumpid);
2363 statusPtr = createStatusNode();
2365 statusPtr->taskId = taskId;
2366 statusPtr->port = port;
2367 statusPtr->jobNumber = bc_jobNumber();
2368 statusPtr->flags |= (SILENT | NOREMOVE); /* No msg & keep statusPtr */
2369 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2370 sprintf(statusPtr->taskName, "DeleteDump");
2373 /* Wait for task to finish */
2374 taskflag = waitForTask(taskId);
2375 if (taskflag & (TASK_ERROR | ABORT_DONE)) {
2376 afs_com_err(whoami, BUTX_DELETEOBJFAIL,
2377 "; Unable to delete dumpID %u via butc", dumpid);
2378 ERROR(BUTX_DELETEOBJFAIL); /* the task failed */
2385 deleteStatusNode(statusPtr); /* Clean up statusPtr - because NOREMOVE */
2387 rx_DestroyConnection(tconn); /* Destroy the connection */
2389 /* Remove the dump from the backup database */
2390 if (!code || force) {
2391 dumps.budb_dumpsList_len = 0;
2392 dumps.budb_dumpsList_val = 0;
2394 tcode = bcdb_deleteDump(dumpid, 0, 0, &dumps);
2396 afs_com_err(whoami, tcode,
2397 "; Unable to delete dumpID %u from database", dumpid);
2398 dumps.budb_dumpsList_len = 0;
2403 /* Display the dumps that were deleted - includes appended dumps */
2404 for (i = 0; i < dumps.budb_dumpsList_len; i++)
2405 printf(" %u%s\n", dumps.budb_dumpsList_val[i],
2406 (i > 0) ? " Appended Dump" : "");
2407 if (dumps.budb_dumpsList_val)
2408 free(dumps.budb_dumpsList_val);
2415 * Delete a specified dump from the database
2417 * dump id - single required arg as param 0.
2420 bc_deleteDumpCmd(struct cmd_syndesc *as, void *arock)
2424 afs_int32 rcode = 0;
2425 afs_int32 groupId = 0, havegroupid, sflags, noexecute;
2426 struct cmd_item *ti;
2427 afs_uint32 fromTime = 0, toTime = 0, havetime = 0;
2429 budb_dumpsList dumps, flags;
2431 afs_int32 port = -1, force;
2433 /* Must specify at least one of -dumpid, -from, or -to */
2434 if (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items
2435 && !as->parms[4].items) {
2436 afs_com_err(whoami, 0, "Must specify at least one field");
2440 /* Must have -to option with -from option */
2441 if (as->parms[1].items && !as->parms[2].items) {
2442 afs_com_err(whoami, 0, "Must specify '-to' field with '-from' field");
2446 /* Get the time to delete from */
2447 if (as->parms[1].items) { /* -from */
2448 timeString = concatParams(as->parms[1].items);
2453 * Now parse this string for the time to start.
2455 code = ktime_DateToLong(timeString, &fromTime);
2458 afs_com_err(whoami, 0, "Can't parse 'from' date and time");
2459 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2465 port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -port */
2466 if (as->parms[5].items) /* -dbonly */
2469 force = (as->parms[6].items ? 1 : 0);
2471 havegroupid = (as->parms[4].items ? 1 : 0);
2473 groupId = atoi(as->parms[4].items->data);
2475 noexecute = (as->parms[7].items ? 1 : 0);
2477 /* Get the time to delete to */
2478 if (as->parms[2].items) { /* -to */
2479 timeString = concatParams(as->parms[2].items);
2484 * Now parse this string for the time to start. Simce
2485 * times are at minute granularity, add 59 seconds.
2487 code = ktime_DateToLong(timeString, &toTime);
2490 afs_com_err(whoami, 0, "Can't parse 'to' date and time");
2491 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2498 if (fromTime > toTime) {
2499 afs_com_err(whoami, 0,
2500 "'-from' date/time cannot be later than '-to' date/time");
2504 /* Remove speicific dump ids - if any */
2505 printf("The following dumps %s deleted:\n",
2506 (noexecute ? "would have been" : "were"));
2507 for (ti = as->parms[0].items; ti != 0; ti = ti->next) { /* -dumpid */
2508 dumpid = atoi(ti->data);
2510 code = deleteDump(dumpid, port, force);
2512 printf(" %u\n", dumpid);
2517 * Now remove dumps between to and from dates.
2519 if (havegroupid || havetime) {
2520 dumps.budb_dumpsList_len = 0;
2521 dumps.budb_dumpsList_val = 0;
2522 flags.budb_dumpsList_len = 0;
2523 flags.budb_dumpsList_val = 0;
2526 sflags |= BUDB_OP_GROUPID;
2528 sflags |= BUDB_OP_DATES;
2531 bcdb_listDumps(sflags, groupId, fromTime, toTime, &dumps, &flags);
2533 afs_com_err(whoami, code,
2534 "; Error while deleting dumps from %u to %u", fromTime,
2539 for (i = 0; i < dumps.budb_dumpsList_len; i++) {
2540 if (flags.budb_dumpsList_val[i] & BUDB_OP_DBDUMP)
2544 if (flags.budb_dumpsList_val[i] & BUDB_OP_APPDUMP)
2546 code = deleteDump(dumps.budb_dumpsList_val[i], port, force);
2547 /* Ignore code and continue */
2549 printf(" %u%s%s\n", dumps.budb_dumpsList_val[i],
2551 budb_dumpsList_val[i] & BUDB_OP_APPDUMP) ?
2552 " Appended Dump" : "",
2554 budb_dumpsList_val[i] & BUDB_OP_DBDUMP) ?
2555 " Database Dump" : "");
2560 if (dumps.budb_dumpsList_val)
2561 free(dumps.budb_dumpsList_val);
2562 dumps.budb_dumpsList_len = 0;
2563 dumps.budb_dumpsList_val = 0;
2564 if (flags.budb_dumpsList_val)
2565 free(flags.budb_dumpsList_val);
2566 flags.budb_dumpsList_len = 0;
2567 flags.budb_dumpsList_val = 0;
2574 bc_saveDbCmd(struct cmd_syndesc *as, void *arock)
2576 struct rx_connection *tconn;
2577 afs_int32 portOffset = 0;
2584 code = bc_UpdateHosts();
2586 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2590 if (as->parms[0].items) {
2591 portOffset = getPortOffset(as->parms[0].items->data);
2596 /* Get the time to delete to */
2597 if (as->parms[1].items) {
2598 timeString = concatParams(as->parms[1].items);
2603 * Now parse this string for the time. Since
2604 * times are at minute granularity, add 59 seconds.
2606 code = ktime_DateToLong(timeString, &toTime);
2609 afs_com_err(whoami, 0, "Can't parse '-archive' date and time");
2610 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2617 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2621 code = TC_SaveDb(tconn, toTime, &taskId);
2623 afs_com_err(whoami, code, "; Failed to save database");
2627 /* create status monitor block */
2628 statusPtr = createStatusNode();
2630 statusPtr->taskId = taskId;
2631 statusPtr->port = portOffset;
2632 statusPtr->jobNumber = bc_jobNumber();
2633 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2634 sprintf(statusPtr->taskName, "SaveDb");
2638 rx_DestroyConnection(tconn);
2643 bc_restoreDbCmd(struct cmd_syndesc *as, void *arock)
2645 struct rx_connection *tconn;
2646 afs_int32 portOffset = 0;
2651 code = bc_UpdateHosts();
2653 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2657 if (as->parms[0].items) {
2658 portOffset = getPortOffset(as->parms[0].items->data);
2663 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2667 code = TC_RestoreDb(tconn, &taskId);
2669 afs_com_err(whoami, code, "; Failed to restore database");
2673 /* create status monitor block */
2674 statusPtr = createStatusNode();
2676 statusPtr->taskId = taskId;
2677 statusPtr->port = portOffset;
2678 statusPtr->jobNumber = bc_jobNumber();
2679 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2680 sprintf(statusPtr->taskName, "RestoreDb");
2684 rx_DestroyConnection(tconn);
2688 /* ----------------------------------
2689 * supporting routines for database examination
2690 * ----------------------------------
2693 /* structures and defines for DBLookupByVolume */
2695 #define DBL_MAX_VOLUMES 20 /* max. for each dump */
2697 /* dumpedVol - saves interesting information so that we can print it out
2702 struct dumpedVol *next;
2704 afs_int32 initialDumpID;
2705 char tapeName[BU_MAXTAPELEN];
2708 afs_int32 createTime;
2709 afs_int32 incTime; /* actually the clone time */
2712 /* -----------------------------------------
2713 * routines for examining the database
2714 * -----------------------------------------
2718 * Lookup the volumename in the backup database and print the results
2720 * volumeName - volume to lookup
2724 DBLookupByVolume(char *volumeName)
2726 struct budb_dumpEntry dumpEntry;
2727 struct budb_volumeEntry volumeEntry[DBL_MAX_VOLUMES];
2728 afs_int32 numEntries;
2729 afs_int32 tapedumpid;
2730 afs_int32 last, next;
2732 struct dumpedVol *dvptr = 0;
2733 struct dumpedVol *tempPtr = 0;
2736 char vname[BU_MAXNAMELEN];
2739 for (pass = 0; pass < 2; pass++) {
2741 /* On second pass, search for backup volume */
2743 if (!BackupName(volumeName)) {
2744 strcpy(vname, volumeName);
2745 strcat(vname, ".backup");
2753 while (next != -1) { /*w */
2755 bcdb_LookupVolume(volumeName, &volumeEntry[0], last, &next,
2756 DBL_MAX_VOLUMES, &numEntries);
2760 /* add the volumes to the list */
2761 for (i = 0; i < numEntries; i++) { /*f */
2762 struct dumpedVol *insPtr, **prevPtr;
2765 (struct dumpedVol *)malloc(sizeof(struct dumpedVol));
2769 memset(tempPtr, 0, sizeof(*tempPtr));
2770 tempPtr->incTime = volumeEntry[i].clone;
2771 tempPtr->dumpID = volumeEntry[i].dump;
2772 strncpy(tempPtr->tapeName, volumeEntry[i].tape,
2775 /* check if we need to null terminate it - just for safety */
2776 if (strlen(volumeEntry[i].tape) >= BU_MAXTAPELEN)
2777 tempPtr->tapeName[BU_MAXTAPELEN - 1] = 0;
2779 code = bcdb_FindDumpByID(tempPtr->dumpID, &dumpEntry);
2785 tempPtr->initialDumpID = dumpEntry.initialDumpID;
2786 tempPtr->parent = dumpEntry.parent;
2787 tempPtr->level = dumpEntry.level;
2788 tempPtr->createTime = dumpEntry.created;
2790 /* add volume to list in reverse chronological order */
2794 while ((insPtr != 0)
2795 && (insPtr->createTime > tempPtr->createTime)
2797 prevPtr = &insPtr->next;
2798 insPtr = insPtr->next;
2801 /* now at the right place - insert the block */
2802 tempPtr->next = *prevPtr;
2812 ("DumpID lvl parentID creation date clone date tape name\n");
2813 for (tempPtr = dvptr; tempPtr; tempPtr = tempPtr->next) {
2814 /* For the user, the tape name is its name and initial dump id */
2816 (tempPtr->initialDumpID ? tempPtr->initialDumpID : tempPtr->
2819 /* beware the static items in compactDateString */
2820 compactDateString(&tempPtr->createTime, ds, 50);
2821 printf("%-9d %-2d %-9d %16s", tempPtr->dumpID, tempPtr->level,
2822 tempPtr->parent, ds);
2823 compactDateString(&tempPtr->incTime, ds, 50);
2824 printf(" %16s %s (%u)\n", ds, tempPtr->tapeName, tapedumpid);
2830 for (tempPtr = dvptr; tempPtr; tempPtr = dvptr) {
2831 dvptr = dvptr->next;
2836 afs_com_err(whoami, code, "");
2840 /* structures for dumpInfo */
2843 struct volumeLink *nextVolume;
2844 struct budb_volumeEntry volumeEntry;
2848 struct tapeLink *nextTape;
2849 struct budb_tapeEntry tapeEntry;
2850 struct volumeLink *firstVolume;
2855 * print information about a dump and all its tapes and volumes.
2859 dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
2861 struct budb_dumpEntry dumpEntry;
2862 struct tapeLink *head = 0;
2863 struct tapeLink *tapeLinkPtr, *lastTapeLinkPtr;
2864 struct volumeLink **link, *volumeLinkPtr, *lastVolumeLinkPtr;
2867 afs_int32 last, next, dbTime;
2868 afs_int32 tapedumpid;
2876 extern struct udbHandleS udbHandle;
2879 lastTapeLinkPtr = 0;
2881 lastVolumeLinkPtr = 0;
2883 /* first get information about the dump */
2885 code = bcdb_FindDumpByID(dumpid, &dumpEntry);
2889 /* For the user, the tape name is its name and initial dump id */
2890 tapedumpid = (dumpEntry.initialDumpID ? dumpEntry.initialDumpID : dumpid);
2892 /* Is this a database dump id or not */
2893 if (strcmp(dumpEntry.name, DUMP_TAPE_NAME) == 0)
2898 /* print out the information about the dump */
2902 printDumpEntry(&dumpEntry);
2904 time_t t = dumpEntry.created;
2906 printf("Dump: id %u, created: %s\n", dumpEntry.id,
2909 printf("Dump: id %u, level %d, volumes %d, created: %s\n",
2910 dumpEntry.id, dumpEntry.level, dumpEntry.nVolumes,
2914 if (!detailFlag && (strlen(dumpEntry.tapes.tapeServer) > 0)
2915 && (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA))) {
2916 printf("Backup Service: TSM: Server: %s\n",
2917 dumpEntry.tapes.tapeServer);
2920 /* now get the list of tapes */
2921 for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) { /*f */
2922 tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
2924 afs_com_err(whoami, BC_NOMEM, "");
2928 memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
2929 code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
2936 /* add this tape to previous chain */
2937 if (lastTapeLinkPtr) {
2938 lastTapeLinkPtr->nextTape = tapeLinkPtr;
2939 lastTapeLinkPtr = tapeLinkPtr;
2944 lastTapeLinkPtr = head;
2948 while (next != -1) { /*wn */
2949 vl.budb_volumeList_len = 0;
2950 vl.budb_volumeList_val = 0;
2953 /* now get all the volumes in this dump. */
2954 code = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client, UF_SINGLESERVER, BUDB_MAJORVERSION, BUDB_OP_DUMPID | BUDB_OP_TAPENAME, tapeLinkPtr->tapeEntry.name, /* tape name */
2955 dumpid, /* dumpid (not initial dumpid) */
2958 &next, /* nextindex */
2959 &dbTime, /* update time */
2963 if (code == BUDB_ENDOFLIST) { /* 0 volumes on tape */
2970 for (i = 0; i < vl.budb_volumeList_len; i++) {
2971 link = &tapeLinkPtr->firstVolume;
2974 (struct volumeLink *)malloc(sizeof(struct volumeLink));
2975 if (!volumeLinkPtr) {
2976 afs_com_err(whoami, BC_NOMEM, "");
2979 memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
2981 memcpy(&volumeLinkPtr->volumeEntry,
2982 &vl.budb_volumeList_val[i],
2983 sizeof(struct budb_volumeEntry));
2985 /* now insert it onto the right place */
2987 && (volumeLinkPtr->volumeEntry.position >
2988 (*link)->volumeEntry.position)) {
2989 link = &((*link)->nextVolume);
2992 /* now link it in */
2993 volumeLinkPtr->nextVolume = *link;
2994 *link = volumeLinkPtr;
2997 if (vl.budb_volumeList_val)
2998 free(vl.budb_volumeList_val);
3002 for (tapeLinkPtr = head; tapeLinkPtr; tapeLinkPtr = tapeLinkPtr->nextTape) {
3006 printTapeEntry(&tapeLinkPtr->tapeEntry);
3008 printf("Tape: name %s (%u)\n", tapeLinkPtr->tapeEntry.name,
3010 printf("nVolumes %d, ", tapeLinkPtr->tapeEntry.nVolumes);
3011 compactDateString(&tapeLinkPtr->tapeEntry.written, ds, 50);
3012 printf("created %16s", ds);
3013 if (tapeLinkPtr->tapeEntry.expires != 0) {
3014 compactDateString(&tapeLinkPtr->tapeEntry.expires, ds, 50);
3015 printf(", expires %16s", ds);
3020 /* print out all the volumes */
3022 /* print header for volume listing - db dumps have no volumes */
3023 if ((detailFlag == 0) && !dbDump)
3024 printf("%4s %16s %9s %-s\n", "Pos", "Clone time", "Nbytes",
3027 for (volumeLinkPtr = tapeLinkPtr->firstVolume; volumeLinkPtr;
3028 volumeLinkPtr = volumeLinkPtr->nextVolume) {
3030 printf("\nVolume\n");
3032 printVolumeEntry(&volumeLinkPtr->volumeEntry);
3034 compactDateString(&volumeLinkPtr->volumeEntry.clone, ds, 50),
3035 printf("%4d %s %10u %16s\n",
3036 volumeLinkPtr->volumeEntry.position, ds,
3037 volumeLinkPtr->volumeEntry.nBytes,
3038 volumeLinkPtr->volumeEntry.name);
3045 afs_com_err("dumpInfo", code, "; Can't get dump information");
3047 /* free all allocated structures */
3049 while (tapeLinkPtr) {
3050 volumeLinkPtr = tapeLinkPtr->firstVolume;
3051 while (volumeLinkPtr) {
3052 lastVolumeLinkPtr = volumeLinkPtr;
3053 volumeLinkPtr = volumeLinkPtr->nextVolume;
3054 free(lastVolumeLinkPtr);
3057 lastTapeLinkPtr = tapeLinkPtr;
3058 tapeLinkPtr = tapeLinkPtr->nextTape;
3059 free(lastTapeLinkPtr);
3065 compareDump(struct budb_dumpEntry *ptr1, struct budb_dumpEntry *ptr2)
3067 if (ptr1->created < ptr2->created)
3069 else if (ptr1->created > ptr2->created)
3075 printRecentDumps(int ndumps)
3078 afs_int32 nextindex, index = 0;
3081 struct budb_dumpEntry *dumpPtr;
3085 extern struct udbHandleS udbHandle;
3087 do { /* while (nextindex != -1) */
3088 /* initialize the dump list */
3089 dl.budb_dumpList_len = 0;
3090 dl.budb_dumpList_val = 0;
3092 /* outline algorithm */
3093 code = ubik_Call(BUDB_GetDumps, udbHandle.uh_client, 0, BUDB_MAJORVERSION, BUDB_OP_NPREVIOUS, "", /* no name */
3097 &nextindex, &dbTime, &dl);
3099 if (code == BUDB_ENDOFLIST)
3101 afs_com_err("dumpInfo", code, "; Can't get dump information");
3105 /* No need to sort, it's already sorted */
3107 if (dl.budb_dumpList_len && (index == 0))
3108 printf("%10s %10s %2s %-16s %2s %5s dump name\n", "dumpid",
3109 "parentid", "lv", "created", "nt", "nvols");
3111 dumpPtr = dl.budb_dumpList_val;
3112 for (i = 1; i <= dl.budb_dumpList_len; i++) {
3113 compactDateString(&dumpPtr->created, ds, 50),
3114 printf("%10u %10u %-2d %16s %2d %5d %s", dumpPtr->id,
3115 dumpPtr->parent, dumpPtr->level, ds,
3116 dumpPtr->tapes.maxTapes - dumpPtr->tapes.b + 1,
3117 dumpPtr->nVolumes, dumpPtr->name);
3118 if (dumpPtr->initialDumpID) /* an appended dump */
3119 printf(" (%u)", dumpPtr->initialDumpID);
3120 else if (dumpPtr->appendedDumpID) /* has appended dumps */
3121 printf(" (%u)", dumpPtr->id);
3127 if (dl.budb_dumpList_val)
3128 free(dl.budb_dumpList_val);
3130 } while (nextindex != -1);
3136 * list the dumps and contens of the dumps.
3142 bc_dumpInfoCmd(struct cmd_syndesc *as, void *arock)
3145 afs_int32 detailFlag;
3149 if (as->parms[0].items) {
3150 if (as->parms[1].items) {
3151 afs_com_err(whoami, 0,
3152 "These options are exclusive - select only one");
3155 ndumps = atoi(as->parms[0].items->data);
3157 afs_com_err(whoami, 0, "Must provide a positive number");
3161 code = printRecentDumps(ndumps);
3162 } else if (as->parms[1].items) {
3163 detailFlag = (as->parms[2].items ? 1 : 0); /* 1 = detailed listing */
3164 dumpid = atoi(as->parms[1].items->data);
3165 code = dumpInfo(dumpid, detailFlag);
3167 code = printRecentDumps(10);