create bash script to snapshot a database source

  • 1
  • 1
  • Question
  • Updated 2 years ago
  • Answered
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
Photo of Sergio Gianandrea

Sergio Gianandrea

  • 136 Points 100 badge 2x thumb

Posted 2 years ago

  • 1
  • 1
Photo of Gianpiero Piccolo

Gianpiero Piccolo

  • 2,336 Points 2k badge 2x thumb
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
Photo of Benoit Contri

Benoit Contri

  • 72 Points
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
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
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 \
    -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"; \
    -b ~/cookies.txt -H "Content-Type: application/json" <<-EOF
{
}
EOF
Photo of Gianpiero Piccolo

Gianpiero Piccolo

  • 2,336 Points 2k badge 2x thumb
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.
Photo of Sergio Gianandrea

Sergio Gianandrea

  • 136 Points 100 badge 2x thumb
Thank you
I resolved my problem with this hint