Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Importing/ exporting Data in TDM using a script

[Deleted User]
[Deleted User] Posts: 0 admin
edited December 2016 in CTP

TDM allows us to manage and manipulate data in CTP. There are many cases where we would want to store snapshots of our data in source control. The following scripts utilize the TDM apis to accomplish this.


  • [Deleted User]
    [Deleted User] Posts: 0 admin
    edited April 2017

    Export From TDM to check into Source Control

    #Set these
    #EM host
    #EM PORT
    #ID of dataRepository Server that has the repository to be exported
    #name of repository to be exported.  You can see all repositories with http://<EM host and port>/em/tdm/api/v1/servers
    #name of export a unique Data will be appended to this name
    #Description Of Export (optional)
    EXPORT_DESCRIPTION="This is a description"
    #File path where the downlaoded export will appear
    #Export the Data Repository into TDM
    curl -vs -u admin:admin -H "Content-Type: application/json" -X POST -d '{ "name": "'"$UNIQUE_EXPORT_ID"'",  "description": "'"$EXPORT_DESCRIPTION"'" }' http://$EM_HOST:$EM_PORT/em/tdm/api/v1/servers/$DR_ID/repositories/$DR_NAME/export
    #Using the export Name get information on the export
    results=$(curl -vs -u admin:admin -H "Content-Type: application/json" -X GET http://localhost:8080/em/tdm/api/v1/exports?name=$UNIQUE_EXPORT_ID)
        echo $results
    #Get the ID of the export
    EXPORT_ID=$(echo $results | awk -F "<id>" '{print $2}' | awk -F "\</id\>" '{print $1}')
    echo "The file was successfully exported and the Export ID is " $EXPORT_ID
    sleep 5
    #Download the export from TDM
    curl -vs -u admin:admin -H "Content-Type: application/json" -X GET http://$EM_HOST:$EM_PORT/em/tdm/api/v1/exports/$EXPORT_ID/download > $FILEPATH/$EXPORT_NAME.json
    #Delete the export from TDM(Optional)
    curl -vs -u admin:admin -H "Content-Type: application/json" -X DELETE http://$EM_HOST:$EM_PORT/em/tdm/api/v1/exports/$EXPORT_ID
    #Now check the file into GIT Here
    echo checking $FILEPATH/$EXPORT_NAME.json into GIT
  • [Deleted User]
    [Deleted User] Posts: 0 admin
    edited April 2017

    `##Import data from Source Control to TDM

    Set these

    File path where the DR was checked out to


    File name of the DR to be imported


    EM host




    name of import


    Description Of import (optional)

    IMPORT_DESCRIPTION="This is a description"

    ID of dataRepository Server to recieve the import You can see all repositories with http:///em/tdm/api/v1/servers

    #name of repository to be once imported.  
    #check out the file from GIT Here
    echo checking out DR to $FILEPATH/$EXPORT_NAME.json 
    #write the data file
    echo '<?xml version="1.0" encoding="UTF-8"?><exportUploadRequest  xmlns=""> <name>'$IMPORT_NAME'</name>    <serverID>'$DR_ID'</serverID></exportUploadRequest>' > /home/parasoft/data.txt
    #Upload the DR into TDM
    results=$(curl -vs -u admin:admin -F "data=@/home/parasoft/data.txt" -F "file=@/home/parasoft/drExports/Parabank.json" http://$EM_HOST:$EM_PORT/em/tdm/api/v1/exports/upload)
    echo $results
    #Get the ID of the import
    IMPORT_ID=$(echo $results | awk -F "<job><id>" '{print $2}' | awk -F "</id><name>" '{print $1}')
    echo "the import ID is "$IMPORT_ID
    sleep 5
    #Create the repository.  If the repository already exists then it will not be affected
    curl -vs -u admin:admin -H "Content-Type: application/json" -X POST -d '{"name": "'"$DR_NAME"'"}' http://$EM_HOST:$EM_PORT/em/tdm/api//v1/servers/$DR_ID/repositories
    #import the upload into TDM
    curl -vs -u admin:admin -H "Content-Type: application/json" -X POST -d '{ "name": "'"$IMPORT_NAME"'", "description": "'"$IMPORT_DESCRIPTION"'", "export": '"$IMPORT_ID"'}' http://$EM_HOST:$EM_PORT/em/tdm/api/v1/servers/$DR_ID/repositories/$DR_NAME/import
    #Delete the import from TDM(Optional)
    curl -vs -u admin:admin -H "Content-Type: application/json" -X DELETE http://$EM_HOST:$EM_PORT/em/tdm/api/v1/exports/$IMPORT_ID`