-
-
Save samuelloza/32c9dc991066499406cc8128b136e33d to your computer and use it in GitHub Desktop.
Backup Postgres.sh
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 | |
| # | |
| # Postgres backup script | |
| # This script must be run with root mysql account | |
| # | |
| # POSTGRES connection info | |
| MYUSER=postgres | |
| MYPASS=Zorro1 | |
| MYHOST=localhost | |
| # Location to place backups. | |
| backup_dir="/home/backup" | |
| # Exclude databases, separate by spaces | |
| excludedb="template0 template1" | |
| ##### No changes after this line ##### | |
| LANG=US | |
| day=$(date '+%A') | |
| databases="bd_sigre" | |
| for db in $databases; do | |
| skipdb=-1 | |
| if [ "$excludedb" != "" ]; then | |
| for i in $excludedb; do | |
| if [ "$db" == "$i" ]; then | |
| skipdb=1 | |
| logger -p info "Skiping backup of database $db" | |
| fi | |
| done | |
| fi | |
| if [ "$skipdb" == "-1" ]; then | |
| logger -p info "Starting backup of database $db" | |
| PGPASSWORD="$MYPASS" pg_dump -U $MYUSER -h $MYHOST $db | ssh [email protected] "cat | gzip -9 > $backup_dir/$db-$day.sql.gz" | |
| logger -p info "Finished backup of database $db" | |
| fi | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment