Last active
January 4, 2025 03:53
-
-
Save fishuke/0fcdcce7086ef561850253306d318c09 to your computer and use it in GitHub Desktop.
postgis-backup
This file contains hidden or 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 | |
| apk add --no-cache aws-cli | |
| # Set backup name prefix if provided, otherwise use empty string | |
| BACKUP_PREFIX="${BACKUP_NAME:+${BACKUP_NAME}_}" | |
| pg_dump --format=custom --no-acl --no-owner --username=$POSTGRES_USER $POSTGRES_DB > /tmp/backup.dump | |
| [ $? -eq 0 ] || { echo "Error creating backup. Exiting..."; exit 1; } | |
| aws s3 cp /tmp/backup.dump "s3://$S3_BUCKET_NAME/${BACKUP_PREFIX}backup_$(date +%F_%H-%M-%S).dump" --endpoint-url=$S3_URL | |
| [ $? -eq 0 ] && rm /tmp/backup.dump || { echo "Error uploading backup. Exiting..."; exit 1; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment