Skip to content

Instantly share code, notes, and snippets.

@rhenter
Last active November 9, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhenter/c13773ab9b80642dba2eed1c7d914532 to your computer and use it in GitHub Desktop.
Save rhenter/c13773ab9b80642dba2eed1c7d914532 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
apps=( "olist-orders-api" "olist-freights-api" "olist-correios-api" )
order_exclude_tables=( "olist_orders_orderhistory" "olist_orders_orderhistory" "seller_orders_sellerorderhistory" "seller_orders_sellerorderitemhistory" )
correios_exclude_tables=( )
freights_exclude_tables=( )
get_exclude_params() {
app=$(echo $1);
exclude_table_data=""
case $app in
"olist-orders-api")
exclude_table_data=${order_exclude_tables[@]}
;;
"olist-correios-api-api")
exclude_table_data=${correios_exclude_tables[@]}
;;
"olist-freights-api")
exclude_table_data=${freights_exclude_tables[@]}
;;
*)
echo ""
;;
esac
exclude_params=( )
for table in ${exclude_table_data[@]}
do
exclude_params+=( "--exclude-table-data=$table" )
done
echo "${exclude_params[@]}";
}
for app in ${apps[@]}
do
output=$(heroku config --app $app| grep DATABASE_URL | awk '{print $2}')
regex="postgres:\/\/(.*):(.*)@(.*):5432\/(.*)"
if [[ $output =~ $regex ]]
then
user="${BASH_REMATCH[1]}"
password="${BASH_REMATCH[2]}"
host="${BASH_REMATCH[3]}"
database="${BASH_REMATCH[4]}"
else
echo "Deu ruim"
fi
exclude_params=$(get_exclude_params $app);
echo "PGPASSWORD=$password pg_dump -v -U $user -Fc -h $host $exclude_params $database > $app.dump"
done
$ bash backup_large_databases.sh
PGPASSWORD=paaf5e3d1e4eeb652082a4fd6853c19c4be6a9bf1b1ffaccfb72b0c4403738531 pg_dump -v -U uccicakiufg2h0 -Fc -h ec2-52-45-230-101.compute-1.amazonaws.com --exclude-table-data=olist_orders_orderhistory --exclude-table-data=olist_orders_orderhistory --exclude-table-data=seller_orders_sellerorderhistory --exclude-table-data=seller_orders_sellerorderitemhistory d7s8p1j2nluekb > olist-orders-api.dump
PGPASSWORD=p83vqmgik6nsvscdo66hmq6ki5v pg_dump -v -U u4ek5pcivmissb -Fc -h ec2-54-80-246-9.compute-1.amazonaws.com ddfd5kescarqr4 > olist-freights-api.dump
PGPASSWORD=p9qmlrmqc7guov4r6khc8ehbv6o pg_dump -v -U u2pkf8noqk8r1s -Fc -h ec2-52-55-7-160.compute-1.amazonaws.com d8fbiulrfrav0f > olist-correios-api.dump
Obs: Não adicionei as tabelas para excluir para a freights e correios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment