Skip to content

Instantly share code, notes, and snippets.

@hall757
Created September 26, 2023 18:50
Show Gist options
  • Save hall757/1dc5d4c65b037f05af444160f0488337 to your computer and use it in GitHub Desktop.
Save hall757/1dc5d4c65b037f05af444160f0488337 to your computer and use it in GitHub Desktop.
export orchestrator database for import into existing upgraded schema
#!/bin/bash
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
eval $(parse_yaml /opt/aspera/orchestrator/config/database.yml)
/opt/aspera/common/mysql/bin/mysqldump \
-u $production_username \
-p$production_password \
-h $production_host \
-P $production_port \
--skip-lock-tables \
--complete-insert \
--ignore-table=${production_database}.schema_migrations \
$production_database | \
sed -e 's/^DROP TABLE /TRUNCATE TABLE /' \
-e 's/^CREATE TABLE /CREATE TABLE IF NOT EXISTS /'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment