Last active
May 22, 2023 18:50
-
-
Save adam704a/ebd2d7151cf1d1648ff1640db81f3091 to your computer and use it in GitHub Desktop.
dhis on docker postgres back up
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 | |
# 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