Skip to content

Instantly share code, notes, and snippets.

@miguelpeixe
Created March 7, 2018 14:58
Show Gist options
  • Save miguelpeixe/8b688922b04cd7f74bba16abe8cad75b to your computer and use it in GitHub Desktop.
Save miguelpeixe/8b688922b04cd7f74bba16abe8cad75b to your computer and use it in GitHub Desktop.
PG backups in Rancher
#!/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