Some scripts, quickly-and-dirtily written, but might be useful anyway.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
928B

  1. #!/bin/bash
  2. # Configuration
  3. # Le fichier sera nommé BASE_DIR/PREFIXEbasenameSUFFIXE
  4. BASE_DIR="/var/backups/postgresql"
  5. PREFIXE="sauv_pgsql"
  6. SUFFIXE=_$( date +%Y%m%d-%H%M ).sql.gz
  7. DUREE_DE_VIE=5
  8. # Exit at first error
  9. # note : check that you receive crontab's mails in case something goes wrong.
  10. set -e
  11. if [ -n "$BASH" ]; then
  12. # Bash required for this. If not available, return code will be 0
  13. # even if pg_dumpall fails (but usually it write something on stderr
  14. # so cron will send a mail nevertheless).
  15. set -o pipefail
  16. fi
  17. # Initial checks
  18. if [ ! -d "$BASE_DIR" ]; then
  19. echo "ERREUR : répertoire de sauvegarde inexistant : $BASE_DIR ." >&2
  20. exit 1
  21. fi
  22. # Backup of the whole default cluster
  23. su -l -c pg_dumpall postgres | gzip -c > "$BASE_DIR/$PREFIXE$SUFFIXE"
  24. # Deletion of old backups
  25. if [ "$1" = "--delete-olds" ]; then
  26. find $BASE_DIR -name "$PREFIXE*" -mtime +$DUREE_DE_VIE -print0 | xargs -n 200 -r -0 rm -f
  27. fi