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 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
28 #include <afs/com_err.h>
31 #include <afs/bubasics.h> /* PA */
32 #include <afs/volser.h>
33 #include <afs/voldefs.h> /* PA */
34 #include <afs/vldbint.h> /* PA */
35 #include <afs/ktime.h> /* PA */
41 #include <afs/tcdata.h>
44 #include "error_macros.h"
47 extern struct bc_config *bc_globalConfig;
48 extern struct bc_dumpSchedule *bc_FindDumpSchedule();
49 extern struct bc_volumeSet *bc_FindVolumeSet(struct bc_config *cfg,
51 extern struct bc_dumpTask bc_dumpTasks[BC_MAXSIMDUMPS];
52 extern struct ubik_client *cstruct;
53 extern int bc_Dumper(); /* function to do dumps */
54 extern int bc_Restorer(); /* function to do restores */
56 extern struct ktc_token ttoken;
57 extern char *tailCompPtr();
58 extern statusP createStatusNode();
61 extern afs_int32 lastTaskCode;
64 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.S_un.S_addr
66 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
70 bc_EvalVolumeSet(aconfig, avs, avols, uclient)
71 struct bc_config *aconfig;
72 register struct bc_volumeSet *avs;
73 struct bc_volumeDump **avols;
74 struct ubik_client *uclient;
75 { /*bc_EvalVolumeSet */
77 static afs_int32 use = 2;
79 if (use == 2) { /* Use EvalVolumeSet2() */
80 code = EvalVolumeSet2(aconfig, avs, avols, uclient);
81 if (code == RXGEN_OPCODE)
84 if (use == 1) { /* Use EvalVolumeSet1() */
85 code = EvalVolumeSet1(aconfig, avs, avols, uclient);
88 } /*bc_EvalVolumeSet */
90 struct partitionsort {
92 struct bc_volumeDump *vdlist;
93 struct bc_volumeDump *lastvdlist;
94 struct bc_volumeDump *dupvdlist;
95 struct bc_volumeEntry *vole;
96 struct partitionsort *next;
100 struct partitionsort *partitions;
101 struct serversort *next;
105 getSPEntries(server, partition, serverlist, ss, ps)
108 struct serversort **serverlist, **ss;
109 struct partitionsort **ps;
111 if (!(*ss) || ((*ss)->ipaddr != server)) {
113 for ((*ss) = *serverlist; (*ss); *ss = (*ss)->next) {
114 if ((*ss)->ipaddr == server)
118 /* No server entry added. Add one */
120 *ss = (struct serversort *)malloc(sizeof(struct serversort));
122 com_err(whoami, BC_NOMEM, "");
126 memset(*ss, 0, sizeof(struct serversort));
127 (*ss)->ipaddr = server;
128 (*ss)->next = *serverlist;
133 if (!(*ps) || ((*ps)->part != partition)) {
134 for (*ps = (*ss)->partitions; *ps; *ps = (*ps)->next) {
135 if ((*ps)->part == partition)
139 /* No partition entry added. Add one */
141 *ps = (struct partitionsort *)malloc(sizeof(struct partitionsort));
143 com_err(whoami, BC_NOMEM, "");
149 memset(*ps, 0, sizeof(struct partitionsort));
150 (*ps)->part = partition;
151 (*ps)->next = (*ss)->partitions;
152 (*ss)->partitions = *ps;
158 randSPEntries(serverlist, avols)
159 struct serversort *serverlist;
160 struct bc_volumeDump **avols;
162 struct serversort *ss, **pss;
163 struct partitionsort *ps, **pps;
165 afs_int32 scount, pcount;
169 /* Seed random number generator */
170 r = time(0) + getpid();
173 /* Count number of servers, remove one at a time */
174 for (scount = 0, ss = serverlist; ss; ss = ss->next, scount++);
175 for (; scount; scount--) {
176 /* Pick a random server in list and remove it */
177 r = (rand() >> 4) % scount;
178 for (pss = &serverlist, ss = serverlist; r;
179 pss = &ss->next, ss = ss->next, r--);
182 /* Count number of partitions, remove one at a time */
183 for (pcount = 0, ps = ss->partitions; ps; ps = ps->next, pcount++);
184 for (; pcount; pcount--) {
185 /* Pick a random parition in list and remove it */
186 r = (rand() >> 4) % pcount;
187 for (pps = &ss->partitions, ps = ss->partitions; r;
188 pps = &ps->next, ps = ps->next, r--);
191 ps->lastvdlist->next = *avols;
201 EvalVolumeSet2(aconfig, avs, avols, uclient)
202 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, *lastserver = 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 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 com_err(whoami, BC_NOMEM, "");
325 memset(tvd, 0, sizeof(*tvd));
327 tvd->name = (char *)malloc(strlen(entries[e].name) + 10);
329 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(aconfig, avs, avols, uclient)
424 struct bc_config *aconfig;
425 struct bc_volumeSet *avs;
426 struct bc_volumeDump **avols;
427 struct ubik_client *uclient;
428 { /*EvalVolumeSet1 */
429 afs_int32 code; /*Result of various calls */
431 struct bc_volumeDump *tvd; /*Ptr to new dump instance */
432 struct bc_volumeEntry *tve, *ctve; /*Ptr to new volume entry instance */
433 char patt[256]; /*Composite regex; also, target string */
434 int volType; /*Type of volume that worked */
435 afs_int32 index; /*Current VLDB entry index */
436 afs_int32 count; /*Needed by VL_ListEntry() */
437 afs_int32 next_index; /*Next index to list */
438 struct vldbentry entry; /*VLDB entry */
439 int srvpartpair; /*Loop counter: server/partition pair */
441 int found, foundentry;
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);
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 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 com_err(whoami, code, "");
562 tvd = (struct bc_volumeDump *)
563 malloc(sizeof(struct bc_volumeDump));
565 com_err(whoami, BC_NOMEM, "");
568 memset(tvd, 0, sizeof(*tvd));
570 tvd->name = (char *)malloc(strlen(entry.name) + 10);
572 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(date_long, string, size)
618 afs_int32 *date_long, size;
626 if (*date_long == NEVERDATE) {
627 sprintf(string, "NEVER");
629 time_t t = *date_long;
630 ltime = localtime(&t);
631 /* prints date in U.S. format of mm/dd/yyyy */
632 strftime(string, size, "%m/%d/%Y %H:%M", ltime);
643 for (; *anum; anum++) {
644 if ((*anum < '0') || (*anum > '9'))
646 total = (10 * total) + (afs_int32) (*anum - '0');
652 * Take a string and parse it for a number (could be float) followed
653 * by a character representing the units (K,M,G,T). Default is 'K'.
654 * Return the size in KBytes.
662 afs_int32 fraction = 0; /* > 0 if past the decimal */
664 for (; *anum; anum++) {
665 if ((*anum == 't') || (*anum == 'T')) {
666 total *= 1024 * 1024 * 1024;
669 if ((*anum == 'g') || (*anum == 'G')) {
670 total *= 1024 * 1024;
673 if ((*anum == 'm') || (*anum == 'M')) {
677 if ((*anum == 'k') || (*anum == 'K')) {
684 if ((*anum < '0') || (*anum > '9'))
688 total = (10. * total) + (float)(*anum - '0');
690 total += ((float)(*anum - '0')) / (float)fraction;
695 total += 0.5; /* Round up */
696 if (total > 0x7fffffff) /* Don't go over 2G */
698 rtotal = (afs_int32) total;
702 /* make a copy of a string so that it can be freed later */
704 bc_CopyString(astring)
711 return (NULL); /* propagate null strings easily */
712 tlen = strlen(astring);
713 tp = (char *)malloc(tlen + 1); /* don't forget the terminating null */
715 com_err(whoami, BC_NOMEM, "");
724 * Concatenates the parameters of an option and returns the string.
729 concatParams(itemPtr)
730 struct cmd_item *itemPtr;
732 struct cmd_item *tempPtr;
733 afs_int32 length = 0;
736 /* compute the length of string required */
737 for (tempPtr = itemPtr; tempPtr; tempPtr = tempPtr->next) {
738 length += strlen(tempPtr->data);
739 length++; /* space or null terminator */
742 if (length == 0) { /* no string (0 length) */
743 com_err(whoami, 0, "Can't have zero length date and time string");
747 string = (char *)malloc(length); /* allocate the string */
749 com_err(whoami, BC_NOMEM, "");
754 tempPtr = itemPtr; /* now assemble the string */
756 strcat(string, tempPtr->data);
757 tempPtr = tempPtr->next;
762 return (string); /* return the string */
766 * print out an interface status node as received from butc
769 printIfStatus(statusPtr)
770 struct tciStatusS *statusPtr;
772 printf("Task %d: %s: ", statusPtr->taskId, statusPtr->taskName);
773 if (statusPtr->nKBytes)
774 printf("%ld Kbytes transferred", statusPtr->nKBytes);
775 if (strlen(statusPtr->volumeName) != 0) {
776 if (statusPtr->nKBytes)
778 printf("volume %s", statusPtr->volumeName);
783 if (statusPtr->flags & ABORT_REQUEST)
784 printf(" [abort request rcvd]");
786 if (statusPtr->flags & ABORT_DONE)
787 printf(" [abort complete]");
789 if (statusPtr->flags & OPR_WAIT)
790 printf(" [operator wait]");
792 if (statusPtr->flags & CALL_WAIT)
793 printf(" [callout in progress]");
795 if (statusPtr->flags & DRIVE_WAIT)
796 printf(" [drive wait]");
798 if (statusPtr->flags & TASK_DONE)
807 afs_int32 portOffset;
809 portOffset = bc_SafeATOI(port);
811 if (portOffset < 0) {
812 com_err(whoami, 0, "Can't decode port offset '%s'", port);
814 } else if (portOffset > BC_MAXPORTOFFSET) {
815 com_err(whoami, 0, "%u exceeds max port offset %u", portOffset,
822 /* bc_GetTapeStatusCmd
823 * display status of all tasks on a particular tape coordinator
826 bc_GetTapeStatusCmd(as, arock)
827 struct cmd_syndesc *as;
831 struct rx_connection *tconn;
832 afs_int32 portOffset = 0;
837 struct tciStatusS status;
839 code = bc_UpdateHosts();
841 com_err(whoami, code, "; Can't retrieve tape hosts");
845 if (as->parms[0].items) {
846 portOffset = getPortOffset(as->parms[0].items->data);
851 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
855 flags = TSK_STAT_FIRST;
859 while ((flags & TSK_STAT_END) == 0) {
860 code = TC_ScanStatus(tconn, &taskId, &status, &flags);
862 if (code == TC_NOTASKS)
864 com_err(whoami, code, "; Can't get status from butc");
867 if ((flags & TSK_STAT_NOTFOUND))
868 break; /* Can't find the task id */
869 flags &= ~TSK_STAT_FIRST; /* turn off flag */
871 printIfStatus(&status);
876 printf("Tape coordinator is idle\n");
878 if (flags & TSK_STAT_ADSM)
879 printf("TSM Tape coordinator\n");
880 else if (flags & TSK_STAT_XBSA)
881 printf("XBSA Tape coordinator\n");
886 extern struct Lock dispatchLock;
889 * wait for all jobs to terminate
896 int usefulJobRunning = 1;
898 extern dlqlinkT statusHead;
900 com_err(whoami, 0, "waiting for job termination");
902 while (usefulJobRunning) {
903 usefulJobRunning = (dlqEmpty(&statusHead) ? 0 : 1);
904 if (dispatchLock.excl_locked)
905 usefulJobRunning = 1;
906 for (i = 0; (!usefulJobRunning && (i < BC_MAXSIMDUMPS)); i++) {
907 if (bc_dumpTasks[i].flags & BC_DI_INUSE)
908 usefulJobRunning = 1;
911 /* Wait 5 seconds and check again */
912 if (usefulJobRunning)
915 return (lastTaskCode);
919 * print status on running jobs
921 * ignored - a null "as" prints only jobs.
924 bc_JobsCmd(as, arock)
925 struct cmd_syndesc *as;
935 extern dlqlinkT statusHead;
937 dlqInit(&atJobsHead);
940 ptr = (&statusHead)->dlq_next;
941 while (ptr != &statusHead) {
942 statusPtr = (statusP) ptr;
945 if (statusPtr->scheduledDump) {
946 dlqUnlink((dlqlinkP) statusPtr);
947 dlqLinkb(&atJobsHead, (dlqlinkP) statusPtr);
949 printf("Job %d:", statusPtr->jobNumber);
951 printf(" %s", statusPtr->taskName);
953 if (statusPtr->dbDumpId)
954 printf(": DumpID %u", statusPtr->dbDumpId);
955 if (statusPtr->nKBytes)
956 printf(", %ld Kbytes", statusPtr->nKBytes);
957 if (strlen(statusPtr->volumeName) != 0)
958 printf(", volume %s", statusPtr->volumeName);
960 if (statusPtr->flags & CONTACT_LOST)
961 printf(" [butc contact lost]");
963 if (statusPtr->flags & ABORT_REQUEST)
964 printf(" [abort request]");
966 if (statusPtr->flags & ABORT_SENT)
967 printf(" [abort sent]");
969 if (statusPtr->flags & OPR_WAIT)
970 printf(" [operator wait]");
972 if (statusPtr->flags & CALL_WAIT)
973 printf(" [callout in progress]");
975 if (statusPtr->flags & DRIVE_WAIT)
976 printf(" [drive wait]");
982 * Now print the scheduled dumps.
984 if (!dlqEmpty(&statusHead) && as)
985 printf("\n"); /* blank line between running and scheduled dumps */
988 while (!dlqEmpty(&atJobsHead)) {
989 ptr = (&atJobsHead)->dlq_next;
990 youngest = (statusP) ptr;
993 while (ptr != &atJobsHead) { /* Find the dump that starts the earliest */
994 statusPtr = (statusP) ptr;
995 if (statusPtr->scheduledDump < youngest->scheduledDump)
996 youngest = statusPtr;
1000 /* Print token expiration time */
1001 if ((ttoken.endTime > prevTime)
1002 && (ttoken.endTime <= youngest->scheduledDump) && as
1003 && (ttoken.endTime != NEVERDATE)) {
1004 if (ttoken.endTime > time(0)) {
1005 compactDateString(&ttoken.endTime, ds, 50);
1006 printf(" %16s: TOKEN EXPIRATION\n", ds);
1008 printf(" TOKEN HAS EXPIRED\n");
1011 prevTime = youngest->scheduledDump;
1013 /* Print the info */
1014 compactDateString(&youngest->scheduledDump, ds, 50);
1015 printf("Job %d:", youngest->jobNumber);
1016 printf(" %16s: %s", ds, youngest->cmdLine);
1019 /* return to original list */
1020 dlqUnlink((dlqlinkP) youngest);
1021 dlqLinkb(&statusHead, (dlqlinkP) youngest);
1024 /* Print token expiration time if havn't already */
1025 if ((ttoken.endTime == NEVERDATE) && as)
1026 printf(" : TOKEN NEVER EXPIRES\n");
1027 else if ((ttoken.endTime > prevTime) && as) {
1028 if (ttoken.endTime > time(0)) {
1029 compactDateString(&ttoken.endTime, ds, 50);
1030 printf(" %16s: TOKEN EXPIRATION\n", ds);
1032 printf(" : TOKEN HAS EXPIRED\n");
1040 bc_KillCmd(as, arock)
1041 struct cmd_syndesc *as;
1046 struct bc_dumpTask *td;
1053 extern dlqlinkT statusHead;
1054 extern statusP findStatus();
1057 tp = as->parms[0].items->data;
1058 if (strchr(tp, '.') == 0) {
1059 slot = bc_SafeATOI(tp);
1061 com_err(whoami, 0, "Bad syntax for number '%s'", tp);
1066 ptr = (&statusHead)->dlq_next;
1067 while (ptr != &statusHead) {
1068 statusPtr = (statusP) ptr;
1069 if (statusPtr->jobNumber == slot) {
1070 statusPtr->flags |= ABORT_REQUEST;
1074 ptr = ptr->dlq_next;
1078 fprintf(stderr, "Job %d not found\n", slot);
1083 for (i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1084 if (td->flags & BC_DI_INUSE) {
1086 strcpy(tbuffer, td->volSetName);
1087 strcat(tbuffer, ".");
1088 strcat(tbuffer, tailCompPtr(td->dumpName));
1089 if (strcmp(tbuffer, tp) == 0)
1093 if (i >= BC_MAXSIMDUMPS) {
1094 com_err(whoami, 0, "Can't find job %s", tp);
1099 statusPtr = findStatus(td->dumpID);
1101 if (statusPtr == 0) {
1102 com_err(whoami, 0, "Can't locate status - internal error");
1106 statusPtr->flags |= ABORT_REQUEST;
1113 /* restore a volume or volumes */
1114 bc_VolRestoreCmd(as, arock)
1115 struct cmd_syndesc *as;
1119 * parm 0 is the new server to restore to
1120 * parm 1 is the new partition to restore to
1121 * parm 2 is volume(s) to restore
1122 * parm 3 is the new extension, if any, for the volume name.
1123 * parm 4 gives the new volume # to restore this volume as (removed).
1124 * parm 4 date is a string representing the date
1126 * We handle four types of restores. If old is set, then we restore the
1127 * volume with the same name and ID. If old is not set, we allocate
1128 * a new volume ID for the restored volume. If a new extension is specified,
1129 * we add that extension to the volume name of the restored volume.
1131 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1132 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1133 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1134 struct bc_volumeDump *tvol; /* temp for same */
1135 struct sockaddr_in destServ; /* machine to which to restore volumes */
1136 afs_int32 destPartition; /* partition to which to restore volumes */
1138 struct cmd_item *ti;
1142 char *newExt, *timeString;
1144 afs_int32 *ports = NULL;
1145 afs_int32 portCount = 0;
1148 code = bc_UpdateHosts();
1150 com_err(whoami, code, "; Can't retrieve tape hosts");
1154 /* specified other destination host */
1155 if (as->parms[0].items) {
1156 tp = as->parms[0].items->data;
1157 if (bc_ParseHost(tp, &destServ)) {
1158 com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
1163 /* specified other destination partition */
1164 if (as->parms[1].items) {
1165 tp = as->parms[1].items->data;
1166 if (bc_GetPartitionID(tp, &destPartition)) {
1167 com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1172 for (ti = as->parms[2].items; ti; ti = ti->next) {
1173 /* build list of volume items */
1174 tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1176 com_err(whoami, BC_NOMEM, "");
1179 memset(tvol, 0, sizeof(struct bc_volumeDump));
1181 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1183 com_err(whoami, BC_NOMEM, "");
1186 strncpy(tvol->name, ti->data, VOLSER_OLDMAXVOLNAME);
1187 tvol->entry = &tvolumeEntry;
1190 lastVol->next = tvol; /* thread onto end of list */
1192 volsToRestore = tvol;
1196 if (as->parms[4].items) {
1197 timeString = concatParams(as->parms[4].items);
1201 code = ktime_DateToLong(timeString, &fromDate);
1204 com_err(whoami, 0, "Can't parse restore date and time");
1205 com_err(whoami, 0, "%s", ktime_GetDateUsage());
1209 fromDate = 0x7fffffff; /* latest one */
1212 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1215 /* Read all the port offsets into the ports array. The first element in the
1216 * array is for full restore and the rest are for incremental restores
1218 if (as->parms[5].items) {
1219 for (ti = as->parms[5].items; ti; ti = ti->next)
1221 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1223 com_err(whoami, BC_NOMEM, "");
1227 for (ti = as->parms[5].items, i = 0; ti; ti = ti->next, i++) {
1228 ports[i] = getPortOffset(ti->data);
1234 dontExecute = (as->parms[6].items ? 1 : 0); /* -n */
1237 * Perform the call to start the restore.
1240 bc_StartDmpRst(bc_globalConfig, "volume", "restore", volsToRestore,
1241 &destServ, destPartition, fromDate, newExt, oldFlag,
1242 /*parentDump */ 0, /*dumpLevel */ 0,
1243 bc_Restorer, ports, portCount,
1244 /*dumpSched */ 0, /*append */ 0, dontExecute);
1246 com_err(whoami, code, "; Failed to queue restore");
1251 /* restore a whole partition or server */
1253 /* bc_DiskRestoreCmd
1254 * restore a whole partition
1256 * first, reqd - machine (server) to restore
1257 * second, reqd - partition to restore
1261 bc_DiskRestoreCmd(as, arock)
1262 struct cmd_syndesc *as;
1265 struct bc_volumeSet tvolumeSet; /* temporary volume set for EvalVolumeSet call */
1266 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1267 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1268 struct sockaddr_in destServ; /* machine to which to restore volumes */
1269 afs_int32 destPartition; /* partition to which to restore volumes */
1275 afs_int32 *ports = NULL;
1276 afs_int32 portCount = 0;
1278 struct bc_volumeDump *prev, *tvol, *nextvol;
1279 struct cmd_item *ti;
1282 /* parm 0 is the server to restore
1283 * parm 1 is the partition to restore
1285 * parm 8 and above as in VolRestoreCmd:
1286 * parm 8 is the new server to restore to
1287 * parm 9 is the new partition to restore to
1290 code = bc_UpdateVolumeSet();
1292 com_err(whoami, code, "; Can't retrieve volume sets");
1295 code = bc_UpdateHosts();
1297 com_err(whoami, code, "; Can't retrieve tape hosts");
1301 /* create a volume set corresponding to the volume pattern we've been given */
1302 memset(&tvolumeSet, 0, sizeof(tvolumeSet));
1303 memset(&tvolumeEntry, 0, sizeof(tvolumeEntry));
1304 tvolumeSet.name = "TempVolumeSet";
1305 tvolumeSet.ventries = &tvolumeEntry;
1306 tvolumeEntry.serverName = as->parms[0].items->data;
1307 tvolumeEntry.partname = as->parms[1].items->data;
1309 if (bc_GetPartitionID(tvolumeEntry.partname, &tvolumeEntry.partition)) {
1310 com_err(whoami, 0, "Can't parse partition '%s'",
1311 tvolumeEntry.partname);
1315 if (bc_ParseHost(tvolumeEntry.serverName, &tvolumeEntry.server)) {
1316 com_err(whoami, 0, "Can't locate host '%s'", tvolumeEntry.serverName);
1320 /* specified other destination host */
1321 if (as->parms[8].items) {
1322 tp = as->parms[8].items->data;
1323 if (bc_ParseHost(tp, &destServ)) {
1324 com_err(whoami, 0, "Can't locate destination host '%s'", tp);
1327 } else /* use destination host == original host */
1328 memcpy(&destServ, &tvolumeEntry.server, sizeof(destServ));
1330 /* specified other destination partition */
1331 if (as->parms[9].items) {
1332 tp = as->parms[9].items->data;
1333 if (bc_GetPartitionID(tp, &destPartition)) {
1334 com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1337 } else /* use original partition */
1338 destPartition = tvolumeEntry.partition;
1340 tvolumeEntry.name = ".*"; /* match all volumes (this should be a parameter) */
1342 if (as->parms[2].items) {
1343 for (ti = as->parms[2].items; ti; ti = ti->next)
1345 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1347 com_err(whoami, BC_NOMEM, "");
1351 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1352 ports[i] = getPortOffset(ti->data);
1358 newExt = (as->parms[10].items ? as->parms[10].items->data : NULL);
1359 dontExecute = (as->parms[11].items ? 1 : 0); /* -n */
1362 * Expand out the volume set into its component list of volumes, by calling VLDB server.
1365 bc_EvalVolumeSet(bc_globalConfig, &tvolumeSet, &volsToRestore,
1368 com_err(whoami, code, "; Failed to evaluate volume set");
1372 /* Since we want only RW volumes, remove any
1373 * BK or RO volumes from the list.
1375 for (prev = 0, tvol = volsToRestore; tvol; tvol = nextvol) {
1376 nextvol = tvol->next;
1377 if (BackupName(tvol->name)) {
1380 "Will not restore volume %s (its RW does not reside on the partition)\n",
1383 if (tvol == volsToRestore) {
1384 volsToRestore = nextvol;
1386 prev->next = nextvol;
1396 fromDate = 0x7fffffff; /* last one before this date */
1397 oldFlag = 1; /* do restore same volid (and name) */
1400 * Perform the call to start the dump.
1403 bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1404 &destServ, destPartition, fromDate, newExt, oldFlag,
1405 /*parentDump */ 0, /*dumpLevel */ 0,
1406 bc_Restorer, ports, portCount,
1407 /*dumpSched */ 0, /*append */ 0, dontExecute);
1409 com_err(whoami, code, "; Failed to queue restore");
1414 /* bc_VolsetRestoreCmd
1415 * restore a volumeset or list of volumes.
1418 bc_VolsetRestoreCmd(as, arock)
1419 struct cmd_syndesc *as;
1427 afs_int32 *ports = NULL;
1428 afs_int32 portCount = 0;
1430 afs_int32 portoffset = 0;
1432 struct bc_volumeSet *volsetPtr; /* Ptr to list of generated volume info */
1433 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1434 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1435 struct sockaddr_in destServer; /* machine to which to restore volume */
1436 afs_int32 destPartition; /* partition to which to restore volumes */
1437 struct cmd_item *ti;
1440 code = bc_UpdateVolumeSet();
1442 com_err(whoami, code, "; Can't retrieve volume sets");
1445 code = bc_UpdateHosts();
1447 com_err(whoami, code, "; Can't retrieve tape hosts");
1451 if (as->parms[0].items) {
1452 if (as->parms[1].items) {
1453 com_err(whoami, 0, "Can't have both -name and -file options");
1457 volsetName = as->parms[0].items->data;
1458 volsetPtr = bc_FindVolumeSet(bc_globalConfig, volsetName);
1461 "Can't find volume set '%s' in backup database",
1466 /* Expand out the volume set into its component list of volumes. */
1468 bc_EvalVolumeSet(bc_globalConfig, volsetPtr, &volsToRestore,
1471 com_err(whoami, code, "; Failed to evaluate volume set");
1474 } else if (as->parms[1].items) {
1477 char server[50], partition[50], volume[50], rest[256];
1479 struct bc_volumeDump *tvol;
1481 fd = fopen(as->parms[1].items->data, "r");
1483 com_err(whoami, errno, "; Cannot open file '%s'",
1484 as->parms[1].items->data);
1488 while (fgets(line, 255, fd)) {
1490 sscanf(line, "%s %s %s %s", server, partition, volume, rest);
1496 "Invalid volumeset file format: Wrong number of arguments: Ignoring\n");
1497 fprintf(stderr, " %s", line);
1501 if (bc_ParseHost(server, &destServer)) {
1502 com_err(whoami, 0, "Failed to locate host '%s'", server);
1506 if (bc_GetPartitionID(partition, &destPartition)) {
1508 "Failed to parse destination partition '%s'",
1513 /* Allocate a volumeDump structure and link it in */
1515 (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1516 memset(tvol, 0, sizeof(struct bc_volumeDump));
1518 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1520 com_err(whoami, BC_NOMEM, "");
1523 strncpy(tvol->name, volume, VOLSER_OLDMAXVOLNAME);
1524 memcpy(&tvol->server, &destServer, sizeof(destServer));
1525 tvol->partition = destPartition;
1528 lastVol->next = tvol; /* thread onto end of list */
1530 volsToRestore = tvol;
1535 com_err(whoami, 0, "-name or -file option required");
1540 /* Get the port offset for the restore */
1541 if (as->parms[2].items) {
1542 for (ti = as->parms[2].items; ti; ti = ti->next)
1544 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1546 com_err(whoami, BC_NOMEM, "");
1550 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1551 ports[i] = getPortOffset(ti->data);
1557 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1558 dontExecute = (as->parms[4].items ? 1 : 0);
1560 fromDate = 0x7fffffff; /* last one before this date */
1561 oldFlag = 1; /* do restore same volid (and name) */
1563 /* Perform the call to start the restore */
1564 code = bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1565 /*destserver */ 0, /*destpartition */ 0, fromDate,
1567 /*parentDump */ 0, /*dumpLevel */ 0,
1568 bc_Restorer, ports, portCount,
1569 /*dumpSched */ 0, /*append */ 0, dontExecute);
1571 com_err(whoami, code, "; Failed to queue restore");
1576 /*-----------------------------------------------------------------------------
1580 * Perform a dump of the set of volumes provided.
1581 * user specifies: -volumeset .. -dump .. [-portoffset ..] [-n]
1584 * as : Parsed command line information.
1585 * arock : Ptr to misc stuff; not used.
1589 * The result of bc_StartDump() otherwise
1596 *---------------------------------------------------------------------------
1601 bc_DumpCmd(as, arock)
1602 struct cmd_syndesc *as;
1605 static char rn[] = "bc_DumpCmd"; /*Routine name */
1606 char *dumpPath, *vsName; /*Ptrs to various names */
1607 struct bc_volumeSet *tvs; /*Ptr to list of generated volume info */
1608 struct bc_dumpSchedule *tds, *baseds; /*Ptr to dump schedule node */
1609 struct bc_volumeDump *tve, *volsToDump; /*Ptr to individual vols to be dumped */
1610 struct budb_dumpEntry dumpEntry, de, fde; /* dump entry */
1613 afs_int32 parent; /* parent dump */
1614 afs_int32 level; /* this dump's level # */
1615 afs_int32 problemFindingDump; /* can't find parent(s) */
1617 afs_int32 *portp = NULL;
1618 afs_int32 portCount = 0;
1619 afs_int32 doAt, atTime; /* Time a timed-dump is to start at */
1622 int doAppend; /* Append the dump to dump set */
1623 afs_int32 code; /* Return code */
1624 int loadfile; /* whether to load a file or not */
1628 extern struct bc_dumpTask bc_dumpTasks[];
1629 extern afs_int32 bcdb_FindLastVolClone();
1630 extern afs_int32 volImageTime();
1632 code = bc_UpdateDumpSchedule();
1634 com_err(whoami, code, "; Can't retrieve dump schedule");
1637 code = bc_UpdateVolumeSet();
1639 com_err(whoami, code, "; Can't retrieve volume sets");
1642 code = bc_UpdateHosts();
1644 com_err(whoami, code, "; Can't retrieve tape hosts");
1649 * Some parameters cannot be specified together
1650 * The "-file" option cannot exist with the "-volume", "-dump",
1651 * "-portoffset", or "-append" option
1653 if (as->parms[6].items) {
1655 if (as->parms[0].items || as->parms[1].items || as->parms[2].items
1656 || as->parms[4].items) {
1657 com_err(whoami, 0, "Invalid option specified with -file option");
1662 if (!as->parms[0].items || !as->parms[1].items) {
1664 "Must specify volume set name and dump level name");
1670 * Get the time we are to perform this dump
1672 if (as->parms[3].items) {
1675 timeString = concatParams(as->parms[3].items);
1680 * Now parse this string for the time to start.
1682 code = ktime_DateToLong(timeString, &atTime);
1685 com_err(whoami, 0, "Can't parse dump start date and time");
1686 com_err(whoami, 0, "%s", ktime_GetDateUsage());
1692 dontExecute = (as->parms[5].items ? 1 : 0); /* -n */
1695 * If this dump is not a load file, then check the parameters.
1697 if (!loadfile) { /*6 */
1698 vsName = as->parms[0].items->data; /* get volume set name */
1699 dumpPath = as->parms[1].items->data; /* get dump path */
1701 /* get the port number, if one was specified */
1702 if (as->parms[2].items) {
1704 portp = (afs_int32 *) malloc(sizeof(afs_int32));
1706 com_err(whoami, BC_NOMEM, "");
1710 *portp = getPortOffset(as->parms[2].items->data);
1715 doAppend = (as->parms[4].items ? 1 : 0); /* -append */
1718 * Get a hold of the given volume set and dump set.
1720 tvs = bc_FindVolumeSet(bc_globalConfig, vsName);
1723 "Can't find volume set '%s' in backup database", vsName);
1726 baseds = bc_FindDumpSchedule(bc_globalConfig, dumpPath);
1729 "Can't find dump schedule '%s' in backup database",
1738 * If given the "-at" option, then add this to the jobs list and return
1741 * Create a status node for this timed dump.
1742 * Fill in the time to dump and the cmd line for the dump leaving off
1743 * the -at option. If the -n option is there, it is scheduled with
1744 * the Timed dump as opposed to not scheduling the time dump at all.
1747 if (atTime < time(0)) {
1749 "Time of dump is earlier then current time - not added");
1751 statusPtr = createStatusNode();
1753 statusPtr->scheduledDump = atTime;
1755 /* Determine length of the dump command */
1757 length += 4; /* "dump" */
1759 length += 6; /* " -file" */
1760 length += 1 + strlen(as->parms[6].items->data); /* " <file>" */
1762 /* length += 11; *//* " -volumeset" */
1763 length += 1 + strlen(as->parms[0].items->data); /* " <volset> */
1765 /* length += 6; *//* " -dump" */
1766 length += 1 + strlen(as->parms[1].items->data); /* " <dumpset> */
1768 if (as->parms[2].items) {
1769 /* length += 12; *//* " -portoffset" */
1770 length += 1 + strlen(as->parms[2].items->data); /* " <port>" */
1773 if (as->parms[4].items)
1774 length += 8; /* " -append" */
1778 length += 3; /* " -n" */
1779 length++; /* end-of-line */
1781 /* Allocate status block for this timed dump */
1782 sprintf(statusPtr->taskName, "Scheduled Dump");
1783 statusPtr->jobNumber = bc_jobNumber();
1784 statusPtr->scheduledDump = atTime;
1785 statusPtr->cmdLine = (char *)malloc(length);
1786 if (!statusPtr->cmdLine) {
1787 com_err(whoami, BC_NOMEM, "");
1791 /* Now reconstruct the dump command */
1792 statusPtr->cmdLine[0] = 0;
1793 strcat(statusPtr->cmdLine, "dump");
1795 strcat(statusPtr->cmdLine, " -file");
1796 strcat(statusPtr->cmdLine, " ");
1797 strcat(statusPtr->cmdLine, as->parms[6].items->data);
1799 /* strcat(statusPtr->cmdLine, " -volumeset"); */
1800 strcat(statusPtr->cmdLine, " ");
1801 strcat(statusPtr->cmdLine, as->parms[0].items->data);
1803 /* strcat(statusPtr->cmdLine, " -dump"); */
1804 strcat(statusPtr->cmdLine, " ");
1805 strcat(statusPtr->cmdLine, as->parms[1].items->data);
1807 if (as->parms[2].items) {
1808 /* strcat(statusPtr->cmdLine, " -portoffset"); */
1809 strcat(statusPtr->cmdLine, " ");
1810 strcat(statusPtr->cmdLine, as->parms[2].items->data);
1813 if (as->parms[4].items)
1814 strcat(statusPtr->cmdLine, " -append");
1817 strcat(statusPtr->cmdLine, " -n");
1819 printf("Add scheduled dump as job %d\n", statusPtr->jobNumber);
1820 if ((atTime > ttoken.endTime) && (ttoken.endTime != NEVERDATE))
1822 "Warning: job %d starts after expiration of AFS token",
1823 statusPtr->jobNumber);
1832 * Read and execute the load file if specified. The work of reading is done
1833 * in the main routine prior the dispatch call. loadFile and dontExecute are
1834 * global variables so this can take place in main.
1837 loadFile = (char *)malloc(strlen(as->parms[6].items->data) + 1);
1839 com_err(whoami, BC_NOMEM, "");
1842 strcpy(loadFile, as->parms[6].items->data);
1847 * We are doing a real dump (no load file or timed dump).
1849 printf("Starting dump of volume set '%s' (dump level '%s')\n", vsName,
1852 /* For each dump-level above this one, see if the volumeset was dumped
1853 * at the level. We search all dump-levels since a higher dump-level
1854 * may have actually been done AFTER a lower dump level.
1856 parent = level = problemFindingDump = 0;
1857 for (tds = baseds->parent; tds; tds = tds->parent) {
1858 /* Find the most recent dump of the volume-set at this dump-level.
1859 * Raise problem flag if didn't find a dump and a parent not yet found.
1861 code = bcdb_FindLatestDump(vsName, tds->name, &dumpEntry);
1864 problemFindingDump = 1; /* skipping a dump level */
1868 /* We found the most recent dump at this level. Now check
1869 * if we should use it by seeing if its full dump hierarchy
1870 * exists. If it doesn't, we don't want to base our incremental
1873 if (!parent || (dumpEntry.id > parent)) {
1874 /* Follow the parent dumps to see if they are all there */
1875 for (d = dumpEntry.parent; d; d = de.parent) {
1876 code = bcdb_FindDumpByID(d, &de);
1881 /* If we found the entire level, remember it. Otherwise raise flag.
1882 * If we had already found a dump, raise the problem flag.
1886 problemFindingDump = 1;
1887 parent = dumpEntry.id;
1888 level = dumpEntry.level + 1;
1889 memcpy(&fde, &dumpEntry, sizeof(dumpEntry));
1891 /* Dump hierarchy not complete so can't base off the latest */
1892 problemFindingDump = 1;
1897 /* If the problemflag was raise, it means we are not doing the
1898 * dump at the level we requested it be done at.
1900 if (problemFindingDump) {
1902 "Warning: Doing level %d dump due to missing higher-level dumps",
1905 printf("Parent dump: dump %s (DumpID %u)\n", fde.name, parent);
1907 } else if (parent) {
1908 printf("Found parent: dump %s (DumpID %u)\n", fde.name, parent);
1911 /* Expand out the volume set into its component list of volumes. */
1912 code = bc_EvalVolumeSet(bc_globalConfig, tvs, &volsToDump, cstruct);
1914 com_err(whoami, code, "; Failed to evaluate volume set");
1918 printf("No volumes to dump\n");
1922 /* Determine what the clone time of the volume was when it was
1923 * last dumped (tve->date). This is the time from when an
1924 * incremental should be done (remains zero if a full dump).
1927 for (tve = volsToDump; tve; tve = tve->next) {
1928 code = bcdb_FindClone(parent, tve->name, &tve->date);
1932 /* Get the time the volume was last cloned and see if the volume has
1933 * changed since then. Only do this when the "-n" flag is specified
1934 * because butc will get the cloneDate at time of dump.
1938 volImageTime(tve->server.sin_addr.s_addr, tve->partition,
1939 tve->vid, tve->volType, &tve->cloneDate);
1943 if (tve->cloneDate && (tve->cloneDate == tve->date)) {
1945 "Warning: Timestamp on volume %s unchanged from previous dump",
1953 printf("Would have dumped the following volumes:\n");
1955 printf("Preparing to dump the following volumes:\n");
1956 for (tve = volsToDump; tve; tve = tve->next) {
1957 printf("\t%s (%u)\n", tve->name, tve->vid);
1962 code = bc_StartDmpRst(bc_globalConfig, dumpPath, vsName, volsToDump,
1963 /*destServer */ 0, /*destPartition */ 0,
1965 /*newExt */ 0, /*oldFlag */ 0,
1966 parent, level, bc_Dumper, portp, /*portCount */ 1,
1967 baseds, doAppend, dontExecute);
1969 com_err(whoami, code, "; Failed to queue dump");
1976 * terminate the backup process. Insists that that all running backup
1977 * jobs be terminated before it will quit
1982 bc_QuitCmd(as, arock)
1983 struct cmd_syndesc *as;
1987 struct bc_dumpTask *td;
1988 extern dlqlinkT statusHead;
1992 /* Check the status list for outstanding jobs */
1994 for (ptr = (&statusHead)->dlq_next; ptr != &statusHead;
1995 ptr = ptr->dlq_next) {
1996 statusPtr = (statusP) ptr;
1997 if (!(statusPtr->flags & ABORT_REQUEST)) {
1999 com_err(whoami, 0, "Job %d still running (and not aborted)",
2000 statusPtr->jobNumber);
2002 "You must at least 'kill' all running jobs before quitting");
2008 /* A job still being initialized (but no status structure or job number since it
2009 * has not been handed to a butc process yet)
2011 for (td = bc_dumpTasks, i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
2012 if (td->flags & BC_DI_INUSE) {
2013 com_err(whoami, 0, "A job is still running");
2015 "You must at least 'kill' all running jobs before quitting");
2021 /* close the all temp text files before quitting */
2022 for (i = 0; i < TB_NUM; i++)
2023 bc_closeTextFile(&bc_globalConfig->configText[i],
2024 &bc_globalConfig->tmpTextFileNames[i][0]);
2030 * Labels a tape i.e. request the tape coordinator to perform this
2034 bc_LabelTapeCmd(as, arock)
2035 struct cmd_syndesc *as;
2038 char *tapename = 0, *pname = 0;
2043 code = bc_UpdateHosts();
2045 com_err(whoami, code, "; Can't retrieve tape hosts");
2049 if (as->parms[0].items) { /* -name */
2050 tapename = as->parms[0].items->data;
2051 if (strlen(tapename) >= TC_MAXTAPELEN) {
2052 com_err(whoami, 0, "AFS tape name '%s' is too long", tapename);
2057 if (as->parms[3].items) { /* -pname */
2059 com_err(whoami, 0, "Can only specify -name or -pname");
2062 pname = as->parms[3].items->data;
2063 if (strlen(pname) >= TC_MAXTAPELEN) {
2064 com_err(whoami, 0, "Permanent tape name '%s' is too long", pname);
2069 if (as->parms[1].items) {
2070 size = bc_FloatATOI(as->parms[1].items->data);
2072 com_err(whoami, 0, "Bad syntax for tape size '%s'",
2073 as->parms[1].items->data);
2079 if (as->parms[2].items) {
2080 port = getPortOffset(as->parms[2].items->data);
2085 code = bc_LabelTape(tapename, pname, size, bc_globalConfig, port);
2092 * read the label on a tape
2094 * optional port number
2097 bc_ReadLabelCmd(as, arock)
2098 struct cmd_syndesc *as;
2104 code = bc_UpdateHosts();
2106 com_err(whoami, code, "; Can't retrieve tape hosts");
2110 if (as->parms[0].items) {
2111 port = getPortOffset(as->parms[0].items->data);
2116 code = bc_ReadLabel(bc_globalConfig, port);
2123 * read content information from dump tapes, and if user desires,
2124 * add it to the database
2127 bc_ScanDumpsCmd(as, arock)
2128 struct cmd_syndesc *as;
2132 afs_int32 dbAddFlag = 0;
2135 code = bc_UpdateHosts();
2137 com_err(whoami, code, "; Can't retrieve tape hosts");
2141 /* check for flag */
2142 if (as->parms[0].items != 0) { /* add scan to database */
2146 /* check for port */
2147 if (as->parms[1].items) {
2148 port = getPortOffset(as->parms[1].items->data);
2153 code = bc_ScanDumps(bc_globalConfig, dbAddFlag, port);
2157 /* bc_ParseExpiration
2160 * dates are specified as absolute or relative, the syntax is:
2161 * absolute: at %d/%d/%d [%d:%d] where [..] is optional
2162 * relative: in [%dy][%dm][%dd] where at least one component
2167 bc_ParseExpiration(paramPtr, expType, expDate)
2168 struct cmd_parmdesc *paramPtr;
2172 struct cmd_item *itemPtr;
2173 struct ktime_date kt;
2174 char *dateString = 0;
2177 *expType = BC_NO_EXPDATE;
2180 if (!paramPtr->items)
2181 ERROR(0); /* no expiration specified */
2183 /* some form of expiration date specified. First validate the prefix */
2184 itemPtr = paramPtr->items;
2186 if (strcmp(itemPtr->data, "at") == 0) {
2187 *expType = BC_ABS_EXPDATE;
2189 dateString = concatParams(itemPtr->next);
2193 code = ktime_DateToLong(dateString, expDate);
2196 } else if (strcmp(itemPtr->data, "in") == 0) {
2197 *expType = BC_REL_EXPDATE;
2199 dateString = concatParams(itemPtr->next);
2203 code = ParseRelDate(dateString, &kt);
2206 *expDate = ktimeRelDate_ToLong(&kt);
2208 dateString = concatParams(itemPtr);
2212 if (ktime_DateToLong(dateString, expDate) == 0) {
2213 *expType = BC_ABS_EXPDATE;
2214 code = ktime_DateToLong(dateString, expDate);
2217 } else if (ParseRelDate(dateString, &kt) == 0) {
2218 *expType = BC_REL_EXPDATE;
2219 *expDate = ktimeRelDate_ToLong(&kt);
2231 /* database lookup command and routines */
2234 * Currently a single option, volumename to search for. Reports
2235 * all dumps containing the specified volume
2238 bc_dblookupCmd(as, arock)
2239 struct cmd_syndesc *as;
2242 struct cmd_item *ciptr;
2245 ciptr = as->parms[0].items;
2246 if (ciptr == 0) /* no argument specified */
2249 code = DBLookupByVolume(ciptr->data);
2255 /* for ubik version */
2257 bc_dbVerifyCmd(as, arock)
2258 struct cmd_syndesc *as;
2265 struct hostent *hostPtr;
2269 extern struct udbHandleS udbHandle;
2271 detail = (as->parms[0].items ? 1 : 0); /* print more details */
2274 ubik_Call(BUDB_DbVerify, udbHandle.uh_client, 0, &status, &orphans,
2278 com_err(whoami, code, "; Unable to verify database");
2282 /* verification call succeeded */
2285 printf("Database OK\n");
2287 com_err(whoami, status, "; Database is NOT_OK");
2290 printf("Orphan blocks %d\n", orphans);
2293 printf("Unable to lookup host id\n");
2295 hostPtr = gethostbyaddr((char *)&host, sizeof(host), AF_INET);
2297 printf("Database checker was %d.%d.%d.%d\n",
2298 ((host & 0xFF000000) >> 24), ((host & 0xFF0000) >> 16),
2299 ((host & 0xFF00) >> 8), (host & 0xFF));
2301 printf("Database checker was %s\n", hostPtr->h_name);
2304 return ((status ? -1 : 0));
2308 * Delete a dump. If port is >= 0, it means try to delete from XBSA server
2310 deleteDump(dumpid, port, force)
2311 afs_uint32 dumpid; /* The dumpid to delete */
2312 afs_int32 port; /* port==-1 means don't go to butc */
2315 afs_int32 code = 0, tcode;
2316 struct budb_dumpEntry dumpEntry;
2317 struct rx_connection *tconn = 0;
2318 afs_int32 i, taskflag, xbsadump;
2319 statusP statusPtr = 0;
2320 budb_dumpsList dumps;
2323 /* If the port is set, we will try to send a delete request to the butc */
2325 tcode = bc_UpdateHosts();
2327 com_err(whoami, tcode, "; Can't retrieve tape hosts");
2331 /* Find the dump in the backup database */
2332 tcode = bcdb_FindDumpByID(dumpid, &dumpEntry);
2334 com_err(whoami, tcode, "; Unable to locate dumpID %u in database",
2338 xbsadump = (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA));
2340 /* If dump is to an XBSA server, connect to butc and send it
2341 * the dump to delete. Butc will contact the XBSA server.
2342 * The dump will not be an appended dump because XBSA butc
2343 * does not support the append option.
2345 if (xbsadump && dumpEntry.nVolumes) {
2346 tcode = ConnectButc(bc_globalConfig, port, &tconn);
2350 tcode = TC_DeleteDump(tconn, dumpid, &taskId);
2352 if (tcode == RXGEN_OPCODE)
2353 tcode = BC_VERSIONFAIL;
2354 com_err(whoami, tcode,
2355 "; Unable to delete dumpID %u via butc", dumpid);
2359 statusPtr = createStatusNode();
2361 statusPtr->taskId = taskId;
2362 statusPtr->port = port;
2363 statusPtr->jobNumber = bc_jobNumber();
2364 statusPtr->flags |= (SILENT | NOREMOVE); /* No msg & keep statusPtr */
2365 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2366 sprintf(statusPtr->taskName, "DeleteDump");
2369 /* Wait for task to finish */
2370 taskflag = waitForTask(taskId);
2371 if (taskflag & (TASK_ERROR | ABORT_DONE)) {
2372 com_err(whoami, BUTX_DELETEOBJFAIL,
2373 "; Unable to delete dumpID %u via butc", dumpid);
2374 ERROR(BUTX_DELETEOBJFAIL); /* the task failed */
2381 deleteStatusNode(statusPtr); /* Clean up statusPtr - because NOREMOVE */
2383 rx_DestroyConnection(tconn); /* Destroy the connection */
2385 /* Remove the dump from the backup database */
2386 if (!code || force) {
2387 dumps.budb_dumpsList_len = 0;
2388 dumps.budb_dumpsList_val = 0;
2390 tcode = bcdb_deleteDump(dumpid, 0, 0, &dumps);
2392 com_err(whoami, tcode,
2393 "; Unable to delete dumpID %u from database", dumpid);
2394 dumps.budb_dumpsList_len = 0;
2399 /* Display the dumps that were deleted - includes appended dumps */
2400 for (i = 0; i < dumps.budb_dumpsList_len; i++)
2401 printf(" %u%s\n", dumps.budb_dumpsList_val[i],
2402 (i > 0) ? " Appended Dump" : "");
2403 if (dumps.budb_dumpsList_val)
2404 free(dumps.budb_dumpsList_val);
2411 * Delete a specified dump from the database
2413 * dump id - single required arg as param 0.
2416 bc_deleteDumpCmd(as, arock)
2417 struct cmd_syndesc *as;
2422 afs_int32 rcode = 0;
2423 afs_int32 groupId = 0, havegroupid, sflags, noexecute;
2424 struct cmd_item *ti;
2425 afs_uint32 fromTime = 0, toTime = 0, havetime = 0;
2427 budb_dumpsList dumps, flags;
2429 afs_int32 port = -1, dbonly = 0, force;
2431 /* Must specify at least one of -dumpid, -from, or -to */
2432 if (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items
2433 && !as->parms[4].items) {
2434 com_err(whoami, 0, "Must specify at least one field");
2438 /* Must have -to option with -from option */
2439 if (as->parms[1].items && !as->parms[2].items) {
2440 com_err(whoami, 0, "Must specify '-to' field with '-from' field");
2444 /* Get the time to delete from */
2445 if (as->parms[1].items) { /* -from */
2446 timeString = concatParams(as->parms[1].items);
2451 * Now parse this string for the time to start.
2453 code = ktime_DateToLong(timeString, &fromTime);
2456 com_err(whoami, 0, "Can't parse 'from' date and time");
2457 com_err(whoami, 0, "%s", ktime_GetDateUsage());
2463 port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -port */
2464 if (as->parms[5].items) /* -dbonly */
2467 force = (as->parms[6].items ? 1 : 0);
2469 havegroupid = (as->parms[4].items ? 1 : 0);
2471 groupId = atoi(as->parms[4].items->data);
2473 noexecute = (as->parms[7].items ? 1 : 0);
2475 /* Get the time to delete to */
2476 if (as->parms[2].items) { /* -to */
2477 timeString = concatParams(as->parms[2].items);
2482 * Now parse this string for the time to start. Simce
2483 * times are at minute granularity, add 59 seconds.
2485 code = ktime_DateToLong(timeString, &toTime);
2488 com_err(whoami, 0, "Can't parse 'to' date and time");
2489 com_err(whoami, 0, "%s", ktime_GetDateUsage());
2496 if (fromTime > toTime) {
2498 "'-from' date/time cannot be later than '-to' date/time");
2502 /* Remove speicific dump ids - if any */
2503 printf("The following dumps %s deleted:\n",
2504 (noexecute ? "would have been" : "were"));
2505 for (ti = as->parms[0].items; ti != 0; ti = ti->next) { /* -dumpid */
2506 dumpid = atoi(ti->data);
2508 code = deleteDump(dumpid, port, force);
2510 printf(" %u\n", dumpid);
2515 * Now remove dumps between to and from dates.
2517 if (havegroupid || havetime) {
2518 dumps.budb_dumpsList_len = 0;
2519 dumps.budb_dumpsList_val = 0;
2520 flags.budb_dumpsList_len = 0;
2521 flags.budb_dumpsList_val = 0;
2524 sflags |= BUDB_OP_GROUPID;
2526 sflags |= BUDB_OP_DATES;
2529 bcdb_listDumps(sflags, groupId, fromTime, toTime, &dumps, &flags);
2531 com_err(whoami, code,
2532 "; Error while deleting dumps from %u to %u", fromTime,
2537 for (i = 0; i < dumps.budb_dumpsList_len; i++) {
2538 if (flags.budb_dumpsList_val[i] & BUDB_OP_DBDUMP)
2542 if (flags.budb_dumpsList_val[i] & BUDB_OP_APPDUMP)
2544 code = deleteDump(dumps.budb_dumpsList_val[i], port, force);
2545 /* Ignore code and continue */
2547 printf(" %u%s%s\n", dumps.budb_dumpsList_val[i],
2549 budb_dumpsList_val[i] & BUDB_OP_APPDUMP) ?
2550 " Appended Dump" : "",
2552 budb_dumpsList_val[i] & BUDB_OP_DBDUMP) ?
2553 " Database Dump" : "");
2558 if (dumps.budb_dumpsList_val)
2559 free(dumps.budb_dumpsList_val);
2560 dumps.budb_dumpsList_len = 0;
2561 dumps.budb_dumpsList_val = 0;
2562 if (flags.budb_dumpsList_val)
2563 free(flags.budb_dumpsList_val);
2564 flags.budb_dumpsList_len = 0;
2565 flags.budb_dumpsList_val = 0;
2571 bc_saveDbCmd(as, arock)
2572 struct cmd_syndesc *as;
2575 struct rx_connection *tconn;
2576 afs_int32 portOffset = 0;
2583 code = bc_UpdateHosts();
2585 com_err(whoami, code, "; Can't retrieve tape hosts");
2589 if (as->parms[0].items) {
2590 portOffset = getPortOffset(as->parms[0].items->data);
2595 /* Get the time to delete to */
2596 if (as->parms[1].items) {
2597 timeString = concatParams(as->parms[1].items);
2602 * Now parse this string for the time. Since
2603 * times are at minute granularity, add 59 seconds.
2605 code = ktime_DateToLong(timeString, &toTime);
2608 com_err(whoami, 0, "Can't parse '-archive' date and time");
2609 com_err(whoami, 0, "%s", ktime_GetDateUsage());
2616 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2620 code = TC_SaveDb(tconn, toTime, &taskId);
2622 com_err(whoami, code, "; Failed to save database");
2626 /* create status monitor block */
2627 statusPtr = createStatusNode();
2629 statusPtr->taskId = taskId;
2630 statusPtr->port = portOffset;
2631 statusPtr->jobNumber = bc_jobNumber();
2632 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2633 sprintf(statusPtr->taskName, "SaveDb");
2637 rx_DestroyConnection(tconn);
2641 bc_restoreDbCmd(as, arock)
2642 struct cmd_syndesc *as;
2645 struct rx_connection *tconn;
2646 afs_int32 portOffset = 0;
2651 code = bc_UpdateHosts();
2653 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 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
2723 DBLookupByVolume(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 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(dumpid, detailFlag)
2861 afs_int32 detailFlag;
2863 struct budb_dumpEntry dumpEntry;
2864 struct tapeLink *head = 0;
2865 struct tapeLink *tapeLinkPtr, *lastTapeLinkPtr;
2866 struct volumeLink **link, *volumeLinkPtr, *lastVolumeLinkPtr;
2869 afs_int32 last, next, dbTime;
2870 afs_int32 tapedumpid;
2878 extern struct udbHandleS udbHandle;
2881 lastTapeLinkPtr = 0;
2883 lastVolumeLinkPtr = 0;
2885 /* first get information about the dump */
2887 code = bcdb_FindDumpByID(dumpid, &dumpEntry);
2891 /* For the user, the tape name is its name and initial dump id */
2892 tapedumpid = (dumpEntry.initialDumpID ? dumpEntry.initialDumpID : dumpid);
2894 /* Is this a database dump id or not */
2895 if (strcmp(dumpEntry.name, DUMP_TAPE_NAME) == 0)
2900 /* print out the information about the dump */
2904 printDumpEntry(&dumpEntry);
2906 time_t t = dumpEntry.created;
2908 printf("Dump: id %u, created: %s\n", dumpEntry.id,
2911 printf("Dump: id %u, level %d, volumes %d, created: %s\n",
2912 dumpEntry.id, dumpEntry.level, dumpEntry.nVolumes,
2916 if (!detailFlag && (strlen(dumpEntry.tapes.tapeServer) > 0)
2917 && (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA))) {
2918 printf("Backup Service: TSM: Server: %s\n",
2919 dumpEntry.tapes.tapeServer);
2922 /* now get the list of tapes */
2923 for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) { /*f */
2924 tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
2926 com_err(whoami, BC_NOMEM, "");
2930 memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
2931 code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
2938 /* add this tape to previous chain */
2939 if (lastTapeLinkPtr) {
2940 lastTapeLinkPtr->nextTape = tapeLinkPtr;
2941 lastTapeLinkPtr = tapeLinkPtr;
2946 lastTapeLinkPtr = head;
2950 while (next != -1) { /*wn */
2951 vl.budb_volumeList_len = 0;
2952 vl.budb_volumeList_val = 0;
2955 /* now get all the volumes in this dump. */
2956 code = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client, UF_SINGLESERVER, BUDB_MAJORVERSION, BUDB_OP_DUMPID | BUDB_OP_TAPENAME, tapeLinkPtr->tapeEntry.name, /* tape name */
2957 dumpid, /* dumpid (not initial dumpid) */
2960 &next, /* nextindex */
2961 &dbTime, /* update time */
2965 if (code == BUDB_ENDOFLIST) { /* 0 volumes on tape */
2972 for (i = 0; i < vl.budb_volumeList_len; i++) {
2973 link = &tapeLinkPtr->firstVolume;
2976 (struct volumeLink *)malloc(sizeof(struct volumeLink));
2977 if (!volumeLinkPtr) {
2978 com_err(whoami, BC_NOMEM, "");
2981 memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
2983 memcpy(&volumeLinkPtr->volumeEntry,
2984 &vl.budb_volumeList_val[i],
2985 sizeof(struct budb_volumeEntry));
2987 /* now insert it onto the right place */
2989 && (volumeLinkPtr->volumeEntry.position >
2990 (*link)->volumeEntry.position)) {
2991 link = &((*link)->nextVolume);
2994 /* now link it in */
2995 volumeLinkPtr->nextVolume = *link;
2996 *link = volumeLinkPtr;
2999 if (vl.budb_volumeList_val)
3000 free(vl.budb_volumeList_val);
3004 for (tapeLinkPtr = head; tapeLinkPtr; tapeLinkPtr = tapeLinkPtr->nextTape) {
3008 printTapeEntry(&tapeLinkPtr->tapeEntry);
3010 printf("Tape: name %s (%u)\n", tapeLinkPtr->tapeEntry.name,
3012 printf("nVolumes %d, ", tapeLinkPtr->tapeEntry.nVolumes);
3013 compactDateString(&tapeLinkPtr->tapeEntry.written, ds, 50);
3014 printf("created %16s", ds);
3015 if (tapeLinkPtr->tapeEntry.expires != 0) {
3016 compactDateString(&tapeLinkPtr->tapeEntry.expires, ds, 50);
3017 printf(", expires %16s", ds);
3022 /* print out all the volumes */
3024 /* print header for volume listing - db dumps have no volumes */
3025 if ((detailFlag == 0) && !dbDump)
3026 printf("%4s %16s %9s %-s\n", "Pos", "Clone time", "Nbytes",
3029 for (volumeLinkPtr = tapeLinkPtr->firstVolume; volumeLinkPtr;
3030 volumeLinkPtr = volumeLinkPtr->nextVolume) {
3032 printf("\nVolume\n");
3034 printVolumeEntry(&volumeLinkPtr->volumeEntry);
3036 compactDateString(&volumeLinkPtr->volumeEntry.clone, ds, 50),
3037 printf("%4d %s %10u %16s\n",
3038 volumeLinkPtr->volumeEntry.position, ds,
3039 volumeLinkPtr->volumeEntry.nBytes,
3040 volumeLinkPtr->volumeEntry.name);
3047 com_err("dumpInfo", code, "; Can't get dump information");
3049 /* free all allocated structures */
3051 while (tapeLinkPtr) {
3052 volumeLinkPtr = tapeLinkPtr->firstVolume;
3053 while (volumeLinkPtr) {
3054 lastVolumeLinkPtr = volumeLinkPtr;
3055 volumeLinkPtr = volumeLinkPtr->nextVolume;
3056 free(lastVolumeLinkPtr);
3059 lastTapeLinkPtr = tapeLinkPtr;
3060 tapeLinkPtr = tapeLinkPtr->nextTape;
3061 free(lastTapeLinkPtr);
3067 compareDump(ptr1, ptr2)
3068 struct budb_dumpEntry *ptr1, *ptr2;
3070 if (ptr1->created < ptr2->created)
3072 else if (ptr1->created > ptr2->created)
3078 printRecentDumps(ndumps)
3082 afs_int32 nextindex, index = 0;
3085 struct budb_dumpEntry *dumpPtr;
3089 extern struct udbHandleS udbHandle;
3090 extern compareDump();
3092 do { /* while (nextindex != -1) */
3093 /* initialize the dump list */
3094 dl.budb_dumpList_len = 0;
3095 dl.budb_dumpList_val = 0;
3097 /* outline algorithm */
3098 code = ubik_Call(BUDB_GetDumps, udbHandle.uh_client, 0, BUDB_MAJORVERSION, BUDB_OP_NPREVIOUS, "", /* no name */
3102 &nextindex, &dbTime, &dl);
3104 if (code == BUDB_ENDOFLIST)
3106 com_err("dumpInfo", code, "; Can't get dump information");
3110 /* No need to sort, it's already sorted */
3112 if (dl.budb_dumpList_len && (index == 0))
3113 printf("%10s %10s %2s %-16s %2s %5s dump name\n", "dumpid",
3114 "parentid", "lv", "created", "nt", "nvols");
3116 dumpPtr = dl.budb_dumpList_val;
3117 for (i = 1; i <= dl.budb_dumpList_len; i++) {
3118 compactDateString(&dumpPtr->created, ds, 50),
3119 printf("%10u %10u %-2d %16s %2d %5d %s", dumpPtr->id,
3120 dumpPtr->parent, dumpPtr->level, ds,
3121 dumpPtr->tapes.maxTapes - dumpPtr->tapes.b + 1,
3122 dumpPtr->nVolumes, dumpPtr->name);
3123 if (dumpPtr->initialDumpID) /* an appended dump */
3124 printf(" (%u)", dumpPtr->initialDumpID);
3125 else if (dumpPtr->appendedDumpID) /* has appended dumps */
3126 printf(" (%u)", dumpPtr->id);
3132 if (dl.budb_dumpList_val)
3133 free(dl.budb_dumpList_val);
3135 } while (nextindex != -1);
3141 * list the dumps and contens of the dumps.
3146 bc_dumpInfoCmd(as, arock)
3147 struct cmd_syndesc *as;
3151 afs_int32 detailFlag;
3155 afs_int32 dumpInfo();
3157 if (as->parms[0].items) {
3158 if (as->parms[1].items) {
3160 "These options are exclusive - select only one");
3163 ndumps = atoi(as->parms[0].items->data);
3165 com_err(whoami, 0, "Must provide a positive number");
3169 code = printRecentDumps(ndumps);
3170 } else if (as->parms[1].items) {
3171 detailFlag = (as->parms[2].items ? 1 : 0); /* 1 = detailed listing */
3172 dumpid = atoi(as->parms[1].items->data);
3173 code = dumpInfo(dumpid, detailFlag);
3175 code = printRecentDumps(10);