Created
March 7, 2018 14:58
-
-
Save miguelpeixe/8b688922b04cd7f74bba16abe8cad75b to your computer and use it in GitHub Desktop.
PG backups in Rancher
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 | |
date="$(date -I)" | |
timestamp="$(date +%s)" | |
origin="/nfs/accessible/postgresql/data/backups" | |
target="/final/backup/destination/path" | |
rancherContainer="1s203" | |
filename="db-$(date +%H).sql.gz" | |
echo "--------" | |
echo "$(date +%c)" | |
echo "Starting backup" | |
echo "Creating backup directories" | |
mkdir -p ${origin} ${target} | |
echo "Creating database backup file" | |
/usr/local/bin/rancher exec -i ${rancherContainer} bash -c "pg_dump -U postgres postgres | gzip > /var/lib/postgresql/data/backups/${filename}" | |
sleep 1m | |
echo "Storing database backup file" | |
mv ${origin}/${filename} ${target}/ | |
echo "Backup finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment