Delete example
This delete example is very simple. It assumes that the copyId has been populated from a previous query or from information stored by the XBSA application. It then deletes one object and commits the transaction that does the delete of the object. In another transaction, an entire image is deleted.
BSA_Handle BsaHandle;
BSA_ObjectOwner BsaObjectOwner;
BSA_SecurityToken *security_tokenPtr;
BSA_ObjectDescriptor *object_desc;
BSA_ObjectDescriptor *object_desc2;
BSA_QueryDescriptor *query_desc;
BSA_UInt32 Size;
char *envx[3];
char ErrorString[512];
char msg[1024];
int status;
.
.
BSAInit(&BsaHandle, security_tokenPtr, &BsaObjectOwner, envx);
.
.
BSABeginTxn(BsaHandle);
/ * Delete the object from NetBackup. */
status = BSADeleteObject(BsaHandle, object_desc->copyId);
if (status != BSA_RC_SUCCESS) {
Size = 512;
NBBSAGetErrorString(status, &Size, ErrorString);
sprintf(msg, "ERROR: BSADeleteObject() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Delete");
BSAEndTxn(BsaHandle, BSA_Vote_ABORT);
BSATerminate(BsaHandle);
exit(status);
}
/ * End the delete transaction, commit will delete the object */
status = BSAEndTxn(BsaHandle, BSA_Vote_COMMIT);
if (status != BSA_RC_SUCCESS) {
Size = 512;
NBBSAGetErrorString(status, &Size, ErrorString);
sprintf(msg, "ERROR: BSAEndTxn() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Delete");
BSATerminate(BsaHandle);
exit(status);
}
BSABeginTxn(BsaHandle);
/* Delete an image from NetBackup. It may contain multiple objects. */
status = NBBSADeleteImage(BsaHandle, object_desc2->copyId);
if (status != BSA_RC_SUCCESS) {
Size = 512;
NBBSAGetErrorString(statuGetSs, &Size, ErrorString);
sprintf(msg, "ERROR: NBBSADeleteImage() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Delete Image");
BSAEndTxn(BsaHandle, BSA_Vote_ABORT);
BSATerminate(BsaHandle);
exit(status);
}
/* The deletion of the image has occurred during the NBBSADeleteImage() call */
status = BSAEndTxn(BsaHandle, BSA_Vote_COMMIT);
if (status != BSA_RC_SUCCESS) {
Size = 512;
NBBSAGetErrorString(status, &Size, ErrorString);
sprintf(msg, "ERROR: BSAEndTxn() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Delete Image");
BSATerminate(BsaHandle);
exit(status);
}