Skip to content

Instantly share code, notes, and snippets.

@tureki
Created March 18, 2014 11:27
Show Gist options
  • Save tureki/9618245 to your computer and use it in GitHub Desktop.
Save tureki/9618245 to your computer and use it in GitHub Desktop.
Linux postgresql backup shell script
#!/bin/bash
export PGCLIENTENCODING="UTF8"
DBLIST="$@"
if [ -z "${DBLIST}" ]; then
DBLIST="citytalk"
fi
#backup directory
BACKUP=/var/backup/database/pgsql/
ARCHNAME=`date +%Y%m%d-%H`
YEARMONTH=`date +%y%m`
TODAY=`date +%d`
mkdir -p ${BACKUP}/${YEARMONTH}/${TODAY}
for DBNAME in ${DBLIST} ; do
BACKFILE=${DBNAME}.${ARCHNAME}.bz2
if [ -f ${BACKUP}/${YEARMONTH}/${TODAY}/${BACKFILE} ]; then
continue
fi
pg_dump -U postgres ${DBNAME} \
| bzip2 -c -9 \
> ${BACKUP}/${YEARMONTH}/${TODAY}/${BACKFILE}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment