Guest User

Untitled

a guest
Jan 9th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Written 2018-11-15 by 4410287
  4. # This script will create a backup file of a postgres database and compress it. It is capable of access a local or remote server to pull the backup. After creating a new backup, it will delete backups that are older than 15 days, with the exception of backups created the first of every month. It is recommended to create a seperate database user specifically for backup purposes, and to set the permissions of this script to prevent access to the login details. Backup scripts for different databases should be run in seperate folders or they will overwrite each other.
  5.  
  6. HOSTNAME=
  7. USERNAME=
  8. PASSWORD=
  9. DATABASE=
  10.  
  11. # Note that we are setting the password to a global environment variable temporarily.
  12. echo "Pulling Database: This may take a few minutes"
  13. export PGPASSWORD="$PASSWORD"
  14. pg_dump -F t -h $HOSTNAME -U $USERNAME $DATABASE > $(date +%Y-%m-%d).backup
  15. unset PGPASSWORD
  16. gzip $(date +%Y-%m-%d).backup
  17. echo "Pull Complete"
  18.  
  19. echo "Clearing old backups"
  20. find . -type f -iname '*.backup.gz' -ctime +15 -not -name '????-??-01.backup.gz' -delete
  21. echo "Clearing Complete"
Add Comment
Please, Sign In to add comment