API/Python/Open-Source Solutions

Expand all | Collapse all

create bash script to snapshot a database source

Jump to Best Answer
  • 1.  create bash script to snapshot a database source

    Posted 03-04-2016 02:49:00 PM
    Hello,
     I need to manage one Oracle's database source without LogSync.
    One my bash script will load data on this database source. At end of my bash script I want create a new Delphix snapshot of this database source.
    How can I do ? Any example?

    Thank you,
    Sergio






  • 2.  RE: create bash script to snapshot a database source

    Posted 03-04-2016 02:55:00 PM
    Ciao Sergio,

    you have to prepare a CLI script and then launch it through SSH session to Delphix Engine.
    Here is a link to create a snapshot (on VDB, but it's the same on a dSource) through the CLI:
    https://docs.delphix.com/display/DOCS43/CLI+Cookbook%3A+Taking+a+Snapshot

    Regards.
    Gianpiero


  • 3.  RE: create bash script to snapshot a database source

    Posted 03-04-2016 04:37:00 PM
    Hi, I think it's more easier to invok a websevice at the ens of your shell to achive your need You can look at the delphix doc for webservice samples MSA


  • 4.  RE: create bash script to snapshot a database source

    Posted 03-04-2016 05:27:00 PM
    Here is a snippet from a shell script from some of my automation in the new version of Landshark that is forthcoming. I use jq on a linux box to help me easily parse json. I've included a couple helper functions in there that I wrote and use in my template, as well.




    DEIP="<SOMETHING>"
    DEUSERNAME="<SOMETHING>"
    DEPASSWORD="<SOMETHING>"
    SOURCEDBNAME="<SOMETHING>"

    function ENGINE_TEST {
    #runs simple curl calls to attempt to establish as simple login to the Delphix Engine
    echo "Testing Delphix Engine"
    echo "Establishing a Session to the Delphix Engine"
    SESS=$(curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/session">http://${DEIP}/resources/json/delphix/session">http://${DEIP}/resources/json/delphix/session \
        -c ~/cookies.txt -H "Content-Type: application/json" <<-EOF
    {
       "type": "APISession",
       "version": {
           "type": "APIVersion",
           "major": 1,
           "minor": 6,
           "micro": 0
       }
    }
    EOF
    )

    if [[ "'echo $SESS |jq '.status''" == "\"OK\"" ]]; then
    echo "Delphix Engine Session was created"
    else
    echo "Delphix Engine Session was unable to be created"
    until  [[ "$CONT" == "Y" ]] || [[ "$CONT" == "N" ]]; do
    read -p "Are you sure you want to continue? (Y/N)" CONT
    CONT=${CONT^^}
    done
    if [[ "$CONT" == "N" ]]; then
    echo "Please validate your Delphix Engine parameters, and try again."
    exit 1
    else
    return
    fi
    fi
    echo "Authenticating with the Delphix Engine"
    AUTH=$(curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/login \
       -b ~/cookies.txt -H "Content-Type: application/json"<<-EOF
    {
       "type": "LoginRequest",
       "username": "${DEUSERNAME}",
       "password": "${DEPASSWORD}"
    }
    EOF
    )

    if [[ "'echo $AUTH|jq '.status''" == "\"OK\"" ]]; then
    echo "Delphix Engine Authentication was successful"
    else
    echo "Delphix Engine Authentication was unsuccessful"
    until  [[ "$CONT" == "Y" ]] || [[ "$CONT" == "N" ]]; do
    read -p "Are you sure you want to continue? (Y/N)" CONT
    CONT=${CONT^^}
    done
    if [[ "$CONT" == "N" ]]; then
    echo "Please validate your Delphix Engine parameters, and try again."
    exit 1
    else
    return
    fi
    fi
    echo "Delphix Engine tests completed successfully"
    }

    function GET_DATABASE_REFS {
    DATABASES=$(curl -X GET -k "http://${DEIP}/resources/json/delphix/database"; \
    -b ~/cookies.txt -H "Content-Type: application/json")
    SOURCEDATABASE=$(echo $DATABASES | jq -r ".result[] | select(.name == \"${SOURCEDBNAME}\")")
    SOURCECONTAINERREF=$(echo $SOURCEDATABASE | jq -r '.reference')
    echo "Source Database Reference:"
    echo "${SOURCEDBCONTAINERREF}"
    }

    GET_DATABASE_REFS
    curl -X POST -k --data @- "http://${DEIP}/resources/json/delphix/database/${SOURCEDBCONTAINERREF}/sync"">http://${DEIP}/resources/json/delphix/database/${SOURCEDBCONTAINERREF}/sync"">http://${DEIP}/resources/json/delphix/database/${SOURCEDBCONTAINERREF}/sync"; \
        -b ~/cookies.txt -H "Content-Type: application/json" <<-EOF
    {
    }
    EOF



  • 5.  RE: create bash script to snapshot a database source
    Best Answer

    Posted 03-04-2016 10:16:00 PM
    The RESTful API is a valid alternative and is more flexible.
    For completeness, via CLI is:

    ssh delphix_admin@172.16.180.3 < snapshot.sh

    the content of the snapshot.sh is:

    database
    select 'DB1'
    sync
    commit

    You have to configure Key-based SSH Authentication to avoid the script wait for entering the password. See https://docs.delphix.com/display/DOCS43/CLI+Cookbook%3A+Configuring+Key-Based+SSH+Authentication+for...

    Hope it is helpful.




  • 6.  RE: create bash script to snapshot a database source
    Best Answer

    Posted 03-07-2016 12:01:00 PM
    Thank you
    I resolved my problem with this hint