Created
January 29, 2020 18:00
-
-
Save filipecifali/d99a16ce06a25a24f407c2181eeb1db9 to your computer and use it in GitHub Desktop.
YOLO.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
BLOCK="===============================" | |
DATE=`date +%d-%m-%Y` | |
CNAME=ansible_db_pg_1 | |
VNAME=ansible_db_pg | |
PG_VERSIONS=(9.3 9.4 9.5 9.6 10.11 11.6) | |
PG_NOF_VERSIONS=${#PG_VERSIONS[@]} | |
for V in `seq 0 ${PG_NOF_VERSIONS}`; | |
do | |
if (( $V == `expr ${PG_NOF_VERSIONS} - 1` )); then | |
break | |
fi | |
echo ${BLOCK} | |
echo "Migrating from ${PG_VERSIONS[$V]} to ${PG_VERSIONS[`expr $V + 1`]}" | |
echo "Backing up ${V}" | |
echo ${BLOCK} | |
docker exec -t ${CNAME} pg_dump postgres -c -U postgres > dump_${DATE}_${PG_VERSIONS[$V]}.sql | |
docker stop ${CNAME} | |
docker rm ${CNAME} | |
docker volume rm ${VNAME} | |
sed -i "s/${PG_VERSIONS[$V]}/${PG_VERSIONS[`expr $V + 1`]}/g" docker-compose.yml | |
docker-compose up -d db_pg | |
sleep 10 | |
cat dump_${DATE}_${PG_VERSIONS[$V]}.sql | docker exec -i ${CNAME} psql -U postgres postgres | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment