Skip to content

Instantly share code, notes, and snippets.

@fishuke
Last active January 4, 2025 03:53
Show Gist options
  • Select an option

  • Save fishuke/0fcdcce7086ef561850253306d318c09 to your computer and use it in GitHub Desktop.

Select an option

Save fishuke/0fcdcce7086ef561850253306d318c09 to your computer and use it in GitHub Desktop.
postgis-backup
#!/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