Автоматический бэкап Postgres


Файл: save_pgsql.sh

#!/bin/bash

pg="/usr/bin/pg_dump -U postgres"
date=`date "+%Y-%m-%d"`
bakpath=/home/bak/pgsql/$date
file=`basename $0`
pidfile=/tmp/${file%%.sh}.run
gzip=/bin/gzip

if [ ! -e "$pidfile" ]
then
    echo $$ > $pidfile
    if [ ! -e "$bakpath" ]
    then
        mkdir -p "$bakpath"
    fi
    $pg tab2tab | $gzip > $bakpath/tab2tab.sql.gz
    rm $pidfile
fi