Skip to content

Instantly share code, notes, and snippets.

@adam704a
Last active May 22, 2023 18:50
Show Gist options
  • Save adam704a/ebd2d7151cf1d1648ff1640db81f3091 to your computer and use it in GitHub Desktop.
Save adam704a/ebd2d7151cf1d1648ff1640db81f3091 to your computer and use it in GitHub Desktop.
dhis on docker postgres back up
#!/bin/bash
# run sudo aws configure first!
# then schedule like this: sudo crontab -e
# 0 0 * * * /opt/scripts/db_backup.sh # take a backup every midnight
RETENTION_DAYS=14
BUCKET=org.rti-ghd.notresante
DIR=`date +%d-%m-%y`
DEST=./db_backups/$DIR
mkdir $DEST
PGPASSWORD='dhis' docker exec dhis2-database pg_dump --inserts --column-inserts --username=dhis dhis > $DEST/dbbackup.sql
# remove old backups
old_backup=$(date --date="$RETENTION_DAYS days ago" +"%Y-%m-%d")
rm -rf $old_backup
aws s3 sync ./db_backups s3://$BUCKET
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment