00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <SUM.h>
00015 #include <soi_key.h>
00016 #include <sys/time.h>
00017 #include <sys/errno.h>
00018 #include <rpc/rpc.h>
00019 #include <rpc/pmap_clnt.h>
00020 #include <sum_rpc.h>
00021 #include <soi_error.h>
00022 #include <printk.h>
00023
00024 char *get_eff_date(int plusdays);
00025
00026 #define TODAY (atol(get_eff_date(0)))
00027 #define TAR_FILE_SZ 500000000
00028 #define ARCH_CHUNK 30
00029 #define NOTAPEARC "/usr/local/logs/soc/NOTAPEARC"
00030 bool file_exists( char * filename);
00031 void do_disk_write( PADATA *p);
00032 extern void printkey (KEY *key);
00033 void usage();
00034 void get_cmd(int argc, char *argv[]);
00035 void setup();
00036 void goaway();
00037 void print_list(char *title, PADATA *p);
00038 void print_entry(PADATA *p);
00039 void sighandler(int sig);
00040 KEY *tapearcdo_1(KEY *params);
00041 static void tapearcprog_1(struct svc_req *rqstp, SVCXPRT *transp);
00042
00043 static struct timeval TIMEOUT = { 3, 0 };
00044 static int WRTSTATUS;
00045 uint32_t rinfo;
00046 int call_tape_svc_cnt;
00047 int TAPEARCDO_called;
00048 int curr_group_id;
00049 PADATA *walker;
00050 PADATA *aplist = NULL;
00051 KEY *alist;
00052 CLIENT *current_client, *clnttape, *clntsum;
00053 SVCXPRT *glb_transp;
00054 SVCXPRT *transp;
00055
00056 int count_list(PADATA *p);
00057 int storeunitarch(int docnt);
00058 int soi_errno = NO_ERROR;
00059 char *dbname;
00060 char *adir;
00061 char *username;
00062 char thishost[MAX_STR];
00063 time_t now;
00064 int adirflg = 0;
00065 int verbose = 0;
00066 int debugflg = 0;
00067 int queryflg = 0;
00068 int test60d = 0;
00069 int aminflg = 0;
00070 int archive_minimum = 0;
00071 int archive_pending = 0;
00072 int is_connected=0;
00073 int ctrlcnt = 0;
00074
00075 static struct timeval first[6], second[6];
00076 float ftmp;
00077
00078
00079 void StartTimer(int n)
00080 {
00081 gettimeofday (&first[n], NULL);
00082 }
00083
00084 float StopTimer(int n)
00085 {
00086 gettimeofday (&second[n], NULL);
00087 if (first[n].tv_usec > second[n].tv_usec) {
00088 second[n].tv_usec += 1000000;
00089 second[n].tv_sec--;
00090 }
00091 return (float) (second[n].tv_sec-first[n].tv_sec) +
00092 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00093 }
00094
00095
00096
00097
00098
00099
00100 int find_tapearc()
00101 {
00102 FILE *fplog;
00103 char acmd[128], line[128], look[64];
00104 char log[] = "/usr/local/logs/SUM/find_tapearc.log";
00105 int count = 0;
00106
00107 sprintf(acmd, "ps -ef | grep tapearc 1> %s 2>&1", log);
00108 if(system(acmd)) {
00109 printf("Can't execute %s.\n", acmd);
00110 return(-1);
00111 }
00112 if((fplog=fopen(log, "r")) == NULL) {
00113 printf("Can't open %s to find tapearc\n", log);
00114 return(-1);
00115 }
00116 sprintf(look, " %s", dbname);
00117 while(fgets(line, 128, fplog)) {
00118 if (strstr(line, look) && strstr(line, "tapearc")) {
00119 if(!strstr(line, "sh ")) count++;
00120 }
00121 }
00122 fclose(fplog);
00123 return (count);
00124 }
00125
00126 int count_list(PADATA *p) {
00127 PADATA *walker = p;
00128 int count=0;
00129 while (walker) {
00130 count++;
00131 walker=walker->next;
00132 }
00133 return count;
00134 }
00135
00136
00137 void print_entry(PADATA *p) {
00138 if (!p) return;
00139 printf ("%d\t%15.6e\t%s\n", p->group_id, p->bytes, p->wd);
00140 }
00141
00142 void print_list(char *title, PADATA *p) {
00143 PADATA *walker = p;
00144 if (title) printf("\n%s\n", title);
00145 while (walker) {
00146 print_entry (walker);
00147 walker = walker->next;
00148 }
00149 }
00150
00151 int send_mail(char *fmt, ...)
00152 {
00153 va_list args;
00154 char string[1024], cmd[1024];
00155
00156 va_start(args, fmt);
00157 vsprintf(string, fmt, args);
00158
00159
00160 sprintf(cmd, "echo \"%s\" | Mail -s \"diskarc mail\" carl@sun.stanford.edu", string);
00161 system(cmd);
00162 va_end(args);
00163 return(0);
00164 }
00165
00166 void usage()
00167 {
00168 printf("This is a stand alone program that will archive all the SUMS\n");
00169 printf("Write the archive pending datasets to disk (or /dev/null)\n");
00170 printf("Usage:\n");
00171 printf(" diskarc [-v] [-d] [-q] -a archive_dir] database_name\n");
00172 printf(" where -v = Verbose mode\n");
00173 printf(" -d = Debug mode\n");
00174 printf(" -q = Query only to see what's available for archive\n");
00175 printf(" -a = Archive to disk instead of to tape.\n");
00176 printf(" Give the dir to cp the archived ds to.\n");
00177 printf(" Use /dev/null to not archive but make del pend.\n");
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 exit(1);
00189 }
00190
00191
00192 void get_cmd(int argc, char *argv[])
00193 {
00194 int c;
00195
00196 while(--argc > 0 && (*++argv)[0] == '-') {
00197 while((c = *++argv[0]))
00198 switch(c) {
00199 case 'd':
00200 debugflg=1;
00201 break;
00202 case 'v':
00203 verbose=1;
00204 break;
00205
00206
00207
00208 case 'q':
00209 queryflg=1;
00210 break;
00211
00212
00213
00214 case 'a':
00215 adirflg=1;
00216 break;
00217 default:
00218 usage();
00219 break;
00220 }
00221 }
00222 if (adirflg) {
00223 adir = argv[0]; dbname = argv[1];
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 }
00236
00237
00238
00239
00240 if(!adirflg) {
00241 printf("ERROR: Must speicfy either tape or disk write.\n\n");
00242 usage();
00243 }
00244 }
00245
00246
00247 void goaway()
00248 {
00249 if(is_connected)
00250 if(DS_DisConnectDB())
00251 fprintf(stderr, "DS_DisconnectDB() error\n");
00252 exit(1);
00253 }
00254
00255
00256 void sighandler(int sig)
00257 {
00258 char line[80];
00259
00260
00261
00262
00263 if(ctrlcnt++ == 0) {
00264 printf("\nInterrupt not allowed during tape write operations...\n");
00265 printf("Hit ^C again for an option to abort...\n");
00266 }
00267 else {
00268 printf("Do you want to force an abort (make sure you know what you're doing) [y/n] = ");
00269 if(gets(line) == NULL) { return; }
00270 if(!strcmp(line, "y")) { goaway(); }
00271 }
00272 }
00273
00274
00275
00276 void setup()
00277 {
00278 char *cptr;
00279 int n;
00280 char pgport[32];
00281
00282 printk_set(printf, printf);
00283 gethostname(thishost, MAX_STR);
00284 cptr = index(thishost, '.');
00285 if(cptr) *cptr = (char)NULL;
00287
00288 n = find_tapearc();
00289 if(n > 1) {
00290 printf("%s: Only one tapearc %s allowed at a time. I see %d\n",
00291 thishost, dbname,n);
00292
00293
00294 exit(1);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
00305 signal(SIGINT, sighandler);
00306 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
00307 signal(SIGTERM, sighandler);
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 printf ("3-before connect to db where dbname:%s\n", dbname);
00342 if (DS_ConnectDB(dbname)) {
00343 fprintf(stderr,"Error in connecting to database %s\n", dbname);
00344 goaway();
00345 }
00346 is_connected=1;
00347 printf ("4-is connected to db where dbname:%s\n", dbname);
00348 call_tape_svc_cnt = 0;
00349 }
00350
00351
00352
00353
00354 int call_tape_svc(int groupid, double bytes, uint64_t index) {
00355 int status;
00356 uint32_t retstat;
00357 char *call_err;
00358
00359 WRTSTATUS = 0;
00360 StartTimer(0);
00361 setkey_int(&alist, "tapearcvers", TAPEARCVERS);
00362 status = clnt_call(clnttape, WRITEDO, (xdrproc_t)xdr_Rkey, (char *)alist,
00363 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
00364
00365
00366
00367
00368 if(status != 0) {
00369 clnt_perrno(status);
00370 printf("***Error on clnt_call() to tape_svc WRITEDO procedure\n");
00371
00372
00373 call_err = clnt_sperror(clnttape, "Err");
00374 printf("%s\n", call_err);
00375 if(status != RPC_TIMEDOUT) {
00376 printf("I'm aborting now...\n");
00377 if(is_connected)
00378 if(DS_DisConnectDB())
00379 fprintf(stderr, "DS_DisconnectDB() error\n");
00380 exit(1);
00381 }
00382 else {
00383
00384 ftmp = StopTimer(0);
00385 printf("Measured timeout was %f sec\n", ftmp);
00386 call_tape_svc_cnt++;
00387 printf("RESULT_PEND (!!ASSUMED) group_id=%d bytes=%g 1st_ds_index=%lu. Arc in progress...\n", groupid, bytes, index);
00388 return(0);
00389 }
00390 }
00391 if(retstat == RESULT_PEND) {
00392 call_tape_svc_cnt++;
00393 printf("RESULT_PEND group_id=%d bytes=%g 1st_ds_index=%lu. Arc in progress...\n",
00394 groupid, bytes, index);
00395 }
00396 else {
00397 if(retstat == NO_TAPE_IN_GROUP) {
00398 printf("Can't assign tape for group id %d\n", groupid);
00399 printf("Check tape_svc log for any error messages\n");
00400 printf("I'm aborting now...\n");
00401 if(is_connected)
00402 if(DS_DisConnectDB())
00403 fprintf(stderr, "DS_DisconnectDB() error\n");
00404 exit(1);
00405 }
00406 else if(retstat == NO_CLNTTCP_CREATE) {
00407 printf("NO_CLNTTCP_CREATE error on ret from clnt_call(clntape,WRITEDO)\n");
00408 printf("Check tape_svc log for any error messages\n");
00409 printf("I'm aborting now...\n");
00410 if(is_connected)
00411 if(DS_DisConnectDB())
00412 fprintf(stderr, "DS_DisconnectDB() error\n");
00413 exit(1);
00414 }
00415 else
00416 printf("retstat = %d on ret from clnt_call(clntape,WRITEDO)\n",retstat);
00417 }
00418 return(0);
00419 }
00420
00421 int main(int argc, char *argv[])
00422 {
00423 FILE *notapearc;
00424 PADATA *ap = NULL;
00425
00426 get_cmd(argc, argv);
00427 if(!(username = (char *)getenv("USER"))) username = "nouser";
00428
00429 if(strcmp(username, "sumsadmin" )) {
00430 printf("!!NOTE: You must be user sumsadmin to run diskarc!\n");
00431 exit(1);
00432 }
00433 if((notapearc=fopen(NOTAPEARC, "r")) != NULL) {
00434 printf("Can't run a tapearc while Imp/Exp of tapes is active\n");
00435 fclose(notapearc);
00436 exit(-1);
00437 }
00438
00439 printf ("0-Current effective_date is %ld\n", TODAY);
00440 time (&now); printf ("%s\n",asctime(localtime(&now)));
00441 printf ("1-Datasets will be archived if there are more than %d\n",
00442 archive_minimum);
00443 setup();
00444
00445
00446 if(test60d) {
00447 aplist = NC_PaRequest_AP_60d();
00448 }
00449 else {
00450
00451
00452
00453 aplist = NC_PaRequest_AP(9);
00454 }
00455 archive_pending = count_list(aplist);
00456 printf ("5-archive_pending count %d\n", archive_pending);
00457
00458 if (verbose || queryflg) {
00459 printf("\n6-There are %d entries in the archive pending list.\n",
00460 archive_pending);
00461 print_list ("7-archive pending list", aplist);
00462 printf("archive pending will be grouped into %d byte tar files\n", TAR_FILE_SZ);
00463 if(queryflg) goaway();
00464 }
00465 if (archive_pending <= archive_minimum) {
00466 printf("\nThe number of archive pending entries (%d) is <= %d\n",
00467 archive_pending, archive_minimum);
00468 goaway();
00469 }
00470
00471 walker = aplist;
00472 if (adirflg == 1) {
00473 (void)do_disk_write(walker);
00474 if(is_connected)
00475 if(DS_DisConnectDB())
00476 fprintf(stderr, "DS_DisconnectDB() error\n");
00477 exit(0);
00478 }
00479 else {
00480 storeunitarch(ARCH_CHUNK);
00481 if(call_tape_svc_cnt == 0) {
00482 if(is_connected)
00483 if(DS_DisConnectDB())
00484 fprintf(stderr, "DS_DisconnectDB() error\n");
00485 exit(0);
00486 }
00487 svc_run();
00488 }
00489 }
00490
00491
00492
00493
00494
00495 static void
00496 tapearcprog_1(rqstp, transp)
00497 struct svc_req *rqstp;
00498 SVCXPRT *transp;
00499 {
00500 union __svcargun {
00501 Rkey tapearcdo_1_arg;
00502 } argument;
00503 char *result;
00504
00505 bool_t (*xdr_argument)(), (*xdr_result)();
00506 char *(*local)();
00507 switch (rqstp->rq_proc) {
00508 case NULLPROC:
00509 printf("Called NULLPROC in tapearcprog_1()\n");
00510 (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
00511 return;
00512 case TAPEARCDO:
00513
00514 TAPEARCDO_called = 1;
00515 xdr_argument = xdr_Rkey;
00516 xdr_result = xdr_Rkey;;
00517 local = (char *(*)()) tapearcdo_1;
00518 break;
00519 default:
00520 printf("**tapearcprog_1() dispatch default procedure %ld,ignore\n", rqstp->rq_proc);
00521 (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
00522 svcerr_noproc(transp);
00523 return;
00524 }
00525 bzero((char *)&argument, sizeof(argument));
00526 if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
00527 printf("***Error on svc_getargs()\n");
00528 svcerr_decode(transp);
00529 svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
00530 return;
00531
00532 }
00533
00534 if(!svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL)) {
00535 svcerr_systemerr(transp);
00536 return;
00537 }
00538 glb_transp = transp;
00539 result = (*local)(&argument, rqstp);
00540
00541
00542 if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
00543 printf("**unable to free arguments\n");
00544
00545 }
00546 return;
00547 }
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 KEY *tapearcdo_1(KEY *params)
00595 {
00596 int groupid;
00597 uint64_t index;
00598
00599
00600 groupid = getkey_int(params, "group_id");
00601 index = getkey_uint64(params, "ds_index_0");
00602 if(findkey(params, "DEBUGFLG")) {
00603 debugflg = getkey_int(params, "DEBUGFLG");
00604 if(debugflg) {
00605 printf("!!TEMP in tapearcdo_1() call in tapearc. keylist is:\n");
00606 keyiterate(printkey, params);
00607 }
00608 }
00609 if(WRTSTATUS = getkey_int(params, "STATUS")) {
00610 printf("**Error return for write of group_id=%d 1st ds_index=%lu\n",
00611 groupid, index);
00612 }
00613 else {
00614 printf("Successful write for group_id=%d 1st_ds_index=%lu\n",
00615 groupid, index);
00616 }
00617 --call_tape_svc_cnt;
00618 printf("call_tape_svc_cnt = %d\n", call_tape_svc_cnt);
00619
00620 if(storeunitarch(1)) {
00621 if(call_tape_svc_cnt == 0) {
00622 if(is_connected)
00623 if(DS_DisConnectDB())
00624 fprintf(stderr, "DS_DisconnectDB() error\n");
00625 exit(0);
00626 }
00627 }
00628
00629
00630 return((KEY *)1);
00631 }
00632
00633
00634
00635
00636
00637
00638
00639 int storeunitarch(int docnt)
00640 {
00641 int i, chunkcnt, wd_max_call_cnt;
00642 uint32_t sback;
00643 uint64_t first_index;
00644 char name[128];
00645 enum clnt_stat status;
00646 double curr_group_sz, total_bytes;
00647
00648 if(!walker) return(1);
00649 curr_group_id = walker->group_id;
00650 first_index = walker->ds_index;
00651 curr_group_sz = 0.0;
00652 i = 0;
00653 chunkcnt = 0;
00654 wd_max_call_cnt = 0;
00655 alist = newkeylist();
00656 while(walker) {
00657
00658 if(walker->archsub == DAAEDDP) {
00659 printf("Don't archive temp storage unit at %s\n", walker->wd);
00660 if(NC_PaUpdate(walker->wd, walker->sumid, walker->bytes, walker->status,
00661 walker->archsub, walker->effective_date, 0, 0, walker->ds_index,
00662 0, 1))
00663 {
00664 printf("Error on NC_PaUpdate of %s to del from arch pend\n",walker->wd);
00665 }
00666
00667 walker->status = DADP;
00668 if(NC_PaUpdate(walker->wd, walker->sumid, walker->bytes, walker->status,
00669 walker->archsub, walker->effective_date, walker->group_id, 0,
00670 walker->ds_index, 1, 1))
00671 {
00672 printf("Error on NC_PaUpdate of %s to add to del pend\n",walker->wd);
00673 }
00674 walker=walker->next;
00675 continue;
00676 }
00677
00678
00679
00680 curr_group_sz += walker->bytes;
00681 if(curr_group_sz >= TAR_FILE_SZ) {
00682 total_bytes = curr_group_sz;
00683 sprintf(name, "wd_%d", i);
00684 setkey_str(&alist, name, walker->wd);
00685 sprintf(name, "effective_date_%d", i);
00686 setkey_str(&alist, name, walker->effective_date);
00687 sprintf(name, "sumid_%d", i);
00688 setkey_uint64(&alist, name, walker->sumid);
00689 sprintf(name, "bytes_%d", i);
00690 setkey_double(&alist, name, walker->bytes);
00691 sprintf(name, "status_%d", i);
00692 setkey_int(&alist, name, walker->status);
00693 sprintf(name, "archsub_%d", i);
00694 setkey_int(&alist, name, walker->archsub);
00695 sprintf(name, "group_id_%d", i);
00696 setkey_int(&alist, name, walker->group_id);
00697 sprintf(name, "safe_id_%d", i);
00698 setkey_int(&alist, name, walker->safe_id);
00699 sprintf(name, "ds_index_%d", i);
00700 setkey_uint64(&alist, name, walker->ds_index);
00701 sprintf(name, "username_%d", i);
00702 setkey_str(&alist, name, username);
00703 setkey_int(&alist, "DEBUGFLG", debugflg);
00704 chunkcnt++;
00705 i++;
00706 walker=walker->next;
00707 }
00708 else if((walker->group_id == curr_group_id) && (curr_group_sz < TAR_FILE_SZ) && (wd_max_call_cnt < MAXSUMREQCNT)) {
00709 total_bytes = curr_group_sz;
00710 wd_max_call_cnt++;
00711 sprintf(name, "wd_%d", i);
00712 setkey_str(&alist, name, walker->wd);
00713 sprintf(name, "effective_date_%d", i);
00714 setkey_str(&alist, name, walker->effective_date);
00715 sprintf(name, "sumid_%d", i);
00716 setkey_uint64(&alist, name, walker->sumid);
00717 sprintf(name, "bytes_%d", i);
00718 setkey_double(&alist, name, walker->bytes);
00719 sprintf(name, "status_%d", i);
00720 setkey_int(&alist, name, walker->status);
00721 sprintf(name, "archsub_%d", i);
00722 setkey_int(&alist, name, walker->archsub);
00723 sprintf(name, "group_id_%d", i);
00724 setkey_int(&alist, name, walker->group_id);
00725 sprintf(name, "safe_id_%d", i);
00726 setkey_int(&alist, name, walker->safe_id);
00727 sprintf(name, "ds_index_%d", i);
00728 setkey_uint64(&alist, name, walker->ds_index);
00729 sprintf(name, "username_%d", i);
00730 setkey_str(&alist, name, username);
00731 setkey_int(&alist, "DEBUGFLG", debugflg);
00732 i++;
00733 walker=walker->next;
00734 continue;
00735 }
00736 setkey_double(&alist, "total_bytes", total_bytes);
00737 setkey_int(&alist, "reqcnt", i);
00738 if(i != 0) {
00739
00740 if((curr_group_sz >= TAR_FILE_SZ) || (wd_max_call_cnt >= MAXSUMREQCNT)) {
00741 if(call_tape_svc(curr_group_id, total_bytes, first_index)) {
00742 fprintf(stderr, "**Error on tape write for group %d\n", curr_group_id);
00743 }
00744 }
00745 else {
00746 printf("Abandon partial block for group=%d index=%lu files=%d bytes=%g\n", curr_group_id, first_index, wd_max_call_cnt, total_bytes);
00747 }
00748 }
00749 freekeylist(&alist);
00750 if(chunkcnt == docnt) {
00751 return(0);
00752 }
00753 if(walker) {
00754 curr_group_id = walker->group_id;
00755 first_index = walker->ds_index;
00756 }
00757 curr_group_sz = 0.0;
00758 wd_max_call_cnt = 0;
00759 i = 0;
00760 alist = newkeylist();
00761 }
00762 if(i != 0) {
00763 if(curr_group_sz >= TAR_FILE_SZ) {
00764 setkey_double(&alist, "total_bytes", total_bytes);
00765 setkey_int(&alist, "reqcnt", i);
00766 if(call_tape_svc(curr_group_id, total_bytes, first_index)) {
00767 fprintf(stderr, "**Error on tape write for group %d\n", curr_group_id);
00768 }
00769 }
00770 else {
00771 printf("Abandon left over for group=%d index=%lu bytes=%g\n",
00772 curr_group_id, first_index, total_bytes);
00773 }
00774 }
00775 return(0);
00776 }
00777
00778
00779
00780
00781 char *get_eff_date(int plusdays)
00782 {
00783 struct timeval tvalr;
00784 struct tm *t_ptr;
00785 time_t newtime;
00786 char *timestr;
00787
00788 if(gettimeofday(&tvalr, NULL) == -1) {
00789 return("200712121212");
00790 }
00791 t_ptr = localtime(&tvalr.tv_sec);
00792 t_ptr->tm_mday = t_ptr->tm_mday + plusdays;
00793 newtime = mktime(t_ptr);
00794 t_ptr = localtime(&newtime);
00795 timestr = (char *)malloc(32);
00796 sprintf(timestr, "%04d%02d%02d%02d%02d",
00797 t_ptr->tm_year+1900, t_ptr->tm_mon+1, t_ptr->tm_mday,
00798 t_ptr->tm_hour, t_ptr->tm_min);
00799 return(timestr);
00800 }
00801 void do_disk_write( PADATA *p)
00802 {
00803 int dosafe, permanent, archsub, apstatus;
00804 char cmd[256], pcmd[256], arch_tape_date[32];
00805 PADATA *walker;
00806 char subdir[50];
00807 char slotdir[50];
00808
00809 strcpy(subdir,"iris");
00810 sprintf(slotdir,"%s%lu","D",p->ds_index);
00811 strcat(slotdir,"\0");
00812
00813
00814 sprintf(cmd, "%s/%s", adir,subdir);
00815 if (!file_exists(cmd))
00816 {
00817 sprintf(cmd, "mkdir %s/%s", adir,subdir);
00818 if(system(cmd)) {
00819 printf("!!FAILED: %s\n", cmd);
00820 return;
00821 }
00822 }
00823 while(p) {
00824 if(strstr(adir, "/dev/null")) {
00825 printf("Effective cp of %s to /dev/null\n", p->wd);
00826 }
00827 else {
00828 printf("\nGROUPID=%d\n",p->group_id);
00829
00830 sprintf(cmd, "%s/%s", adir,subdir,slotdir);
00831 if (!file_exists(cmd))
00832 {
00833 sprintf(cmd, "mkdir %s/%s/%s", adir,subdir,slotdir);
00834 if(system(cmd)) {
00835 printf("!!FAILED: %s\n", cmd);
00836 p = p->next;
00837 continue;
00838 }
00839 }
00840
00841
00842
00843 sprintf(cmd, "cp -rp %s %s/%s", p->wd,adir,subdir);
00844 printf("%s\n", cmd);
00845 if(system(cmd)) {
00846 printf("!!FAILED: %s\n", cmd);
00847 p = p->next;
00848 continue;
00849 }
00850 }
00851 sprintf(arch_tape_date, "%s", get_datetime());
00852 sprintf(cmd, "UPDATE SUM_MAIN SET ARCHIVE_STATUS = 'Y', ARCH_TAPE = '%s', ARCH_TAPE_DATE = '%s' WHERE DS_INDEX = %lu",
00853 adir, arch_tape_date, p->ds_index);
00854
00855 sprintf(pcmd, "echo \"%s\" | psql -p 5434 irisdb_sums", cmd);
00856 printf("%s\n", pcmd);
00857 if(system(pcmd)) {
00858 printf("Failed: %s\n", pcmd);
00859 exit(1);
00860 }
00861 archsub = p->archsub;
00862 dosafe = (apstatus==DASAP);
00863 permanent = (archsub==DAAPERM);
00864 apstatus = dosafe?DAAP:(permanent?DAPERM:DADP);
00865
00866 sprintf(cmd, "update sum_partn_alloc set status=%d where ds_index=%lu",
00867 apstatus, p->ds_index);
00868 sprintf(pcmd, "echo \"%s\" | psql -p 5434 irisdb_sums", cmd);
00869 printf("%s\n", pcmd);
00870 if(system(pcmd)) {
00871 printf("Failed: %s\n", pcmd);
00872 exit(1);
00873 }
00874
00875 p=p->next;
00876 continue;
00877 }
00878 }
00879
00880 bool file_exists(char * filename)
00881 {
00882
00883 struct stat st;
00884 if(stat(filename,&st) == 0) return true;
00885 return false;
00886 }