From 983751d1af341eabca42df3fd1dad4736bac5ec5 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 14 Nov 2010 15:32:54 +1100 Subject: [PATCH] Added Date, Added PIT recovery, Added use default ENV config --- tsmpipe.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 15 deletions(-) diff --git a/tsmpipe.c b/tsmpipe.c index dbfc206..41f32e8 100644 --- a/tsmpipe.c +++ b/tsmpipe.c @@ -59,6 +59,7 @@ static const char rcsid[] = /*Add RCS version string to binary */ /* We (HPC2N) have 512kB tcpbuff */ #define BUFLEN (64*1024-4) +static dsmDate xStringToDate (char *s); off_t atooff(const char *s) { @@ -407,7 +408,7 @@ typedef int (*tsm_query_callback)(dsmQueryType, DataBlk *, void *); dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmObjName *objName, char *description, dsmSendType sendtype, char verbose, - tsm_query_callback usercb, void * userdata) + tsm_query_callback usercb, void * userdata, char *pitdate) { dsmQueryType qType; qryArchiveData qaData; @@ -450,8 +451,13 @@ dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmObjName *objName, qbData.stVersion = qryBackupDataVersion; qbData.objName = objName; qbData.owner = ""; - qbData.objState = DSM_ACTIVE; - qbData.pitDate.year = DATE_MINUS_INFINITE; + qbData.objState = DSM_ANY_MATCH; + + if (pitdate) { + qbData.pitDate = xStringToDate(pitdate); + } else { + qbData.pitDate.year = DATE_MINUS_INFINITE; + } qDataP = &qbData; @@ -577,7 +583,7 @@ int tsm_deletefile(dsUint32_t sesshandle, char *fsname, char *filename, cbdata.numfound = 0; rc = tsm_queryfile(sesshandle, &objName, description, sendtype, - verbose, tsm_matchone_cb, &cbdata); + verbose, tsm_matchone_cb, &cbdata, NULL); if(rc != DSM_RC_OK) { return 0; } @@ -634,7 +640,7 @@ int tsm_deletefile(dsUint32_t sesshandle, char *fsname, char *filename, int tsm_restorefile(dsUint32_t sesshandle, char *fsname, char *filename, - char *description, dsmSendType sendtype, char verbose) + char *description, dsmSendType sendtype, char verbose, char *pitdate) { dsInt16_t rc; struct matchone_cb_data cbdata; @@ -653,7 +659,7 @@ int tsm_restorefile(dsUint32_t sesshandle, char *fsname, char *filename, cbdata.numfound = 0; rc = tsm_queryfile(sesshandle, &objName, description, sendtype, - verbose, tsm_matchone_cb, &cbdata); + verbose, tsm_matchone_cb, &cbdata, pitdate); if(rc != DSM_RC_OK) { return 0; } @@ -722,12 +728,61 @@ int tsm_restorefile(dsUint32_t sesshandle, char *fsname, char *filename, return 1; } +// Display the dsmDate value as a string +static void QryDateToStr(char *s,dsmDate date) +{ + sprintf(s,"%i/%02i/%02i %02i:%02i:%02i", + date.year, + (dsInt16_t)date.month, + (dsInt16_t)date.day, + (dsInt16_t)date.hour, + (dsInt16_t)date.minute, + (dsInt16_t)date.second); +} + +static dsmDate xStringToDate(char *s) +{ + dsUint32_t temp; + dsUint32_t temp1; + dsmDate *date; + + date = (dsmDate*)malloc(sizeof(dsmDate)); + /* printf("\n Date String: %s", s); */ + /* if user key in some inputs */ + if (s[0] != '\0') + { + temp1 = atol(s); + date->month = temp1 / 1000000; + temp = temp1 % 1000000; + date->day = temp / 10000; + date->year = temp % 10000; + } + /* if user just hit enter key */ + /* everythin else except year is initialized. */ + /* we don't know it's hi or lo year. */ + else + { + date->month = 12; + date->day = 31; + } + /* printf("\ndate = %d, month = %d, year = %d", date->day, date->month, date->year);*/ + + return *date; +} /* static void xStringToDate(char *s, dsmDate *date) */ + int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void * userdata) { unsigned long long filesize; dsStruct64_t *rSizeEst; dsmObjName *rObjName; + dsmDate *insDate; + char *s; + char *state="?"; + dsUint8_t *objstate=0; + + s = (char*)malloc(sizeof(dsmObjName)); + insDate = (dsmDate*)malloc(sizeof(dsmDate)); if(userdata != NULL ) { fprintf(stderr, "tsm_listfile_cb: Internal error: userdate != NULL"); return -1; @@ -744,6 +799,13 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void * userdata) rSizeEst = &qr->sizeEstimate; rObjName = &qr->objName; + insDate = &qr->insDate; + objstate = &qr->objState; + if (*objstate==DSM_INACTIVE) + state="I"; + if (*objstate==DSM_ACTIVE) + state="A"; + } else { fprintf(stderr, @@ -754,14 +816,15 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void * userdata) filesize = rSizeEst->hi; filesize <<= 32; filesize |= rSizeEst->lo; - printf("%lld %s%s%s\n", filesize, rObjName->fs, rObjName->hl, rObjName->ll); + QryDateToStr(s, *insDate); + printf("%s %s %lld %s %s%s\n", s, state, filesize, rObjName->fs, rObjName->hl, rObjName->ll); return 1; } int tsm_listfile(dsUint32_t sesshandle, char *fsname, char *filename, - char *description, dsmSendType sendtype, char verbose) + char *description, dsmSendType sendtype, char verbose, char *pitdate) { dsInt16_t rc; dsmObjName objName; @@ -774,7 +837,7 @@ int tsm_listfile(dsUint32_t sesshandle, char *fsname, char *filename, } rc = tsm_queryfile(sesshandle, &objName, description, sendtype, - verbose, tsm_listfile_cb, NULL); + verbose, tsm_listfile_cb, NULL, pitdate); if(rc != DSM_RC_OK && rc != DSM_RC_ABORT_NO_MATCH) { return 0; } @@ -820,6 +883,7 @@ void usage(void) { " -l length Length of object to store. If guesstimating too large\n" " is better than too small\n" " -D desc Description of archive object\n" + " -P pitdate PITDate (mmddYYYY)\n" " -O options Extra options to pass to dsmInitEx\n" " -v Verbose. More -v's gives more verbosity\n" ); @@ -832,13 +896,13 @@ int main(int argc, char *argv[]) { extern char *optarg; char archmode=0, backmode=0, create=0, xtract=0, delete=0, verbose=0; char list=0; - char *space=NULL, *filename=NULL, *lenstr=NULL, *desc=NULL; + char *space=NULL, *filename=NULL, *lenstr=NULL, *desc=NULL, *pitdate=NULL; char *options=NULL; off_t length; dsUint32_t sesshandle; dsmSendType sendtype; - while ((c = getopt(argc, argv, "hABcxdtvs:f:l:D:O:")) != -1) { + while ((c = getopt(argc, argv, "hABcxdtvs:f:l:D:O:P:")) != -1) { switch(c) { case 'h': usage(); @@ -879,6 +943,9 @@ int main(int argc, char *argv[]) { case 'O': options = optarg; break; + case 'P': + pitdate = optarg; + break; case ':': fprintf(stderr, "tsmpipe: Option -%c requires an operand\n", optopt); exit(1); @@ -929,11 +996,11 @@ int main(int argc, char *argv[]) { signal(SIGINT, SIG_IGN); signal(SIGUSR1, SIG_IGN); - if(!copy_env("DSM_DIR", "DSMI_DIR")) { + if(getenv("DSM_DIR") && (!copy_env("DSM_DIR", "DSMI_DIR"))) { exit(2); } - if(!copy_env("DSM_CONFIG", "DSMI_CONFIG")) { + if(getenv("DSM_DIR") && (!copy_env("DSM_CONFIG", "DSMI_CONFIG"))) { exit(2); } @@ -973,7 +1040,7 @@ int main(int argc, char *argv[]) { } if(xtract) { - if(!tsm_restorefile(sesshandle, space, filename, desc, sendtype, verbose)) + if(!tsm_restorefile(sesshandle, space, filename, desc, sendtype, verbose, pitdate)) { dsmTerminate(sesshandle); exit(8); @@ -981,7 +1048,7 @@ int main(int argc, char *argv[]) { } if(list) { - if(!tsm_listfile(sesshandle, space, filename, desc, sendtype, verbose)) + if(!tsm_listfile(sesshandle, space, filename, desc, sendtype, verbose, pitdate)) { dsmTerminate(sesshandle); exit(9);