Added version, moved exten to .h, and major internal rework
This commit is contained in:
parent
367f265d52
commit
2fd647af8d
@ -1,19 +1,15 @@
|
||||
TSMAPIDIR=/opt/tivoli/tsm/client/api/bin/sample
|
||||
TSMLIB=-lApiDS
|
||||
CC=gcc
|
||||
CFLAGS=-g -W -Wall -Wextra -m32 -O -I$(TSMAPIDIR)
|
||||
CFLAGS=-g -W -Wall -Wextra -O -m32 -I$(TSMAPIDIR)
|
||||
LDFLAGS=
|
||||
|
||||
FILES=tsmpipe.c
|
||||
|
||||
|
||||
all: tsmpipe
|
||||
|
||||
tsmpipe: tsmpipe.o lib/dsmobjects.o lib/dsmsession.o lib/dsmlist.o lib/dsmsendrecv.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(TSMLIB) -lm
|
||||
|
||||
tsmpipe.c:
|
||||
echo 'hello'
|
||||
$(CC) $(CFLAGS) -c -o $(@:.c=.o) $@ $(TSMLIB)
|
||||
|
||||
lib/dsmlist:
|
||||
@ -29,4 +25,4 @@ lib/dsmobjects:
|
||||
$(CC) $(CFLAGS) -c -o lib/$@.o lib/$@.c $(TSMLIB)
|
||||
|
||||
clean:
|
||||
rm tsmpipe *.o lib/*.o
|
||||
rm -f tsmpipe *.o lib/*.o
|
||||
|
@ -10,7 +10,6 @@ tsmpipe: tsmpipe.o lib/dsmobjects.o lib/dsmsession.o lib/dsmlist.o lib/dsmsendre
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(TSMLIB) -lm
|
||||
|
||||
tsmpipe.c:
|
||||
echo 'hello'
|
||||
$(CC) $(CFLAGS) -c -o $(@:.c=.o) $@ $(TSMLIB)
|
||||
|
||||
lib/dsmlist:
|
||||
@ -26,4 +25,4 @@ lib/dsmobjects:
|
||||
$(CC) $(CFLAGS) -c -o lib/$@.o lib/$@.c $(TSMLIB)
|
||||
|
||||
clean:
|
||||
rm tsmpipe *.o lib/*.o
|
||||
rm -f tsmpipe *.o lib/*.o
|
||||
|
@ -12,12 +12,6 @@
|
||||
|
||||
dsBool_t headerPrinted=bFalse; // Have we rendered the heading row yet
|
||||
|
||||
extern char *dsmDateToStr(dsmDate date);
|
||||
extern char *dsmObjnameToStr(dsmObjName objName);
|
||||
extern double dsmSizeToNum(dsStruct64_t dsStruct64);
|
||||
extern dsmObjName dsmNameToObjname(char *fsname, char *filename, int verbose);
|
||||
extern dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmObjName *objName, char *description, dsmSendType sendtype, char verbose, tsm_query_callback usercb, void * userdata, char *pitdate, int querytype);
|
||||
|
||||
/*
|
||||
* Our Callback to show what is in TSM
|
||||
*/
|
||||
@ -26,9 +20,6 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
char state[3];
|
||||
char ced[4];
|
||||
|
||||
qryRespBackupData respBackup;
|
||||
qryRespArchiveData respArchive;
|
||||
|
||||
if (userdata != NULL ) {
|
||||
fprintf(stderr, "tsm_listfile_cb: Internal error: userdate != NULL");
|
||||
return -1;
|
||||
@ -48,6 +39,7 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
"DESC"
|
||||
);
|
||||
|
||||
qryRespArchiveData respArchive;
|
||||
memset(&respArchive,0x00,sizeof(qryRespArchiveData));
|
||||
qryRespArchiveData *qr = (void *) qResp->bufferPtr;
|
||||
respArchive = *qr;
|
||||
@ -56,14 +48,14 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
switch (respArchive.objName.objType) {
|
||||
case (DSM_OBJ_FILE) : strcpy(state,"F"); break;
|
||||
case (DSM_OBJ_DIRECTORY) : strcpy(state,"D"); break;
|
||||
default : strcpy(state,"?");
|
||||
default: strcpy(state,"?");
|
||||
}
|
||||
|
||||
// Location
|
||||
switch (respArchive.mediaClass) {
|
||||
case (MEDIA_FIXED) : strcpy(stor,"D"); break;
|
||||
case (MEDIA_LIBRARY) : strcpy(stor,"T"); break;
|
||||
default : strcpy(stor,"?");
|
||||
default: strcpy(stor,"?");
|
||||
}
|
||||
|
||||
// Compression, Encryption, De-Duplication
|
||||
@ -78,7 +70,7 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
// The Object Status
|
||||
printf("%40s|%2s|%s|%3s|%19s|%19s|%7.3f MB|%u-%u|%s\n",dsmObjnameToStr(respArchive.objName),state,stor,ced,dsmDateToStr(respArchive.insDate),respArchive.expDate.year ? dsmDateToStr(respArchive.expDate) : "",dsmSizeToNum(respArchive.sizeEstimate),respArchive.objId.hi,respArchive.objId.lo,respArchive.descr);
|
||||
|
||||
} else if (qType ==qtBackup) {
|
||||
} else if (qType == qtBackup) {
|
||||
if (! headerPrinted++)
|
||||
printf("%40s %2s %s %3s %19s %19s %10s %s\n",
|
||||
"NAME",
|
||||
@ -91,6 +83,7 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
"ID"
|
||||
);
|
||||
|
||||
qryRespBackupData respBackup;
|
||||
memset(&respBackup,0x00,sizeof(qryRespBackupData));
|
||||
qryRespBackupData *qr = (void *) qResp->bufferPtr;
|
||||
respBackup = *qr;
|
||||
@ -99,20 +92,20 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
switch (respBackup.objName.objType) {
|
||||
case (DSM_OBJ_FILE) : strcpy(state,"F"); break;
|
||||
case (DSM_OBJ_DIRECTORY) : strcpy(state,"D"); break;
|
||||
default : strcpy(state,"?");
|
||||
default: strcpy(state,"?");
|
||||
}
|
||||
|
||||
switch (respBackup.objState) {
|
||||
case (DSM_ACTIVE) : strcat(state,"A"); break;
|
||||
case (DSM_INACTIVE) : strcat(state,"I"); break;
|
||||
default : strcat(state,"?");
|
||||
default: strcat(state,"?");
|
||||
}
|
||||
|
||||
// Location
|
||||
switch (respBackup.mediaClass) {
|
||||
case (MEDIA_FIXED) : strcpy(stor,"D"); break;
|
||||
case (MEDIA_LIBRARY) : strcpy(stor,"T"); break;
|
||||
default : strcpy(stor,"?");
|
||||
default: strcpy(stor,"?");
|
||||
}
|
||||
|
||||
// Compression, Encryption, De-Duplication
|
||||
@ -128,7 +121,6 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
|
||||
} else {
|
||||
fprintf(stderr,"tsm_listfile_cb: Internal error: Unknown qType %d\n",qType);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -138,13 +130,10 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
/*
|
||||
* List objects that are in TSM
|
||||
*/
|
||||
int tsm_listfile(dsUint32_t sesshandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose, char *pitdate) {
|
||||
int tsm_listfile(dsUint32_t sesshandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
||||
dsInt16_t rc=0;
|
||||
dsmObjName objName;
|
||||
|
||||
objName = dsmNameToObjname(fsname,filename,verbose);
|
||||
|
||||
rc = tsm_queryfile(sesshandle, &objName, description, sendtype, verbose, tsm_listfile_cb, NULL, pitdate, DSM_ANY_MATCH);
|
||||
rc = tsm_queryfile(sesshandle,qType,tsm_listfile_cb,NULL,qaData,qbData,verbose);
|
||||
|
||||
if (rc != DSM_RC_OK && rc != DSM_RC_ABORT_NO_MATCH)
|
||||
return 0;
|
||||
|
@ -28,15 +28,7 @@
|
||||
|
||||
#include "../tsmpipe.h"
|
||||
|
||||
extern dsBool_t compressEnabled;
|
||||
|
||||
extern void tsm_printerr(dsUint32_t dsmHandle, dsInt16_t rc, char *str);
|
||||
extern char *dsmObjnameToStr(dsmObjName objName);
|
||||
extern double dsmSizeToNum(dsStruct64_t dsStruct64);
|
||||
extern dsmObjName dsmNameToObjname(char *fsname, char *filename, int verbose);
|
||||
extern dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmObjName *objName, char *description, dsmSendType sendtype, char verbose, tsm_query_callback usercb, void * userdata, char *pitdate, int querytype);
|
||||
|
||||
int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void * userdata) {
|
||||
int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
||||
struct matchone_cb_data *cbdata = userdata;
|
||||
|
||||
cbdata->numfound++;
|
||||
@ -58,8 +50,7 @@ int tsm_matchone_cb(dsmQueryType qType, DataBlk *qResp, void * userdata) {
|
||||
}
|
||||
|
||||
if (cbdata->numfound > 1) {
|
||||
fprintf(stderr,"tsmpipe: FAILED: The file specification matched multiple files.\n");
|
||||
|
||||
fprintf(stderr,"tsm_matchone_cb: FAILED: The file specification matched multiple files.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -127,7 +118,7 @@ int tsm_regfs(dsUint32_t dsmHandle, char *fsname) {
|
||||
}
|
||||
|
||||
/* Send data to TSM for storage */
|
||||
int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, char verbose) {
|
||||
int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, int verbose) {
|
||||
char *buffer;
|
||||
dsInt16_t rc=0;
|
||||
dsmObjName objName;
|
||||
@ -183,8 +174,12 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
|
||||
if ((sendtype == stArchiveMountWait || sendtype == stArchive) && mcBindKey.archive_cg_exists) {
|
||||
cgdest = mcBindKey.archive_copy_dest;
|
||||
|
||||
} else if(mcBindKey.backup_cg_exists) {
|
||||
} else if ((sendtype == stBackupMountWait || sendtype == stBackup) && mcBindKey.backup_cg_exists) {
|
||||
cgdest = mcBindKey.backup_copy_dest;
|
||||
|
||||
} else {
|
||||
fprintf(stderr,"tsm_sendfile: Internal error: Unknown qType %d\n",sendtype);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cgdest)
|
||||
@ -221,8 +216,9 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
|
||||
nbytes = rw_full(STDIN_FILENO,buffer,BUFLEN);
|
||||
|
||||
if (nbytes < 0) {
|
||||
perror("tsmpipe: read");
|
||||
perror("tsm_sendmail: read");
|
||||
return 0;
|
||||
|
||||
} else if (nbytes == 0) {
|
||||
break;
|
||||
}
|
||||
@ -234,7 +230,7 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
|
||||
rc = dsmSendData(dsmHandle,&dataBlk);
|
||||
|
||||
if (rc != DSM_RC_OK && rc != DSM_RC_COMPRESS_GREW) {
|
||||
tsm_printerr(dsmHandle,rc,"tsm_senfile: dsmSendData failed");
|
||||
tsm_printerr(dsmHandle,rc,"tsm_sendfile: dsmSendData failed");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -281,27 +277,34 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
|
||||
}
|
||||
|
||||
/* Get data from TSM for restore */
|
||||
int tsm_restorefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose, char *pitdate) {
|
||||
int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
||||
dsInt16_t rc=0;
|
||||
struct matchone_cb_data cbdata;
|
||||
dsmObjName objName;
|
||||
dsmGetList getList;
|
||||
dsmGetType getType;
|
||||
DataBlk dataBlk;
|
||||
|
||||
objName = dsmNameToObjname(fsname,filename,verbose);
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(objName));
|
||||
dsmGetType gType;
|
||||
|
||||
memset(&cbdata,0x00,sizeof(cbdata));
|
||||
cbdata.numfound = 0;
|
||||
|
||||
// Retrieve a list based on the PITDATE or if no PITDATE, the last ACTIVE
|
||||
if (sendtype == stBackupMountWait)
|
||||
rc = tsm_queryfile(dsmHandle,&objName,description,sendtype,verbose,tsm_matchone_cb,&cbdata,pitdate,pitdate ? DSM_ANY_MATCH : DSM_ACTIVE);
|
||||
else
|
||||
rc = tsm_queryfile(dsmHandle,&objName,description,sendtype,verbose,tsm_matchone_cb,&cbdata,NULL,0);
|
||||
if (qType == qtArchive) {
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(*qaData.objName));
|
||||
|
||||
gType = gtArchive;
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,verbose);
|
||||
|
||||
} else if (qType == qtBackup) {
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(*qbData.objName));
|
||||
|
||||
gType = gtBackup;
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,verbose);
|
||||
|
||||
} else {
|
||||
fprintf(stderr,"tsm_restorefile: Internal error: Unknown qType %d\n",qType);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc != DSM_RC_OK)
|
||||
return 0;
|
||||
@ -317,13 +320,7 @@ int tsm_restorefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *de
|
||||
getList.objId = &cbdata.objId;
|
||||
getList.partialObjData = NULL;
|
||||
|
||||
if (sendtype == stArchiveMountWait || sendtype == stArchive) {
|
||||
getType = gtArchive;
|
||||
} else {
|
||||
getType = gtBackup;
|
||||
}
|
||||
|
||||
rc = dsmBeginGetData(dsmHandle,bTrue,getType,&getList);
|
||||
rc = dsmBeginGetData(dsmHandle,bTrue,gType,&getList);
|
||||
if (rc != DSM_RC_OK) {
|
||||
tsm_printerr(dsmHandle,rc,"tsm_restorefile: dsmBeginGetData failed");
|
||||
return 0;
|
||||
@ -378,24 +375,16 @@ int tsm_restorefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *de
|
||||
}
|
||||
|
||||
/* Delete data in TSM */
|
||||
int tsm_deletefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose) {
|
||||
int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
||||
dsInt16_t rc=0;
|
||||
dsUint16_t reason=0;
|
||||
dsmDelInfo *dInfoP;
|
||||
dsmDelType dType;
|
||||
struct matchone_cb_data cbdata;
|
||||
delArch daInfo;
|
||||
delBack dbInfo;
|
||||
dsmObjName objName;
|
||||
|
||||
objName = dsmNameToObjname(fsname,filename,verbose);
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_deletefile: Deleting file %s\n",dsmObjnameToStr(objName));
|
||||
|
||||
cbdata.numfound = 0;
|
||||
|
||||
rc = tsm_queryfile(dsmHandle,&objName,description,sendtype,verbose,tsm_matchone_cb,&cbdata,NULL,DSM_ACTIVE);
|
||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,verbose);
|
||||
if (rc != DSM_RC_OK) {
|
||||
return 0;
|
||||
}
|
||||
@ -405,21 +394,34 @@ int tsm_deletefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *des
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sendtype == stArchiveMountWait || sendtype == stArchive) {
|
||||
if (qType == qtArchive) {
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_deletefile: Deleting archive file %s\n",dsmObjnameToStr(*qaData.objName));
|
||||
|
||||
dType = dtArchive;
|
||||
|
||||
delArch daInfo;
|
||||
daInfo.stVersion = delArchVersion;
|
||||
daInfo.objId = cbdata.objId;
|
||||
|
||||
dInfoP = (dsmDelInfo *) &daInfo;
|
||||
} else {
|
||||
|
||||
} else if (qType == qtBackup) {
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_deletefile: Deleting backup file %s\n",dsmObjnameToStr(*qbData.objName));
|
||||
|
||||
dType = dtBackup;
|
||||
|
||||
delBack dbInfo;
|
||||
dbInfo.stVersion = delBackVersion;
|
||||
dbInfo.objNameP = &objName;
|
||||
dbInfo.objNameP = qbData.objName;
|
||||
dbInfo.copyGroup = cbdata.copyGroup;
|
||||
|
||||
dInfoP = (dsmDelInfo *) &dbInfo;
|
||||
|
||||
} else {
|
||||
fprintf(stderr,"tsm_matchone_cb: Internal error: Unknown qType %d\n",qType);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = dsmBeginTxn(dsmHandle);
|
||||
|
119
lib/dsmsession.c
119
lib/dsmsession.c
@ -15,10 +15,6 @@
|
||||
|
||||
dsBool_t compressEnabled=bFalse; // Is compression enabled
|
||||
|
||||
extern char *dsmDateToStr(dsmDate date);
|
||||
extern dsmDate dsmStrToDate(char *s,int verbose);
|
||||
extern char *dsmObjnameToStr(dsmObjName objName);
|
||||
|
||||
/* Print out TSM Error Code */
|
||||
void tsm_printerr(dsUint32_t dsmHandle, dsInt16_t rc, char *str) {
|
||||
char rcStr[DSM_MAX_RC_MSG_LENGTH];
|
||||
@ -140,7 +136,7 @@ dsUint32_t tsm_initsess(char *options) {
|
||||
case COMPRESS_YES : compressEnabled = bTrue; break;
|
||||
case COMPRESS_NO : compressEnabled = bFalse; break;
|
||||
case COMPRESS_CD : compressEnabled = dsmOpt.compression; break;
|
||||
default : rc=0;
|
||||
default: rc=0;
|
||||
}
|
||||
|
||||
if (!rc || (compressEnabled && ! dsmOpt.compressalways)) {
|
||||
@ -165,6 +161,8 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
dsmQueryApiVersionEx(&apiLibVer);
|
||||
|
||||
printf("Application Version:\n");
|
||||
printf(" TSMPIPE Version: %s\n",
|
||||
_TSMPIPE_VERSION);
|
||||
printf(" TSMPIPE API Version: %d.%d.%d.%d\n",
|
||||
DSM_API_VERSION,
|
||||
DSM_API_RELEASE,
|
||||
@ -188,7 +186,15 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
printf(" DSMI_DIR: %s\n",dsmOpt.dsmiDir);
|
||||
printf(" DSMI_CONFIG: %s\n",dsmOpt.dsmiConfig);
|
||||
printf(" SErvername: %s\n",dsmOpt.serverName);
|
||||
printf(" COMMmethod: %d\n",dsmOpt.commMethod);
|
||||
|
||||
switch (dsmOpt.commMethod) {
|
||||
case DSM_COMM_TCP : strcpy(t,"TCP/IP"); break;
|
||||
case DSM_COMM_NAMEDPIPE : strcpy(t,"NAMED PIPE"); break;
|
||||
case DSM_COMM_SHM : strcpy(t,"SHARED MEMORY"); break;
|
||||
default: strcpy(t,"UNKNOWN");
|
||||
}
|
||||
printf(" COMMmethod: %s\n",t);
|
||||
|
||||
printf(" TCPServerAddress: %s\n",dsmOpt.serverAddress);
|
||||
printf(" NODEName: %s\n",dsmOpt.nodeName);
|
||||
printf(" COMPRESSIon: %d\n",dsmOpt.compression);
|
||||
@ -228,21 +234,21 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
case COMPRESS_YES : strcpy(t,"ON"); break;
|
||||
case COMPRESS_NO : strcpy(t,"OFF"); break;
|
||||
case COMPRESS_CD : strcpy(t,"CLIENT"); break;
|
||||
default : strcpy(t,"UNKNOWN");
|
||||
default: strcpy(t,"UNKNOWN");
|
||||
}
|
||||
printf(" Client compression: %s\n",t);
|
||||
|
||||
switch (dsmSessInfo.archDel) {
|
||||
case ARCHDEL_YES : strcpy(t,"YES"); break;
|
||||
case ARCHDEL_NO : strcpy(t,"NO"); break;
|
||||
default : strcpy(t,"UNKNOWN");
|
||||
default: strcpy(t,"UNKNOWN");
|
||||
}
|
||||
printf(" ARCHIVE Delete: %s\n",t);
|
||||
|
||||
switch (dsmSessInfo.backDel) {
|
||||
case BACKDEL_YES : strcpy(t,"YES"); break;
|
||||
case ARCHDEL_NO : strcpy(t,"NO"); break;
|
||||
default : strcpy(t,"UNKNOWN");
|
||||
default: strcpy(t,"UNKNOWN");
|
||||
}
|
||||
printf(" BACKUP delete: %s\n",t);
|
||||
|
||||
@ -261,6 +267,7 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
printf(" Default management class: %s\n",dsmSessInfo.dfltMCName);
|
||||
printf(" BACKUP retention grace: %u days\n",dsmSessInfo.gpBackRetn);
|
||||
printf(" ARCHIVE retention grace: %u days\n",dsmSessInfo.gpArchRetn);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,68 +279,48 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||
* 0 if tsm_queryfile() should skip processing the remaining matches.
|
||||
* 1 otherwise.
|
||||
*/
|
||||
dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmObjName *objName, char *description, dsmSendType sendtype, char verbose, tsm_query_callback usercb, void * userdata, char *pitdate, int querytype) {
|
||||
dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
||||
dsInt16_t rc=0;
|
||||
DataBlk qResp;
|
||||
dsmQueryType qType;
|
||||
qryArchiveData qaData;
|
||||
qryRespArchiveData qaResp;
|
||||
qryBackupData qbData;
|
||||
qryRespBackupData qbResp;
|
||||
dsmQueryBuff *qDataP;
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_queryfile: Query filespace %s\n",dsmObjnameToStr(*objName));
|
||||
|
||||
DataBlk qResp;
|
||||
memset(&qResp,0x00,sizeof(DataBlk));
|
||||
qResp.stVersion = DataBlkVersion;
|
||||
|
||||
if (sendtype == stArchiveMountWait || sendtype == stArchive) {
|
||||
qType = qtArchive;
|
||||
switch (qType) {
|
||||
case qtArchive:
|
||||
qDataP = &qaData;
|
||||
|
||||
memset(&qaData,0x00,sizeof(qryArchiveData));
|
||||
qaData.stVersion = qryArchiveDataVersion;
|
||||
qaData.objName = objName;
|
||||
qaData.owner = "";
|
||||
if (pitdate) {
|
||||
fprintf(stderr,"tsm_queryfile: Archive Date Range Query not yet setup\n");
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_queryfile: Query filespace %s\n",dsmObjnameToStr(*qaData.objName));
|
||||
|
||||
qryRespArchiveData qaResp;
|
||||
qaResp.stVersion = qryRespArchiveDataVersion;
|
||||
|
||||
qResp.bufferPtr = (char *) &qaResp;
|
||||
qResp.bufferLen = sizeof(qaResp);
|
||||
break;
|
||||
|
||||
case qtBackup:
|
||||
qDataP = &qbData;
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr,"tsm_queryfile: Query filespace %s\n",dsmObjnameToStr(*qbData.objName));
|
||||
if (verbose > 1) {
|
||||
fprintf(stderr,"tsm_queryfile: PIT Date: %s\n",dsmDateToStr(qbData.pitDate));
|
||||
fprintf(stderr,"tsm_queryfile: OBJSTATE : %s\n",qbData.objState==DSM_ACTIVE ? "DSM_ACTIVE" : "DSM_ANY_MATCH");
|
||||
}
|
||||
|
||||
qryRespBackupData qbResp;
|
||||
qbResp.stVersion = qryRespBackupDataVersion;
|
||||
|
||||
qResp.bufferPtr = (char *) &qbResp;
|
||||
qResp.bufferLen = sizeof(qbResp);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"tsm_queryfile: ERROR: Unknown qType: %d?\n",qType);
|
||||
exit(1);
|
||||
} else {
|
||||
qaData.insDateLowerBound.year = DATE_MINUS_INFINITE;
|
||||
qaData.insDateUpperBound.year = DATE_PLUS_INFINITE;
|
||||
qaData.expDateLowerBound.year = DATE_MINUS_INFINITE;
|
||||
qaData.expDateUpperBound.year = DATE_PLUS_INFINITE;
|
||||
}
|
||||
qaData.descr = description ? description : "*";
|
||||
|
||||
qDataP = &qaData;
|
||||
|
||||
qaResp.stVersion = qryRespArchiveDataVersion;
|
||||
|
||||
qResp.bufferPtr = (char *) &qaResp;
|
||||
qResp.bufferLen = sizeof(qaResp);
|
||||
|
||||
} else {
|
||||
qType = qtBackup;
|
||||
|
||||
memset(&qbData,0x00,sizeof(qryBackupData));
|
||||
qbData.stVersion = qryBackupDataVersion;
|
||||
qbData.objName = objName;
|
||||
qbData.owner = "";
|
||||
qbData.objState = querytype;
|
||||
|
||||
if (pitdate) {
|
||||
qbData.pitDate = dsmStrToDate(pitdate,verbose);
|
||||
} else {
|
||||
qbData.pitDate.year = DATE_MINUS_INFINITE;
|
||||
}
|
||||
|
||||
qDataP = &qbData;
|
||||
|
||||
qbResp.stVersion = qryRespBackupDataVersion;
|
||||
|
||||
qResp.bufferPtr = (char *) &qbResp;
|
||||
qResp.bufferLen = sizeof(qbResp);
|
||||
}
|
||||
|
||||
rc = dsmBeginQuery(dsmHandle, qType, qDataP);
|
||||
@ -349,11 +336,11 @@ dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmObjName *objName, char *descrip
|
||||
if(verbose > 1) {
|
||||
dsmObjName *rObjName;
|
||||
|
||||
if(qType == qtArchive) {
|
||||
if (qType == qtArchive) {
|
||||
qryRespArchiveData *qr = (void *) qResp.bufferPtr;
|
||||
rObjName = &(qr->objName);
|
||||
|
||||
} else if(qType == qtBackup) {
|
||||
} else if (qType == qtBackup) {
|
||||
qryRespBackupData *qr = (void *) qResp.bufferPtr;
|
||||
rObjName = &(qr->objName);
|
||||
|
||||
@ -379,7 +366,7 @@ dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmObjName *objName, char *descrip
|
||||
}
|
||||
|
||||
if (rc != DSM_RC_FINISHED && rc != DSM_RC_MORE_DATA) {
|
||||
tsm_printerr(dsmHandle, rc, "tsm_queryfile: dsmGetNextObj failed");
|
||||
tsm_printerr(dsmHandle,rc,"tsm_queryfile: dsmGetNextObj failed");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
143
tsmpipe.c
143
tsmpipe.c
@ -36,13 +36,7 @@ SOFTWARE.
|
||||
#include "dsmrc.h"
|
||||
#include "dsmapitd.h"
|
||||
#include "dsmapifp.h"
|
||||
|
||||
extern dsUint32_t tsm_initsess(char *options);
|
||||
extern void tsm_sessioninfo(dsUint32_t dsmHandle);
|
||||
extern int tsm_listfile(dsUint32_t dsmHandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose, char *pitdate);
|
||||
extern int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, char verbose);
|
||||
extern int tsm_restorefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose, char *pitdate);
|
||||
extern int tsm_deletefile(dsUint32_t dsmHandle, char *fsname, char *filename, char *description, dsmSendType sendtype, char verbose);
|
||||
#include "tsmpipe.h"
|
||||
|
||||
int copy_env(const char *from, const char *to) {
|
||||
char *e;
|
||||
@ -67,7 +61,7 @@ int copy_env(const char *from, const char *to) {
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr,
|
||||
"tsmpipe $Revision: 1.5-dg $, usage:\n"
|
||||
"tsmpipe %s, usage:\n"
|
||||
"\n"
|
||||
"tsmpipe [-i] [-A|-B] [-c|-x|-d|-t] -s fsname -f filepath [-l len]\n"
|
||||
" -i Show session information:\n"
|
||||
@ -88,7 +82,7 @@ void usage(void) {
|
||||
" -P pitdate PITDate (mmddYYYY) (BACKUP Objects)\n"
|
||||
" -O options Extra options to pass to dsmInitEx\n"
|
||||
" -v Verbose. More -v's gives more verbosity\n"
|
||||
);
|
||||
,_TSMPIPE_VERSION);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@ -97,11 +91,12 @@ int main(int argc, char *argv[]) {
|
||||
int c;
|
||||
extern int optopt;
|
||||
extern char *optarg;
|
||||
char archive=0, backup=0, create=0, xtract=0, delete=0, verbose=0, info=0, list=0;
|
||||
char archive=0, backup=0, create=0, xtract=0, delete=0, info=0, list=0;
|
||||
int verbose=0;
|
||||
char *space=NULL, *filename=NULL, *lenstr=NULL, *desc=NULL, *pitdate=NULL, *options=NULL;
|
||||
off_t length;
|
||||
dsUint32_t dsmHandle;
|
||||
dsmSendType sendtype;
|
||||
dsmQueryType qType;
|
||||
|
||||
while ((c = getopt(argc, argv, "hiABcxdtvs:f:l:D:O:P:")) != -1) {
|
||||
switch(c) {
|
||||
@ -135,6 +130,7 @@ int main(int argc, char *argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// @todo To change.
|
||||
if (pitdate && ! backup) {
|
||||
fprintf(stderr, "tsmpipe: ERROR: -P can only be used with -A\n");
|
||||
exit(1);
|
||||
@ -172,7 +168,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
sendtype = archive ? stArchiveMountWait : stBackupMountWait;
|
||||
qType = backup ? qtBackup : qtArchive;
|
||||
|
||||
/* Let the TSM api get the signals */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
@ -184,8 +180,12 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// OK, we are ready to talk to TSM
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: Create TSM session\n");
|
||||
dsmHandle = tsm_initsess(options);
|
||||
if (! dsmHandle) {
|
||||
fprintf(stderr,"tsmpipe: Unable to create TSM session?\n");
|
||||
|
||||
exit(2);
|
||||
}
|
||||
|
||||
@ -194,50 +194,117 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Show our session information
|
||||
if (info) {
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: INFO operation\n");
|
||||
|
||||
tsm_sessioninfo(dsmHandle);
|
||||
}
|
||||
|
||||
// If we are backing up
|
||||
if (create) {
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: BACKUP operation\n");
|
||||
|
||||
length = atof(lenstr);
|
||||
if (length <= 0) {
|
||||
fprintf(stderr,"tsmpipe: ERROR: Provide positive length, overestimate if guessing");
|
||||
fprintf(stderr,"tsmpipe: ERROR: Provide positive length, overestimate if guessing\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (! tsm_sendfile(dsmHandle,space,filename,length,desc,sendtype,verbose)){
|
||||
if (! tsm_sendfile(dsmHandle,space,filename,length,desc,(archive ? stArchiveMountWait : stBackupMountWait),verbose)){
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Delete an object from TSM
|
||||
if (delete) {
|
||||
// @todo Delete Archives by date range.
|
||||
if (! tsm_deletefile(dsmHandle,space,filename,desc,sendtype,verbose)) {
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
// Restore from TSM
|
||||
if(xtract) {
|
||||
// @todo Query Archives by date range.
|
||||
if (! tsm_restorefile(dsmHandle,space,filename,desc,sendtype,verbose,(sendtype == stBackupMountWait ? pitdate : NULL))) {
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
// List objects in TSM
|
||||
if (list) {
|
||||
// @todo Query Archives by date range.
|
||||
if (! tsm_listfile(dsmHandle,space,filename,desc,sendtype,verbose,(sendtype == stBackupMountWait ? pitdate : NULL))) {
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
if (! info && ! create) {
|
||||
qryArchiveData qaData;
|
||||
qryBackupData qbData;
|
||||
dsmObjName objName;
|
||||
memset(&qaData,0x00,sizeof(qryArchiveData));
|
||||
memset(&qbData,0x00,sizeof(qryBackupData));
|
||||
objName = dsmNameToObjname(space,filename,verbose);
|
||||
|
||||
// Setup our Query Object
|
||||
if (backup) {
|
||||
qbData.stVersion = qryBackupDataVersion;
|
||||
qbData.objName = &objName;
|
||||
qbData.owner = "";
|
||||
qbData.objState = delete ? DSM_ACTIVE : DSM_ANY_MATCH;
|
||||
|
||||
if (delete || ! pitdate) {
|
||||
qbData.pitDate.year = DATE_MINUS_INFINITE;
|
||||
} else {
|
||||
// @todo Need to include time
|
||||
qbData.pitDate = dsmStrToDate(pitdate,verbose);
|
||||
}
|
||||
|
||||
// We must be archive then
|
||||
} else {
|
||||
if (archive) {
|
||||
qaData.stVersion = qryArchiveDataVersion;
|
||||
qaData.objName = &objName;
|
||||
qaData.owner = "";
|
||||
|
||||
if (pitdate) {
|
||||
fprintf(stderr,"tsmpipe: Archive Date Range Query not yet setup\n");
|
||||
exit(1);
|
||||
|
||||
} else {
|
||||
qaData.insDateLowerBound.year = DATE_MINUS_INFINITE;
|
||||
qaData.insDateUpperBound.year = DATE_PLUS_INFINITE;
|
||||
qaData.expDateLowerBound.year = DATE_MINUS_INFINITE;
|
||||
qaData.expDateUpperBound.year = DATE_PLUS_INFINITE;
|
||||
}
|
||||
|
||||
qaData.descr = desc ? desc : "*";
|
||||
|
||||
} else {
|
||||
fprintf(stderr,"tsmpipe: ERROR: How can we not be a backup or archive?\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete an object from TSM
|
||||
if (delete) {
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: DELETE operation\n");
|
||||
|
||||
// @todo Delete Archives by date range.
|
||||
if (! tsm_deletefile(dsmHandle,qType,qaData,qbData,verbose)) {
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
// Restore from TSM
|
||||
if(xtract) {
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: RESTORE operation\n");
|
||||
|
||||
// @todo Query Archives by date range.
|
||||
if (! tsm_restorefile(dsmHandle,qType,qaData,qbData,verbose)) {
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
// List objects in TSM
|
||||
if (list) {
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: LIST operation\n");
|
||||
|
||||
// @todo Query Archives by date range.
|
||||
if (! tsm_listfile(dsmHandle,qType,qaData,qbData,verbose)) {
|
||||
dsmTerminate(dsmHandle);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose > 0)
|
||||
fprintf(stderr,"tsmpipe: Terminate TSM session\n");
|
||||
dsmTerminate(dsmHandle);
|
||||
|
||||
if (verbose > 0)
|
||||
|
21
tsmpipe.h
21
tsmpipe.h
@ -1,3 +1,24 @@
|
||||
#define _TSMPIPE_VERSION "1.5.1"
|
||||
|
||||
typedef int (*tsm_query_callback)(dsmQueryType, DataBlk *, void *);
|
||||
|
||||
struct matchone_cb_data { int numfound; dsStruct64_t objId; dsUint32_t copyGroup; };
|
||||
|
||||
extern void tsm_printerr (dsUint32_t dsmHandle, dsInt16_t rc, char *str);
|
||||
extern void tsm_sessioninfo(dsUint32_t dsmHandle);
|
||||
|
||||
extern dsmDate dsmStrToDate(char *s,int verbose);
|
||||
extern dsmObjName dsmNameToObjname(char *fsname, char *filename, int verbose);
|
||||
extern dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
||||
extern dsUint32_t tsm_initsess(char *options);
|
||||
extern dsBool_t compressEnabled;
|
||||
|
||||
extern int tsm_deletefile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
||||
extern int tsm_listfile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
||||
extern int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
||||
extern int tsm_sendfile (dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, int verbose);
|
||||
|
||||
extern char *dsmDateToStr(dsmDate date);
|
||||
extern char *dsmObjnameToStr(dsmObjName objName);
|
||||
|
||||
extern double dsmSizeToNum(dsStruct64_t dsStruct64);
|
||||
|
Reference in New Issue
Block a user