Added Date, Added PIT recovery, Added use default ENV config

This commit is contained in:
Deon George 2010-11-14 15:32:54 +11:00
parent 425a7987c5
commit 983751d1af

View File

@ -59,6 +59,7 @@ static const char rcsid[] = /*Add RCS version string to binary */
/* We (HPC2N) have 512kB tcpbuff */ /* We (HPC2N) have 512kB tcpbuff */
#define BUFLEN (64*1024-4) #define BUFLEN (64*1024-4)
static dsmDate xStringToDate (char *s);
off_t atooff(const 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, dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmObjName *objName,
char *description, dsmSendType sendtype, char verbose, char *description, dsmSendType sendtype, char verbose,
tsm_query_callback usercb, void * userdata) tsm_query_callback usercb, void * userdata, char *pitdate)
{ {
dsmQueryType qType; dsmQueryType qType;
qryArchiveData qaData; qryArchiveData qaData;
@ -450,8 +451,13 @@ dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmObjName *objName,
qbData.stVersion = qryBackupDataVersion; qbData.stVersion = qryBackupDataVersion;
qbData.objName = objName; qbData.objName = objName;
qbData.owner = ""; qbData.owner = "";
qbData.objState = DSM_ACTIVE; qbData.objState = DSM_ANY_MATCH;
qbData.pitDate.year = DATE_MINUS_INFINITE;
if (pitdate) {
qbData.pitDate = xStringToDate(pitdate);
} else {
qbData.pitDate.year = DATE_MINUS_INFINITE;
}
qDataP = &qbData; qDataP = &qbData;
@ -577,7 +583,7 @@ int tsm_deletefile(dsUint32_t sesshandle, char *fsname, char *filename,
cbdata.numfound = 0; cbdata.numfound = 0;
rc = tsm_queryfile(sesshandle, &objName, description, sendtype, rc = tsm_queryfile(sesshandle, &objName, description, sendtype,
verbose, tsm_matchone_cb, &cbdata); verbose, tsm_matchone_cb, &cbdata, NULL);
if(rc != DSM_RC_OK) { if(rc != DSM_RC_OK) {
return 0; 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, 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; dsInt16_t rc;
struct matchone_cb_data cbdata; struct matchone_cb_data cbdata;
@ -653,7 +659,7 @@ int tsm_restorefile(dsUint32_t sesshandle, char *fsname, char *filename,
cbdata.numfound = 0; cbdata.numfound = 0;
rc = tsm_queryfile(sesshandle, &objName, description, sendtype, rc = tsm_queryfile(sesshandle, &objName, description, sendtype,
verbose, tsm_matchone_cb, &cbdata); verbose, tsm_matchone_cb, &cbdata, pitdate);
if(rc != DSM_RC_OK) { if(rc != DSM_RC_OK) {
return 0; return 0;
} }
@ -722,12 +728,61 @@ int tsm_restorefile(dsUint32_t sesshandle, char *fsname, char *filename,
return 1; 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) int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void * userdata)
{ {
unsigned long long filesize; unsigned long long filesize;
dsStruct64_t *rSizeEst; dsStruct64_t *rSizeEst;
dsmObjName *rObjName; 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 ) { if(userdata != NULL ) {
fprintf(stderr, "tsm_listfile_cb: Internal error: userdate != NULL"); fprintf(stderr, "tsm_listfile_cb: Internal error: userdate != NULL");
return -1; return -1;
@ -744,6 +799,13 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void * userdata)
rSizeEst = &qr->sizeEstimate; rSizeEst = &qr->sizeEstimate;
rObjName = &qr->objName; rObjName = &qr->objName;
insDate = &qr->insDate;
objstate = &qr->objState;
if (*objstate==DSM_INACTIVE)
state="I";
if (*objstate==DSM_ACTIVE)
state="A";
} }
else { else {
fprintf(stderr, fprintf(stderr,
@ -754,14 +816,15 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void * userdata)
filesize = rSizeEst->hi; filesize = rSizeEst->hi;
filesize <<= 32; filesize <<= 32;
filesize |= rSizeEst->lo; 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; return 1;
} }
int tsm_listfile(dsUint32_t sesshandle, char *fsname, char *filename, 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; dsInt16_t rc;
dsmObjName objName; dsmObjName objName;
@ -774,7 +837,7 @@ int tsm_listfile(dsUint32_t sesshandle, char *fsname, char *filename,
} }
rc = tsm_queryfile(sesshandle, &objName, description, sendtype, 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) { if(rc != DSM_RC_OK && rc != DSM_RC_ABORT_NO_MATCH) {
return 0; return 0;
} }
@ -820,6 +883,7 @@ void usage(void) {
" -l length Length of object to store. If guesstimating too large\n" " -l length Length of object to store. If guesstimating too large\n"
" is better than too small\n" " is better than too small\n"
" -D desc Description of archive object\n" " -D desc Description of archive object\n"
" -P pitdate PITDate (mmddYYYY)\n"
" -O options Extra options to pass to dsmInitEx\n" " -O options Extra options to pass to dsmInitEx\n"
" -v Verbose. More -v's gives more verbosity\n" " -v Verbose. More -v's gives more verbosity\n"
); );
@ -832,13 +896,13 @@ int main(int argc, char *argv[]) {
extern char *optarg; extern char *optarg;
char archmode=0, backmode=0, create=0, xtract=0, delete=0, verbose=0; char archmode=0, backmode=0, create=0, xtract=0, delete=0, verbose=0;
char list=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; char *options=NULL;
off_t length; off_t length;
dsUint32_t sesshandle; dsUint32_t sesshandle;
dsmSendType sendtype; 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) { switch(c) {
case 'h': case 'h':
usage(); usage();
@ -879,6 +943,9 @@ int main(int argc, char *argv[]) {
case 'O': case 'O':
options = optarg; options = optarg;
break; break;
case 'P':
pitdate = optarg;
break;
case ':': case ':':
fprintf(stderr, "tsmpipe: Option -%c requires an operand\n", optopt); fprintf(stderr, "tsmpipe: Option -%c requires an operand\n", optopt);
exit(1); exit(1);
@ -929,11 +996,11 @@ int main(int argc, char *argv[]) {
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
signal(SIGUSR1, 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); exit(2);
} }
if(!copy_env("DSM_CONFIG", "DSMI_CONFIG")) { if(getenv("DSM_DIR") && (!copy_env("DSM_CONFIG", "DSMI_CONFIG"))) {
exit(2); exit(2);
} }
@ -973,7 +1040,7 @@ int main(int argc, char *argv[]) {
} }
if(xtract) { if(xtract) {
if(!tsm_restorefile(sesshandle, space, filename, desc, sendtype, verbose)) if(!tsm_restorefile(sesshandle, space, filename, desc, sendtype, verbose, pitdate))
{ {
dsmTerminate(sesshandle); dsmTerminate(sesshandle);
exit(8); exit(8);
@ -981,7 +1048,7 @@ int main(int argc, char *argv[]) {
} }
if(list) { if(list) {
if(!tsm_listfile(sesshandle, space, filename, desc, sendtype, verbose)) if(!tsm_listfile(sesshandle, space, filename, desc, sendtype, verbose, pitdate))
{ {
dsmTerminate(sesshandle); dsmTerminate(sesshandle);
exit(9); exit(9);