Обсуждение: How do you backup functions only?

Поиск
Список
Период
Сортировка

How do you backup functions only?

От
"Andrew Walmsley"
Дата:
We have a reasonably sized postgres database where we want to make
coding changes to the functions within it.
Before we alter the functions, it would be a good idea to backup the
current functions in the database. The database itself is too large to
do a full backup every time we make a coding change.
We currently use the following script to backup (some of the) functions.

bash-3.00$ cat backup_phpcron.sh
DATE=`date "+%Y%m%d"`

if [ -r phpcron-$DATE.sql.gz ]
then
    echo "ABORTED phpcron-$DATE.sql.gz already exists"
    exit 1
fi

psql -At <<-'!' | gzip -c > phpcron-$DATE.sql.gz || exit 1
\df+ avail_oneway
\df+ avail_return
\df+ clear_flightdata
\df+ clear_flightdata_update
\df+ load_flights
\df+ load_flights_update
\df+ load_prices
\df+ load_prices_update
\df+ load_routes
\df+ prepare_avlpkgs
\df+ prepare_avlpkgs_update
!

This creates a non-restorable snapshot of the functions. Is there a way
to output the functions (only) so that they can be restored in one easy
operation if there is an error in the new code? An option to pg_dump
that I have missed perhaps?

Thanks in advance.

--
Andrew Walmsley
Software Development
Travel Technology Systems Ltd.
2 Nile Close, Riversway
Preston, PR2 2XU
Tel: 01772 766800
Fax: 01772 766801

(please note the new address and contact number)

This Email may contain information of a confidential and/or privileged
nature.
The information transmitted is intended only for the benefit of the
person or entity to which it is addressed and must not be copied or
forwarded without the sender's express permission.
This Email does not reflect the views or opinions of Travel Technology
Systems Ltd.
This Email is without prejudice.
This Email does not constitute an agreement either explicitly or
implicitly with Travel Technology Systems Ltd.

Re: How do you backup functions only?

От
Tom Lane
Дата:
"Andrew Walmsley" <andrew.walmsley@ttsltd.com> writes:
> This creates a non-restorable snapshot of the functions. Is there a way
> to output the functions (only) so that they can be restored in one easy
> operation if there is an error in the new code? An option to pg_dump
> that I have missed perhaps?

No, but I'd still recommend using "pg_dump -s -Fc" to backup the
complete database schema including the functions.  A semi-automated
way to extract just the functions from such a dump is to use
pg_restore -l, grep the output for FUNCTION, then feed the resulting
list into pg_restore -L.

            regards, tom lane