Skip to content

Instantly share code, notes, and snippets.

@tsohr
Created August 14, 2014 00:21
Show Gist options
  • Select an option

  • Save tsohr/5f2c6cc6e881a82f92b3 to your computer and use it in GitHub Desktop.

Select an option

Save tsohr/5f2c6cc6e881a82f92b3 to your computer and use it in GitHub Desktop.
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"
pushd "$DIR" > /dev/null
su -l -c "pg_dumpall" postgres | gzip > `date +"%Y%m%d-%H%M%S"`.sql.gz
BACKUP_CNT=`ls *.sql.gz | wc -l`
if [ "$BACKUP_CNT" -gt "15" ]; then
LAST_BACKUP=`ls *.sql.gz | sort | head -n 1`
rm -f $LAST_BACKUP
fi
popd > /dev/null
@tsohr
Copy link
Author

tsohr commented Aug 14, 2014

$POSTGRES_HOME_DIR/.pgpass should be exist first.

localhost:*:*:postgres:PASSWORD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment