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>
17 #if defined(AFS_LINUX24_ENV)
18 #define _REGEX_RE_COMP
20 #include <sys/types.h>
21 #if defined(AFS_LINUX24_ENV)
28 #include <sys/socket.h>
29 #include <netinet/in.h>
33 #include <afs/com_err.h>
36 #include <afs/bubasics.h> /* PA */
37 #include <afs/volser.h>
38 #include <afs/voldefs.h> /* PA */
39 #include <afs/vldbint.h> /* PA */
40 #include <afs/ktime.h> /* PA */
45 #include <afs/tcdata.h>
47 #include <afs/vsutils_prototypes.h>
49 #include "error_macros.h"
50 #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 */
430 struct bc_volumeDump *tvd; /*Ptr to new dump instance */
431 struct bc_volumeEntry *tve, *ctve; /*Ptr to new volume entry instance */
432 char patt[256]; /*Composite regex; also, target string */
433 int volType = 0; /*Type of volume that worked */
434 afs_int32 index; /*Current VLDB entry index */
435 afs_int32 count; /*Needed by VL_ListEntry() */
436 afs_int32 next_index; /*Next index to list */
437 struct vldbentry entry; /*VLDB entry */
438 int srvpartpair; /*Loop counter: server/partition pair */
442 struct serversort *servers = 0, *ss = 0;
443 struct partitionsort *ps = 0;
445 *avols = (struct bc_volumeDump *)0;
446 ctve = (struct bc_volumeEntry *)0; /* no compiled entry */
448 /* For each vldb entry.
449 * Variable next_index is set to the index of the next VLDB entry
450 * in the enumeration.
452 for (index = 0; 1; index = next_index) { /*w */
453 memset(&entry, 0, sizeof(entry));
454 code = ubik_Call(VL_ListEntry, /*Routine to invoke */
455 uclient, /*Ubik client structure */
457 index, /*Current index */
458 &count, /*Ptr to working variable */
459 &next_index, /*Ptr to next index value to list */
460 &entry); /*Ptr to entry to fill */
464 break; /* If the next index is invalid, bail out now. */
466 /* For each entry in the volume set */
467 found = 0; /* No match in volume set yet */
468 for (tve = avs->ventries; tve; tve = tve->next) { /*ve */
469 /* for each server in the vldb entry */
470 for (srvpartpair = 0; srvpartpair < entry.nServers; srvpartpair++) { /*s */
471 /* On the same server */
472 if (tve->server.sin_addr.s_addr
473 && !VLDB_IsSameAddrs(tve->server.sin_addr.s_addr,
474 entry.serverNumber[srvpartpair],
482 /* On the same partition */
483 if ((tve->partition != -1)
484 && (tve->partition != entry.serverPartition[srvpartpair]))
487 /* If the volume entry is not compiled, then compile it */
489 sprintf(patt, "^%s$", tve->name);
490 errm = (char *)re_comp(patt);
492 afs_com_err(whoami, 0,
493 "Can't compile regular expression '%s': %s",
500 /* If the RW name matches the volume set entry, take
501 * it and exit. First choice is to use the RW volume.
503 if (entry.serverFlags[srvpartpair] & ITSRWVOL) {
504 if (entry.flags & RW_EXISTS) {
505 sprintf(patt, "%s", entry.name);
506 code = re_exec(patt);
509 foundentry = srvpartpair;
515 /* If the BK name matches the volume set entry, take
516 * it and exit. Second choice is to use the BK volume.
518 if (entry.flags & BACK_EXISTS) {
519 sprintf(patt, "%s.backup", entry.name);
520 code = re_exec(patt);
523 foundentry = srvpartpair;
530 /* If the RO name matches the volume set entry, remember
531 * it, but continue searching. Further entries may be
532 * RW or backup entries that will match.
534 else if (!found && (entry.serverFlags[srvpartpair] & ITSROVOL)
535 && (entry.flags & RO_EXISTS)) {
536 sprintf(patt, "%s.readonly", entry.name);
537 code = re_exec(patt);
540 foundentry = srvpartpair;
546 afs_com_err(whoami, 0, "Internal error in regex package");
549 /* If found a match, then create a new volume dump entry */
551 /* Find server and partition structure to hang the entry off of */
553 getSPEntries(entry.serverNumber[foundentry],
554 entry.serverPartition[foundentry], &servers,
557 afs_com_err(whoami, code, "");
562 tvd = (struct bc_volumeDump *)
563 malloc(sizeof(struct bc_volumeDump));
565 afs_com_err(whoami, BC_NOMEM, "");
568 memset(tvd, 0, sizeof(*tvd));
570 tvd->name = (char *)malloc(strlen(entry.name) + 10);
572 afs_com_err(whoami, BC_NOMEM, "");
577 strcpy(tvd->name, entry.name);
578 if (volType == BACKVOL)
579 strcat(tvd->name, ".backup");
580 else if (volType == ROVOL)
581 strcat(tvd->name, ".readonly");
582 tvd->vid = entry.volumeId[volType];
584 tvd->volType = volType;
585 tvd->partition = entry.serverPartition[foundentry];
586 tvd->server.sin_addr.s_addr = entry.serverNumber[foundentry];
587 tvd->server.sin_port = 0; /* default FS port */
588 tvd->server.sin_family = AF_INET;
590 /* String tvd off of partition struct */
591 tvd->next = ps->vdlist;
594 ps->lastvdlist = tvd;
601 /* Randomly link the volumedump entries together */
602 randSPEntries(servers, avols);
604 fprintf(stderr, "Total number of volumes : %u\n", total);
606 } /*EvalVolumeSet1 */
609 * print out a date in compact format, 16 chars, format is
612 * date_long - ptr to a long containing the time
614 * ptr to a string containing a representation of the date
617 compactDateString(afs_uint32 *date_long, char *string, afs_int32 size)
624 if (*date_long == NEVERDATE) {
625 sprintf(string, "NEVER");
627 time_t t = *date_long;
628 ltime = localtime(&t);
629 /* prints date in U.S. format of mm/dd/yyyy */
630 strftime(string, size, "%m/%d/%Y %H:%M", ltime);
636 bc_SafeATOI(char *anum)
640 for (; *anum; anum++) {
641 if ((*anum < '0') || (*anum > '9'))
643 total = (10 * total) + (afs_int32) (*anum - '0');
649 * Take a string and parse it for a number (could be float) followed
650 * by a character representing the units (K,M,G,T). Default is 'K'.
651 * Return the size in KBytes.
654 bc_FloatATOI(char *anum)
658 afs_int32 fraction = 0; /* > 0 if past the decimal */
660 for (; *anum; anum++) {
661 if ((*anum == 't') || (*anum == 'T')) {
662 total *= 1024 * 1024 * 1024;
665 if ((*anum == 'g') || (*anum == 'G')) {
666 total *= 1024 * 1024;
669 if ((*anum == 'm') || (*anum == 'M')) {
673 if ((*anum == 'k') || (*anum == 'K')) {
680 if ((*anum < '0') || (*anum > '9'))
684 total = (10. * total) + (float)(*anum - '0');
686 total += ((float)(*anum - '0')) / (float)fraction;
691 total += 0.5; /* Round up */
692 if (total > 0x7fffffff) /* Don't go over 2G */
694 rtotal = (afs_int32) total;
698 /* make a copy of a string so that it can be freed later */
700 bc_CopyString(char *astring)
706 return (NULL); /* propagate null strings easily */
707 tlen = strlen(astring);
708 tp = (char *)malloc(tlen + 1); /* don't forget the terminating null */
710 afs_com_err(whoami, BC_NOMEM, "");
719 * Concatenates the parameters of an option and returns the string.
724 concatParams(struct cmd_item *itemPtr)
726 struct cmd_item *tempPtr;
727 afs_int32 length = 0;
730 /* compute the length of string required */
731 for (tempPtr = itemPtr; tempPtr; tempPtr = tempPtr->next) {
732 length += strlen(tempPtr->data);
733 length++; /* space or null terminator */
736 if (length == 0) { /* no string (0 length) */
737 afs_com_err(whoami, 0, "Can't have zero length date and time string");
741 string = (char *)malloc(length); /* allocate the string */
743 afs_com_err(whoami, BC_NOMEM, "");
748 tempPtr = itemPtr; /* now assemble the string */
750 strcat(string, tempPtr->data);
751 tempPtr = tempPtr->next;
756 return (string); /* return the string */
760 * print out an interface status node as received from butc
764 printIfStatus(struct tciStatusS *statusPtr)
766 printf("Task %d: %s: ", statusPtr->taskId, statusPtr->taskName);
767 if (statusPtr->nKBytes)
768 printf("%ld Kbytes transferred", (long unsigned int) statusPtr->nKBytes);
769 if (strlen(statusPtr->volumeName) != 0) {
770 if (statusPtr->nKBytes)
772 printf("volume %s", statusPtr->volumeName);
777 if (statusPtr->flags & ABORT_REQUEST)
778 printf(" [abort request rcvd]");
780 if (statusPtr->flags & ABORT_DONE)
781 printf(" [abort complete]");
783 if (statusPtr->flags & OPR_WAIT)
784 printf(" [operator wait]");
786 if (statusPtr->flags & CALL_WAIT)
787 printf(" [callout in progress]");
789 if (statusPtr->flags & DRIVE_WAIT)
790 printf(" [drive wait]");
792 if (statusPtr->flags & TASK_DONE)
798 getPortOffset(char *port)
800 afs_int32 portOffset;
802 portOffset = bc_SafeATOI(port);
804 if (portOffset < 0) {
805 afs_com_err(whoami, 0, "Can't decode port offset '%s'", port);
807 } else if (portOffset > BC_MAXPORTOFFSET) {
808 afs_com_err(whoami, 0, "%u exceeds max port offset %u", portOffset,
815 /* bc_GetTapeStatusCmd
816 * display status of all tasks on a particular tape coordinator
819 bc_GetTapeStatusCmd(struct cmd_syndesc *as, void *arock)
822 struct rx_connection *tconn;
823 afs_int32 portOffset = 0;
828 struct tciStatusS status;
830 code = bc_UpdateHosts();
832 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
836 if (as->parms[0].items) {
837 portOffset = getPortOffset(as->parms[0].items->data);
842 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
846 flags = TSK_STAT_FIRST;
850 while ((flags & TSK_STAT_END) == 0) {
851 code = TC_ScanStatus(tconn, &taskId, &status, &flags);
853 if (code == TC_NOTASKS)
855 afs_com_err(whoami, code, "; Can't get status from butc");
858 if ((flags & TSK_STAT_NOTFOUND))
859 break; /* Can't find the task id */
860 flags &= ~TSK_STAT_FIRST; /* turn off flag */
862 printIfStatus(&status);
867 printf("Tape coordinator is idle\n");
869 if (flags & TSK_STAT_ADSM)
870 printf("TSM Tape coordinator\n");
871 else if (flags & TSK_STAT_XBSA)
872 printf("XBSA Tape coordinator\n");
877 extern struct Lock dispatchLock;
880 * wait for all jobs to terminate
883 bc_WaitForNoJobs(void)
886 int usefulJobRunning = 1;
888 extern dlqlinkT statusHead;
890 afs_com_err(whoami, 0, "waiting for job termination");
892 while (usefulJobRunning) {
893 usefulJobRunning = (dlqEmpty(&statusHead) ? 0 : 1);
894 if (dispatchLock.excl_locked)
895 usefulJobRunning = 1;
896 for (i = 0; (!usefulJobRunning && (i < BC_MAXSIMDUMPS)); i++) {
897 if (bc_dumpTasks[i].flags & BC_DI_INUSE)
898 usefulJobRunning = 1;
901 /* Wait 5 seconds and check again */
902 if (usefulJobRunning)
905 return (lastTaskCode);
909 * print status on running jobs
911 * ignored - a null "as" prints only jobs.
914 bc_JobsCmd(struct cmd_syndesc *as, void *arock)
923 extern dlqlinkT statusHead;
925 dlqInit(&atJobsHead);
928 ptr = (&statusHead)->dlq_next;
929 while (ptr != &statusHead) {
930 statusPtr = (statusP) ptr;
933 if (statusPtr->scheduledDump) {
934 dlqUnlink((dlqlinkP) statusPtr);
935 dlqLinkb(&atJobsHead, (dlqlinkP) statusPtr);
937 printf("Job %d:", statusPtr->jobNumber);
939 printf(" %s", statusPtr->taskName);
941 if (statusPtr->dbDumpId)
942 printf(": DumpID %u", statusPtr->dbDumpId);
943 if (statusPtr->nKBytes)
944 printf(", %ld Kbytes", afs_cast_int32(statusPtr->nKBytes));
945 if (strlen(statusPtr->volumeName) != 0)
946 printf(", volume %s", statusPtr->volumeName);
948 if (statusPtr->flags & CONTACT_LOST)
949 printf(" [butc contact lost]");
951 if (statusPtr->flags & ABORT_REQUEST)
952 printf(" [abort request]");
954 if (statusPtr->flags & ABORT_SENT)
955 printf(" [abort sent]");
957 if (statusPtr->flags & OPR_WAIT)
958 printf(" [operator wait]");
960 if (statusPtr->flags & CALL_WAIT)
961 printf(" [callout in progress]");
963 if (statusPtr->flags & DRIVE_WAIT)
964 printf(" [drive wait]");
970 * Now print the scheduled dumps.
972 if (!dlqEmpty(&statusHead) && as)
973 printf("\n"); /* blank line between running and scheduled dumps */
976 while (!dlqEmpty(&atJobsHead)) {
977 ptr = (&atJobsHead)->dlq_next;
978 youngest = (statusP) ptr;
981 while (ptr != &atJobsHead) { /* Find the dump that starts the earliest */
982 statusPtr = (statusP) ptr;
983 if (statusPtr->scheduledDump < youngest->scheduledDump)
984 youngest = statusPtr;
988 /* Print token expiration time */
989 if ((ttoken.endTime > prevTime)
990 && (ttoken.endTime <= youngest->scheduledDump) && as
991 && (ttoken.endTime != NEVERDATE)) {
992 if (ttoken.endTime > time(0)) {
993 compactDateString(&ttoken.endTime, ds, 50);
994 printf(" %16s: TOKEN EXPIRATION\n", ds);
996 printf(" TOKEN HAS EXPIRED\n");
999 prevTime = youngest->scheduledDump;
1001 /* Print the info */
1002 compactDateString(&youngest->scheduledDump, ds, 50);
1003 printf("Job %d:", youngest->jobNumber);
1004 printf(" %16s: %s", ds, youngest->cmdLine);
1007 /* return to original list */
1008 dlqUnlink((dlqlinkP) youngest);
1009 dlqLinkb(&statusHead, (dlqlinkP) youngest);
1012 /* Print token expiration time if havn't already */
1013 if ((ttoken.endTime == NEVERDATE) && as)
1014 printf(" : TOKEN NEVER EXPIRES\n");
1015 else if ((ttoken.endTime > prevTime) && as) {
1016 if (ttoken.endTime > time(0)) {
1017 compactDateString(&ttoken.endTime, ds, 50);
1018 printf(" %16s: TOKEN EXPIRATION\n", ds);
1020 printf(" : TOKEN HAS EXPIRED\n");
1029 bc_KillCmd(struct cmd_syndesc *as, void *arock)
1033 struct bc_dumpTask *td;
1040 extern dlqlinkT statusHead;
1042 tp = as->parms[0].items->data;
1043 if (strchr(tp, '.') == 0) {
1044 slot = bc_SafeATOI(tp);
1046 afs_com_err(whoami, 0, "Bad syntax for number '%s'", tp);
1051 ptr = (&statusHead)->dlq_next;
1052 while (ptr != &statusHead) {
1053 statusPtr = (statusP) ptr;
1054 if (statusPtr->jobNumber == slot) {
1055 statusPtr->flags |= ABORT_REQUEST;
1059 ptr = ptr->dlq_next;
1063 fprintf(stderr, "Job %d not found\n", slot);
1068 for (i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1069 if (td->flags & BC_DI_INUSE) {
1071 strcpy(tbuffer, td->volSetName);
1072 strcat(tbuffer, ".");
1073 strcat(tbuffer, tailCompPtr(td->dumpName));
1074 if (strcmp(tbuffer, tp) == 0)
1078 if (i >= BC_MAXSIMDUMPS) {
1079 afs_com_err(whoami, 0, "Can't find job %s", tp);
1084 statusPtr = findStatus(td->dumpID);
1086 if (statusPtr == 0) {
1087 afs_com_err(whoami, 0, "Can't locate status - internal error");
1091 statusPtr->flags |= ABORT_REQUEST;
1098 /* restore a volume or volumes */
1100 bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
1103 * parm 0 is the new server to restore to
1104 * parm 1 is the new partition to restore to
1105 * parm 2 is volume(s) to restore
1106 * parm 3 is the new extension, if any, for the volume name.
1107 * parm 4 gives the new volume # to restore this volume as (removed).
1108 * parm 4 date is a string representing the date
1110 * We handle four types of restores. If old is set, then we restore the
1111 * volume with the same name and ID. If old is not set, we allocate
1112 * a new volume ID for the restored volume. If a new extension is specified,
1113 * we add that extension to the volume name of the restored volume.
1115 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1116 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1117 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1118 struct bc_volumeDump *tvol; /* temp for same */
1119 struct sockaddr_in destServ; /* machine to which to restore volumes */
1120 afs_int32 destPartition; /* partition to which to restore volumes */
1122 struct cmd_item *ti;
1126 afs_int32 dumpID = 0;
1127 char *newExt, *timeString;
1129 afs_int32 *ports = NULL;
1130 afs_int32 portCount = 0;
1133 code = bc_UpdateHosts();
1135 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1139 /* specified other destination host */
1140 if (as->parms[0].items) {
1141 tp = as->parms[0].items->data;
1142 if (bc_ParseHost(tp, &destServ)) {
1143 afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
1148 /* specified other destination partition */
1149 if (as->parms[1].items) {
1150 tp = as->parms[1].items->data;
1151 if (bc_GetPartitionID(tp, &destPartition)) {
1152 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1157 for (ti = as->parms[2].items; ti; ti = ti->next) {
1158 /* build list of volume items */
1159 tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1161 afs_com_err(whoami, BC_NOMEM, "");
1164 memset(tvol, 0, sizeof(struct bc_volumeDump));
1166 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1168 afs_com_err(whoami, BC_NOMEM, "");
1171 strncpy(tvol->name, ti->data, VOLSER_OLDMAXVOLNAME);
1172 tvol->entry = &tvolumeEntry;
1175 lastVol->next = tvol; /* thread onto end of list */
1177 volsToRestore = tvol;
1181 if (as->parms[4].items) {
1182 timeString = concatParams(as->parms[4].items);
1186 code = ktime_DateToLong(timeString, &fromDate);
1189 afs_com_err(whoami, 0, "Can't parse restore date and time");
1190 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1194 fromDate = 0x7fffffff; /* latest one */
1197 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1200 /* Read all the port offsets into the ports array. The first element in the
1201 * array is for full restore and the rest are for incremental restores
1203 if (as->parms[5].items) {
1204 for (ti = as->parms[5].items; ti; ti = ti->next)
1206 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1208 afs_com_err(whoami, BC_NOMEM, "");
1212 for (ti = as->parms[5].items, i = 0; ti; ti = ti->next, i++) {
1213 ports[i] = getPortOffset(ti->data);
1219 dontExecute = (as->parms[6].items ? 1 : 0); /* -n */
1221 if (as->parms[7].items)
1223 dumpID = atoi(as->parms[7].items->data);
1229 * Perform the call to start the restore.
1232 bc_StartDmpRst(bc_globalConfig, "volume", "restore", volsToRestore,
1233 &destServ, destPartition, fromDate, newExt, oldFlag,
1234 /*parentDump */ dumpID, /*dumpLevel */ 0,
1235 bc_Restorer, ports, portCount,
1236 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1238 afs_com_err(whoami, code, "; Failed to queue restore");
1243 /* restore a whole partition or server */
1245 /* bc_DiskRestoreCmd
1246 * restore a whole partition
1248 * first, reqd - machine (server) to restore
1249 * second, reqd - partition to restore
1254 bc_DiskRestoreCmd(struct cmd_syndesc *as, void *arock)
1256 struct bc_volumeSet tvolumeSet; /* temporary volume set for EvalVolumeSet call */
1257 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1258 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1259 struct sockaddr_in destServ; /* machine to which to restore volumes */
1260 afs_int32 destPartition; /* partition to which to restore volumes */
1266 afs_int32 *ports = NULL;
1267 afs_int32 portCount = 0;
1269 struct bc_volumeDump *prev, *tvol, *nextvol;
1270 struct cmd_item *ti;
1273 /* parm 0 is the server to restore
1274 * parm 1 is the partition to restore
1276 * parm 8 and above as in VolRestoreCmd:
1277 * parm 8 is the new server to restore to
1278 * parm 9 is the new partition to restore to
1281 code = bc_UpdateVolumeSet();
1283 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1286 code = bc_UpdateHosts();
1288 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1292 /* create a volume set corresponding to the volume pattern we've been given */
1293 memset(&tvolumeSet, 0, sizeof(tvolumeSet));
1294 memset(&tvolumeEntry, 0, sizeof(tvolumeEntry));
1295 tvolumeSet.name = "TempVolumeSet";
1296 tvolumeSet.ventries = &tvolumeEntry;
1297 tvolumeEntry.serverName = as->parms[0].items->data;
1298 tvolumeEntry.partname = as->parms[1].items->data;
1300 if (bc_GetPartitionID(tvolumeEntry.partname, &tvolumeEntry.partition)) {
1301 afs_com_err(whoami, 0, "Can't parse partition '%s'",
1302 tvolumeEntry.partname);
1306 if (bc_ParseHost(tvolumeEntry.serverName, &tvolumeEntry.server)) {
1307 afs_com_err(whoami, 0, "Can't locate host '%s'", tvolumeEntry.serverName);
1311 /* specified other destination host */
1312 if (as->parms[8].items) {
1313 tp = as->parms[8].items->data;
1314 if (bc_ParseHost(tp, &destServ)) {
1315 afs_com_err(whoami, 0, "Can't locate destination host '%s'", tp);
1318 } else /* use destination host == original host */
1319 memcpy(&destServ, &tvolumeEntry.server, sizeof(destServ));
1321 /* specified other destination partition */
1322 if (as->parms[9].items) {
1323 tp = as->parms[9].items->data;
1324 if (bc_GetPartitionID(tp, &destPartition)) {
1325 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1328 } else /* use original partition */
1329 destPartition = tvolumeEntry.partition;
1331 tvolumeEntry.name = ".*"; /* match all volumes (this should be a parameter) */
1333 if (as->parms[2].items) {
1334 for (ti = as->parms[2].items; ti; ti = ti->next)
1336 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1338 afs_com_err(whoami, BC_NOMEM, "");
1342 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1343 ports[i] = getPortOffset(ti->data);
1349 newExt = (as->parms[10].items ? as->parms[10].items->data : NULL);
1350 dontExecute = (as->parms[11].items ? 1 : 0); /* -n */
1353 * Expand out the volume set into its component list of volumes, by calling VLDB server.
1356 bc_EvalVolumeSet(bc_globalConfig, &tvolumeSet, &volsToRestore,
1359 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1363 /* Since we want only RW volumes, remove any
1364 * BK or RO volumes from the list.
1366 for (prev = 0, tvol = volsToRestore; tvol; tvol = nextvol) {
1367 nextvol = tvol->next;
1368 if (BackupName(tvol->name)) {
1371 "Will not restore volume %s (its RW does not reside on the partition)\n",
1374 if (tvol == volsToRestore) {
1375 volsToRestore = nextvol;
1377 prev->next = nextvol;
1387 fromDate = 0x7fffffff; /* last one before this date */
1388 oldFlag = 1; /* do restore same volid (and name) */
1391 * Perform the call to start the dump.
1394 bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1395 &destServ, destPartition, fromDate, newExt, oldFlag,
1396 /*parentDump */ 0, /*dumpLevel */ 0,
1397 bc_Restorer, ports, portCount,
1398 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1400 afs_com_err(whoami, code, "; Failed to queue restore");
1405 /* bc_VolsetRestoreCmd
1406 * restore a volumeset or list of volumes.
1410 bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
1417 afs_int32 *ports = NULL;
1418 afs_int32 portCount = 0;
1421 struct bc_volumeSet *volsetPtr; /* Ptr to list of generated volume info */
1422 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1423 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1424 struct sockaddr_in destServer; /* machine to which to restore volume */
1425 afs_int32 destPartition; /* partition to which to restore volumes */
1426 struct cmd_item *ti;
1429 code = bc_UpdateVolumeSet();
1431 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1434 code = bc_UpdateHosts();
1436 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1440 if (as->parms[0].items) {
1441 if (as->parms[1].items) {
1442 afs_com_err(whoami, 0, "Can't have both -name and -file options");
1446 volsetName = as->parms[0].items->data;
1447 volsetPtr = bc_FindVolumeSet(bc_globalConfig, volsetName);
1449 afs_com_err(whoami, 0,
1450 "Can't find volume set '%s' in backup database",
1455 /* Expand out the volume set into its component list of volumes. */
1457 bc_EvalVolumeSet(bc_globalConfig, volsetPtr, &volsToRestore,
1460 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1463 } else if (as->parms[1].items) {
1466 char server[50], partition[50], volume[50], rest[256];
1468 struct bc_volumeDump *tvol;
1470 fd = fopen(as->parms[1].items->data, "r");
1472 afs_com_err(whoami, errno, "; Cannot open file '%s'",
1473 as->parms[1].items->data);
1477 while (fgets(line, 255, fd)) {
1479 sscanf(line, "%s %s %s %s", server, partition, volume, rest);
1485 "Invalid volumeset file format: Wrong number of arguments: Ignoring\n");
1486 fprintf(stderr, " %s", line);
1490 if (bc_ParseHost(server, &destServer)) {
1491 afs_com_err(whoami, 0, "Failed to locate host '%s'", server);
1495 if (bc_GetPartitionID(partition, &destPartition)) {
1496 afs_com_err(whoami, 0,
1497 "Failed to parse destination partition '%s'",
1502 /* Allocate a volumeDump structure and link it in */
1504 (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1505 memset(tvol, 0, sizeof(struct bc_volumeDump));
1507 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1509 afs_com_err(whoami, BC_NOMEM, "");
1512 strncpy(tvol->name, volume, VOLSER_OLDMAXVOLNAME);
1513 memcpy(&tvol->server, &destServer, sizeof(destServer));
1514 tvol->partition = destPartition;
1517 lastVol->next = tvol; /* thread onto end of list */
1519 volsToRestore = tvol;
1524 afs_com_err(whoami, 0, "-name or -file option required");
1529 /* Get the port offset for the restore */
1530 if (as->parms[2].items) {
1531 for (ti = as->parms[2].items; ti; ti = ti->next)
1533 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1535 afs_com_err(whoami, BC_NOMEM, "");
1539 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1540 ports[i] = getPortOffset(ti->data);
1546 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1547 dontExecute = (as->parms[4].items ? 1 : 0);
1549 fromDate = 0x7fffffff; /* last one before this date */
1550 oldFlag = 1; /* do restore same volid (and name) */
1552 /* Perform the call to start the restore */
1553 code = bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1554 /*destserver */ NULL, /*destpartition */ 0, fromDate,
1556 /*parentDump */ 0, /*dumpLevel */ 0,
1557 bc_Restorer, ports, portCount,
1558 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1560 afs_com_err(whoami, code, "; Failed to queue restore");
1565 /*-----------------------------------------------------------------------------
1569 * Perform a dump of the set of volumes provided.
1570 * user specifies: -volumeset .. -dump .. [-portoffset ..] [-n]
1573 * as : Parsed command line information.
1574 * arock : Ptr to misc stuff; not used.
1578 * The result of bc_StartDump() otherwise
1585 *---------------------------------------------------------------------------
1590 bc_DumpCmd(struct cmd_syndesc *as, void *arock)
1592 char *dumpPath = NULL;
1593 char *vsName = NULL; /*Ptrs to various names */
1594 struct bc_volumeSet *tvs = NULL; /*Ptr to list of generated volume info */
1595 struct bc_dumpSchedule *tds;
1596 struct bc_dumpSchedule *baseds = NULL; /*Ptr to dump schedule node */
1597 struct bc_volumeDump *tve, *volsToDump; /*Ptr to individual vols to be dumped */
1598 struct budb_dumpEntry dumpEntry, de, fde; /* dump entry */
1601 afs_int32 parent; /* parent dump */
1602 afs_int32 level; /* this dump's level # */
1603 afs_int32 problemFindingDump; /* can't find parent(s) */
1605 afs_int32 *portp = NULL;
1606 afs_int32 portCount = 0;
1607 afs_int32 doAt, atTime; /* Time a timed-dump is to start at */
1610 int doAppend = 0; /* Append the dump to dump set */
1611 afs_int32 code; /* Return code */
1612 int loadfile; /* whether to load a file or not */
1616 extern struct bc_dumpTask bc_dumpTasks[];
1618 code = bc_UpdateDumpSchedule();
1620 afs_com_err(whoami, code, "; Can't retrieve dump schedule");
1623 code = bc_UpdateVolumeSet();
1625 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1628 code = bc_UpdateHosts();
1630 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1635 * Some parameters cannot be specified together
1636 * The "-file" option cannot exist with the "-volume", "-dump",
1637 * "-portoffset", or "-append" option
1639 if (as->parms[6].items) {
1641 if (as->parms[0].items || as->parms[1].items || as->parms[2].items
1642 || as->parms[4].items) {
1643 afs_com_err(whoami, 0, "Invalid option specified with -file option");
1648 if (!as->parms[0].items || !as->parms[1].items) {
1649 afs_com_err(whoami, 0,
1650 "Must specify volume set name and dump level name");
1656 * Get the time we are to perform this dump
1658 if (as->parms[3].items) {
1661 timeString = concatParams(as->parms[3].items);
1666 * Now parse this string for the time to start.
1668 code = ktime_DateToLong(timeString, &atTime);
1671 afs_com_err(whoami, 0, "Can't parse dump start date and time");
1672 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1678 dontExecute = (as->parms[5].items ? 1 : 0); /* -n */
1681 * If this dump is not a load file, then check the parameters.
1683 if (!loadfile) { /*6 */
1684 vsName = as->parms[0].items->data; /* get volume set name */
1685 dumpPath = as->parms[1].items->data; /* get dump path */
1687 /* get the port number, if one was specified */
1688 if (as->parms[2].items) {
1690 portp = (afs_int32 *) malloc(sizeof(afs_int32));
1692 afs_com_err(whoami, BC_NOMEM, "");
1696 *portp = getPortOffset(as->parms[2].items->data);
1701 doAppend = (as->parms[4].items ? 1 : 0); /* -append */
1704 * Get a hold of the given volume set and dump set.
1706 tvs = bc_FindVolumeSet(bc_globalConfig, vsName);
1708 afs_com_err(whoami, 0,
1709 "Can't find volume set '%s' in backup database", vsName);
1712 baseds = bc_FindDumpSchedule(bc_globalConfig, dumpPath);
1714 afs_com_err(whoami, 0,
1715 "Can't find dump schedule '%s' in backup database",
1724 * If given the "-at" option, then add this to the jobs list and return
1727 * Create a status node for this timed dump.
1728 * Fill in the time to dump and the cmd line for the dump leaving off
1729 * the -at option. If the -n option is there, it is scheduled with
1730 * the Timed dump as opposed to not scheduling the time dump at all.
1733 if (atTime < time(0)) {
1734 afs_com_err(whoami, 0,
1735 "Time of dump is earlier then current time - not added");
1737 statusPtr = createStatusNode();
1739 statusPtr->scheduledDump = atTime;
1741 /* Determine length of the dump command */
1743 length += 4; /* "dump" */
1745 length += 6; /* " -file" */
1746 length += 1 + strlen(as->parms[6].items->data); /* " <file>" */
1748 /* length += 11; *//* " -volumeset" */
1749 length += 1 + strlen(as->parms[0].items->data); /* " <volset> */
1751 /* length += 6; *//* " -dump" */
1752 length += 1 + strlen(as->parms[1].items->data); /* " <dumpset> */
1754 if (as->parms[2].items) {
1755 /* length += 12; *//* " -portoffset" */
1756 length += 1 + strlen(as->parms[2].items->data); /* " <port>" */
1759 if (as->parms[4].items)
1760 length += 8; /* " -append" */
1764 length += 3; /* " -n" */
1765 length++; /* end-of-line */
1767 /* Allocate status block for this timed dump */
1768 sprintf(statusPtr->taskName, "Scheduled Dump");
1769 statusPtr->jobNumber = bc_jobNumber();
1770 statusPtr->scheduledDump = atTime;
1771 statusPtr->cmdLine = (char *)malloc(length);
1772 if (!statusPtr->cmdLine) {
1773 afs_com_err(whoami, BC_NOMEM, "");
1777 /* Now reconstruct the dump command */
1778 statusPtr->cmdLine[0] = 0;
1779 strcat(statusPtr->cmdLine, "dump");
1781 strcat(statusPtr->cmdLine, " -file");
1782 strcat(statusPtr->cmdLine, " ");
1783 strcat(statusPtr->cmdLine, as->parms[6].items->data);
1785 /* strcat(statusPtr->cmdLine, " -volumeset"); */
1786 strcat(statusPtr->cmdLine, " ");
1787 strcat(statusPtr->cmdLine, as->parms[0].items->data);
1789 /* strcat(statusPtr->cmdLine, " -dump"); */
1790 strcat(statusPtr->cmdLine, " ");
1791 strcat(statusPtr->cmdLine, as->parms[1].items->data);
1793 if (as->parms[2].items) {
1794 /* strcat(statusPtr->cmdLine, " -portoffset"); */
1795 strcat(statusPtr->cmdLine, " ");
1796 strcat(statusPtr->cmdLine, as->parms[2].items->data);
1799 if (as->parms[4].items)
1800 strcat(statusPtr->cmdLine, " -append");
1803 strcat(statusPtr->cmdLine, " -n");
1805 printf("Add scheduled dump as job %d\n", statusPtr->jobNumber);
1806 if ((atTime > ttoken.endTime) && (ttoken.endTime != NEVERDATE))
1807 afs_com_err(whoami, 0,
1808 "Warning: job %d starts after expiration of AFS token",
1809 statusPtr->jobNumber);
1818 * Read and execute the load file if specified. The work of reading is done
1819 * in the main routine prior the dispatch call. loadFile and dontExecute are
1820 * global variables so this can take place in main.
1823 loadFile = (char *)malloc(strlen(as->parms[6].items->data) + 1);
1825 afs_com_err(whoami, BC_NOMEM, "");
1828 strcpy(loadFile, as->parms[6].items->data);
1833 * We are doing a real dump (no load file or timed dump).
1835 printf("Starting dump of volume set '%s' (dump level '%s')\n", vsName,
1838 /* For each dump-level above this one, see if the volumeset was dumped
1839 * at the level. We search all dump-levels since a higher dump-level
1840 * may have actually been done AFTER a lower dump level.
1842 parent = level = problemFindingDump = 0;
1843 for (tds = baseds->parent; tds; tds = tds->parent) {
1844 /* Find the most recent dump of the volume-set at this dump-level.
1845 * Raise problem flag if didn't find a dump and a parent not yet found.
1847 code = bcdb_FindLatestDump(vsName, tds->name, &dumpEntry);
1850 problemFindingDump = 1; /* skipping a dump level */
1854 /* We found the most recent dump at this level. Now check
1855 * if we should use it by seeing if its full dump hierarchy
1856 * exists. If it doesn't, we don't want to base our incremental
1859 if (!parent || (dumpEntry.id > parent)) {
1860 /* Follow the parent dumps to see if they are all there */
1861 for (d = dumpEntry.parent; d; d = de.parent) {
1862 code = bcdb_FindDumpByID(d, &de);
1867 /* If we found the entire level, remember it. Otherwise raise flag.
1868 * If we had already found a dump, raise the problem flag.
1872 problemFindingDump = 1;
1873 parent = dumpEntry.id;
1874 level = dumpEntry.level + 1;
1875 memcpy(&fde, &dumpEntry, sizeof(dumpEntry));
1877 /* Dump hierarchy not complete so can't base off the latest */
1878 problemFindingDump = 1;
1883 /* If the problemflag was raise, it means we are not doing the
1884 * dump at the level we requested it be done at.
1886 if (problemFindingDump) {
1887 afs_com_err(whoami, 0,
1888 "Warning: Doing level %d dump due to missing higher-level dumps",
1891 printf("Parent dump: dump %s (DumpID %u)\n", fde.name, parent);
1893 } else if (parent) {
1894 printf("Found parent: dump %s (DumpID %u)\n", fde.name, parent);
1897 /* Expand out the volume set into its component list of volumes. */
1898 code = bc_EvalVolumeSet(bc_globalConfig, tvs, &volsToDump, cstruct);
1900 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1904 printf("No volumes to dump\n");
1908 /* Determine what the clone time of the volume was when it was
1909 * last dumped (tve->date). This is the time from when an
1910 * incremental should be done (remains zero if a full dump).
1913 for (tve = volsToDump; tve; tve = tve->next) {
1914 code = bcdb_FindClone(parent, tve->name, &tve->date);
1918 /* Get the time the volume was last cloned and see if the volume has
1919 * changed since then. Only do this when the "-n" flag is specified
1920 * because butc will get the cloneDate at time of dump.
1924 volImageTime(tve->server.sin_addr.s_addr, tve->partition,
1925 tve->vid, tve->volType, &tve->cloneDate);
1929 if (tve->cloneDate && (tve->cloneDate == tve->date)) {
1930 afs_com_err(whoami, 0,
1931 "Warning: Timestamp on volume %s unchanged from previous dump",
1939 printf("Would have dumped the following volumes:\n");
1941 printf("Preparing to dump the following volumes:\n");
1942 for (tve = volsToDump; tve; tve = tve->next) {
1943 printf("\t%s (%u)\n", tve->name, tve->vid);
1948 code = bc_StartDmpRst(bc_globalConfig, dumpPath, vsName, volsToDump,
1949 /*destServer */ NULL, /*destPartition */ 0,
1951 /*newExt */ NULL, /*oldFlag */ 0,
1952 parent, level, bc_Dumper, portp, /*portCount */ 1,
1953 baseds, doAppend, dontExecute);
1955 afs_com_err(whoami, code, "; Failed to queue dump");
1962 * terminate the backup process. Insists that that all running backup
1963 * jobs be terminated before it will quit
1968 bc_QuitCmd(struct cmd_syndesc *as, void *arock)
1971 struct bc_dumpTask *td;
1972 extern dlqlinkT statusHead;
1976 /* Check the status list for outstanding jobs */
1978 for (ptr = (&statusHead)->dlq_next; ptr != &statusHead;
1979 ptr = ptr->dlq_next) {
1980 statusPtr = (statusP) ptr;
1981 if (!(statusPtr->flags & ABORT_REQUEST)) {
1983 afs_com_err(whoami, 0, "Job %d still running (and not aborted)",
1984 statusPtr->jobNumber);
1985 afs_com_err(whoami, 0,
1986 "You must at least 'kill' all running jobs before quitting");
1992 /* A job still being initialized (but no status structure or job number since it
1993 * has not been handed to a butc process yet)
1995 for (td = bc_dumpTasks, i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1996 if (td->flags & BC_DI_INUSE) {
1997 afs_com_err(whoami, 0, "A job is still running");
1998 afs_com_err(whoami, 0,
1999 "You must at least 'kill' all running jobs before quitting");
2005 /* close the all temp text files before quitting */
2006 for (i = 0; i < TB_NUM; i++)
2007 bc_closeTextFile(&bc_globalConfig->configText[i],
2008 &bc_globalConfig->tmpTextFileNames[i][0]);
2014 * Labels a tape i.e. request the tape coordinator to perform this
2018 bc_LabelTapeCmd(struct cmd_syndesc *as, void *arock)
2020 char *tapename = 0, *pname = 0;
2025 code = bc_UpdateHosts();
2027 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2031 if (as->parms[0].items) { /* -name */
2032 tapename = as->parms[0].items->data;
2033 if (strlen(tapename) >= TC_MAXTAPELEN) {
2034 afs_com_err(whoami, 0, "AFS tape name '%s' is too long", tapename);
2039 if (as->parms[3].items) { /* -pname */
2041 afs_com_err(whoami, 0, "Can only specify -name or -pname");
2044 pname = as->parms[3].items->data;
2045 if (strlen(pname) >= TC_MAXTAPELEN) {
2046 afs_com_err(whoami, 0, "Permanent tape name '%s' is too long", pname);
2051 if (as->parms[1].items) {
2052 size = bc_FloatATOI(as->parms[1].items->data);
2054 afs_com_err(whoami, 0, "Bad syntax for tape size '%s'",
2055 as->parms[1].items->data);
2061 if (as->parms[2].items) {
2062 port = getPortOffset(as->parms[2].items->data);
2067 code = bc_LabelTape(tapename, pname, size, bc_globalConfig, port);
2074 * read the label on a tape
2076 * optional port number
2079 bc_ReadLabelCmd(struct cmd_syndesc *as, void *arock)
2084 code = bc_UpdateHosts();
2086 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2090 if (as->parms[0].items) {
2091 port = getPortOffset(as->parms[0].items->data);
2096 code = bc_ReadLabel(bc_globalConfig, port);
2103 * read content information from dump tapes, and if user desires,
2104 * add it to the database
2107 bc_ScanDumpsCmd(struct cmd_syndesc *as, void *arock)
2110 afs_int32 dbAddFlag = 0;
2113 code = bc_UpdateHosts();
2115 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2119 /* check for flag */
2120 if (as->parms[0].items != 0) { /* add scan to database */
2124 /* check for port */
2125 if (as->parms[1].items) {
2126 port = getPortOffset(as->parms[1].items->data);
2131 code = bc_ScanDumps(bc_globalConfig, dbAddFlag, port);
2135 /* bc_ParseExpiration
2138 * dates are specified as absolute or relative, the syntax is:
2139 * absolute: at %d/%d/%d [%d:%d] where [..] is optional
2140 * relative: in [%dy][%dm][%dd] where at least one component
2145 bc_ParseExpiration(struct cmd_parmdesc *paramPtr, afs_int32 *expType,
2148 struct cmd_item *itemPtr;
2149 struct ktime_date kt;
2150 char *dateString = 0;
2153 *expType = BC_NO_EXPDATE;
2156 if (!paramPtr->items)
2157 ERROR(0); /* no expiration specified */
2159 /* some form of expiration date specified. First validate the prefix */
2160 itemPtr = paramPtr->items;
2162 if (strcmp(itemPtr->data, "at") == 0) {
2163 *expType = BC_ABS_EXPDATE;
2165 dateString = concatParams(itemPtr->next);
2169 code = ktime_DateToLong(dateString, expDate);
2172 } else if (strcmp(itemPtr->data, "in") == 0) {
2173 *expType = BC_REL_EXPDATE;
2175 dateString = concatParams(itemPtr->next);
2179 code = ParseRelDate(dateString, &kt);
2182 *expDate = ktimeRelDate_ToLong(&kt);
2184 dateString = concatParams(itemPtr);
2188 if (ktime_DateToLong(dateString, expDate) == 0) {
2189 *expType = BC_ABS_EXPDATE;
2190 code = ktime_DateToLong(dateString, expDate);
2193 } else if (ParseRelDate(dateString, &kt) == 0) {
2194 *expType = BC_REL_EXPDATE;
2195 *expDate = ktimeRelDate_ToLong(&kt);
2207 /* database lookup command and routines */
2210 * Currently a single option, volumename to search for. Reports
2211 * all dumps containing the specified volume
2214 bc_dblookupCmd(struct cmd_syndesc *as, void *arock)
2216 struct cmd_item *ciptr;
2219 ciptr = as->parms[0].items;
2220 if (ciptr == 0) /* no argument specified */
2223 code = DBLookupByVolume(ciptr->data);
2229 /* for ubik version */
2231 bc_dbVerifyCmd(struct cmd_syndesc *as, void *arock)
2237 struct hostent *hostPtr;
2241 extern struct udbHandleS udbHandle;
2243 detail = (as->parms[0].items ? 1 : 0); /* print more details */
2246 ubik_Call(BUDB_DbVerify, udbHandle.uh_client, 0, &status, &orphans,
2250 afs_com_err(whoami, code, "; Unable to verify database");
2254 /* verification call succeeded */
2257 printf("Database OK\n");
2259 afs_com_err(whoami, status, "; Database is NOT_OK");
2262 printf("Orphan blocks %d\n", orphans);
2265 printf("Unable to lookup host id\n");
2267 hostPtr = gethostbyaddr((char *)&host, sizeof(host), AF_INET);
2269 printf("Database checker was %d.%d.%d.%d\n",
2270 ((host & 0xFF000000) >> 24), ((host & 0xFF0000) >> 16),
2271 ((host & 0xFF00) >> 8), (host & 0xFF));
2273 printf("Database checker was %s\n", hostPtr->h_name);
2276 return ((status ? -1 : 0));
2280 * Delete a dump. If port is >= 0, it means try to delete from XBSA server
2283 deleteDump(afs_uint32 dumpid, /* The dumpid to delete */
2284 afs_int32 port, /* port==-1 means don't go to butc */
2287 afs_int32 code = 0, tcode;
2288 struct budb_dumpEntry dumpEntry;
2289 struct rx_connection *tconn = 0;
2290 afs_int32 i, taskflag, xbsadump;
2291 statusP statusPtr = 0;
2292 budb_dumpsList dumps;
2295 /* If the port is set, we will try to send a delete request to the butc */
2297 tcode = bc_UpdateHosts();
2299 afs_com_err(whoami, tcode, "; Can't retrieve tape hosts");
2303 /* Find the dump in the backup database */
2304 tcode = bcdb_FindDumpByID(dumpid, &dumpEntry);
2306 afs_com_err(whoami, tcode, "; Unable to locate dumpID %u in database",
2310 xbsadump = (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA));
2312 /* If dump is to an XBSA server, connect to butc and send it
2313 * the dump to delete. Butc will contact the XBSA server.
2314 * The dump will not be an appended dump because XBSA butc
2315 * does not support the append option.
2317 if (xbsadump && dumpEntry.nVolumes) {
2318 tcode = ConnectButc(bc_globalConfig, port, &tconn);
2322 tcode = TC_DeleteDump(tconn, dumpid, &taskId);
2324 if (tcode == RXGEN_OPCODE)
2325 tcode = BC_VERSIONFAIL;
2326 afs_com_err(whoami, tcode,
2327 "; Unable to delete dumpID %u via butc", dumpid);
2331 statusPtr = createStatusNode();
2333 statusPtr->taskId = taskId;
2334 statusPtr->port = port;
2335 statusPtr->jobNumber = bc_jobNumber();
2336 statusPtr->flags |= (SILENT | NOREMOVE); /* No msg & keep statusPtr */
2337 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2338 sprintf(statusPtr->taskName, "DeleteDump");
2341 /* Wait for task to finish */
2342 taskflag = waitForTask(taskId);
2343 if (taskflag & (TASK_ERROR | ABORT_DONE)) {
2344 afs_com_err(whoami, BUTX_DELETEOBJFAIL,
2345 "; Unable to delete dumpID %u via butc", dumpid);
2346 ERROR(BUTX_DELETEOBJFAIL); /* the task failed */
2353 deleteStatusNode(statusPtr); /* Clean up statusPtr - because NOREMOVE */
2355 rx_DestroyConnection(tconn); /* Destroy the connection */
2357 /* Remove the dump from the backup database */
2358 if (!code || force) {
2359 dumps.budb_dumpsList_len = 0;
2360 dumps.budb_dumpsList_val = 0;
2362 tcode = bcdb_deleteDump(dumpid, 0, 0, &dumps);
2364 afs_com_err(whoami, tcode,
2365 "; Unable to delete dumpID %u from database", dumpid);
2366 dumps.budb_dumpsList_len = 0;
2371 /* Display the dumps that were deleted - includes appended dumps */
2372 for (i = 0; i < dumps.budb_dumpsList_len; i++)
2373 printf(" %u%s\n", dumps.budb_dumpsList_val[i],
2374 (i > 0) ? " Appended Dump" : "");
2375 if (dumps.budb_dumpsList_val)
2376 free(dumps.budb_dumpsList_val);
2383 * Delete a specified dump from the database
2385 * dump id - single required arg as param 0.
2388 bc_deleteDumpCmd(struct cmd_syndesc *as, void *arock)
2392 afs_int32 rcode = 0;
2393 afs_int32 groupId = 0, havegroupid, sflags, noexecute;
2394 struct cmd_item *ti;
2395 afs_uint32 fromTime = 0, toTime = 0, havetime = 0;
2397 budb_dumpsList dumps, flags;
2399 afs_int32 port = -1, dbonly = 0, force;
2401 /* Must specify at least one of -dumpid, -from, or -to */
2402 if (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items
2403 && !as->parms[4].items) {
2404 afs_com_err(whoami, 0, "Must specify at least one field");
2408 /* Must have -to option with -from option */
2409 if (as->parms[1].items && !as->parms[2].items) {
2410 afs_com_err(whoami, 0, "Must specify '-to' field with '-from' field");
2414 /* Get the time to delete from */
2415 if (as->parms[1].items) { /* -from */
2416 timeString = concatParams(as->parms[1].items);
2421 * Now parse this string for the time to start.
2423 code = ktime_DateToLong(timeString, &fromTime);
2426 afs_com_err(whoami, 0, "Can't parse 'from' date and time");
2427 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2433 port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -port */
2434 if (as->parms[5].items) /* -dbonly */
2437 force = (as->parms[6].items ? 1 : 0);
2439 havegroupid = (as->parms[4].items ? 1 : 0);
2441 groupId = atoi(as->parms[4].items->data);
2443 noexecute = (as->parms[7].items ? 1 : 0);
2445 /* Get the time to delete to */
2446 if (as->parms[2].items) { /* -to */
2447 timeString = concatParams(as->parms[2].items);
2452 * Now parse this string for the time to start. Simce
2453 * times are at minute granularity, add 59 seconds.
2455 code = ktime_DateToLong(timeString, &toTime);
2458 afs_com_err(whoami, 0, "Can't parse 'to' date and time");
2459 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2466 if (fromTime > toTime) {
2467 afs_com_err(whoami, 0,
2468 "'-from' date/time cannot be later than '-to' date/time");
2472 /* Remove speicific dump ids - if any */
2473 printf("The following dumps %s deleted:\n",
2474 (noexecute ? "would have been" : "were"));
2475 for (ti = as->parms[0].items; ti != 0; ti = ti->next) { /* -dumpid */
2476 dumpid = atoi(ti->data);
2478 code = deleteDump(dumpid, port, force);
2480 printf(" %u\n", dumpid);
2485 * Now remove dumps between to and from dates.
2487 if (havegroupid || havetime) {
2488 dumps.budb_dumpsList_len = 0;
2489 dumps.budb_dumpsList_val = 0;
2490 flags.budb_dumpsList_len = 0;
2491 flags.budb_dumpsList_val = 0;
2494 sflags |= BUDB_OP_GROUPID;
2496 sflags |= BUDB_OP_DATES;
2499 bcdb_listDumps(sflags, groupId, fromTime, toTime, &dumps, &flags);
2501 afs_com_err(whoami, code,
2502 "; Error while deleting dumps from %u to %u", fromTime,
2507 for (i = 0; i < dumps.budb_dumpsList_len; i++) {
2508 if (flags.budb_dumpsList_val[i] & BUDB_OP_DBDUMP)
2512 if (flags.budb_dumpsList_val[i] & BUDB_OP_APPDUMP)
2514 code = deleteDump(dumps.budb_dumpsList_val[i], port, force);
2515 /* Ignore code and continue */
2517 printf(" %u%s%s\n", dumps.budb_dumpsList_val[i],
2519 budb_dumpsList_val[i] & BUDB_OP_APPDUMP) ?
2520 " Appended Dump" : "",
2522 budb_dumpsList_val[i] & BUDB_OP_DBDUMP) ?
2523 " Database Dump" : "");
2528 if (dumps.budb_dumpsList_val)
2529 free(dumps.budb_dumpsList_val);
2530 dumps.budb_dumpsList_len = 0;
2531 dumps.budb_dumpsList_val = 0;
2532 if (flags.budb_dumpsList_val)
2533 free(flags.budb_dumpsList_val);
2534 flags.budb_dumpsList_len = 0;
2535 flags.budb_dumpsList_val = 0;
2542 bc_saveDbCmd(struct cmd_syndesc *as, void *arock)
2544 struct rx_connection *tconn;
2545 afs_int32 portOffset = 0;
2552 code = bc_UpdateHosts();
2554 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2558 if (as->parms[0].items) {
2559 portOffset = getPortOffset(as->parms[0].items->data);
2564 /* Get the time to delete to */
2565 if (as->parms[1].items) {
2566 timeString = concatParams(as->parms[1].items);
2571 * Now parse this string for the time. Since
2572 * times are at minute granularity, add 59 seconds.
2574 code = ktime_DateToLong(timeString, &toTime);
2577 afs_com_err(whoami, 0, "Can't parse '-archive' date and time");
2578 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2585 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2589 code = TC_SaveDb(tconn, toTime, &taskId);
2591 afs_com_err(whoami, code, "; Failed to save database");
2595 /* create status monitor block */
2596 statusPtr = createStatusNode();
2598 statusPtr->taskId = taskId;
2599 statusPtr->port = portOffset;
2600 statusPtr->jobNumber = bc_jobNumber();
2601 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2602 sprintf(statusPtr->taskName, "SaveDb");
2606 rx_DestroyConnection(tconn);
2611 bc_restoreDbCmd(struct cmd_syndesc *as, void *arock)
2613 struct rx_connection *tconn;
2614 afs_int32 portOffset = 0;
2619 code = bc_UpdateHosts();
2621 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2625 if (as->parms[0].items) {
2626 portOffset = getPortOffset(as->parms[0].items->data);
2631 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2635 code = TC_RestoreDb(tconn, &taskId);
2637 afs_com_err(whoami, code, "; Failed to restore database");
2641 /* create status monitor block */
2642 statusPtr = createStatusNode();
2644 statusPtr->taskId = taskId;
2645 statusPtr->port = portOffset;
2646 statusPtr->jobNumber = bc_jobNumber();
2647 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2648 sprintf(statusPtr->taskName, "RestoreDb");
2652 rx_DestroyConnection(tconn);
2656 /* ----------------------------------
2657 * supporting routines for database examination
2658 * ----------------------------------
2661 /* structures and defines for DBLookupByVolume */
2663 #define DBL_MAX_VOLUMES 20 /* max. for each dump */
2665 /* dumpedVol - saves interesting information so that we can print it out
2670 struct dumpedVol *next;
2672 afs_int32 initialDumpID;
2673 char tapeName[BU_MAXTAPELEN];
2676 afs_int32 createTime;
2677 afs_int32 incTime; /* actually the clone time */
2680 /* -----------------------------------------
2681 * routines for examining the database
2682 * -----------------------------------------
2686 * Lookup the volumename in the backup database and print the results
2688 * volumeName - volume to lookup
2692 DBLookupByVolume(char *volumeName)
2694 struct budb_dumpEntry dumpEntry;
2695 struct budb_volumeEntry volumeEntry[DBL_MAX_VOLUMES];
2696 afs_int32 numEntries;
2697 afs_int32 tapedumpid;
2698 afs_int32 last, next;
2700 struct dumpedVol *dvptr = 0;
2701 struct dumpedVol *tempPtr = 0;
2704 char vname[BU_MAXNAMELEN];
2707 for (pass = 0; pass < 2; pass++) {
2709 /* On second pass, search for backup volume */
2711 if (!BackupName(volumeName)) {
2712 strcpy(vname, volumeName);
2713 strcat(vname, ".backup");
2721 while (next != -1) { /*w */
2723 bcdb_LookupVolume(volumeName, &volumeEntry[0], last, &next,
2724 DBL_MAX_VOLUMES, &numEntries);
2728 /* add the volumes to the list */
2729 for (i = 0; i < numEntries; i++) { /*f */
2730 struct dumpedVol *insPtr, **prevPtr;
2733 (struct dumpedVol *)malloc(sizeof(struct dumpedVol));
2737 memset(tempPtr, 0, sizeof(*tempPtr));
2738 tempPtr->incTime = volumeEntry[i].clone;
2739 tempPtr->dumpID = volumeEntry[i].dump;
2740 strncpy(tempPtr->tapeName, volumeEntry[i].tape,
2743 /* check if we need to null terminate it - just for safety */
2744 if (strlen(volumeEntry[i].tape) >= BU_MAXTAPELEN)
2745 tempPtr->tapeName[BU_MAXTAPELEN - 1] = 0;
2747 code = bcdb_FindDumpByID(tempPtr->dumpID, &dumpEntry);
2753 tempPtr->initialDumpID = dumpEntry.initialDumpID;
2754 tempPtr->parent = dumpEntry.parent;
2755 tempPtr->level = dumpEntry.level;
2756 tempPtr->createTime = dumpEntry.created;
2758 /* add volume to list in reverse chronological order */
2762 while ((insPtr != 0)
2763 && (insPtr->createTime > tempPtr->createTime)
2765 prevPtr = &insPtr->next;
2766 insPtr = insPtr->next;
2769 /* now at the right place - insert the block */
2770 tempPtr->next = *prevPtr;
2780 ("DumpID lvl parentID creation date clone date tape name\n");
2781 for (tempPtr = dvptr; tempPtr; tempPtr = tempPtr->next) {
2782 /* For the user, the tape name is its name and initial dump id */
2784 (tempPtr->initialDumpID ? tempPtr->initialDumpID : tempPtr->
2787 /* beware the static items in compactDateString */
2788 compactDateString(&tempPtr->createTime, ds, 50);
2789 printf("%-9d %-2d %-9d %16s", tempPtr->dumpID, tempPtr->level,
2790 tempPtr->parent, ds);
2791 compactDateString(&tempPtr->incTime, ds, 50);
2792 printf(" %16s %s (%u)\n", ds, tempPtr->tapeName, tapedumpid);
2798 for (tempPtr = dvptr; tempPtr; tempPtr = dvptr) {
2799 dvptr = dvptr->next;
2804 afs_com_err(whoami, code, "");
2808 /* structures for dumpInfo */
2811 struct volumeLink *nextVolume;
2812 struct budb_volumeEntry volumeEntry;
2816 struct tapeLink *nextTape;
2817 struct budb_tapeEntry tapeEntry;
2818 struct volumeLink *firstVolume;
2823 * print information about a dump and all its tapes and volumes.
2827 dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
2829 struct budb_dumpEntry dumpEntry;
2830 struct tapeLink *head = 0;
2831 struct tapeLink *tapeLinkPtr, *lastTapeLinkPtr;
2832 struct volumeLink **link, *volumeLinkPtr, *lastVolumeLinkPtr;
2835 afs_int32 last, next, dbTime;
2836 afs_int32 tapedumpid;
2844 extern struct udbHandleS udbHandle;
2847 lastTapeLinkPtr = 0;
2849 lastVolumeLinkPtr = 0;
2851 /* first get information about the dump */
2853 code = bcdb_FindDumpByID(dumpid, &dumpEntry);
2857 /* For the user, the tape name is its name and initial dump id */
2858 tapedumpid = (dumpEntry.initialDumpID ? dumpEntry.initialDumpID : dumpid);
2860 /* Is this a database dump id or not */
2861 if (strcmp(dumpEntry.name, DUMP_TAPE_NAME) == 0)
2866 /* print out the information about the dump */
2870 printDumpEntry(&dumpEntry);
2872 time_t t = dumpEntry.created;
2874 printf("Dump: id %u, created: %s\n", dumpEntry.id,
2877 printf("Dump: id %u, level %d, volumes %d, created: %s\n",
2878 dumpEntry.id, dumpEntry.level, dumpEntry.nVolumes,
2882 if (!detailFlag && (strlen(dumpEntry.tapes.tapeServer) > 0)
2883 && (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA))) {
2884 printf("Backup Service: TSM: Server: %s\n",
2885 dumpEntry.tapes.tapeServer);
2888 /* now get the list of tapes */
2889 for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) { /*f */
2890 tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
2892 afs_com_err(whoami, BC_NOMEM, "");
2896 memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
2897 code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
2904 /* add this tape to previous chain */
2905 if (lastTapeLinkPtr) {
2906 lastTapeLinkPtr->nextTape = tapeLinkPtr;
2907 lastTapeLinkPtr = tapeLinkPtr;
2912 lastTapeLinkPtr = head;
2916 while (next != -1) { /*wn */
2917 vl.budb_volumeList_len = 0;
2918 vl.budb_volumeList_val = 0;
2921 /* now get all the volumes in this dump. */
2922 code = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client, UF_SINGLESERVER, BUDB_MAJORVERSION, BUDB_OP_DUMPID | BUDB_OP_TAPENAME, tapeLinkPtr->tapeEntry.name, /* tape name */
2923 dumpid, /* dumpid (not initial dumpid) */
2926 &next, /* nextindex */
2927 &dbTime, /* update time */
2931 if (code == BUDB_ENDOFLIST) { /* 0 volumes on tape */
2938 for (i = 0; i < vl.budb_volumeList_len; i++) {
2939 link = &tapeLinkPtr->firstVolume;
2942 (struct volumeLink *)malloc(sizeof(struct volumeLink));
2943 if (!volumeLinkPtr) {
2944 afs_com_err(whoami, BC_NOMEM, "");
2947 memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
2949 memcpy(&volumeLinkPtr->volumeEntry,
2950 &vl.budb_volumeList_val[i],
2951 sizeof(struct budb_volumeEntry));
2953 /* now insert it onto the right place */
2955 && (volumeLinkPtr->volumeEntry.position >
2956 (*link)->volumeEntry.position)) {
2957 link = &((*link)->nextVolume);
2960 /* now link it in */
2961 volumeLinkPtr->nextVolume = *link;
2962 *link = volumeLinkPtr;
2965 if (vl.budb_volumeList_val)
2966 free(vl.budb_volumeList_val);
2970 for (tapeLinkPtr = head; tapeLinkPtr; tapeLinkPtr = tapeLinkPtr->nextTape) {
2974 printTapeEntry(&tapeLinkPtr->tapeEntry);
2976 printf("Tape: name %s (%u)\n", tapeLinkPtr->tapeEntry.name,
2978 printf("nVolumes %d, ", tapeLinkPtr->tapeEntry.nVolumes);
2979 compactDateString(&tapeLinkPtr->tapeEntry.written, ds, 50);
2980 printf("created %16s", ds);
2981 if (tapeLinkPtr->tapeEntry.expires != 0) {
2982 compactDateString(&tapeLinkPtr->tapeEntry.expires, ds, 50);
2983 printf(", expires %16s", ds);
2988 /* print out all the volumes */
2990 /* print header for volume listing - db dumps have no volumes */
2991 if ((detailFlag == 0) && !dbDump)
2992 printf("%4s %16s %9s %-s\n", "Pos", "Clone time", "Nbytes",
2995 for (volumeLinkPtr = tapeLinkPtr->firstVolume; volumeLinkPtr;
2996 volumeLinkPtr = volumeLinkPtr->nextVolume) {
2998 printf("\nVolume\n");
3000 printVolumeEntry(&volumeLinkPtr->volumeEntry);
3002 compactDateString(&volumeLinkPtr->volumeEntry.clone, ds, 50),
3003 printf("%4d %s %10u %16s\n",
3004 volumeLinkPtr->volumeEntry.position, ds,
3005 volumeLinkPtr->volumeEntry.nBytes,
3006 volumeLinkPtr->volumeEntry.name);
3013 afs_com_err("dumpInfo", code, "; Can't get dump information");
3015 /* free all allocated structures */
3017 while (tapeLinkPtr) {
3018 volumeLinkPtr = tapeLinkPtr->firstVolume;
3019 while (volumeLinkPtr) {
3020 lastVolumeLinkPtr = volumeLinkPtr;
3021 volumeLinkPtr = volumeLinkPtr->nextVolume;
3022 free(lastVolumeLinkPtr);
3025 lastTapeLinkPtr = tapeLinkPtr;
3026 tapeLinkPtr = tapeLinkPtr->nextTape;
3027 free(lastTapeLinkPtr);
3033 compareDump(struct budb_dumpEntry *ptr1, struct budb_dumpEntry *ptr2)
3035 if (ptr1->created < ptr2->created)
3037 else if (ptr1->created > ptr2->created)
3043 printRecentDumps(int ndumps)
3046 afs_int32 nextindex, index = 0;
3049 struct budb_dumpEntry *dumpPtr;
3053 extern struct udbHandleS udbHandle;
3055 do { /* while (nextindex != -1) */
3056 /* initialize the dump list */
3057 dl.budb_dumpList_len = 0;
3058 dl.budb_dumpList_val = 0;
3060 /* outline algorithm */
3061 code = ubik_Call(BUDB_GetDumps, udbHandle.uh_client, 0, BUDB_MAJORVERSION, BUDB_OP_NPREVIOUS, "", /* no name */
3065 &nextindex, &dbTime, &dl);
3067 if (code == BUDB_ENDOFLIST)
3069 afs_com_err("dumpInfo", code, "; Can't get dump information");
3073 /* No need to sort, it's already sorted */
3075 if (dl.budb_dumpList_len && (index == 0))
3076 printf("%10s %10s %2s %-16s %2s %5s dump name\n", "dumpid",
3077 "parentid", "lv", "created", "nt", "nvols");
3079 dumpPtr = dl.budb_dumpList_val;
3080 for (i = 1; i <= dl.budb_dumpList_len; i++) {
3081 compactDateString(&dumpPtr->created, ds, 50),
3082 printf("%10u %10u %-2d %16s %2d %5d %s", dumpPtr->id,
3083 dumpPtr->parent, dumpPtr->level, ds,
3084 dumpPtr->tapes.maxTapes - dumpPtr->tapes.b + 1,
3085 dumpPtr->nVolumes, dumpPtr->name);
3086 if (dumpPtr->initialDumpID) /* an appended dump */
3087 printf(" (%u)", dumpPtr->initialDumpID);
3088 else if (dumpPtr->appendedDumpID) /* has appended dumps */
3089 printf(" (%u)", dumpPtr->id);
3095 if (dl.budb_dumpList_val)
3096 free(dl.budb_dumpList_val);
3098 } while (nextindex != -1);
3104 * list the dumps and contens of the dumps.
3110 bc_dumpInfoCmd(struct cmd_syndesc *as, void *arock)
3113 afs_int32 detailFlag;
3117 if (as->parms[0].items) {
3118 if (as->parms[1].items) {
3119 afs_com_err(whoami, 0,
3120 "These options are exclusive - select only one");
3123 ndumps = atoi(as->parms[0].items->data);
3125 afs_com_err(whoami, 0, "Must provide a positive number");
3129 code = printRecentDumps(ndumps);
3130 } else if (as->parms[1].items) {
3131 detailFlag = (as->parms[2].items ? 1 : 0); /* 1 = detailed listing */
3132 dumpid = atoi(as->parms[1].items->data);
3133 code = dumpInfo(dumpid, detailFlag);
3135 code = printRecentDumps(10);