refcodes-batch.1.0.2.source-code.clone-db-template.job Maven / Gradle / Ivy
#!/bin/bash
. $SCRIPT_DIR/lib-filesystem.inc
if [[ $HELP = y ]] ; then
echo "The switch \"-j $JOB\" uses a given configuration to " >&2
echo "clone template DB to a (target) DB. " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
. $SCRIPT_DIR/validate-db-config.job
. $SCRIPT_DIR/validate-db-template-config.job
if [[ $HELP = y ]] ; then
exit $EXIT_SUCCESS
fi
exitOnConfigOff "DB"
exitOnConfigOff "DB_TEMPLATE"
. $SCRIPT_DIR/create-db.job
if [[ $VERBOSE = y ]] ; then
echo "Cloning DB \"$DB_TEMPLATE_NAME\" to \"$DB_NAME\" ..." >&2
echo "--------------------------------------------------------------------------------" >&2
fi
mysqldump -u $DB_TEMPLATE_USER_NAME --password=$DB_TEMPLATE_USER_PASSWORD -h $DB_TEMPLATE_HOSTNAME $DB_TEMPLATE_NAME | mysql -u $DB_USER_NAME --password=$DB_USER_PASSWORD -h $DB_HOSTNAME $DB_NAME
exitOnError "Unable to clone DB \"$DB_TEMPLATE_NAME\" to \"$DB_NAME\" !!!"
echo " DB clone \"$DB_NAME\" from \"$DB_TEMPLATE_NAME\" was created:" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "+ DB clone details see: \"$DB_NAME@$DB_HOSTNAME\"" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
showSuccess "Cloned \"$DB_TEMPLATE_NAME\" to \"$DB_NAME\" !"