Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
echo "Running dyndamo_db_backup.sh with arguments $@"
if [ "$#" -ne 4 ]; then
echo "Illegal number of parameters, expected 4! [SOURCE_REGION, SOURCE_TABLE, DESTINATION_REGION, DESTINATION_TABLE]"
exit
fi
SOURCE_REGION=$1
SOURCE_TABLE=$2
DESTINATION_REGION=$3
DESTINATION_TABLE=$4
DYNAMO_SOURCE_ENDPOINT="dynamodb.$SOURCE_REGION.amazonaws.com"
DYNAMO_DESTINATION_ENDPOINT="dynamodb.$DESTINATION_REGION.amazonaws.com"
echo "Installing required dependencies"
sudo yum install -y git java-1.8.0-openjdk-devel.x86_64 maven.noarch
export JAVA_HOME="/usr/lib/jvm/java-1.8.0"
if [ ! -d "$DIRECTORY" ]; then
echo "Cloning and building dynamodb-cross-region-library project"
git clone https://github.com/awslabs/dynamodb-cross-region-library.git
fi
cd dynamodb-cross-region-library && mvn clean package -DskipTests
echo "Starting replication process with values sourceEndpoint=$DYNAMO_SOURCE_ENDPOINT, sourceTable=$SOURCE_TABLE, destinationEndpoint=$DYNAMO_DESTINATION_ENDPOINT, destinationTable=$DESTINATION_TABLE"
cd target
JAR_NAME=$(ls -l *jar | grep -v original | awk '{print $9}')
JAVA_COMMAND="nohup java -jar $JAR_NAME --sourceEndpoint $DYNAMO_SOURCE_ENDPOINT --sourceTable $SOURCE_TABLE --destinationEndpoint $DYNAMO_DESTINATION_ENDPOINT --destinationTable $DESTINATION_TABLE"
echo "Executing $JAVA_COMMAND"
$JAVA_COMMAND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment