sauv_postgresql: correct return code with Bash
This commit is contained in:
parent
f79dd1a13b
commit
d1ad5103ed
1 changed files with 14 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
# Le fichier sera nommé BASE_DIR/PREFIXEbasenameSUFFIXE
|
||||
|
@ -7,17 +7,27 @@ PREFIXE="sauv_pgsql"
|
|||
SUFFIXE=_$( date +%Y%m%d-%H%M ).sql.gz
|
||||
DUREE_DE_VIE=5
|
||||
|
||||
# Vérifications initiales
|
||||
# Exit at first error
|
||||
# note : check that you receive crontab's mails in case something goes wrong.
|
||||
set -e
|
||||
if [ -n "$BASH" ]; then
|
||||
# Bash required for this. If not available, return code will be 0
|
||||
# even if pg_dumpall fails (but usually it write something on stderr
|
||||
# so cron will send a mail nevertheless).
|
||||
set -o pipefail
|
||||
fi
|
||||
|
||||
# Initial checks
|
||||
if [ ! -d "$BASE_DIR" ]; then
|
||||
echo "ERREUR : répertoire de sauvegarde inexistant : $BASE_DIR ." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Sauvegarde des bases
|
||||
# Backup of the whole default cluster
|
||||
su -l -c pg_dumpall postgres | gzip -c > "$BASE_DIR/$PREFIXE$SUFFIXE"
|
||||
|
||||
|
||||
# Suppression des anciennes bases
|
||||
# Deletion of old backups
|
||||
if [ "$1" = "--delete-olds" ]; then
|
||||
find $BASE_DIR -name "$PREFIXE*" -mtime +$DUREE_DE_VIE -print0 | xargs -n 200 -r -0 rm -f
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue