I've been made auto backup/dumb Postgresql per-schema
- Auto backup database all or per-schema files
- Auto zip with password (secure)
- Auto upload to your AWS S3 Storage
- Auto-send link AWS S3 to the email you set
- Install zip
brew install zip
- Install expect
brew install expect
- Install aws cli
brew install awscli
- Install aws sendemail
brew install sendemail
- Change to your Zip Password
zip_password="your_password"
- Change to your PSQL Connection
# Database connection details
backup_all=false # false means backup will split per-schema
db_host="http://localhost"
db_port="5432"
db_username="db_username"
db_name="db_name"
db_password="db_password"
- Configure your SMTP Credentials
# Sender Email
smtp_user="yourmail@gmail.com"
smtp_password="your_mail_password"
smtp_host="smtp.gmail.com"
smtp_port="587"
# Recipient Email Where do you want to send the link to the S3 storage
recipient_email="yourmail@gmail.com"
- Configure your AWS Credentials
# AWS credentials
export AWS_ACCESS_KEY_ID="aws_key"
export AWS_SECRET_ACCESS_KEY="aws_secret_key"
export AWS_DEFAULT_REGION="aws_region"
# S3 bucket details
s3_bucket="your_bucket_storage"
- Change to your Backup Directory Path
backup_dir="./$folder_name"
- Give Permission To Give Flexibility
chmod +x backup_postgresql.sh
- Setting your cronjob (Example for Centos 7)
crontab -e
# Script will be running every 1 AM
0 1 * * * bash /home/your_user_name/backup_postgresql.sh
To exit, press "ESC" press ":" and "wq"
- Verify your cronjob settings (Example for Centos 7)
crontab -l
bash backup_postgresql.sh
please star this if you like and be happy 🤙