Spaces:
Running
Running
Download scripts/backup_postgres.sh from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/2c5de26c1a17aff6794de780c66253fd5bb2f22b/scripts/backup_postgres.sh
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api@2c5de26c1a17aff6794de780c66253fd5bb2f22b/scripts/backup_postgres.sh
-
curl -L -o backup_postgres.sh https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/2c5de26c1a17aff6794de780c66253fd5bb2f22b/scripts/backup_postgres.sh
1.55 kB
| # PostgreSQL backup script for MicroFunnel | |
| # Run this script daily via cron: 0 2 * * * /path/to/backup_postgres.sh | |
| # Configuration | |
| BACKUP_DIR="/backups/postgres" | |
| TIMESTAMP=$(date +"%Y%m%d_%H%M%S") | |
| BACKUP_FILE="microfunnel_backup_${TIMESTAMP}.sql.gz" | |
| DAYS_TO_KEEP=30 | |
| # Database credentials (read from env or .env file) | |
| source /path/to/your/.env | |
| DB_HOST="${POSTGRES_HOST:-localhost}" | |
| DB_PORT="${POSTGRES_PORT:-5432}" | |
| DB_NAME="${POSTGRES_DB:-microfunnel}" | |
| DB_USER="${POSTGRES_USER:-postgres}" | |
| # S3 Configuration (optional - for cloud backups) | |
| S3_BUCKET="${S3_BACKUP_BUCKET}" | |
| S3_PATH="postgres-backups/" | |
| # Create backup directory if it doesn't exist | |
| mkdir -p $BACKUP_DIR | |
| # Perform backup | |
| echo "Starting backup at $(date)" | |
| pg_dump -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME | gzip > "${BACKUP_DIR}/${BACKUP_FILE}" | |
| if [ $? -eq 0 ]; then | |
| echo "Backup completed successfully: ${BACKUP_FILE}" | |
| # Upload to S3 if configured | |
| if [ ! -z "$S3_BUCKET" ]; then | |
| echo "Uploading to S3..." | |
| aws s3 cp "${BACKUP_DIR}/${BACKUP_FILE}" "s3://${S3_BUCKET}/${S3_PATH}${BACKUP_FILE}" | |
| if [ $? -eq 0 ]; then | |
| echo "S3 upload successful" | |
| else | |
| echo "ERROR: S3 upload failed" | |
| fi | |
| fi | |
| # Clean up old backups (keep last 30 days) | |
| echo "Cleaning up old backups..." | |
| find $BACKUP_DIR -name "microfunnel_backup_*.sql.gz" -mtime +$DAYS_TO_KEEP -delete | |
| echo "Backup process completed at $(date)" | |
| else | |
| echo "ERROR: Backup failed" | |
| exit 1 | |
| fi | |