Enabled Archive Date Query, enabled query with time, some minor internal work
This commit is contained in:
parent
2fd647af8d
commit
b3334a2401
@ -130,10 +130,10 @@ int tsm_listfile_cb(dsmQueryType qType, DataBlk *qResp, void *userdata) {
|
|||||||
/*
|
/*
|
||||||
* List objects that are in TSM
|
* List objects that are in TSM
|
||||||
*/
|
*/
|
||||||
int tsm_listfile(dsUint32_t sesshandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
int tsm_listfile(dsUint32_t sesshandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData) {
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
|
|
||||||
rc = tsm_queryfile(sesshandle,qType,tsm_listfile_cb,NULL,qaData,qbData,verbose);
|
rc = tsm_queryfile(sesshandle,qType,tsm_listfile_cb,NULL,qaData,qbData);
|
||||||
|
|
||||||
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;
|
||||||
|
@ -14,11 +14,15 @@
|
|||||||
*
|
*
|
||||||
* The date is passed to this function in the format mmddYYYY
|
* The date is passed to this function in the format mmddYYYY
|
||||||
*/
|
*/
|
||||||
dsmDate dsmStrToDate(char *s,int verbose) {
|
dsmDate dsmStrToDate(char *s) {
|
||||||
|
extern int verbose;
|
||||||
dsmDate *date;
|
dsmDate *date;
|
||||||
dsUint32_t x;
|
dsUint32_t d,t;
|
||||||
|
char *x=NULL, *y=NULL;
|
||||||
|
|
||||||
date = (dsmDate*)malloc(sizeof(dsmDate));
|
date = (dsmDate*)malloc(sizeof(dsmDate));
|
||||||
|
x = (char *)malloc(sizeof(s));
|
||||||
|
y = (char *)malloc(sizeof(s));
|
||||||
|
|
||||||
if (date==NULL) {
|
if (date==NULL) {
|
||||||
perror("Arg, out of memory?");
|
perror("Arg, out of memory?");
|
||||||
@ -30,18 +34,31 @@ dsmDate dsmStrToDate(char *s,int verbose) {
|
|||||||
if (verbose)
|
if (verbose)
|
||||||
printf("dsmStrToDate: Date String: %s\n", s);
|
printf("dsmStrToDate: Date String: %s\n", s);
|
||||||
|
|
||||||
|
|
||||||
/* if user key in some inputs */
|
/* if user key in some inputs */
|
||||||
if (s[0] != '\0') {
|
if (s[0] != '\0') {
|
||||||
x = atol(s);
|
strncpy(x,s,sizeof(strchr(s,':')));
|
||||||
date->month = x / 1000000;
|
|
||||||
|
|
||||||
x %= 1000000;
|
d = atol(x);
|
||||||
date->day = x / 10000;
|
date->month = d / 1000000;
|
||||||
date->year = x % 10000;
|
|
||||||
|
d %= 1000000;
|
||||||
|
date->day = d / 10000;
|
||||||
|
date->year = d % 10000;
|
||||||
|
|
||||||
|
if (strlen(x) != strlen(s)) {
|
||||||
|
y = strchr(s,':')+1;
|
||||||
|
t = atol(y);
|
||||||
|
date->hour = t / 10000;
|
||||||
|
|
||||||
|
t %= 10000;
|
||||||
|
date->minute = t / 100;
|
||||||
|
date->second = t % 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("dsmStrToDate: date = %d, month = %d, year = %d\n", date->day, date->month, date->year);
|
printf("dsmStrToDate: date = %d, month = %d, year = %d, hour = %d, minute = %d, second = %d\n", date->day, date->month, date->year, date->hour, date->minute, date->second);
|
||||||
|
|
||||||
return *date;
|
return *date;
|
||||||
}
|
}
|
||||||
@ -70,7 +87,8 @@ char *dsmDateToStr(dsmDate date) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
dsmObjName dsmNameToObjname(char *fsname, char *filename, int verbose) {
|
dsmObjName dsmNameToObjname(char *fsname, char *filename) {
|
||||||
|
extern int verbose;
|
||||||
dsmObjName *objname;
|
dsmObjName *objname;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -141,3 +159,15 @@ double dsmSizeToNum(dsStruct64_t dsStruct64) {
|
|||||||
// Return number in MB
|
// Return number in MB
|
||||||
return (float)filesize/1024/1024;
|
return (float)filesize/1024/1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debugLog(int level, _IO_FILE *output, char *message, int die) {
|
||||||
|
extern int verbose;
|
||||||
|
|
||||||
|
if (level > verbose)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fprintf(output,"%s\n",message);
|
||||||
|
|
||||||
|
if (die)
|
||||||
|
exit(die);
|
||||||
|
}
|
||||||
|
@ -118,7 +118,8 @@ int tsm_regfs(dsUint32_t dsmHandle, char *fsname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Send data to TSM for storage */
|
/* Send data to TSM for storage */
|
||||||
int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, int verbose) {
|
int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype) {
|
||||||
|
extern int verbose;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
dsmObjName objName;
|
dsmObjName objName;
|
||||||
@ -153,7 +154,7 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(&objName,0x00,sizeof(objName));
|
memset(&objName,0x00,sizeof(objName));
|
||||||
objName = dsmNameToObjname(fsname,filename,verbose);
|
objName = dsmNameToObjname(fsname,filename);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr,"tsm_sendfile: Starting to send stdin as %s\n",dsmObjnameToStr(objName));
|
fprintf(stderr,"tsm_sendfile: Starting to send stdin as %s\n",dsmObjnameToStr(objName));
|
||||||
@ -277,7 +278,8 @@ int tsm_sendfile(dsUint32_t dsmHandle, char *fsname, char *filename, long long l
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get data from TSM for restore */
|
/* Get data from TSM for restore */
|
||||||
int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData) {
|
||||||
|
extern int verbose;
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
struct matchone_cb_data cbdata;
|
struct matchone_cb_data cbdata;
|
||||||
dsmGetList getList;
|
dsmGetList getList;
|
||||||
@ -292,14 +294,14 @@ int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaD
|
|||||||
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(*qaData.objName));
|
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(*qaData.objName));
|
||||||
|
|
||||||
gType = gtArchive;
|
gType = gtArchive;
|
||||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,verbose);
|
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData);
|
||||||
|
|
||||||
} else if (qType == qtBackup) {
|
} else if (qType == qtBackup) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(*qbData.objName));
|
fprintf(stderr,"tsm_restorefile: Starting to receive %s via stdin\n",dsmObjnameToStr(*qbData.objName));
|
||||||
|
|
||||||
gType = gtBackup;
|
gType = gtBackup;
|
||||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,verbose);
|
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,"tsm_restorefile: Internal error: Unknown qType %d\n",qType);
|
fprintf(stderr,"tsm_restorefile: Internal error: Unknown qType %d\n",qType);
|
||||||
@ -375,7 +377,8 @@ int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaD
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Delete data in TSM */
|
/* Delete data in TSM */
|
||||||
int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData) {
|
||||||
|
extern int verbose;
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
dsUint16_t reason=0;
|
dsUint16_t reason=0;
|
||||||
dsmDelInfo *dInfoP;
|
dsmDelInfo *dInfoP;
|
||||||
@ -384,7 +387,7 @@ int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaDa
|
|||||||
|
|
||||||
cbdata.numfound = 0;
|
cbdata.numfound = 0;
|
||||||
|
|
||||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,verbose);
|
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData);
|
||||||
if (rc != DSM_RC_OK) {
|
if (rc != DSM_RC_OK) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ dsUint32_t tsm_initsess(char *options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* List objects that are in TSM */
|
/* List objects that are in TSM */
|
||||||
void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
int tsm_sessioninfo(dsUint32_t dsmHandle) {
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
optStruct dsmOpt;
|
optStruct dsmOpt;
|
||||||
ApiSessInfo dsmSessInfo;
|
ApiSessInfo dsmSessInfo;
|
||||||
@ -269,6 +269,8 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
|||||||
printf(" ARCHIVE retention grace: %u days\n",dsmSessInfo.gpArchRetn);
|
printf(" ARCHIVE retention grace: %u days\n",dsmSessInfo.gpArchRetn);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -279,7 +281,8 @@ void tsm_sessioninfo(dsUint32_t dsmHandle) {
|
|||||||
* 0 if tsm_queryfile() should skip processing the remaining matches.
|
* 0 if tsm_queryfile() should skip processing the remaining matches.
|
||||||
* 1 otherwise.
|
* 1 otherwise.
|
||||||
*/
|
*/
|
||||||
dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData, int verbose) {
|
dsInt16_t tsm_queryfile(dsUint32_t dsmHandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData) {
|
||||||
|
extern int verbose;
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
dsmQueryBuff *qDataP;
|
dsmQueryBuff *qDataP;
|
||||||
|
|
||||||
|
241
tsmpipe.c
241
tsmpipe.c
@ -38,6 +38,8 @@ SOFTWARE.
|
|||||||
#include "dsmapifp.h"
|
#include "dsmapifp.h"
|
||||||
#include "tsmpipe.h"
|
#include "tsmpipe.h"
|
||||||
|
|
||||||
|
int verbose=0;
|
||||||
|
|
||||||
int copy_env(const char *from, const char *to) {
|
int copy_env(const char *from, const char *to) {
|
||||||
char *e;
|
char *e;
|
||||||
char n[PATH_MAX+1];
|
char n[PATH_MAX+1];
|
||||||
@ -79,7 +81,11 @@ 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) (BACKUP Objects)\n"
|
" -P pitdate PITDate (mmddYYYY[:HHMMSS]) (BACKUP Objects)\n"
|
||||||
|
" -n insdate Insert Date lower bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n"
|
||||||
|
" -N insdate Insert Date upper bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n"
|
||||||
|
" -e expdate Expire Date lower bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\n"
|
||||||
|
" -E expdate Expire Date upper bound (mmddYYYY[:HHMMSS]) (ARCHIVE Objects)\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"
|
||||||
,_TSMPIPE_VERSION);
|
,_TSMPIPE_VERSION);
|
||||||
@ -87,34 +93,51 @@ void usage(void) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usage_action(void) {
|
||||||
|
fprintf(stderr, "tsmpipe: ERROR: Must give one of -i, -c, -x, -d, -t\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int c;
|
int c;
|
||||||
extern int optopt;
|
extern int optopt;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
char archive=0, backup=0, create=0, xtract=0, delete=0, info=0, list=0;
|
int action=0;
|
||||||
int verbose=0;
|
char *space=NULL, *filename=NULL, *lenstr=NULL, *desc=NULL, *pitdate=NULL, *options=NULL, *expdate_low=NULL, *expdate_high=NULL, *insdate_low=NULL, *insdate_high=NULL;
|
||||||
char *space=NULL, *filename=NULL, *lenstr=NULL, *desc=NULL, *pitdate=NULL, *options=NULL;
|
|
||||||
off_t length;
|
off_t length;
|
||||||
dsUint32_t dsmHandle;
|
dsUint32_t dsmHandle;
|
||||||
dsmQueryType qType;
|
dsmQueryType qType=0xff; // We set this to an unlikely value, it should be set correctly via our getopt
|
||||||
|
qryArchiveData qaData;
|
||||||
|
qryBackupData qbData;
|
||||||
|
dsmObjName objName;
|
||||||
|
int rc=0;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "hiABcxdtvs:f:l:D:O:P:")) != -1) {
|
while ((c = getopt(argc, argv, "hiABcxdtve:E:f:l:n:N:s:D:O:P:")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'h': usage(); break;
|
case 'h': usage(); break;
|
||||||
case 'i': info = 1; break;
|
case 'A': qType = qtArchive; break;
|
||||||
case 'A': archive = 1; break;
|
case 'B': qType = qtBackup; break;
|
||||||
case 'B': backup = 1; break;
|
|
||||||
case 'c': create = 1; break;
|
case 'i': if (action != 0) usage_action(); action = ACTION_INFO; break;
|
||||||
case 'x': xtract = 1; break;
|
case 'c': if (action != 0) usage_action(); action = ACTION_CREATE; break;
|
||||||
case 'd': delete = 1; break;
|
case 'x': if (action != 0) usage_action(); action = ACTION_EXTRACT; break;
|
||||||
case 't': list = 1; break;
|
case 'd': if (action != 0) usage_action(); action = ACTION_DELETE; break;
|
||||||
|
case 't': if (action != 0) usage_action(); action = ACTION_LIST; break;
|
||||||
|
|
||||||
case 'v': verbose++; break;
|
case 'v': verbose++; break;
|
||||||
case 's': space = optarg; break;
|
case 's': space = optarg; break;
|
||||||
case 'f': filename = optarg; break;
|
case 'f': filename = optarg; break;
|
||||||
case 'l': lenstr = optarg; break;
|
case 'l': lenstr = optarg; break;
|
||||||
case 'D': desc = optarg; break;
|
case 'D': desc = optarg; break;
|
||||||
|
|
||||||
case 'O': options = optarg; break;
|
case 'O': options = optarg; break;
|
||||||
|
|
||||||
case 'P': pitdate = optarg; break;
|
case 'P': pitdate = optarg; break;
|
||||||
|
case 'e': expdate_low = optarg; break;
|
||||||
|
case 'E': expdate_high = optarg; break;
|
||||||
|
case 'n': insdate_low = optarg; break;
|
||||||
|
case 'N': insdate_high = optarg; break;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
fprintf(stderr, "tsmpipe: Option -%c requires an operand\n", optopt);
|
fprintf(stderr, "tsmpipe: Option -%c requires an operand\n", optopt);
|
||||||
@ -125,23 +148,23 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (archive+backup+info != 1) {
|
// Arguement Validation
|
||||||
fprintf(stderr, "tsmpipe: ERROR: Must give one of -i, -A or -B\n");
|
if (action == 0) {
|
||||||
|
fprintf(stderr, "tsmpipe: ERROR: Must give one of -i, -c, -x, -d, -t\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo To change.
|
if (pitdate && qType != qtBackup) {
|
||||||
if (pitdate && ! backup) {
|
fprintf(stderr, "tsmpipe: ERROR: -P can only be used with -B\n");
|
||||||
fprintf(stderr, "tsmpipe: ERROR: -P can only be used with -A\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! info) {
|
if ((insdate_low|| insdate_high || expdate_low || expdate_high) && qType != qtArchive) {
|
||||||
if (create+xtract+delete+list != 1) {
|
fprintf(stderr, "tsmpipe: ERROR: -e, -E, -n, -N can only be used with -A\n");
|
||||||
fprintf(stderr, "tsmpipe: ERROR: Must give one of -c, -x, -d or -t\n");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action != ACTION_INFO) {
|
||||||
if (! space) {
|
if (! space) {
|
||||||
fprintf(stderr, "tsmpipe: ERROR: Must give -s filespacename\n");
|
fprintf(stderr, "tsmpipe: ERROR: Must give -s filespacename\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -152,163 +175,145 @@ int main(int argc, char *argv[]) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(create && ! lenstr) {
|
if (action == ACTION_CREATE && ! lenstr) {
|
||||||
fprintf(stderr, "tsmpipe: ERROR: Must give -l length with -c\n");
|
fprintf(stderr, "tsmpipe: ERROR: Must give -l length with -c\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! create && lenstr) {
|
if (action != ACTION_CREATE && lenstr) {
|
||||||
fprintf(stderr, "tsmpipe: ERROR: -l length useless without -c\n");
|
fprintf(stderr, "tsmpipe: ERROR: -l length useless without -c\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! archive && desc) {
|
if (desc && qType != qtArchive) {
|
||||||
fprintf(stderr, "tsmpipe: ERROR: -D desc useless without -A\n");
|
fprintf(stderr, "tsmpipe: ERROR: -D desc useless without -A\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qType = backup ? qtBackup : qtArchive;
|
|
||||||
|
|
||||||
/* Let the TSM api get the signals */
|
/* Let the TSM api get the signals */
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
signal(SIGUSR1, SIG_IGN);
|
signal(SIGUSR1, SIG_IGN);
|
||||||
|
|
||||||
if (getenv("DSM_DIR") && ((! copy_env("DSM_DIR", "DSMI_DIR")) || (! copy_env("DSM_CONFIG", "DSMI_CONFIG")))) {
|
if (getenv("DSM_DIR") && ((! copy_env("DSM_DIR", "DSMI_DIR")) || (! copy_env("DSM_CONFIG", "DSMI_CONFIG"))))
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
|
|
||||||
// OK, we are ready to talk to TSM
|
// OK, we are ready to talk to TSM
|
||||||
if (verbose > 0)
|
debugLog(1,stderr,"tsmpipe: Create TSM session",0);
|
||||||
fprintf(stderr,"tsmpipe: Create TSM session\n");
|
|
||||||
dsmHandle = tsm_initsess(options);
|
dsmHandle = tsm_initsess(options);
|
||||||
if (! dsmHandle) {
|
if (! dsmHandle)
|
||||||
fprintf(stderr,"tsmpipe: Unable to create TSM session?\n");
|
debugLog(0,stderr,"tsmpipe: Unable to create TSM session?",2);
|
||||||
|
|
||||||
exit(2);
|
debugLog(2,stderr,"tsmpipe: Session Initiated",0);
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose > 1)
|
|
||||||
fprintf(stderr, "tsmpipe: Session initiated\n");
|
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
// Show our session information
|
// Show our session information
|
||||||
if (info) {
|
case ACTION_INFO:
|
||||||
if (verbose > 0)
|
debugLog(2,stderr,"tsmpipe: INFO Operation",0);
|
||||||
fprintf(stderr,"tsmpipe: INFO operation\n");
|
|
||||||
|
|
||||||
tsm_sessioninfo(dsmHandle);
|
rc = tsm_sessioninfo(dsmHandle);
|
||||||
}
|
break;
|
||||||
|
|
||||||
// If we are backing up
|
// If we are backing up or archiving
|
||||||
if (create) {
|
case ACTION_CREATE:
|
||||||
if (verbose > 0)
|
debugLog(2,stderr,"tsmpipe: CREATE Operation",0);
|
||||||
fprintf(stderr,"tsmpipe: BACKUP operation\n");
|
|
||||||
|
|
||||||
length = atof(lenstr);
|
length = atof(lenstr);
|
||||||
if (length <= 0) {
|
if (length <= 0)
|
||||||
fprintf(stderr,"tsmpipe: ERROR: Provide positive length, overestimate if guessing\n");
|
debugLog(0,stderr,"tsmpipe: ERROR: Provide positive length, overestimate if guessing",1);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! tsm_sendfile(dsmHandle,space,filename,length,desc,(archive ? stArchiveMountWait : stBackupMountWait),verbose)){
|
rc = tsm_sendfile(dsmHandle,space,filename,length,desc,((qType == qtArchive) ? stArchiveMountWait : stBackupMountWait));
|
||||||
dsmTerminate(dsmHandle);
|
break;
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! info && ! create) {
|
case ACTION_DELETE:
|
||||||
qryArchiveData qaData;
|
case ACTION_LIST:
|
||||||
qryBackupData qbData;
|
case ACTION_EXTRACT:
|
||||||
dsmObjName objName;
|
|
||||||
memset(&qaData,0x00,sizeof(qryArchiveData));
|
memset(&qaData,0x00,sizeof(qryArchiveData));
|
||||||
memset(&qbData,0x00,sizeof(qryBackupData));
|
memset(&qbData,0x00,sizeof(qryBackupData));
|
||||||
objName = dsmNameToObjname(space,filename,verbose);
|
objName = dsmNameToObjname(space,filename);
|
||||||
|
|
||||||
// Setup our Query Object
|
// Setup our Query Object
|
||||||
if (backup) {
|
switch (qType) {
|
||||||
|
case qtBackup:
|
||||||
qbData.stVersion = qryBackupDataVersion;
|
qbData.stVersion = qryBackupDataVersion;
|
||||||
qbData.objName = &objName;
|
qbData.objName = &objName;
|
||||||
qbData.owner = "";
|
qbData.owner = "";
|
||||||
qbData.objState = delete ? DSM_ACTIVE : DSM_ANY_MATCH;
|
qbData.objState = (action == ACTION_DELETE) ? DSM_ACTIVE : DSM_ANY_MATCH;
|
||||||
|
|
||||||
if (delete || ! pitdate) {
|
if (action == ACTION_DELETE || ! pitdate) {
|
||||||
qbData.pitDate.year = DATE_MINUS_INFINITE;
|
qbData.pitDate.year = DATE_MINUS_INFINITE;
|
||||||
} else {
|
} else {
|
||||||
// @todo Need to include time
|
qbData.pitDate = dsmStrToDate(pitdate);
|
||||||
qbData.pitDate = dsmStrToDate(pitdate,verbose);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must be archive then
|
break;
|
||||||
} else {
|
|
||||||
if (archive) {
|
case qtArchive:
|
||||||
qaData.stVersion = qryArchiveDataVersion;
|
qaData.stVersion = qryArchiveDataVersion;
|
||||||
qaData.objName = &objName;
|
qaData.objName = &objName;
|
||||||
qaData.owner = "";
|
qaData.owner = "";
|
||||||
|
qaData.descr = desc ? desc : "*";
|
||||||
|
|
||||||
if (pitdate) {
|
|
||||||
fprintf(stderr,"tsmpipe: Archive Date Range Query not yet setup\n");
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
qaData.insDateLowerBound.year = DATE_MINUS_INFINITE;
|
qaData.insDateLowerBound.year = DATE_MINUS_INFINITE;
|
||||||
qaData.insDateUpperBound.year = DATE_PLUS_INFINITE;
|
qaData.insDateUpperBound.year = DATE_PLUS_INFINITE;
|
||||||
qaData.expDateLowerBound.year = DATE_MINUS_INFINITE;
|
qaData.expDateLowerBound.year = DATE_MINUS_INFINITE;
|
||||||
qaData.expDateUpperBound.year = DATE_PLUS_INFINITE;
|
qaData.expDateUpperBound.year = DATE_PLUS_INFINITE;
|
||||||
|
|
||||||
|
if (insdate_low)
|
||||||
|
qaData.insDateLowerBound = dsmStrToDate(insdate_low);
|
||||||
|
|
||||||
|
if (insdate_high)
|
||||||
|
qaData.insDateUpperBound = dsmStrToDate(insdate_high);
|
||||||
|
|
||||||
|
if (expdate_low)
|
||||||
|
qaData.expDateLowerBound = dsmStrToDate(expdate_low);
|
||||||
|
|
||||||
|
if (expdate_high)
|
||||||
|
qaData.expDateUpperBound = dsmStrToDate(expdate_high);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr,"tsmpipe: UNKNOWN Type %d",qType);
|
||||||
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
qaData.descr = desc ? desc : "*";
|
switch (action) {
|
||||||
|
case ACTION_DELETE:
|
||||||
|
debugLog(2,stderr,"tsmpipe: DELETE Operation",0);
|
||||||
|
rc = tsm_deletefile(dsmHandle,qType,qaData,qbData);
|
||||||
|
break;
|
||||||
|
|
||||||
} else {
|
case ACTION_EXTRACT:
|
||||||
fprintf(stderr,"tsmpipe: ERROR: How can we not be a backup or archive?\n");
|
debugLog(2,stderr,"tsmpipe: EXTRACT Operation",0);
|
||||||
exit(1);
|
rc = tsm_restorefile(dsmHandle,qType,qaData,qbData);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTION_LIST:
|
||||||
|
debugLog(2,stderr,"tsmpipe: LIST Operation",0);
|
||||||
|
rc = tsm_listfile(dsmHandle,qType,qaData,qbData);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr,"tsmpipe: Action not yet programmed for%d",action);
|
||||||
|
exit(2);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr,"tsmpipe: UNKNOWN Operation %d",action);
|
||||||
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete an object from TSM
|
debugLog(1,stderr,"tsmpipe: Terminate TSM session",0);
|
||||||
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);
|
dsmTerminate(dsmHandle);
|
||||||
|
|
||||||
if (verbose > 0)
|
if (! rc)
|
||||||
fprintf(stderr, "tsmpipe: Success\n");
|
debugLog(0,stderr,"tsmpipe: Operation Failed",3);
|
||||||
|
else
|
||||||
|
debugLog(1,stderr,"tsmpipe: Operation Success",0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
23
tsmpipe.h
23
tsmpipe.h
@ -1,22 +1,29 @@
|
|||||||
#define _TSMPIPE_VERSION "1.5.1"
|
#define _TSMPIPE_VERSION "1.5.1"
|
||||||
|
|
||||||
|
#define ACTION_INFO 1
|
||||||
|
#define ACTION_CREATE 2
|
||||||
|
#define ACTION_EXTRACT 3
|
||||||
|
#define ACTION_DELETE 4
|
||||||
|
#define ACTION_LIST 5
|
||||||
|
|
||||||
typedef int (*tsm_query_callback)(dsmQueryType, DataBlk *, void *);
|
typedef int (*tsm_query_callback)(dsmQueryType, DataBlk *, void *);
|
||||||
|
|
||||||
struct matchone_cb_data { int numfound; dsStruct64_t objId; dsUint32_t copyGroup; };
|
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_printerr (dsUint32_t dsmHandle, dsInt16_t rc, char *str);
|
||||||
extern void tsm_sessioninfo(dsUint32_t dsmHandle);
|
extern void debugLog(int level, _IO_FILE *output, char *message, int die);
|
||||||
|
|
||||||
extern dsmDate dsmStrToDate(char *s,int verbose);
|
extern dsmDate dsmStrToDate(char *s);
|
||||||
extern dsmObjName dsmNameToObjname(char *fsname, char *filename, int verbose);
|
extern dsmObjName dsmNameToObjname(char *fsname, char *filename);
|
||||||
extern dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
extern dsInt16_t tsm_queryfile(dsUint32_t sesshandle, dsmQueryType qType, tsm_query_callback usercb, void *userdata, qryArchiveData qaData, qryBackupData qbData);
|
||||||
extern dsUint32_t tsm_initsess(char *options);
|
extern dsUint32_t tsm_initsess(char *options);
|
||||||
extern dsBool_t compressEnabled;
|
extern dsBool_t compressEnabled;
|
||||||
|
|
||||||
extern int tsm_deletefile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
extern int tsm_deletefile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData);
|
||||||
extern int tsm_listfile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
extern int tsm_listfile (dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData);
|
||||||
extern int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData, int verbose);
|
extern int tsm_restorefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaData, qryBackupData qbData);
|
||||||
extern int tsm_sendfile (dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype, int verbose);
|
extern int tsm_sendfile (dsUint32_t dsmHandle, char *fsname, char *filename, long long length, char *description, dsmSendType sendtype);
|
||||||
|
extern int tsm_sessioninfo(dsUint32_t dsmHandle);
|
||||||
|
|
||||||
extern char *dsmDateToStr(dsmDate date);
|
extern char *dsmDateToStr(dsmDate date);
|
||||||
extern char *dsmObjnameToStr(dsmObjName objName);
|
extern char *dsmObjnameToStr(dsmObjName objName);
|
||||||
|
Reference in New Issue
Block a user