Created
March 18, 2014 11:27
-
-
Save tureki/9618245 to your computer and use it in GitHub Desktop.
Linux postgresql backup shell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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