Skip to main content
Skip table of contents

CLI cookbook: how to refresh a Delphix self-service container

The following script is for educational and demonstration purposes only and is not supported by Delphix.

This script can be downloaded by selecting refreshContainer.sh.

Refreshing a container in Delphix self-service

CODE
#!/bin/bash

# A sample script for calls to the CLI. This one refresh Jet Stream container.
#
# VERY IMPORTANT: In order for this to work, you need to go through the steps here:
# https://docs.delphix.com/display/DOCS43/CLI+Cookbook%3A+Configuring+Key-Based+SSH+Authentication+for+Automation
# After this you will not need to use a username and password to log into the delphix engine. If you do not
# setup the SSH authentication you will have to manually enter the password.
#


##### Constants

# Describes a Delphix software revision.
VERSION="1.11.4"


##### Default Values. These can be overwriten with optional arguments.
engine="de-6041-doc-938-vn.dlpxdc.co"
username="admin"


##examples##
# Refresh container from latest point in time of Template
#./refreshContainer.sh -T JS_DATA_TEMPLATE-13 JS_DATA_CONTAINER-20
# Refresh container from specific bookmark
#./refreshContainer.sh -b JS_BOOKMARK-76 JS_DATA_CONTAINER-20
# Refresh container from specific point in time of branch
#./refreshContainer.sh -t "2016-08-08T10:00:00.000Z" -B JS_BRANCH-4 JS_DATA_CONTAINER-20


##### Functions

# Help Menu
function usage {
echo "Usage: refreshContainer.sh [[-h] | options...] <containername>"
echo "Create a Jet Stream Bookmark on the given branch."
echo ""
echo " You need to specify either -T, -B, -b or -t to refresh container. With -t option you also need to specify -B also"
echo "Positional arguments"
echo " <containerName>"
echo ""
echo "Optional Arguments:"
echo " -h Show this message and exit"
echo " -d Delphix engine IP address or host name, otherwise revert to default"
echo " -u Server user. Password needs to manually provide at run time, otherwise revert to default"
echo " -T template reference from which need to refresh from latest point in time"
echo " -B Branch reference from which we need to pick up time from where the container should be refreshed. Type: string. Format JS_BRANCH-<n> (Optional)"
echo " -b Bookmark name from which need to refresh container. If no bookmark is included, the branch will be created at the latest point in time. Type: string. Format JS_BOOKMARK-<n> (Optional)"
echo " -t The time from where the container should be refreshed. This must be accompanied with branch reference from which need to pick up time. Type: date, must be in ISO 8601 extended format [yyyy]-[MM]-[dd]T[HH]:[mm]:[ss].[SSS]Z"
}

# Create Our Session, including establishing the API version.
function create_session
{
echo "Creating session ..."
SSH_CMD="ssh ${username}@${engine}"
${SSH_CMD} "version $VERSION"
check_result
}

# Check the result of the curl. If there are problems, inform the user then exit.
function check_result
{
exitStatus=$?
if [ $exitStatus -ne 0 ]
then
echo "command failed with exit status $exitStatus"
echo $result 
exit 1
fi
}


function restore_container
{

paramString="selfservice/container/select ${containerRef}; restore;"

# If there is no time input and no bookmark name, we need to use JSTimelinePointLatestTimeInput from template.
if [[ -n $template && -z $inputTime && -z $bookmark ]]
then
pointParams="edit timelinePointParameters; set type=JSTimelinePointLatestTimeInput; set sourceDataLayout=\"${template}\";"
# If there is a timeInput and no bookmark name, we need to use Input Time.
elif [[ -n $inputTime && -n $branch && -z $bookmark && -z $template ]]
then
pointParams="edit timelinePointParameters; set type=JSTimelinePointTimeInput; set time=\"${inputTime}\"; set branch=\"${branch}\";"
# If there is a bookmark name and no time input, we need to use bookmark
elif [[ -n $bookmark && -z $template && -z $inputTime ]]
then
pointParams="edit timelinePointParameters; set type=JSTimelinePointBookmarkInput; set bookmark=\"${bookmark}\";"
else
usage
exit 1
fi

paramString="$paramString $pointParams commit;"
echo "Executing the command on CLI ..."
echo $paramString
result=$(${SSH_CMD} $paramString)
check_result

echo "Verifying job status ..."
# Get everything in the result that comes after job.
temp=${result#*job}
# Get rid of everything after 
resultArray=($temp)
jobRef=($resultArray)
jobString="job;select $jobRef;ls"
result=$(${SSH_CMD} $jobString)
check_result
# Get everything in the result that comes after job.
temp=${result#*jobState:}
# Get rid of everything after
resultArray=($temp)
jobState=($resultArray)

if [ $jobState = "COMPLETED" ]
then
echo "Successfully refreshed container- [$containerRef]."
else
echo "Unable to refresh container- [$containerRef]."
echo result
fi

}


##### Main

while getopts "u:d:T:b:t:B:h" flag; do
case "$flag" in
u ) username=${OPTARG%:*}
;;
d ) engine=$OPTARG
;;
T ) template=$OPTARG
;; 
b ) bookmark=$OPTARG
;;
t ) inputTime=$OPTARG
;;
B ) branch=$OPTARG
;;
h ) usage
exit
;;
* ) usage
exit 1
esac

done


# Shift the parameters so we only have the positional arguments left
shift $((OPTIND-1))

# Check that there are 1 positional arguments
if [ $# != 1 ]
then
usage
exit 1
fi

# Get the one positional arguments
containerRef=$1

create_session
restore_container
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.