Fixed #1; Added purge option
This commit is contained in:
parent
58d95525ca
commit
fca8930837
@ -439,14 +439,15 @@ int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaDa
|
|||||||
extern int verbose;
|
extern int verbose;
|
||||||
dsInt16_t rc=0;
|
dsInt16_t rc=0;
|
||||||
dsUint16_t reason=0;
|
dsUint16_t reason=0;
|
||||||
dsmDelInfo *dInfoP;
|
|
||||||
dsmDelType dType;
|
dsmDelType dType;
|
||||||
|
dsmDelInfo delInfo;
|
||||||
struct matchone_cb_data cbdata;
|
struct matchone_cb_data cbdata;
|
||||||
dsmBool_t friendly=bFalse;
|
dsmBool_t friendly=bFalse;
|
||||||
|
|
||||||
cbdata.numfound = 0;
|
cbdata.numfound = 0;
|
||||||
|
|
||||||
rc = tsm_queryfile(dsmHandle,qType,tsm_matchone_cb,&cbdata,qaData,qbData,friendly);
|
/** Our purge function uses qtReserved8 - this will break in a future release of the API **/
|
||||||
|
rc = tsm_queryfile(dsmHandle,((qType == qtBackup || qType == qtReserved8) ? qtBackup : qtArchive),tsm_matchone_cb,&cbdata,qaData,qbData,friendly);
|
||||||
if (rc != DSM_RC_OK) {
|
if (rc != DSM_RC_OK) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -462,24 +463,35 @@ int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaDa
|
|||||||
|
|
||||||
dType = dtArchive;
|
dType = dtArchive;
|
||||||
|
|
||||||
delArch daInfo;
|
delInfo.archInfo.stVersion = delArchVersion;
|
||||||
daInfo.stVersion = delArchVersion;
|
delInfo.archInfo.objId = cbdata.objId;
|
||||||
daInfo.objId = cbdata.objId;
|
|
||||||
|
|
||||||
dInfoP = (dsmDelInfo *) &daInfo;
|
|
||||||
|
|
||||||
} else if (qType == qtBackup) {
|
} else if (qType == qtBackup) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr,"%s: Deleting backup file %s\n",__func__,dsmObjnameToStr(*qbData.objName));
|
fprintf(stderr,"%s: Deleting backup file %s with id [%u-%u]\n",__func__,dsmObjnameToStr(*qbData.objName),cbdata.objId.hi,cbdata.objId.lo);
|
||||||
|
|
||||||
dType = dtBackup;
|
dType = dtBackup;
|
||||||
|
|
||||||
delBack dbInfo;
|
dsmObjName objName;
|
||||||
dbInfo.stVersion = delBackVersion;
|
memset(&objName,0x00,sizeof(objName));
|
||||||
dbInfo.objNameP = qbData.objName;
|
strcpy(objName.fs,qbData.objName->fs);
|
||||||
dbInfo.copyGroup = cbdata.copyGroup;
|
strcpy(objName.hl,qbData.objName->hl);
|
||||||
|
strcpy(objName.ll,qbData.objName->ll);
|
||||||
|
objName.objType = DSM_OBJ_FILE;
|
||||||
|
|
||||||
dInfoP = (dsmDelInfo *) &dbInfo;
|
delInfo.backInfo.stVersion = delBackVersion;
|
||||||
|
delInfo.backInfo.objNameP = &objName;
|
||||||
|
delInfo.backInfo.copyGroup = cbdata.copyGroup;
|
||||||
|
|
||||||
|
/** Our purge function uses qtReserved8 - this will break in a future release of the API **/
|
||||||
|
} else if (qType == qtReserved8) {
|
||||||
|
if (verbose)
|
||||||
|
fprintf(stderr,"%s: Purging backup file %s with id [%u-%u]\n",__func__,dsmObjnameToStr(*qbData.objName),cbdata.objId.hi,cbdata.objId.lo);
|
||||||
|
|
||||||
|
dType = dtBackupID;
|
||||||
|
|
||||||
|
delInfo.backIDInfo.stVersion = delBackIDVersion;
|
||||||
|
delInfo.backIDInfo.objId = cbdata.objId;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,"%s: UNKNOWN Type %d\n",__func__,qType);
|
fprintf(stderr,"%s: UNKNOWN Type %d\n",__func__,qType);
|
||||||
@ -492,7 +504,7 @@ int tsm_deletefile(dsUint32_t dsmHandle, dsmQueryType qType, qryArchiveData qaDa
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = dsmDeleteObj(dsmHandle,dType,*dInfoP);
|
rc = dsmDeleteObj(dsmHandle,dType,delInfo);
|
||||||
if (rc != DSM_RC_OK) {
|
if (rc != DSM_RC_OK) {
|
||||||
printf("%s: dsmDeleteObj() failed %s\n",__func__,tsm_printerr(dsmHandle,rc));
|
printf("%s: dsmDeleteObj() failed %s\n",__func__,tsm_printerr(dsmHandle,rc));
|
||||||
return 0;
|
return 0;
|
||||||
|
77
test/test.sh
77
test/test.sh
@ -1,43 +1,94 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
cd $(dirname $0)
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
FILE=random.1m
|
FILE=random.1m
|
||||||
|
VERBOSE=${VERBOSE:-""}
|
||||||
|
|
||||||
# Create TEST File
|
# Create TEST File
|
||||||
MD5=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null |tee ${FILE} |md5sum |awk '{print $1}')
|
MD5=$(dd if=/dev/urandom bs=10240 count=1024 2>/dev/null |tee ${FILE} |md5sum |awk '{print $1}')
|
||||||
SIZE=$(ls -l ${FILE}|awk '{print $5}')
|
SIZE=$(ls -l ${FILE}|awk '{print $5}')
|
||||||
|
TSMOPT="-VIRTUALNODENAME=TEST -PASSWORD=TEST -COMPRESSALWAYS=YES"
|
||||||
|
|
||||||
TSMPIPE=../tsmpipe
|
TSMPIPE=../tsmpipe
|
||||||
|
|
||||||
echo "MD5 of [${FILE}] is [${MD5}] (${SIZE})"
|
echo "MD5 of [${FILE}] is [${MD5}] (${SIZE})"
|
||||||
|
|
||||||
ln -s /opt/tivoli/tsm/client/api/bin64/EN_US
|
ln -fs /opt/tivoli/tsm/client/api/bin64/EN_US
|
||||||
export DSMI_DIR=./
|
export DSMI_DIR=./
|
||||||
export DSMI_CONFIG=dsm.opt
|
export DSMI_CONFIG=dsm.opt
|
||||||
|
|
||||||
# Send file to TSM
|
# Send file to TSM
|
||||||
echo "+ TEST SEND FILE!"
|
echo "+++ TEST BACKUP ++++!"
|
||||||
cat ${FILE} | ${TSMPIPE} -Bcm MD5 -s /test -f ${FILE} -vvv -l ${SIZE} -O"-VIRTUALNODENAME=TEST -PASSWORD=TEST"
|
echo "+ BACKUP: SEND FILE!"
|
||||||
|
cat ${FILE} | ${TSMPIPE} -Bcm MD5 -s /test -f ${FILE} ${VERBOSE} -l ${SIZE} -O"${TSMOPT}"
|
||||||
|
|
||||||
# Send a second time
|
# Send a second time
|
||||||
echo "+ TEST SEND FILE AGAIN!"
|
echo "+ BACKUP: SEND FILE AGAIN!"
|
||||||
cat ${FILE} | ${TSMPIPE} -Bcm MD5 -s /test -f ${FILE} -vvv -l ${SIZE} -O"-VIRTUALNODENAME=TEST -PASSWORD=TEST"
|
cat ${FILE} | ${TSMPIPE} -Bcm MD5 -s /test -f ${FILE} ${VERBOSE} -l ${SIZE} -O"${TSMOPT}"
|
||||||
|
|
||||||
# List it
|
# List it
|
||||||
echo "+ TEST LIST FILE!"
|
echo "+ BACKUP: LIST FILE!"
|
||||||
${TSMPIPE} -Bts /test -f ${FILE} -vvv -O"-VIRTUALNODENAME=TEST -PASSWORD=TEST"
|
${TSMPIPE} -Bts /test -f ${FILE} -O"${TSMOPT}"
|
||||||
|
|
||||||
# Get it back
|
# Get it back
|
||||||
echo "+ TEST RETRIEVE FILE!"
|
echo "+ BACKUP: RETRIEVE FILE!"
|
||||||
${TSMPIPE} -Bxs /test -f ${FILE} -vvv -O"-VIRTUALNODENAME=TEST -PASSWORD=TEST" > ${FILE}.back
|
${TSMPIPE} -Bxs /test -f ${FILE} ${VERBOSE} -O"${TSMOPT}" > ${FILE}.back
|
||||||
RETRIEVE=$(md5sum ${FILE}.back | awk '{print $1}')
|
RETRIEVE=$(md5sum ${FILE}.back | awk '{print $1}')
|
||||||
if [ "${MD5}" != "${RETRIEVE}" ]; then
|
if [ "${MD5}" != "${RETRIEVE}" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "+ RETRIEVE VALID (${RETRIEVE})!"
|
echo "+ BACKUP: RETRIEVE VALID (${RETRIEVE})!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Purge the last one
|
||||||
|
echo "+ BACKUP: PURGE!"
|
||||||
|
${TSMPIPE} -Bgs /test -f ${FILE} ${VERBOSE} -O"${TSMOPT}"
|
||||||
|
|
||||||
|
# List it
|
||||||
|
echo "+ BACKUP: LIST FILE IS PURGED!"
|
||||||
|
${TSMPIPE} -Bts /test -f ${FILE} -O"${TSMOPT}"
|
||||||
|
|
||||||
# Delete it
|
# Delete it
|
||||||
echo "+ TEST DELETE!"
|
echo "+ BACKUP: DELETE!"
|
||||||
${TSMPIPE} -Bds /test -f ${FILE} -vvv -O"-VIRTUALNODENAME=TEST -PASSWORD=TEST"
|
${TSMPIPE} -Bds /test -f ${FILE} ${VERBOSE} -O"${TSMOPT}"
|
||||||
|
|
||||||
|
# List it
|
||||||
|
echo "+ BACKUP: LIST FILE IS DELETED!"
|
||||||
|
${TSMPIPE} -Bts /test -f ${FILE} -O"${TSMOPT}"
|
||||||
|
echo "+++ END BACKUP ++++!"
|
||||||
|
|
||||||
|
echo "+++ TEST ARCHIVE ++++!"
|
||||||
|
echo "+ ARCHIVE: SEND FILE!"
|
||||||
|
cat ${FILE} | ${TSMPIPE} -Acm MD5 -s /test -f ${FILE} ${VERBOSE} -l ${SIZE} -D"Test Archive File" -O"${TSMOPT}"
|
||||||
|
|
||||||
|
# Send a second time
|
||||||
|
echo "+ ARCHIVE: SEND FILE AGAIN! (delay)"
|
||||||
|
sleep 2
|
||||||
|
cat ${FILE} | ${TSMPIPE} -Acm MD5 -s /test -f ${FILE} ${VERBOSE} -l ${SIZE} -D"Test Archive File" -O"${TSMOPT}"
|
||||||
|
DATE=$(date +%m%d%Y:%H%M%S)
|
||||||
|
|
||||||
|
# List it
|
||||||
|
echo "+ ARCIHVE: LIST FILE!"
|
||||||
|
${TSMPIPE} -Ats /test -f ${FILE} -O"${TSMOPT}"
|
||||||
|
|
||||||
|
# Get it back
|
||||||
|
echo "+ ARCIHVE: RETRIEVE FILE! (${DATE})"
|
||||||
|
${TSMPIPE} -Axs /test -f ${FILE} -n ${DATE} ${VERBOSE} -O"${TSMOPT}" > ${FILE}.back
|
||||||
|
RETRIEVE=$(md5sum ${FILE}.back | awk '{print $1}')
|
||||||
|
if [ "${MD5}" != "${RETRIEVE}" ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "+ ARCHIVE: RETRIEVE VALID (${RETRIEVE})!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Purge the last one
|
||||||
|
echo "+ ARCHIVE: DELETE!"
|
||||||
|
${TSMPIPE} -Ads /test -f ${FILE} -n ${DATE} ${VERBOSE} -O"${TSMOPT}"
|
||||||
|
|
||||||
|
# List it
|
||||||
|
echo "+ ARCHIVE: LIST FILE AFTER DELETE!"
|
||||||
|
${TSMPIPE} -Ats /test -f ${FILE} -O"${TSMOPT}"
|
||||||
|
echo "+++ END ARCHIVE ++++!"
|
||||||
|
|
||||||
rm -f EN_US ${FILE} ${FILE}.back
|
rm -f EN_US ${FILE} ${FILE}.back
|
||||||
|
20
tsmpipe.c
20
tsmpipe.c
@ -69,7 +69,7 @@ void usage(void) {
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"tsmpipe %s, usage:\n"
|
"tsmpipe %s, usage:\n"
|
||||||
"\n"
|
"\n"
|
||||||
"tsmpipe [-i|-p]|[[-A|-B|-U] [-c|-x|-d|-t] -s fsname -f filepath [-l len] ...]\n"
|
"tsmpipe [-i|-p]|[[-A|-B|-U] [-c|-x|-d|-g|-t] -s fsname -f filepath [-l len] ...]\n"
|
||||||
" -i Show session information\n"
|
" -i Show session information\n"
|
||||||
" -p Set Password\n"
|
" -p Set Password\n"
|
||||||
" -A, -B and -U are mutually exclusive:\n"
|
" -A, -B and -U are mutually exclusive:\n"
|
||||||
@ -80,6 +80,7 @@ void usage(void) {
|
|||||||
" -c Create: Read from stdin and store in TSM\n"
|
" -c Create: Read from stdin and store in TSM\n"
|
||||||
" -x eXtract: Recall from TSM and write to stdout\n"
|
" -x eXtract: Recall from TSM and write to stdout\n"
|
||||||
" -d Delete: Delete object from TSM\n"
|
" -d Delete: Delete object from TSM\n"
|
||||||
|
" -g purGe: Active Delete object from TSM\n"
|
||||||
" -t lisT: Print filelist to stdout\n"
|
" -t lisT: Print filelist to stdout\n"
|
||||||
" -s and -f are required arguments for (-A/ -B operations):\n"
|
" -s and -f are required arguments for (-A/ -B operations):\n"
|
||||||
" -s fsname Name of filespace in TSM\n"
|
" -s fsname Name of filespace in TSM\n"
|
||||||
@ -130,7 +131,7 @@ int main(int argc, char *argv[]) {
|
|||||||
char *digest=NULL;
|
char *digest=NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "hiABcxdtUvVe:E:f:Fl:L:m:n:N:s:D:O:pP:")) != -1) {
|
while ((c = getopt(argc, argv, "hiABcxdtUvVe:E:f:Fgl:L:m:n:N:s:D:O:pP:")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'h': usage(); break;
|
case 'h': usage(); break;
|
||||||
case 'A': qType = qtArchive; break;
|
case 'A': qType = qtArchive; break;
|
||||||
@ -141,6 +142,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case 'c': if (action != 0) usage_action(); action = ACTION_CREATE; break;
|
case 'c': if (action != 0) usage_action(); action = ACTION_CREATE; break;
|
||||||
case 'x': if (action != 0) usage_action(); action = ACTION_EXTRACT; break;
|
case 'x': if (action != 0) usage_action(); action = ACTION_EXTRACT; break;
|
||||||
case 'd': if (action != 0) usage_action(); action = ACTION_DELETE; break;
|
case 'd': if (action != 0) usage_action(); action = ACTION_DELETE; break;
|
||||||
|
case 'g': if (action != 0) usage_action(); action = ACTION_PURGE; break;
|
||||||
case 't': if (action != 0) usage_action(); action = ACTION_LIST; break;
|
case 't': if (action != 0) usage_action(); action = ACTION_LIST; break;
|
||||||
case 'U': if (action != 0) usage_action(); action = ACTION_UPDATE; break;
|
case 'U': if (action != 0) usage_action(); action = ACTION_UPDATE; break;
|
||||||
|
|
||||||
@ -223,6 +225,10 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action == ACTION_PURGE && qType != qtBackup) {
|
||||||
|
debugLog(0,__func__,"ERROR: -g can only be used with -B",1);
|
||||||
|
}
|
||||||
|
|
||||||
/* 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);
|
||||||
@ -272,6 +278,7 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_DELETE:
|
case ACTION_DELETE:
|
||||||
|
case ACTION_PURGE:
|
||||||
case ACTION_LIST:
|
case ACTION_LIST:
|
||||||
case ACTION_EXTRACT:
|
case ACTION_EXTRACT:
|
||||||
memset(&qaData,0x00,sizeof(qryArchiveData));
|
memset(&qaData,0x00,sizeof(qryArchiveData));
|
||||||
@ -286,6 +293,7 @@ int main(int argc, char *argv[]) {
|
|||||||
qbData.owner = "";
|
qbData.owner = "";
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case ACTION_PURGE:
|
||||||
case ACTION_DELETE:
|
case ACTION_DELETE:
|
||||||
qbData.objState = DSM_ACTIVE;
|
qbData.objState = DSM_ACTIVE;
|
||||||
break;
|
break;
|
||||||
@ -299,7 +307,7 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_DELETE || ! pitdate) {
|
if (action == ACTION_DELETE || action == ACTION_PURGE || ! pitdate) {
|
||||||
qbData.pitDate.year = DATE_MINUS_INFINITE;
|
qbData.pitDate.year = DATE_MINUS_INFINITE;
|
||||||
} else {
|
} else {
|
||||||
qbData.pitDate = dsmStrToDate(pitdate);
|
qbData.pitDate = dsmStrToDate(pitdate);
|
||||||
@ -342,6 +350,12 @@ int main(int argc, char *argv[]) {
|
|||||||
rc = tsm_deletefile(dsmHandle,qType,qaData,qbData);
|
rc = tsm_deletefile(dsmHandle,qType,qaData,qbData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ACTION_PURGE:
|
||||||
|
debugLog(2,__func__,"PURGE Operation",0);
|
||||||
|
/** We use qtReserved8 to let tsm_deletefile() know that we want to purge - this will break a future API **/
|
||||||
|
rc = tsm_deletefile(dsmHandle,qtReserved8,qaData,qbData);
|
||||||
|
break;
|
||||||
|
|
||||||
case ACTION_EXTRACT:
|
case ACTION_EXTRACT:
|
||||||
debugLog(2,__func__,"EXTRACT Operation",0);
|
debugLog(2,__func__,"EXTRACT Operation",0);
|
||||||
rc = tsm_restorefile(dsmHandle,qType,qaData,qbData);
|
rc = tsm_restorefile(dsmHandle,qType,qaData,qbData);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#define _TSMPIPE_VERSION "1.6.5"
|
#define _TSMPIPE_VERSION "1.6.6"
|
||||||
#define INPUTLEN 1025
|
#define INPUTLEN 1025
|
||||||
|
|
||||||
#define ACTION_INFO 1
|
#define ACTION_INFO 1
|
||||||
@ -9,6 +9,7 @@
|
|||||||
#define ACTION_UPDATE 6
|
#define ACTION_UPDATE 6
|
||||||
#define ACTION_CREATE_UPDATE 7
|
#define ACTION_CREATE_UPDATE 7
|
||||||
#define ACTION_PASSWORD 8
|
#define ACTION_PASSWORD 8
|
||||||
|
#define ACTION_PURGE 9
|
||||||
#define DSM_COMM_TCPIP6 6 // There is no DSM_COMM_ const for TCPIPv6
|
#define DSM_COMM_TCPIP6 6 // There is no DSM_COMM_ const for TCPIPv6
|
||||||
|
|
||||||
// If you want to use MD5/SHA1 calculations as the data goes in here, ensure this is defined.
|
// If you want to use MD5/SHA1 calculations as the data goes in here, ensure this is defined.
|
||||||
|
Reference in New Issue
Block a user