Ransomware attackers specifically target and attempt to destroy backup systems to increase the probability of payment. Hardening your system is critical. Please ensure you have reviewed your platform security using the Security Hardening Checklist
Cohesity

COHESITY Documentation

Explore our documentation to get started, discover products & new features, access troubleshooting guides, register sources, platforms support.

Products
Data Security Alliance
Visit Cohesity.com
Demos
Support
Blogs
Developers
Partner Portals
Cohesity Community
© 2026 Cohesity, Inc. All Rights Reserved.
Terms of Use|
Privacy Policy|
Legal|
  1. Home
  2. Veritas NetBackup™ DataStore SDK Programmer's Guide for XBSA 1.1.0
  3. Using the NetBackup XBSA interface
  4. Creating a NetBackup XBSA application
  5. Restore - retrieving an object's data
  6. Restore example
Veritas NetBackup™ DataStore SDK Programmer's Guide for XBSA 1.1.0

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);
}

Feedback

Was this page helpful?
Previous

Redirected restore to a different client

Next

Multiple object restore

Feedback

Was this page helpful?