Created
December 19, 2018 18:14
-
-
Save michaelfmnk/7ad53c008d41efea95b75b9b8bec2cda to your computer and use it in GitHub Desktop.
This file contains 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 | |
# backup database | |
BASE_DIR=/evolve_backup | |
TTL=20 | |
SUFFIX=_evolve_backup.sql | |
declare -a DATABASES_TO_BACKUP=("api_db" "docs_api_db") | |
USER=postgres #change | |
CODE=`date +"%Y%m%d%H%M"` | |
for db in "${DATABASES_TO_BACKUP[@]}" | |
do | |
FOLDER="${BASE_DIR}/${db}/" | |
if [[ ! -e $FOLDER ]]; then | |
echo "creating folder for backups ${FOLDER}" | |
mkdir $FOLDER | |
fi | |
echo "${CODE}: starting backing up ${db}" | |
OUT_FILE="${FOLDER}${CODE}${SUFFIX}" | |
pg_dump -U ${USER} ${db} -F p -f ${OUT_FILE} | |
gzip $OUT_FILE | |
echo "${CODE}: ${OUT_FILE}.gz was created" | |
ls -l "${OUT_FILE}.gz" | |
done | |
find $BASE_DIR -maxdepth 2 -mtime +$TTL -name "*${SUFFIX}.gz" -exec rm -rf '{}' ';' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment