2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #ifdef HAVE_POSIX_REGEX /* use POSIX regexp library */
21 #include <afs/com_err.h>
22 #include <afs/afsutil.h>
24 #include <afs/budb_prototypes.h>
26 #include <afs/bubasics.h> /* PA */
27 #include <afs/volser.h>
28 #include <afs/voldefs.h> /* PA */
29 #include <afs/vldbint.h> /* PA */
30 #include <afs/ktime.h> /* PA */
33 #include <afs/tcdata.h>
35 #include <afs/vsutils_prototypes.h>
38 #include "error_macros.h"
39 #include "bucoord_internal.h"
40 #include "bucoord_prototypes.h"
42 extern struct bc_config *bc_globalConfig;
43 extern struct bc_dumpTask bc_dumpTasks[BC_MAXSIMDUMPS];
44 extern struct ubik_client *cstruct;
48 extern afs_int32 lastTaskCode;
50 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
52 static int EvalVolumeSet1(struct bc_config *aconfig, struct bc_volumeSet *avs,
53 struct bc_volumeDump **avols,
54 struct ubik_client *uclient);
56 static int EvalVolumeSet2(struct bc_config *aconfig, struct bc_volumeSet *avs,
57 struct bc_volumeDump **avols,
58 struct ubik_client *uclient);
59 static int DBLookupByVolume(char *volumeName);
62 bc_EvalVolumeSet(struct bc_config *aconfig,
63 struct bc_volumeSet *avs,
64 struct bc_volumeDump **avols,
65 struct ubik_client *uclient)
66 { /*bc_EvalVolumeSet */
68 static afs_int32 use = 2;
70 if (use == 2) { /* Use EvalVolumeSet2() */
71 code = EvalVolumeSet2(aconfig, avs, avols, uclient);
72 if (code == RXGEN_OPCODE)
75 if (use == 1) { /* Use EvalVolumeSet1() */
76 code = EvalVolumeSet1(aconfig, avs, avols, uclient);
79 } /*bc_EvalVolumeSet */
81 struct partitionsort {
83 struct bc_volumeDump *vdlist;
84 struct bc_volumeDump *lastvdlist;
85 struct bc_volumeDump *dupvdlist;
86 struct bc_volumeEntry *vole;
87 struct partitionsort *next;
91 struct partitionsort *partitions;
92 struct serversort *next;
96 getSPEntries(afs_uint32 server, afs_int32 partition,
97 struct serversort **serverlist,
98 struct serversort **ss,
99 struct partitionsort **ps)
101 if (!(*ss) || ((*ss)->ipaddr != server)) {
103 for ((*ss) = *serverlist; (*ss); *ss = (*ss)->next) {
104 if ((*ss)->ipaddr == server)
108 /* No server entry added. Add one */
110 *ss = (struct serversort *)malloc(sizeof(struct serversort));
112 afs_com_err(whoami, BC_NOMEM, NULL);
116 memset(*ss, 0, sizeof(struct serversort));
117 (*ss)->ipaddr = server;
118 (*ss)->next = *serverlist;
123 if (!(*ps) || ((*ps)->part != partition)) {
124 for (*ps = (*ss)->partitions; *ps; *ps = (*ps)->next) {
125 if ((*ps)->part == partition)
129 /* No partition entry added. Add one */
131 *ps = (struct partitionsort *)malloc(sizeof(struct partitionsort));
133 afs_com_err(whoami, BC_NOMEM, NULL);
139 memset(*ps, 0, sizeof(struct partitionsort));
140 (*ps)->part = partition;
141 (*ps)->next = (*ss)->partitions;
142 (*ss)->partitions = *ps;
148 randSPEntries(struct serversort *serverlist,
149 struct bc_volumeDump **avols)
151 struct serversort *ss, **pss;
152 struct partitionsort *ps, **pps;
154 afs_int32 scount, pcount;
158 /* Seed random number generator */
159 r = time(0) + getpid();
162 /* Count number of servers, remove one at a time */
163 for (scount = 0, ss = serverlist; ss; ss = ss->next, scount++);
164 for (; scount; scount--) {
165 /* Pick a random server in list and remove it */
166 r = (rand() >> 4) % scount;
167 for (pss = &serverlist, ss = serverlist; r;
168 pss = &ss->next, ss = ss->next, r--);
171 /* Count number of partitions, remove one at a time */
172 for (pcount = 0, ps = ss->partitions; ps; ps = ps->next, pcount++);
173 for (; pcount; pcount--) {
174 /* Pick a random parition in list and remove it */
175 r = (rand() >> 4) % pcount;
176 for (pps = &ss->partitions, ps = ss->partitions; r;
177 pps = &ps->next, ps = ps->next, r--);
180 ps->lastvdlist->next = *avols;
190 EvalVolumeSet2(struct bc_config *aconfig,
191 struct bc_volumeSet *avs,
192 struct bc_volumeDump **avols,
193 struct ubik_client *uclient)
194 { /*EvalVolumeSet2 */
195 struct bc_volumeEntry *tve;
196 struct bc_volumeDump *tavols;
197 struct VldbListByAttributes attributes;
198 afs_int32 si, nsi; /* startIndex and nextStartIndex */
199 afs_int32 nentries, e, ei, et, add, l;
200 nbulkentries bulkentries;
201 struct nvldbentry *entries = 0;
202 struct bc_volumeDump *tvd;
203 afs_int32 code = 0, tcode;
205 struct serversort *servers = 0, *ss = 0;
206 struct partitionsort *ps = 0;
208 *avols = (struct bc_volumeDump *)0;
209 bulkentries.nbulkentries_len = 0;
210 bulkentries.nbulkentries_val = 0;
212 /* For each of the volume set entries - collect the volumes that match it */
213 for (tve = avs->ventries; tve; tve = tve->next) {
214 /* Put together a call to the vlserver for this vlentry. The
215 * performance gain is from letting the vlserver expand the
216 * volumeset and not this routine.
219 if (tve->server.sin_addr.s_addr) { /* The server */
220 attributes.Mask |= VLLIST_SERVER;
221 attributes.server = tve->server.sin_addr.s_addr;
223 if (tve->partition != -1) { /* The partition */
224 attributes.Mask |= VLLIST_PARTITION;
225 attributes.partition = tve->partition;
228 /* Now make the call to the vlserver */
229 for (si = 0; si != -1; si = nsi) {
231 bulkentries.nbulkentries_len = 0;
232 bulkentries.nbulkentries_val = 0;
235 ubik_Call(VL_ListAttributesN2, uclient, 0, &attributes,
236 tve->name, si, &nentries, &bulkentries, &nsi);
240 /* The 3.4 vlserver has a VL_ListAttributesN2() RPC call, but
241 * it is not complete. The only way to tell if it is not complete
242 * is if et == 0 (which we check for below). Also, if the call didn't
243 * match any entries, then we don't know what version the vlserver
244 * is. In both cases, we return RXGEN_OPCODE and the calling routine
245 * will switch to the EvalVolumeSet1() call.
248 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
252 if (nentries > bulkentries.nbulkentries_len)
253 nentries = bulkentries.nbulkentries_len;
255 /* Step through each entry and add it to the list of volumes */
256 entries = bulkentries.nbulkentries_val;
257 for (e = 0; e < nentries; e++) {
258 ei = entries[e].matchindex & 0xffff;
259 et = (entries[e].matchindex >> 16) & 0xffff;
274 ERROR(RXGEN_OPCODE); /* Use EvalVolumeSet1 */
277 /* Find server and partiton structure to hang the entry off of */
279 getSPEntries(entries[e].serverNumber[ei],
280 entries[e].serverPartition[ei], &servers,
283 afs_com_err(whoami, tcode, NULL);
287 /* Detect if this entry should be added (not a duplicate).
288 * Use ps->dupvdlist and ps->vole to only search volumes from
289 * previous volume set entries.
292 if (tve != avs->ventries) {
293 l = strlen(entries[e].name);
294 if (ps->vole != tve) {
296 ps->dupvdlist = ps->vdlist;
298 for (tavols = ps->dupvdlist; add && tavols;
299 tavols = tavols->next) {
300 if (strncmp(tavols->name, entries[e].name, l) == 0) {
301 if ((strcmp(&entries[e].name[l], ".backup") == 0)
302 || (strcmp(&entries[e].name[l], ".readonly")
304 || (strcmp(&entries[e].name[l], "") == 0))
311 /* Allocate a volume dump structure and its name */
312 tvd = (struct bc_volumeDump *)
313 malloc(sizeof(struct bc_volumeDump));
315 afs_com_err(whoami, BC_NOMEM, NULL);
318 memset(tvd, 0, sizeof(*tvd));
320 tvd->name = (char *)malloc(strlen(entries[e].name) + 10);
322 afs_com_err(whoami, BC_NOMEM, NULL);
327 /* Fill it in and thread onto avols list */
328 strcpy(tvd->name, entries[e].name);
330 strcat(tvd->name, ".backup");
331 else if (et == ROVOL)
332 strcat(tvd->name, ".readonly");
333 tvd->vid = entries[e].volumeId[et];
336 tvd->partition = entries[e].serverPartition[ei];
337 tvd->server.sin_addr.s_addr = entries[e].serverNumber[ei];
338 tvd->server.sin_port = 0; /* default FS port */
339 tvd->server.sin_family = AF_INET;
340 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
341 tvd->server.sin_len = sizeof(struct sockaddr_in);
344 /* String tvd off of partition struct */
345 tvd->next = ps->vdlist;
348 ps->lastvdlist = tvd;
354 /* Free memory allocated during VL call */
355 if (bulkentries.nbulkentries_val) {
356 free((char *)bulkentries.nbulkentries_val);
357 bulkentries.nbulkentries_val = 0;
363 /* Randomly link the volumedump entries together */
364 randSPEntries(servers, avols);
365 fprintf(stderr, "Total number of volumes : %u\n", count);
368 if (bulkentries.nbulkentries_val) {
369 free((char *)bulkentries.nbulkentries_val);
372 } /*EvalVolumeSet2 */
374 /*-----------------------------------------------------------------------------
378 * Takes the entries in a volumeset and expands them into a list of
379 * volumes. Every VLDB volume entry is looked at and compared to the
382 * When matching a VLDB volume entry to a volumeset entry,
383 * 1. If the RW volume entry matches, that RW volume is used.
384 * 2. Otherwise, if the BK volume entry matches, the BK volume is used.
385 * 3. Finally, if the RO volume entry matches, the RO volume is used.
386 * For instance: A volumeset entry of ".* .* user.t.*" will match volume
387 * "user.troy" and "user.troy.backup". The rules will use
388 * the RW volume "user.troy".
390 * When a VLDB volume entry matches a volumeset entry (be it RW, BK or RO),
391 * that volume is used and matches against any remaining volumeset entries
393 * For instance: A 1st volumeset entry ".* .* .*.backup" will match with
394 * "user.troy.backup". Its 2nd volumeset entry ".* .* .*"
395 * would have matched its RW volume "user.troy", but the first
396 * match is used and the second match isn't even done.
399 * aconfig : Global configuration info.
401 * avols : Ptr to linked list of entries describing volumes to dump.
402 * uclient : Ptr to Ubik client structure.
405 * 0 on successful volume set evaluation,
406 * Lower-level codes otherwise.
409 * Expand only the single volume set provided (avs); don't go down its chain.
413 *-----------------------------------------------------------------------------
416 EvalVolumeSet1(struct bc_config *aconfig,
417 struct bc_volumeSet *avs,
418 struct bc_volumeDump **avols,
419 struct ubik_client *uclient)
420 { /*EvalVolumeSet1 */
421 afs_int32 code; /*Result of various calls */
422 struct bc_volumeDump *tvd; /*Ptr to new dump instance */
423 struct bc_volumeEntry *tve, *ctve; /*Ptr to new volume entry instance */
424 char patt[256]; /*Composite regex; also, target string */
425 int volType = 0; /*Type of volume that worked */
426 afs_int32 index; /*Current VLDB entry index */
427 afs_int32 count; /*Needed by VL_ListEntry() */
428 afs_int32 next_index; /*Next index to list */
429 struct vldbentry entry; /*VLDB entry */
430 int srvpartpair; /*Loop counter: server/partition pair */
434 struct serversort *servers = 0, *ss = 0;
435 struct partitionsort *ps = 0;
436 #ifdef HAVE_POSIX_REGEX
438 int need_regfree = 0;
443 *avols = (struct bc_volumeDump *)0;
444 ctve = (struct bc_volumeEntry *)0; /* no compiled entry */
446 /* For each vldb entry.
447 * Variable next_index is set to the index of the next VLDB entry
448 * in the enumeration.
450 for (index = 0; 1; index = next_index) { /*w */
451 memset(&entry, 0, sizeof(entry));
452 code = ubik_Call(VL_ListEntry, /*Routine to invoke */
453 uclient, /*Ubik client structure */
455 index, /*Current index */
456 &count, /*Ptr to working variable */
457 &next_index, /*Ptr to next index value to list */
458 &entry); /*Ptr to entry to fill */
462 break; /* If the next index is invalid, bail out now. */
464 /* For each entry in the volume set */
465 found = 0; /* No match in volume set yet */
466 for (tve = avs->ventries; tve; tve = tve->next) { /*ve */
467 /* for each server in the vldb entry */
468 for (srvpartpair = 0; srvpartpair < entry.nServers; srvpartpair++) { /*s */
469 /* On the same server */
470 if (tve->server.sin_addr.s_addr
471 && !VLDB_IsSameAddrs(tve->server.sin_addr.s_addr,
472 entry.serverNumber[srvpartpair],
480 /* On the same partition */
481 if ((tve->partition != -1)
482 && (tve->partition != entry.serverPartition[srvpartpair]))
485 /* If the volume entry is not compiled, then compile it */
487 sprintf(patt, "^%s$", tve->name);
488 #ifdef HAVE_POSIX_REGEX
489 if (regcomp(&re, patt, REG_NOSUB) != 0) {
490 afs_com_err(whoami, 0, "Can't compile regular expression '%s'", patt);
495 errm = (char *)re_comp(patt);
497 afs_com_err(whoami, 0,
498 "Can't compile regular expression '%s': %s",
506 /* If the RW name matches the volume set entry, take
507 * it and exit. First choice is to use the RW volume.
509 if (entry.serverFlags[srvpartpair] & ITSRWVOL) {
510 if (entry.flags & RW_EXISTS) {
511 sprintf(patt, "%s", entry.name);
512 #ifdef HAVE_POSIX_REGEX
513 code = regexec(&re, patt, 0, NULL, 0);
516 code = re_exec(patt);
520 foundentry = srvpartpair;
526 /* If the BK name matches the volume set entry, take
527 * it and exit. Second choice is to use the BK volume.
529 if (entry.flags & BACK_EXISTS) {
530 sprintf(patt, "%s.backup", entry.name);
531 #ifdef HAVE_POSIX_REGEX
532 code = regexec(&re, patt, 0, NULL, 0);
535 code = re_exec(patt);
539 foundentry = srvpartpair;
546 /* If the RO name matches the volume set entry, remember
547 * it, but continue searching. Further entries may be
548 * RW or backup entries that will match.
550 else if (!found && (entry.serverFlags[srvpartpair] & ITSROVOL)
551 && (entry.flags & RO_EXISTS)) {
552 sprintf(patt, "%s.readonly", entry.name);
553 #ifdef HAVE_POSIX_REGEX
554 code = regexec(&re, patt, 0, NULL, 0);
557 code = re_exec(patt);
561 foundentry = srvpartpair;
567 afs_com_err(whoami, 0, "Internal error in regex package");
570 /* If found a match, then create a new volume dump entry */
572 /* Find server and partition structure to hang the entry off of */
574 getSPEntries(entry.serverNumber[foundentry],
575 entry.serverPartition[foundentry], &servers,
578 afs_com_err(whoami, code, NULL);
583 tvd = (struct bc_volumeDump *)
584 malloc(sizeof(struct bc_volumeDump));
586 afs_com_err(whoami, BC_NOMEM, NULL);
589 memset(tvd, 0, sizeof(*tvd));
591 tvd->name = (char *)malloc(strlen(entry.name) + 10);
593 afs_com_err(whoami, BC_NOMEM, NULL);
598 strcpy(tvd->name, entry.name);
599 if (volType == BACKVOL)
600 strcat(tvd->name, ".backup");
601 else if (volType == ROVOL)
602 strcat(tvd->name, ".readonly");
603 tvd->vid = entry.volumeId[volType];
605 tvd->volType = volType;
606 tvd->partition = entry.serverPartition[foundentry];
607 tvd->server.sin_addr.s_addr = entry.serverNumber[foundentry];
608 tvd->server.sin_port = 0; /* default FS port */
609 tvd->server.sin_family = AF_INET;
611 /* String tvd off of partition struct */
612 tvd->next = ps->vdlist;
615 ps->lastvdlist = tvd;
621 #ifdef HAVE_POSIX_REGEX
626 /* Randomly link the volumedump entries together */
627 randSPEntries(servers, avols);
629 fprintf(stderr, "Total number of volumes : %u\n", total);
631 } /*EvalVolumeSet1 */
634 compactTimeString(time_t *date, char *string, afs_int32 size)
641 if (*date == NEVERDATE) {
642 sprintf(string, "NEVER");
644 ltime = localtime(date);
645 strftime(string, size, "%m/%d/%Y %H:%M", ltime);
651 * print out a date in compact format, 16 chars, format is
654 * date_long - ptr to a long containing the time
656 * ptr to a string containing a representation of the date
659 compactDateString(afs_uint32 *date_long, char *string, afs_int32 size)
661 time_t t = *date_long;
662 return compactTimeString(&t, string, size);
667 bc_SafeATOI(char *anum)
671 for (; *anum; anum++) {
672 if ((*anum < '0') || (*anum > '9'))
674 total = (10 * total) + (afs_int32) (*anum - '0');
680 * Take a string and parse it for a number (could be float) followed
681 * by a character representing the units (K,M,G,T). Default is 'K'.
682 * Return the size in KBytes.
685 bc_FloatATOI(char *anum)
689 afs_int32 fraction = 0; /* > 0 if past the decimal */
691 for (; *anum; anum++) {
692 if ((*anum == 't') || (*anum == 'T')) {
693 total *= 1024 * 1024 * 1024;
696 if ((*anum == 'g') || (*anum == 'G')) {
697 total *= 1024 * 1024;
700 if ((*anum == 'm') || (*anum == 'M')) {
704 if ((*anum == 'k') || (*anum == 'K')) {
711 if ((*anum < '0') || (*anum > '9'))
715 total = (10. * total) + (float)(*anum - '0');
717 total += ((float)(*anum - '0')) / (float)fraction;
722 total += 0.5; /* Round up */
723 if (total > 0x7fffffff) /* Don't go over 2G */
725 rtotal = (afs_int32) total;
729 /* make a copy of a string so that it can be freed later */
731 bc_CopyString(char *astring)
737 return (NULL); /* propagate null strings easily */
738 tlen = strlen(astring);
739 tp = (char *)malloc(tlen + 1); /* don't forget the terminating null */
741 afs_com_err(whoami, BC_NOMEM, NULL);
750 * Concatenates the parameters of an option and returns the string.
755 concatParams(struct cmd_item *itemPtr)
757 struct cmd_item *tempPtr;
758 afs_int32 length = 0;
761 /* compute the length of string required */
762 for (tempPtr = itemPtr; tempPtr; tempPtr = tempPtr->next) {
763 length += strlen(tempPtr->data);
764 length++; /* space or null terminator */
767 if (length == 0) { /* no string (0 length) */
768 afs_com_err(whoami, 0, "Can't have zero length date and time string");
772 string = (char *)malloc(length); /* allocate the string */
774 afs_com_err(whoami, BC_NOMEM, NULL);
779 tempPtr = itemPtr; /* now assemble the string */
781 strcat(string, tempPtr->data);
782 tempPtr = tempPtr->next;
787 return (string); /* return the string */
791 * print out an interface status node as received from butc
795 printIfStatus(struct tciStatusS *statusPtr)
797 printf("Task %d: %s: ", statusPtr->taskId, statusPtr->taskName);
798 if (statusPtr->nKBytes)
799 printf("%ld Kbytes transferred", (long unsigned int) statusPtr->nKBytes);
800 if (strlen(statusPtr->volumeName) != 0) {
801 if (statusPtr->nKBytes)
803 printf("volume %s", statusPtr->volumeName);
808 if (statusPtr->flags & ABORT_REQUEST)
809 printf(" [abort request rcvd]");
811 if (statusPtr->flags & ABORT_DONE)
812 printf(" [abort complete]");
814 if (statusPtr->flags & OPR_WAIT)
815 printf(" [operator wait]");
817 if (statusPtr->flags & CALL_WAIT)
818 printf(" [callout in progress]");
820 if (statusPtr->flags & DRIVE_WAIT)
821 printf(" [drive wait]");
823 if (statusPtr->flags & TASK_DONE)
829 getPortOffset(char *port)
831 afs_int32 portOffset;
833 portOffset = bc_SafeATOI(port);
835 if (portOffset < 0) {
836 afs_com_err(whoami, 0, "Can't decode port offset '%s'", port);
838 } else if (portOffset > BC_MAXPORTOFFSET) {
839 afs_com_err(whoami, 0, "%u exceeds max port offset %u", portOffset,
846 /* bc_GetTapeStatusCmd
847 * display status of all tasks on a particular tape coordinator
850 bc_GetTapeStatusCmd(struct cmd_syndesc *as, void *arock)
853 struct rx_connection *tconn;
854 afs_int32 portOffset = 0;
859 struct tciStatusS status;
861 code = bc_UpdateHosts();
863 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
867 if (as->parms[0].items) {
868 portOffset = getPortOffset(as->parms[0].items->data);
873 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
877 flags = TSK_STAT_FIRST;
881 while ((flags & TSK_STAT_END) == 0) {
882 code = TC_ScanStatus(tconn, &taskId, &status, &flags);
884 if (code == TC_NOTASKS)
886 afs_com_err(whoami, code, "; Can't get status from butc");
889 if ((flags & TSK_STAT_NOTFOUND))
890 break; /* Can't find the task id */
891 flags &= ~TSK_STAT_FIRST; /* turn off flag */
893 printIfStatus(&status);
898 printf("Tape coordinator is idle\n");
900 if (flags & TSK_STAT_ADSM)
901 printf("TSM Tape coordinator\n");
902 else if (flags & TSK_STAT_XBSA)
903 printf("XBSA Tape coordinator\n");
908 extern struct Lock dispatchLock;
911 * wait for all jobs to terminate
914 bc_WaitForNoJobs(void)
917 int usefulJobRunning = 1;
919 extern dlqlinkT statusHead;
921 afs_com_err(whoami, 0, "waiting for job termination");
923 while (usefulJobRunning) {
924 usefulJobRunning = (dlqEmpty(&statusHead) ? 0 : 1);
925 if (dispatchLock.excl_locked)
926 usefulJobRunning = 1;
927 for (i = 0; (!usefulJobRunning && (i < BC_MAXSIMDUMPS)); i++) {
928 if (bc_dumpTasks[i].flags & BC_DI_INUSE)
929 usefulJobRunning = 1;
932 /* Wait 5 seconds and check again */
933 if (usefulJobRunning)
936 return (lastTaskCode);
940 * print status on running jobs
942 * ignored - a null "as" prints only jobs.
945 bc_JobsCmd(struct cmd_syndesc *as, void *arock)
954 extern dlqlinkT statusHead;
956 dlqInit(&atJobsHead);
959 ptr = (&statusHead)->dlq_next;
960 while (ptr != &statusHead) {
961 statusPtr = (statusP) ptr;
964 if (statusPtr->scheduledDump) {
965 dlqUnlink((dlqlinkP) statusPtr);
966 dlqLinkb(&atJobsHead, (dlqlinkP) statusPtr);
968 printf("Job %d:", statusPtr->jobNumber);
970 printf(" %s", statusPtr->taskName);
972 if (statusPtr->dbDumpId)
973 printf(": DumpID %u", statusPtr->dbDumpId);
974 if (statusPtr->nKBytes)
975 printf(", %ld Kbytes", afs_printable_int32_ld(statusPtr->nKBytes));
976 if (strlen(statusPtr->volumeName) != 0)
977 printf(", volume %s", statusPtr->volumeName);
979 if (statusPtr->flags & CONTACT_LOST)
980 printf(" [butc contact lost]");
982 if (statusPtr->flags & ABORT_REQUEST)
983 printf(" [abort request]");
985 if (statusPtr->flags & ABORT_SENT)
986 printf(" [abort sent]");
988 if (statusPtr->flags & OPR_WAIT)
989 printf(" [operator wait]");
991 if (statusPtr->flags & CALL_WAIT)
992 printf(" [callout in progress]");
994 if (statusPtr->flags & DRIVE_WAIT)
995 printf(" [drive wait]");
1001 * Now print the scheduled dumps.
1003 if (!dlqEmpty(&statusHead) && as)
1004 printf("\n"); /* blank line between running and scheduled dumps */
1007 while (!dlqEmpty(&atJobsHead)) {
1008 ptr = (&atJobsHead)->dlq_next;
1009 youngest = (statusP) ptr;
1011 ptr = ptr->dlq_next;
1012 while (ptr != &atJobsHead) { /* Find the dump that starts the earliest */
1013 statusPtr = (statusP) ptr;
1014 if (statusPtr->scheduledDump < youngest->scheduledDump)
1015 youngest = statusPtr;
1016 ptr = ptr->dlq_next;
1019 /* Print token expiration time */
1020 if ((tokenExpires > prevTime)
1021 && (tokenExpires <= youngest->scheduledDump) && as
1022 && (tokenExpires != NEVERDATE)) {
1023 if (tokenExpires > time(0)) {
1024 compactTimeString(&tokenExpires, ds, 50);
1025 printf(" %16s: TOKEN EXPIRATION\n", ds);
1027 printf(" TOKEN HAS EXPIRED\n");
1030 prevTime = youngest->scheduledDump;
1032 /* Print the info */
1033 compactDateString(&youngest->scheduledDump, ds, 50);
1034 printf("Job %d:", youngest->jobNumber);
1035 printf(" %16s: %s", ds, youngest->cmdLine);
1038 /* return to original list */
1039 dlqUnlink((dlqlinkP) youngest);
1040 dlqLinkb(&statusHead, (dlqlinkP) youngest);
1043 /* Print token expiration time if havn't already */
1044 if ((tokenExpires == NEVERDATE) && as)
1045 printf(" : TOKEN NEVER EXPIRES\n");
1046 else if ((tokenExpires > prevTime) && as) {
1047 if (tokenExpires > time(0)) {
1048 compactTimeString(&tokenExpires, ds, 50);
1049 printf(" %16s: TOKEN EXPIRATION\n", ds);
1051 printf(" : TOKEN HAS EXPIRED\n");
1060 bc_KillCmd(struct cmd_syndesc *as, void *arock)
1064 struct bc_dumpTask *td;
1071 extern dlqlinkT statusHead;
1073 tp = as->parms[0].items->data;
1074 if (strchr(tp, '.') == 0) {
1075 slot = bc_SafeATOI(tp);
1077 afs_com_err(whoami, 0, "Bad syntax for number '%s'", tp);
1082 ptr = (&statusHead)->dlq_next;
1083 while (ptr != &statusHead) {
1084 statusPtr = (statusP) ptr;
1085 if (statusPtr->jobNumber == slot) {
1086 statusPtr->flags |= ABORT_REQUEST;
1090 ptr = ptr->dlq_next;
1094 fprintf(stderr, "Job %d not found\n", slot);
1099 for (i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
1100 if (td->flags & BC_DI_INUSE) {
1102 strcpy(tbuffer, td->volSetName);
1103 strcat(tbuffer, ".");
1104 strcat(tbuffer, tailCompPtr(td->dumpName));
1105 if (strcmp(tbuffer, tp) == 0)
1109 if (i >= BC_MAXSIMDUMPS) {
1110 afs_com_err(whoami, 0, "Can't find job %s", tp);
1115 statusPtr = findStatus(td->dumpID);
1117 if (statusPtr == 0) {
1118 afs_com_err(whoami, 0, "Can't locate status - internal error");
1122 statusPtr->flags |= ABORT_REQUEST;
1128 /* restore a volume or volumes */
1130 bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
1133 * parm 0 is the new server to restore to
1134 * parm 1 is the new partition to restore to
1135 * parm 2 is volume(s) to restore
1136 * parm 3 is the new extension, if any, for the volume name.
1137 * parm 4 gives the new volume # to restore this volume as (removed).
1138 * parm 4 date is a string representing the date
1140 * We handle four types of restores. If old is set, then we restore the
1141 * volume with the same name and ID. If old is not set, we allocate
1142 * a new volume ID for the restored volume. If a new extension is specified,
1143 * we add that extension to the volume name of the restored volume.
1145 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1146 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1147 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1148 struct bc_volumeDump *tvol; /* temp for same */
1149 struct sockaddr_in destServ; /* machine to which to restore volumes */
1150 afs_int32 destPartition; /* partition to which to restore volumes */
1152 struct cmd_item *ti;
1156 afs_int32 dumpID = 0;
1157 char *newExt, *timeString;
1159 afs_int32 *ports = NULL;
1160 afs_int32 portCount = 0;
1163 code = bc_UpdateHosts();
1165 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1169 /* specified other destination host */
1170 if (as->parms[0].items) {
1171 tp = as->parms[0].items->data;
1172 if (bc_ParseHost(tp, &destServ)) {
1173 afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
1178 /* specified other destination partition */
1179 if (as->parms[1].items) {
1180 tp = as->parms[1].items->data;
1181 if (bc_GetPartitionID(tp, &destPartition)) {
1182 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1187 for (ti = as->parms[2].items; ti; ti = ti->next) {
1188 /* build list of volume items */
1189 tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1191 afs_com_err(whoami, BC_NOMEM, NULL);
1194 memset(tvol, 0, sizeof(struct bc_volumeDump));
1196 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1198 afs_com_err(whoami, BC_NOMEM, NULL);
1201 strncpy(tvol->name, ti->data, VOLSER_OLDMAXVOLNAME);
1202 tvol->entry = &tvolumeEntry;
1205 lastVol->next = tvol; /* thread onto end of list */
1207 volsToRestore = tvol;
1211 if (as->parms[4].items) {
1212 timeString = concatParams(as->parms[4].items);
1216 code = ktime_DateToLong(timeString, &fromDate);
1219 afs_com_err(whoami, 0, "Can't parse restore date and time");
1220 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1224 fromDate = 0x7fffffff; /* latest one */
1227 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1230 /* Read all the port offsets into the ports array. The first element in the
1231 * array is for full restore and the rest are for incremental restores
1233 if (as->parms[5].items) {
1234 for (ti = as->parms[5].items; ti; ti = ti->next)
1236 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1238 afs_com_err(whoami, BC_NOMEM, NULL);
1242 for (ti = as->parms[5].items, i = 0; ti; ti = ti->next, i++) {
1243 ports[i] = getPortOffset(ti->data);
1249 dontExecute = (as->parms[6].items ? 1 : 0); /* -n */
1251 if (as->parms[7].items)
1253 dumpID = atoi(as->parms[7].items->data);
1259 * Perform the call to start the restore.
1262 bc_StartDmpRst(bc_globalConfig, "volume", "restore", volsToRestore,
1263 &destServ, destPartition, fromDate, newExt, oldFlag,
1264 /*parentDump */ dumpID, /*dumpLevel */ 0,
1265 bc_Restorer, ports, portCount,
1266 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1268 afs_com_err(whoami, code, "; Failed to queue restore");
1273 /* restore a whole partition or server */
1275 /* bc_DiskRestoreCmd
1276 * restore a whole partition
1278 * first, reqd - machine (server) to restore
1279 * second, reqd - partition to restore
1284 bc_DiskRestoreCmd(struct cmd_syndesc *as, void *arock)
1286 struct bc_volumeSet tvolumeSet; /* temporary volume set for EvalVolumeSet call */
1287 struct bc_volumeEntry tvolumeEntry; /* entry within the volume set */
1288 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1289 struct sockaddr_in destServ; /* machine to which to restore volumes */
1290 afs_int32 destPartition; /* partition to which to restore volumes */
1296 afs_int32 *ports = NULL;
1297 afs_int32 portCount = 0;
1299 struct bc_volumeDump *prev, *tvol, *nextvol;
1300 struct cmd_item *ti;
1303 /* parm 0 is the server to restore
1304 * parm 1 is the partition to restore
1306 * parm 8 and above as in VolRestoreCmd:
1307 * parm 8 is the new server to restore to
1308 * parm 9 is the new partition to restore to
1311 code = bc_UpdateVolumeSet();
1313 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1316 code = bc_UpdateHosts();
1318 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1322 /* create a volume set corresponding to the volume pattern we've been given */
1323 memset(&tvolumeSet, 0, sizeof(tvolumeSet));
1324 memset(&tvolumeEntry, 0, sizeof(tvolumeEntry));
1325 tvolumeSet.name = "TempVolumeSet";
1326 tvolumeSet.ventries = &tvolumeEntry;
1327 tvolumeEntry.serverName = as->parms[0].items->data;
1328 tvolumeEntry.partname = as->parms[1].items->data;
1330 if (bc_GetPartitionID(tvolumeEntry.partname, &tvolumeEntry.partition)) {
1331 afs_com_err(whoami, 0, "Can't parse partition '%s'",
1332 tvolumeEntry.partname);
1336 if (bc_ParseHost(tvolumeEntry.serverName, &tvolumeEntry.server)) {
1337 afs_com_err(whoami, 0, "Can't locate host '%s'", tvolumeEntry.serverName);
1341 /* specified other destination host */
1342 if (as->parms[8].items) {
1343 tp = as->parms[8].items->data;
1344 if (bc_ParseHost(tp, &destServ)) {
1345 afs_com_err(whoami, 0, "Can't locate destination host '%s'", tp);
1348 } else /* use destination host == original host */
1349 memcpy(&destServ, &tvolumeEntry.server, sizeof(destServ));
1351 /* specified other destination partition */
1352 if (as->parms[9].items) {
1353 tp = as->parms[9].items->data;
1354 if (bc_GetPartitionID(tp, &destPartition)) {
1355 afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
1358 } else /* use original partition */
1359 destPartition = tvolumeEntry.partition;
1361 tvolumeEntry.name = ".*"; /* match all volumes (this should be a parameter) */
1363 if (as->parms[2].items) {
1364 for (ti = as->parms[2].items; ti; ti = ti->next)
1366 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1368 afs_com_err(whoami, BC_NOMEM, NULL);
1372 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1373 ports[i] = getPortOffset(ti->data);
1379 newExt = (as->parms[10].items ? as->parms[10].items->data : NULL);
1380 dontExecute = (as->parms[11].items ? 1 : 0); /* -n */
1383 * Expand out the volume set into its component list of volumes, by calling VLDB server.
1386 bc_EvalVolumeSet(bc_globalConfig, &tvolumeSet, &volsToRestore,
1389 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1393 /* Since we want only RW volumes, remove any
1394 * BK or RO volumes from the list.
1396 for (prev = 0, tvol = volsToRestore; tvol; tvol = nextvol) {
1397 nextvol = tvol->next;
1398 if (BackupName(tvol->name)) {
1401 "Will not restore volume %s (its RW does not reside on the partition)\n",
1404 if (tvol == volsToRestore) {
1405 volsToRestore = nextvol;
1407 prev->next = nextvol;
1417 fromDate = 0x7fffffff; /* last one before this date */
1418 oldFlag = 1; /* do restore same volid (and name) */
1421 * Perform the call to start the dump.
1424 bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1425 &destServ, destPartition, fromDate, newExt, oldFlag,
1426 /*parentDump */ 0, /*dumpLevel */ 0,
1427 bc_Restorer, ports, portCount,
1428 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1430 afs_com_err(whoami, code, "; Failed to queue restore");
1435 /* bc_VolsetRestoreCmd
1436 * restore a volumeset or list of volumes.
1440 bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
1447 afs_int32 *ports = NULL;
1448 afs_int32 portCount = 0;
1451 struct bc_volumeSet *volsetPtr; /* Ptr to list of generated volume info */
1452 struct bc_volumeDump *volsToRestore = (struct bc_volumeDump *)0;
1453 struct bc_volumeDump *lastVol = (struct bc_volumeDump *)0;
1454 struct sockaddr_in destServer; /* machine to which to restore volume */
1455 afs_int32 destPartition; /* partition to which to restore volumes */
1456 struct cmd_item *ti;
1459 code = bc_UpdateVolumeSet();
1461 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1464 code = bc_UpdateHosts();
1466 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1470 if (as->parms[0].items) {
1471 if (as->parms[1].items) {
1472 afs_com_err(whoami, 0, "Can't have both -name and -file options");
1476 volsetName = as->parms[0].items->data;
1477 volsetPtr = bc_FindVolumeSet(bc_globalConfig, volsetName);
1479 afs_com_err(whoami, 0,
1480 "Can't find volume set '%s' in backup database",
1485 /* Expand out the volume set into its component list of volumes. */
1487 bc_EvalVolumeSet(bc_globalConfig, volsetPtr, &volsToRestore,
1490 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1493 } else if (as->parms[1].items) {
1496 char server[50], partition[50], volume[50], rest[256];
1498 struct bc_volumeDump *tvol;
1500 fd = fopen(as->parms[1].items->data, "r");
1502 afs_com_err(whoami, errno, "; Cannot open file '%s'",
1503 as->parms[1].items->data);
1507 while (fgets(line, 255, fd)) {
1509 sscanf(line, "%s %s %s %s", server, partition, volume, rest);
1515 "Invalid volumeset file format: Wrong number of arguments: Ignoring\n");
1516 fprintf(stderr, " %s", line);
1520 if (bc_ParseHost(server, &destServer)) {
1521 afs_com_err(whoami, 0, "Failed to locate host '%s'", server);
1525 if (bc_GetPartitionID(partition, &destPartition)) {
1526 afs_com_err(whoami, 0,
1527 "Failed to parse destination partition '%s'",
1532 /* Allocate a volumeDump structure and link it in */
1534 (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
1535 memset(tvol, 0, sizeof(struct bc_volumeDump));
1537 tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
1539 afs_com_err(whoami, BC_NOMEM, NULL);
1542 strncpy(tvol->name, volume, VOLSER_OLDMAXVOLNAME);
1543 memcpy(&tvol->server, &destServer, sizeof(destServer));
1544 tvol->partition = destPartition;
1547 lastVol->next = tvol; /* thread onto end of list */
1549 volsToRestore = tvol;
1554 afs_com_err(whoami, 0, "-name or -file option required");
1559 /* Get the port offset for the restore */
1560 if (as->parms[2].items) {
1561 for (ti = as->parms[2].items; ti; ti = ti->next)
1563 ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
1565 afs_com_err(whoami, BC_NOMEM, NULL);
1569 for (ti = as->parms[2].items, i = 0; ti; ti = ti->next, i++) {
1570 ports[i] = getPortOffset(ti->data);
1576 newExt = (as->parms[3].items ? as->parms[3].items->data : NULL);
1577 dontExecute = (as->parms[4].items ? 1 : 0);
1579 fromDate = 0x7fffffff; /* last one before this date */
1580 oldFlag = 1; /* do restore same volid (and name) */
1582 /* Perform the call to start the restore */
1583 code = bc_StartDmpRst(bc_globalConfig, "disk", "restore", volsToRestore,
1584 /*destserver */ NULL, /*destpartition */ 0, fromDate,
1586 /*parentDump */ 0, /*dumpLevel */ 0,
1587 bc_Restorer, ports, portCount,
1588 /*dumpSched */ NULL, /*append */ 0, dontExecute);
1590 afs_com_err(whoami, code, "; Failed to queue restore");
1595 /*-----------------------------------------------------------------------------
1599 * Perform a dump of the set of volumes provided.
1600 * user specifies: -volumeset .. -dump .. [-portoffset ..] [-n]
1603 * as : Parsed command line information.
1604 * arock : Ptr to misc stuff; not used.
1608 * The result of bc_StartDump() otherwise
1615 *---------------------------------------------------------------------------
1620 bc_DumpCmd(struct cmd_syndesc *as, void *arock)
1622 char *dumpPath = NULL;
1623 char *vsName = NULL; /*Ptrs to various names */
1624 struct bc_volumeSet *tvs = NULL; /*Ptr to list of generated volume info */
1625 struct bc_dumpSchedule *tds;
1626 struct bc_dumpSchedule *baseds = NULL; /*Ptr to dump schedule node */
1627 struct bc_volumeDump *tve, *volsToDump; /*Ptr to individual vols to be dumped */
1628 struct budb_dumpEntry dumpEntry, de, fde; /* dump entry */
1631 afs_int32 parent; /* parent dump */
1632 afs_int32 level; /* this dump's level # */
1633 afs_int32 problemFindingDump; /* can't find parent(s) */
1635 afs_int32 *portp = NULL;
1636 afs_int32 doAt, atTime; /* Time a timed-dump is to start at */
1639 int doAppend = 0; /* Append the dump to dump set */
1640 afs_int32 code; /* Return code */
1641 int loadfile; /* whether to load a file or not */
1645 extern struct bc_dumpTask bc_dumpTasks[];
1647 code = bc_UpdateDumpSchedule();
1649 afs_com_err(whoami, code, "; Can't retrieve dump schedule");
1652 code = bc_UpdateVolumeSet();
1654 afs_com_err(whoami, code, "; Can't retrieve volume sets");
1657 code = bc_UpdateHosts();
1659 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
1664 * Some parameters cannot be specified together
1665 * The "-file" option cannot exist with the "-volume", "-dump",
1666 * "-portoffset", or "-append" option
1668 if (as->parms[6].items) {
1670 if (as->parms[0].items || as->parms[1].items || as->parms[2].items
1671 || as->parms[4].items) {
1672 afs_com_err(whoami, 0, "Invalid option specified with -file option");
1677 if (!as->parms[0].items || !as->parms[1].items) {
1678 afs_com_err(whoami, 0,
1679 "Must specify volume set name and dump level name");
1685 * Get the time we are to perform this dump
1687 if (as->parms[3].items) {
1690 timeString = concatParams(as->parms[3].items);
1695 * Now parse this string for the time to start.
1697 code = ktime_DateToLong(timeString, &atTime);
1700 afs_com_err(whoami, 0, "Can't parse dump start date and time");
1701 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
1707 dontExecute = (as->parms[5].items ? 1 : 0); /* -n */
1710 * If this dump is not a load file, then check the parameters.
1712 if (!loadfile) { /*6 */
1713 vsName = as->parms[0].items->data; /* get volume set name */
1714 dumpPath = as->parms[1].items->data; /* get dump path */
1716 /* get the port number, if one was specified */
1717 if (as->parms[2].items) {
1718 portp = (afs_int32 *) malloc(sizeof(afs_int32));
1720 afs_com_err(whoami, BC_NOMEM, NULL);
1724 *portp = getPortOffset(as->parms[2].items->data);
1729 doAppend = (as->parms[4].items ? 1 : 0); /* -append */
1732 * Get a hold of the given volume set and dump set.
1734 tvs = bc_FindVolumeSet(bc_globalConfig, vsName);
1736 afs_com_err(whoami, 0,
1737 "Can't find volume set '%s' in backup database", vsName);
1740 baseds = bc_FindDumpSchedule(bc_globalConfig, dumpPath);
1742 afs_com_err(whoami, 0,
1743 "Can't find dump schedule '%s' in backup database",
1752 * If given the "-at" option, then add this to the jobs list and return
1755 * Create a status node for this timed dump.
1756 * Fill in the time to dump and the cmd line for the dump leaving off
1757 * the -at option. If the -n option is there, it is scheduled with
1758 * the Timed dump as opposed to not scheduling the time dump at all.
1761 if (atTime < time(0)) {
1762 afs_com_err(whoami, 0,
1763 "Time of dump is earlier then current time - not added");
1765 statusPtr = createStatusNode();
1767 statusPtr->scheduledDump = atTime;
1769 /* Determine length of the dump command */
1771 length += 4; /* "dump" */
1773 length += 6; /* " -file" */
1774 length += 1 + strlen(as->parms[6].items->data); /* " <file>" */
1776 /* length += 11; *//* " -volumeset" */
1777 length += 1 + strlen(as->parms[0].items->data); /* " <volset> */
1779 /* length += 6; *//* " -dump" */
1780 length += 1 + strlen(as->parms[1].items->data); /* " <dumpset> */
1782 if (as->parms[2].items) {
1783 /* length += 12; *//* " -portoffset" */
1784 length += 1 + strlen(as->parms[2].items->data); /* " <port>" */
1787 if (as->parms[4].items)
1788 length += 8; /* " -append" */
1792 length += 3; /* " -n" */
1793 length++; /* end-of-line */
1795 /* Allocate status block for this timed dump */
1796 sprintf(statusPtr->taskName, "Scheduled Dump");
1797 statusPtr->jobNumber = bc_jobNumber();
1798 statusPtr->scheduledDump = atTime;
1799 statusPtr->cmdLine = (char *)malloc(length);
1800 if (!statusPtr->cmdLine) {
1801 afs_com_err(whoami, BC_NOMEM, NULL);
1805 /* Now reconstruct the dump command */
1806 statusPtr->cmdLine[0] = 0;
1807 strcat(statusPtr->cmdLine, "dump");
1809 strcat(statusPtr->cmdLine, " -file");
1810 strcat(statusPtr->cmdLine, " ");
1811 strcat(statusPtr->cmdLine, as->parms[6].items->data);
1813 /* strcat(statusPtr->cmdLine, " -volumeset"); */
1814 strcat(statusPtr->cmdLine, " ");
1815 strcat(statusPtr->cmdLine, as->parms[0].items->data);
1817 /* strcat(statusPtr->cmdLine, " -dump"); */
1818 strcat(statusPtr->cmdLine, " ");
1819 strcat(statusPtr->cmdLine, as->parms[1].items->data);
1821 if (as->parms[2].items) {
1822 /* strcat(statusPtr->cmdLine, " -portoffset"); */
1823 strcat(statusPtr->cmdLine, " ");
1824 strcat(statusPtr->cmdLine, as->parms[2].items->data);
1827 if (as->parms[4].items)
1828 strcat(statusPtr->cmdLine, " -append");
1831 strcat(statusPtr->cmdLine, " -n");
1833 printf("Add scheduled dump as job %d\n", statusPtr->jobNumber);
1834 if ((atTime > tokenExpires) && (tokenExpires != NEVERDATE))
1835 afs_com_err(whoami, 0,
1836 "Warning: job %d starts after expiration of AFS token",
1837 statusPtr->jobNumber);
1846 * Read and execute the load file if specified. The work of reading is done
1847 * in the main routine prior the dispatch call. loadFile and dontExecute are
1848 * global variables so this can take place in main.
1851 loadFile = (char *)malloc(strlen(as->parms[6].items->data) + 1);
1853 afs_com_err(whoami, BC_NOMEM, NULL);
1856 strcpy(loadFile, as->parms[6].items->data);
1861 * We are doing a real dump (no load file or timed dump).
1863 printf("Starting dump of volume set '%s' (dump level '%s')\n", vsName,
1866 /* For each dump-level above this one, see if the volumeset was dumped
1867 * at the level. We search all dump-levels since a higher dump-level
1868 * may have actually been done AFTER a lower dump level.
1870 parent = level = problemFindingDump = 0;
1871 for (tds = baseds->parent; tds; tds = tds->parent) {
1872 /* Find the most recent dump of the volume-set at this dump-level.
1873 * Raise problem flag if didn't find a dump and a parent not yet found.
1875 code = bcdb_FindLatestDump(vsName, tds->name, &dumpEntry);
1878 problemFindingDump = 1; /* skipping a dump level */
1882 /* We found the most recent dump at this level. Now check
1883 * if we should use it by seeing if its full dump hierarchy
1884 * exists. If it doesn't, we don't want to base our incremental
1887 if (!parent || (dumpEntry.id > parent)) {
1888 /* Follow the parent dumps to see if they are all there */
1889 for (d = dumpEntry.parent; d; d = de.parent) {
1890 code = bcdb_FindDumpByID(d, &de);
1895 /* If we found the entire level, remember it. Otherwise raise flag.
1896 * If we had already found a dump, raise the problem flag.
1900 problemFindingDump = 1;
1901 parent = dumpEntry.id;
1902 level = dumpEntry.level + 1;
1903 memcpy(&fde, &dumpEntry, sizeof(dumpEntry));
1905 /* Dump hierarchy not complete so can't base off the latest */
1906 problemFindingDump = 1;
1911 /* If the problemflag was raise, it means we are not doing the
1912 * dump at the level we requested it be done at.
1914 if (problemFindingDump) {
1915 afs_com_err(whoami, 0,
1916 "Warning: Doing level %d dump due to missing higher-level dumps",
1919 printf("Parent dump: dump %s (DumpID %u)\n", fde.name, parent);
1921 } else if (parent) {
1922 printf("Found parent: dump %s (DumpID %u)\n", fde.name, parent);
1925 /* Expand out the volume set into its component list of volumes. */
1926 code = bc_EvalVolumeSet(bc_globalConfig, tvs, &volsToDump, cstruct);
1928 afs_com_err(whoami, code, "; Failed to evaluate volume set");
1932 printf("No volumes to dump\n");
1936 /* Determine what the clone time of the volume was when it was
1937 * last dumped (tve->date). This is the time from when an
1938 * incremental should be done (remains zero if a full dump).
1941 for (tve = volsToDump; tve; tve = tve->next) {
1942 code = bcdb_FindClone(parent, tve->name, &tve->date);
1946 /* Get the time the volume was last cloned and see if the volume has
1947 * changed since then. Only do this when the "-n" flag is specified
1948 * because butc will get the cloneDate at time of dump.
1952 volImageTime(tve->server.sin_addr.s_addr, tve->partition,
1953 tve->vid, tve->volType, &tve->cloneDate);
1957 if (tve->cloneDate && (tve->cloneDate == tve->date)) {
1958 afs_com_err(whoami, 0,
1959 "Warning: Timestamp on volume %s unchanged from previous dump",
1967 printf("Would have dumped the following volumes:\n");
1969 printf("Preparing to dump the following volumes:\n");
1970 for (tve = volsToDump; tve; tve = tve->next) {
1971 printf("\t%s (%u)\n", tve->name, tve->vid);
1976 code = bc_StartDmpRst(bc_globalConfig, dumpPath, vsName, volsToDump,
1977 /*destServer */ NULL, /*destPartition */ 0,
1979 /*newExt */ NULL, /*oldFlag */ 0,
1980 parent, level, bc_Dumper, portp, /*portCount */ 1,
1981 baseds, doAppend, dontExecute);
1983 afs_com_err(whoami, code, "; Failed to queue dump");
1990 * terminate the backup process. Insists that that all running backup
1991 * jobs be terminated before it will quit
1996 bc_QuitCmd(struct cmd_syndesc *as, void *arock)
1999 struct bc_dumpTask *td;
2000 extern dlqlinkT statusHead;
2004 /* Check the status list for outstanding jobs */
2006 for (ptr = (&statusHead)->dlq_next; ptr != &statusHead;
2007 ptr = ptr->dlq_next) {
2008 statusPtr = (statusP) ptr;
2009 if (!(statusPtr->flags & ABORT_REQUEST)) {
2011 afs_com_err(whoami, 0, "Job %d still running (and not aborted)",
2012 statusPtr->jobNumber);
2013 afs_com_err(whoami, 0,
2014 "You must at least 'kill' all running jobs before quitting");
2020 /* A job still being initialized (but no status structure or job number since it
2021 * has not been handed to a butc process yet)
2023 for (td = bc_dumpTasks, i = 0; i < BC_MAXSIMDUMPS; i++, td++) {
2024 if (td->flags & BC_DI_INUSE) {
2025 afs_com_err(whoami, 0, "A job is still running");
2026 afs_com_err(whoami, 0,
2027 "You must at least 'kill' all running jobs before quitting");
2033 /* close the all temp text files before quitting */
2034 for (i = 0; i < TB_NUM; i++)
2035 bc_closeTextFile(&bc_globalConfig->configText[i],
2036 &bc_globalConfig->tmpTextFileNames[i][0]);
2042 * Labels a tape i.e. request the tape coordinator to perform this
2046 bc_LabelTapeCmd(struct cmd_syndesc *as, void *arock)
2048 char *tapename = 0, *pname = 0;
2053 code = bc_UpdateHosts();
2055 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2059 if (as->parms[0].items) { /* -name */
2060 tapename = as->parms[0].items->data;
2061 if (strlen(tapename) >= TC_MAXTAPELEN) {
2062 afs_com_err(whoami, 0, "AFS tape name '%s' is too long", tapename);
2067 if (as->parms[3].items) { /* -pname */
2069 afs_com_err(whoami, 0, "Can only specify -name or -pname");
2072 pname = as->parms[3].items->data;
2073 if (strlen(pname) >= TC_MAXTAPELEN) {
2074 afs_com_err(whoami, 0, "Permanent tape name '%s' is too long", pname);
2079 if (as->parms[1].items) {
2080 size = bc_FloatATOI(as->parms[1].items->data);
2082 afs_com_err(whoami, 0, "Bad syntax for tape size '%s'",
2083 as->parms[1].items->data);
2089 if (as->parms[2].items) {
2090 port = getPortOffset(as->parms[2].items->data);
2095 code = bc_LabelTape(tapename, pname, size, bc_globalConfig, port);
2102 * read the label on a tape
2104 * optional port number
2107 bc_ReadLabelCmd(struct cmd_syndesc *as, void *arock)
2112 code = bc_UpdateHosts();
2114 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2118 if (as->parms[0].items) {
2119 port = getPortOffset(as->parms[0].items->data);
2124 code = bc_ReadLabel(bc_globalConfig, port);
2131 * read content information from dump tapes, and if user desires,
2132 * add it to the database
2135 bc_ScanDumpsCmd(struct cmd_syndesc *as, void *arock)
2138 afs_int32 dbAddFlag = 0;
2141 code = bc_UpdateHosts();
2143 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2147 /* check for flag */
2148 if (as->parms[0].items != 0) { /* add scan to database */
2152 /* check for port */
2153 if (as->parms[1].items) {
2154 port = getPortOffset(as->parms[1].items->data);
2159 code = bc_ScanDumps(bc_globalConfig, dbAddFlag, port);
2163 /* bc_ParseExpiration
2166 * dates are specified as absolute or relative, the syntax is:
2167 * absolute: at %d/%d/%d [%d:%d] where [..] is optional
2168 * relative: in [%dy][%dm][%dd] where at least one component
2173 bc_ParseExpiration(struct cmd_parmdesc *paramPtr, afs_int32 *expType,
2176 struct cmd_item *itemPtr;
2177 struct ktime_date kt;
2178 char *dateString = 0;
2181 *expType = BC_NO_EXPDATE;
2184 if (!paramPtr->items)
2185 ERROR(0); /* no expiration specified */
2187 /* some form of expiration date specified. First validate the prefix */
2188 itemPtr = paramPtr->items;
2190 if (strcmp(itemPtr->data, "at") == 0) {
2191 *expType = BC_ABS_EXPDATE;
2193 dateString = concatParams(itemPtr->next);
2197 code = ktime_DateToLong(dateString, expDate);
2200 } else if (strcmp(itemPtr->data, "in") == 0) {
2201 *expType = BC_REL_EXPDATE;
2203 dateString = concatParams(itemPtr->next);
2207 code = ParseRelDate(dateString, &kt);
2210 *expDate = ktimeRelDate_ToLong(&kt);
2212 dateString = concatParams(itemPtr);
2216 if (ktime_DateToLong(dateString, expDate) == 0) {
2217 *expType = BC_ABS_EXPDATE;
2218 code = ktime_DateToLong(dateString, expDate);
2221 } else if (ParseRelDate(dateString, &kt) == 0) {
2222 *expType = BC_REL_EXPDATE;
2223 *expDate = ktimeRelDate_ToLong(&kt);
2235 /* database lookup command and routines */
2238 * Currently a single option, volumename to search for. Reports
2239 * all dumps containing the specified volume
2242 bc_dblookupCmd(struct cmd_syndesc *as, void *arock)
2244 struct cmd_item *ciptr;
2247 ciptr = as->parms[0].items;
2248 if (ciptr == 0) /* no argument specified */
2251 code = DBLookupByVolume(ciptr->data);
2257 /* for ubik version */
2259 bc_dbVerifyCmd(struct cmd_syndesc *as, void *arock)
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 afs_com_err(whoami, code, "; Unable to verify database");
2282 /* verification call succeeded */
2285 printf("Database OK\n");
2287 afs_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
2311 deleteDump(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 afs_com_err(whoami, tcode, "; Can't retrieve tape hosts");
2331 /* Find the dump in the backup database */
2332 tcode = bcdb_FindDumpByID(dumpid, &dumpEntry);
2334 afs_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 afs_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 afs_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 afs_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" : NULL);
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(struct cmd_syndesc *as, void *arock)
2420 afs_int32 rcode = 0;
2421 afs_int32 groupId = 0, havegroupid, sflags, noexecute;
2422 struct cmd_item *ti;
2423 afs_int32 fromTime = 0, toTime = 0, havetime = 0;
2425 budb_dumpsList dumps, flags;
2427 afs_int32 port = -1, force;
2429 /* Must specify at least one of -dumpid, -from, or -to */
2430 if (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items
2431 && !as->parms[4].items) {
2432 afs_com_err(whoami, 0, "Must specify at least one field");
2436 /* Must have -to option with -from option */
2437 if (as->parms[1].items && !as->parms[2].items) {
2438 afs_com_err(whoami, 0, "Must specify '-to' field with '-from' field");
2442 /* Get the time to delete from */
2443 if (as->parms[1].items) { /* -from */
2444 timeString = concatParams(as->parms[1].items);
2449 * Now parse this string for the time to start.
2451 code = ktime_DateToLong(timeString, &fromTime);
2454 afs_com_err(whoami, 0, "Can't parse 'from' date and time");
2455 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2461 port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -port */
2462 if (as->parms[5].items) /* -dbonly */
2465 force = (as->parms[6].items ? 1 : 0);
2467 havegroupid = (as->parms[4].items ? 1 : 0);
2469 groupId = atoi(as->parms[4].items->data);
2471 noexecute = (as->parms[7].items ? 1 : 0);
2473 /* Get the time to delete to */
2474 if (as->parms[2].items) { /* -to */
2475 timeString = concatParams(as->parms[2].items);
2480 * Now parse this string for the time to start. Simce
2481 * times are at minute granularity, add 59 seconds.
2483 code = ktime_DateToLong(timeString, &toTime);
2486 afs_com_err(whoami, 0, "Can't parse 'to' date and time");
2487 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2494 if (fromTime > toTime) {
2495 afs_com_err(whoami, 0,
2496 "'-from' date/time cannot be later than '-to' date/time");
2500 /* Remove speicific dump ids - if any */
2501 printf("The following dumps %s deleted:\n",
2502 (noexecute ? "would have been" : "were"));
2503 for (ti = as->parms[0].items; ti != 0; ti = ti->next) { /* -dumpid */
2504 dumpid = atoi(ti->data);
2506 code = deleteDump(dumpid, port, force);
2508 printf(" %u\n", dumpid);
2513 * Now remove dumps between to and from dates.
2515 if (havegroupid || havetime) {
2516 dumps.budb_dumpsList_len = 0;
2517 dumps.budb_dumpsList_val = 0;
2518 flags.budb_dumpsList_len = 0;
2519 flags.budb_dumpsList_val = 0;
2522 sflags |= BUDB_OP_GROUPID;
2524 sflags |= BUDB_OP_DATES;
2527 bcdb_listDumps(sflags, groupId, fromTime, toTime, &dumps, &flags);
2529 afs_com_err(whoami, code,
2530 "; Error while deleting dumps from %u to %u", fromTime,
2535 for (i = 0; i < dumps.budb_dumpsList_len; i++) {
2536 if (flags.budb_dumpsList_val[i] & BUDB_OP_DBDUMP)
2540 if (flags.budb_dumpsList_val[i] & BUDB_OP_APPDUMP)
2542 code = deleteDump(dumps.budb_dumpsList_val[i], port, force);
2543 /* Ignore code and continue */
2545 printf(" %u%s%s\n", dumps.budb_dumpsList_val[i],
2547 budb_dumpsList_val[i] & BUDB_OP_APPDUMP) ?
2548 " Appended Dump" : "",
2550 budb_dumpsList_val[i] & BUDB_OP_DBDUMP) ?
2551 " Database Dump" : "");
2556 if (dumps.budb_dumpsList_val)
2557 free(dumps.budb_dumpsList_val);
2558 dumps.budb_dumpsList_len = 0;
2559 dumps.budb_dumpsList_val = 0;
2560 if (flags.budb_dumpsList_val)
2561 free(flags.budb_dumpsList_val);
2562 flags.budb_dumpsList_len = 0;
2563 flags.budb_dumpsList_val = 0;
2570 bc_saveDbCmd(struct cmd_syndesc *as, void *arock)
2572 struct rx_connection *tconn;
2573 afs_int32 portOffset = 0;
2580 code = bc_UpdateHosts();
2582 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2586 if (as->parms[0].items) {
2587 portOffset = getPortOffset(as->parms[0].items->data);
2592 /* Get the time to delete to */
2593 if (as->parms[1].items) {
2594 timeString = concatParams(as->parms[1].items);
2599 * Now parse this string for the time. Since
2600 * times are at minute granularity, add 59 seconds.
2602 code = ktime_DateToLong(timeString, &toTime);
2605 afs_com_err(whoami, 0, "Can't parse '-archive' date and time");
2606 afs_com_err(whoami, 0, "%s", ktime_GetDateUsage());
2613 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2617 code = TC_SaveDb(tconn, toTime, &taskId);
2619 afs_com_err(whoami, code, "; Failed to save database");
2623 /* create status monitor block */
2624 statusPtr = createStatusNode();
2626 statusPtr->taskId = taskId;
2627 statusPtr->port = portOffset;
2628 statusPtr->jobNumber = bc_jobNumber();
2629 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2630 sprintf(statusPtr->taskName, "SaveDb");
2634 rx_DestroyConnection(tconn);
2639 bc_restoreDbCmd(struct cmd_syndesc *as, void *arock)
2641 struct rx_connection *tconn;
2642 afs_int32 portOffset = 0;
2647 code = bc_UpdateHosts();
2649 afs_com_err(whoami, code, "; Can't retrieve tape hosts");
2653 if (as->parms[0].items) {
2654 portOffset = getPortOffset(as->parms[0].items->data);
2659 code = ConnectButc(bc_globalConfig, portOffset, &tconn);
2663 code = TC_RestoreDb(tconn, &taskId);
2665 afs_com_err(whoami, code, "; Failed to restore database");
2669 /* create status monitor block */
2670 statusPtr = createStatusNode();
2672 statusPtr->taskId = taskId;
2673 statusPtr->port = portOffset;
2674 statusPtr->jobNumber = bc_jobNumber();
2675 statusPtr->flags &= ~STARTING; /* clearstatus to examine */
2676 sprintf(statusPtr->taskName, "RestoreDb");
2680 rx_DestroyConnection(tconn);
2684 /* ----------------------------------
2685 * supporting routines for database examination
2686 * ----------------------------------
2689 /* structures and defines for DBLookupByVolume */
2691 #define DBL_MAX_VOLUMES 20 /* max. for each dump */
2693 /* dumpedVol - saves interesting information so that we can print it out
2698 struct dumpedVol *next;
2700 afs_int32 initialDumpID;
2701 char tapeName[BU_MAXTAPELEN];
2704 afs_int32 createTime;
2705 afs_int32 incTime; /* actually the clone time */
2708 /* -----------------------------------------
2709 * routines for examining the database
2710 * -----------------------------------------
2714 * Lookup the volumename in the backup database and print the results
2716 * volumeName - volume to lookup
2720 DBLookupByVolume(char *volumeName)
2722 struct budb_dumpEntry dumpEntry;
2723 struct budb_volumeEntry volumeEntry[DBL_MAX_VOLUMES];
2724 afs_int32 numEntries;
2725 afs_int32 tapedumpid;
2726 afs_int32 last, next;
2728 struct dumpedVol *dvptr = 0;
2729 struct dumpedVol *tempPtr = 0;
2732 char vname[BU_MAXNAMELEN];
2735 for (pass = 0; pass < 2; pass++) {
2737 /* On second pass, search for backup volume */
2739 if (!BackupName(volumeName)) {
2740 strcpy(vname, volumeName);
2741 strcat(vname, ".backup");
2749 while (next != -1) { /*w */
2751 bcdb_LookupVolume(volumeName, &volumeEntry[0], last, &next,
2752 DBL_MAX_VOLUMES, &numEntries);
2756 /* add the volumes to the list */
2757 for (i = 0; i < numEntries; i++) { /*f */
2758 struct dumpedVol *insPtr, **prevPtr;
2761 (struct dumpedVol *)malloc(sizeof(struct dumpedVol));
2765 memset(tempPtr, 0, sizeof(*tempPtr));
2766 tempPtr->incTime = volumeEntry[i].clone;
2767 tempPtr->dumpID = volumeEntry[i].dump;
2768 strncpy(tempPtr->tapeName, volumeEntry[i].tape,
2771 /* check if we need to null terminate it - just for safety */
2772 if (strlen(volumeEntry[i].tape) >= BU_MAXTAPELEN)
2773 tempPtr->tapeName[BU_MAXTAPELEN - 1] = 0;
2775 code = bcdb_FindDumpByID(tempPtr->dumpID, &dumpEntry);
2781 tempPtr->initialDumpID = dumpEntry.initialDumpID;
2782 tempPtr->parent = dumpEntry.parent;
2783 tempPtr->level = dumpEntry.level;
2784 tempPtr->createTime = dumpEntry.created;
2786 /* add volume to list in reverse chronological order */
2790 while ((insPtr != 0)
2791 && (insPtr->createTime > tempPtr->createTime)
2793 prevPtr = &insPtr->next;
2794 insPtr = insPtr->next;
2797 /* now at the right place - insert the block */
2798 tempPtr->next = *prevPtr;
2808 ("DumpID lvl parentID creation date clone date tape name\n");
2809 for (tempPtr = dvptr; tempPtr; tempPtr = tempPtr->next) {
2810 /* For the user, the tape name is its name and initial dump id */
2812 (tempPtr->initialDumpID ? tempPtr->initialDumpID : tempPtr->
2815 /* beware the static items in compactDateString */
2816 compactDateString(&tempPtr->createTime, ds, 50);
2817 printf("%-9d %-2d %-9d %16s", tempPtr->dumpID, tempPtr->level,
2818 tempPtr->parent, ds);
2819 compactDateString(&tempPtr->incTime, ds, 50);
2820 printf(" %16s %s (%u)\n", ds, tempPtr->tapeName, tapedumpid);
2826 for (tempPtr = dvptr; tempPtr; tempPtr = dvptr) {
2827 dvptr = dvptr->next;
2832 afs_com_err(whoami, code, NULL);
2836 /* structures for dumpInfo */
2839 struct volumeLink *nextVolume;
2840 struct budb_volumeEntry volumeEntry;
2844 struct tapeLink *nextTape;
2845 struct budb_tapeEntry tapeEntry;
2846 struct volumeLink *firstVolume;
2851 * print information about a dump and all its tapes and volumes.
2855 dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
2857 struct budb_dumpEntry dumpEntry;
2858 struct tapeLink *head = 0;
2859 struct tapeLink *tapeLinkPtr, *lastTapeLinkPtr;
2860 struct volumeLink **link, *volumeLinkPtr, *lastVolumeLinkPtr;
2863 afs_int32 last, next, dbTime;
2864 afs_int32 tapedumpid;
2872 extern struct udbHandleS udbHandle;
2875 lastTapeLinkPtr = 0;
2877 lastVolumeLinkPtr = 0;
2879 /* first get information about the dump */
2881 code = bcdb_FindDumpByID(dumpid, &dumpEntry);
2885 /* For the user, the tape name is its name and initial dump id */
2886 tapedumpid = (dumpEntry.initialDumpID ? dumpEntry.initialDumpID : dumpid);
2888 /* Is this a database dump id or not */
2889 if (strcmp(dumpEntry.name, DUMP_TAPE_NAME) == 0)
2894 /* print out the information about the dump */
2898 printDumpEntry(&dumpEntry);
2900 time_t t = dumpEntry.created;
2902 printf("Dump: id %u, created: %s\n", dumpEntry.id,
2905 printf("Dump: id %u, level %d, volumes %d, created: %s\n",
2906 dumpEntry.id, dumpEntry.level, dumpEntry.nVolumes,
2910 if (!detailFlag && (strlen(dumpEntry.tapes.tapeServer) > 0)
2911 && (dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA))) {
2912 printf("Backup Service: TSM: Server: %s\n",
2913 dumpEntry.tapes.tapeServer);
2916 /* now get the list of tapes */
2917 for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) { /*f */
2918 tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
2920 afs_com_err(whoami, BC_NOMEM, NULL);
2924 memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
2925 code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
2932 /* add this tape to previous chain */
2933 if (lastTapeLinkPtr) {
2934 lastTapeLinkPtr->nextTape = tapeLinkPtr;
2935 lastTapeLinkPtr = tapeLinkPtr;
2940 lastTapeLinkPtr = head;
2944 while (next != -1) { /*wn */
2945 vl.budb_volumeList_len = 0;
2946 vl.budb_volumeList_val = 0;
2949 /* now get all the volumes in this dump. */
2950 code = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client, UF_SINGLESERVER, BUDB_MAJORVERSION, BUDB_OP_DUMPID | BUDB_OP_TAPENAME, tapeLinkPtr->tapeEntry.name, /* tape name */
2951 dumpid, /* dumpid (not initial dumpid) */
2954 &next, /* nextindex */
2955 &dbTime, /* update time */
2959 if (code == BUDB_ENDOFLIST) { /* 0 volumes on tape */
2966 for (i = 0; i < vl.budb_volumeList_len; i++) {
2967 link = &tapeLinkPtr->firstVolume;
2970 (struct volumeLink *)malloc(sizeof(struct volumeLink));
2971 if (!volumeLinkPtr) {
2972 afs_com_err(whoami, BC_NOMEM, NULL);
2975 memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
2977 memcpy(&volumeLinkPtr->volumeEntry,
2978 &vl.budb_volumeList_val[i],
2979 sizeof(struct budb_volumeEntry));
2981 /* now insert it onto the right place */
2983 && (volumeLinkPtr->volumeEntry.position >
2984 (*link)->volumeEntry.position)) {
2985 link = &((*link)->nextVolume);
2988 /* now link it in */
2989 volumeLinkPtr->nextVolume = *link;
2990 *link = volumeLinkPtr;
2993 if (vl.budb_volumeList_val)
2994 free(vl.budb_volumeList_val);
2998 for (tapeLinkPtr = head; tapeLinkPtr; tapeLinkPtr = tapeLinkPtr->nextTape) {
3002 printTapeEntry(&tapeLinkPtr->tapeEntry);
3004 printf("Tape: name %s (%u)\n", tapeLinkPtr->tapeEntry.name,
3006 printf("nVolumes %d, ", tapeLinkPtr->tapeEntry.nVolumes);
3007 compactDateString(&tapeLinkPtr->tapeEntry.written, ds, 50);
3008 printf("created %16s", ds);
3009 if (tapeLinkPtr->tapeEntry.expires != 0) {
3010 compactDateString(&tapeLinkPtr->tapeEntry.expires, ds, 50);
3011 printf(", expires %16s", ds);
3016 /* print out all the volumes */
3018 /* print header for volume listing - db dumps have no volumes */
3019 if ((detailFlag == 0) && !dbDump)
3020 printf("%4s %16s %9s %-s\n", "Pos", "Clone time", "Nbytes",
3023 for (volumeLinkPtr = tapeLinkPtr->firstVolume; volumeLinkPtr;
3024 volumeLinkPtr = volumeLinkPtr->nextVolume) {
3026 printf("\nVolume\n");
3028 printVolumeEntry(&volumeLinkPtr->volumeEntry);
3030 compactDateString(&volumeLinkPtr->volumeEntry.clone, ds, 50),
3031 printf("%4d %s %10u %16s\n",
3032 volumeLinkPtr->volumeEntry.position, ds,
3033 volumeLinkPtr->volumeEntry.nBytes,
3034 volumeLinkPtr->volumeEntry.name);
3041 afs_com_err("dumpInfo", code, "; Can't get dump information");
3043 /* free all allocated structures */
3045 while (tapeLinkPtr) {
3046 volumeLinkPtr = tapeLinkPtr->firstVolume;
3047 while (volumeLinkPtr) {
3048 lastVolumeLinkPtr = volumeLinkPtr;
3049 volumeLinkPtr = volumeLinkPtr->nextVolume;
3050 free(lastVolumeLinkPtr);
3053 lastTapeLinkPtr = tapeLinkPtr;
3054 tapeLinkPtr = tapeLinkPtr->nextTape;
3055 free(lastTapeLinkPtr);
3061 compareDump(struct budb_dumpEntry *ptr1, struct budb_dumpEntry *ptr2)
3063 if (ptr1->created < ptr2->created)
3065 else if (ptr1->created > ptr2->created)
3071 printRecentDumps(int ndumps)
3074 afs_int32 nextindex, index = 0;
3077 struct budb_dumpEntry *dumpPtr;
3081 extern struct udbHandleS udbHandle;
3083 do { /* while (nextindex != -1) */
3084 /* initialize the dump list */
3085 dl.budb_dumpList_len = 0;
3086 dl.budb_dumpList_val = 0;
3088 /* outline algorithm */
3089 code = ubik_Call(BUDB_GetDumps, udbHandle.uh_client, 0, BUDB_MAJORVERSION, BUDB_OP_NPREVIOUS, "", /* no name */
3093 &nextindex, &dbTime, &dl);
3095 if (code == BUDB_ENDOFLIST)
3097 afs_com_err("dumpInfo", code, "; Can't get dump information");
3101 /* No need to sort, it's already sorted */
3103 if (dl.budb_dumpList_len && (index == 0))
3104 printf("%10s %10s %2s %-16s %2s %5s dump name\n", "dumpid",
3105 "parentid", "lv", "created", "nt", "nvols");
3107 dumpPtr = dl.budb_dumpList_val;
3108 for (i = 1; i <= dl.budb_dumpList_len; i++) {
3109 compactDateString(&dumpPtr->created, ds, 50),
3110 printf("%10u %10u %-2d %16s %2d %5d %s", dumpPtr->id,
3111 dumpPtr->parent, dumpPtr->level, ds,
3112 dumpPtr->tapes.maxTapes - dumpPtr->tapes.b + 1,
3113 dumpPtr->nVolumes, dumpPtr->name);
3114 if (dumpPtr->initialDumpID) /* an appended dump */
3115 printf(" (%u)", dumpPtr->initialDumpID);
3116 else if (dumpPtr->appendedDumpID) /* has appended dumps */
3117 printf(" (%u)", dumpPtr->id);
3123 if (dl.budb_dumpList_val)
3124 free(dl.budb_dumpList_val);
3126 } while (nextindex != -1);
3132 * list the dumps and contens of the dumps.
3138 bc_dumpInfoCmd(struct cmd_syndesc *as, void *arock)
3141 afs_int32 detailFlag;
3145 if (as->parms[0].items) {
3146 if (as->parms[1].items) {
3147 afs_com_err(whoami, 0,
3148 "These options are exclusive - select only one");
3151 ndumps = atoi(as->parms[0].items->data);
3153 afs_com_err(whoami, 0, "Must provide a positive number");
3157 code = printRecentDumps(ndumps);
3158 } else if (as->parms[1].items) {
3159 detailFlag = (as->parms[2].items ? 1 : 0); /* 1 = detailed listing */
3160 dumpid = atoi(as->parms[1].items->data);
3161 code = dumpInfo(dumpid, detailFlag);
3163 code = printRecentDumps(10);