Please enter search query.
Search <book_title>...
NetBackup™ DataStore SDK Programmer's Guide for XBSA 1.1.0
Last Published:
2022-03-28
Product(s):
NetBackup (10.0)
- Introduction to NetBackup XBSA
- How to set up the SDK
- Using the NetBackup XBSA interface
- Getting help with the API
- NetBackup XBSA data structures
- NetBackup XBSA environment
- XBSA sessions and transactions
- Creating a NetBackup XBSA application
- How to build an XBSA application
- How to run a NetBackup XBSA application
- API reference
- Error messages
- Function calls
- Function specifications
- BSABeginTxn
- BSACreateObject
- BSADeleteObject
- BSAEndData
- BSAEndTxn
- BSAGetData
- BSAGetEnvironment
- BSAGetLastError
- BSAGetNextQueryObject
- BSAGetObject
- BSAInit
- BSAQueryApiVersion
- BSAQueryObject
- BSAQueryServiceProvider
- BSASendData
- BSATerminate
- NBBSAAddToMultiObjectRestoreList
- NBBSADeleteImage
- NBBSAEndGetMultipleObjects
- NBBSAFreeJobInfo
- NBBSAGetEnv
- NBBSAGetErrorString
- NBBSAGetJobId
- NBBSAGetJobInfo
- NBBSAGetMediaIds
- NBBSAGetMultipleObjects
- NBBSAGetServerError
- NBBSALogMsg
- NBBSASetEnv
- NBBSAUpdateEnv
- NBBSAValidateFeatureId
- Type definitions
- Process flow and troubleshooting
- How to use the sample files
- Support and updates
- Appendix A. Register authorized locations
- Index
Restore example
Here is an example of a restore. It assumes that the object descriptor has been populated with the copyId of the object either from a query or the XBSA application having stored this information.
BSA_Handle BsaHandle;
BSA_ObjectOwner BsaObjectOwner;
BSA_SecurityToken *security_tokenPtr;
BSA_DataBlock32 *data_block;
BSA_UInt32 EnvBufSz = 512;
BSA_ObjectDescriptor *object_desc;
BSA_QueryDescriptor *query_desc;
BSA_UInt32 Size;
char *envx[3];
char EnvBuf[512];
char ErrorString[512];
char msg[1024];
char *restore_location;
int total_bytes = 0;
int status;
.
.
BSAInit(&BsaHandle, security_tokenPtr, &BsaObjectOwner, envx);
.
.
BSABeginTxn(BsaHandle);
/ * Get the object. */
data_block = (BSA_DataBlock32 *)malloc(sizeof(BSA_DataBlock32));
status = BSAGetObject(BsaHandle, object_desc, data_block);
if (status != BSA_RC_SUCCESS) {
Size = 512;
NBBSAGetErrorString(status, &Size, ErrorString);
sprintf(msg, "ERROR: BSAQueryObject() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Restore");
BSAEndTxn(BsaHandle, BSA_Vote_ABORT);
BSATerminate(BsaHandle);
exit(status);
}
/ * The application is responsible for recreating the file or other object *
/ * type that is being restored using the information that is stored in the *
/ * object_descriptor. This sample prints the results to the screen. */
restore_location = (char *)malloc((EnvBufSz + 1) * sizeof(char));
memset(restore_location, 0x00, EnvBufSz + 1);
/ * Initialize the data_block structure. */
data_block->bufferLen = EnvBufSz;
data_block->bufferPtr = EnvBuf;
memset(data_block->bufferPtr, 0x00, EnvBufSz);
/ * Read data until the end of data. */
while ((status = BSAGetData(BsaHandle, data_block)) == BSA_RC_SUCCESS) {
/ * Move the retrieved data to where it is to be restored to and *
* reset the data_block buffer. */
memcpy(restore_location, data_block->bufferPtr, data_block->numBytes);
total_bytes += data_block->numBytes;
printf("%s", restore_location);
memset(restore_location, 0x00, EnvBufSz + 1);
memset(data_block->bufferPtr, 0x00, EnvBufSz);
}
if (status == BSA_RC_NO_MORE_DATA) {
/ * The last BSAGetData() that returns BSA_RC_NO_MORE_DATA may have data *
* in the buffer. */
memcpy(restore_location, data_block->bufferPtr, data_block->numBytes);
total_bytes += data_block->numBytes;
printf("%s\n", restore_location);
printf("Total bytes retrieved: %d\n", total_bytes);
} else {
Size = 512;
NBBSAGetErrorString(status, &Size, ErrorString);
sprintf(msg, "ERROR: BSAGetData() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Restore");
BSAEndTxn(BsaHandle, BSA_Vote_ABORT);
BSATerminate(BsaHandle);
exit(status);
}
/ * Done retrieving data. */
status = BSAEndData(BsaHandle);
if (status != BSA_RC_SUCCESS) {
Size = 512;
NBBSAGetErrorString(status, &Size, ErrorString);
sprintf(msg, "ERROR: BSAEndData() failed with error: %s", ErrorString);
NBBSALogMsg(BsaHandle, MSERROR, msg, "Restore");
BSAEndTxn(BsaHandle, BSA_Vote_ABORT);
BSATerminate(BsaHandle);
exit(status);
}
/ * End the restore transaction. BSA_Vote_COMMIT and BSA_Vote_ABORT are *
/ * equivalent as there is nothing to commit or abort for a restore transaction. */
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, "Restore");
BSATerminate(BsaHandle);
exit(status);
}