Re: [GENERAL] Encoding problem using pg_dumpall

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cliff Pratt написа:
[...]
> You should be able to knock up a simple script in bash, perl or python
> to do what you want.
>
> Sort of like:
>
> Use 'psql' to get a list of the databases
> Sanitize the list.
> Loop through the list doing backup.
> At the end zip them all.
>
> With a little bit of trickery you should be able to zip them as you go.
[...]


#!/bin/bash

PSQL=/usr/bin/psql
PG_DUMP=/usr/bin/pg_dump
PG_DUMPALL=/usr/bin/pg_dumpall

if [ $# -eq 0 ] ; then
        BACKUPDIR=/home/db_backup/dumps
elif [ $# -ne 1 ] ; then
        echo -e "Usage: $0 [directory]\n"
        exit 1
else
        BACKUPDIR=$1
fi

if [ ! -d $BACKUPDIR ] ; then
        if ! mkdir $BACKUPDIR ; then
                echo -e "Cannot create backup directory: $BACKUPDIR\n"
                exit 2
        fi
fi


echo Starting at `date "+%Y-%m-%d %H:%M:%S"`
echo -e -n "Dumping globals...\t\t"
$PG_DUMPALL -U postgres --globals-only > $BACKUPDIR/pg_globals.sql
echo "done."

for db in `$PSQL -U postgres -d template1 -t -c "SELECT datname FROM pg_catalog.pg_database WHERE datname "\!"~ 'template(0|1)';"`
do
        echo -n -e "Dumping database $db...\t\t"
        $PG_DUMP -U postgres --format=c $db > $BACKUPDIR/$db.dump
        echo "done."
done
echo Ended at `date "+%Y-%m-%d %H:%M:%S"`


[...]


-- 
Milen A. Radev


-- 
Sent via pgsql-admin mailing list (pgsql-admin@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux