Re: Using cp to back up a database?

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Larry Rosenman <ler(at)lerctr(dot)org>
Cc: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using cp to back up a database?
Date: 2017-10-09 14:01:03
Message-ID: CANu8Fiz5jNtm9y+iLj5HpJB7ZQmBdVDP2vbXi2M2hO_EBW5Hzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 9, 2017 at 9:51 AM, Larry Rosenman <ler(at)lerctr(dot)org> wrote:

> If you want a consistent database (you **REALLY** do), pg_dump is the
> correct tool.
>
>
>
> --
>
> Larry Rosenman http://www.lerctr.org/~ler
>
> Phone: +1 214-642-9640 <(214)%20642-9640> E-Mail:
> ler(at)lerctr(dot)org
>
> US Mail: 5708 Sabbia Drive, Round Rock, TX 78665
> <https://maps.google.com/?q=5708+Sabbia+Drive,+Round+Rock,+TX+78665&entry=gmail&source=g>
> -2106
>
>
>
>
>
> *From: *<pgsql-general-owner(at)postgresql(dot)org> on behalf of Ron Johnson <
> ron(dot)l(dot)johnson(at)cox(dot)net>
> *Date: *Monday, October 9, 2017 at 8:41 AM
> *To: *"pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
> *Subject: *[GENERAL] Using cp to back up a database?
>
>
>
> Hi,
>
> v8.4.20
>
> This is what the current backup script uses:
>
> /usr/bin/psql -U postgres -c "SELECT pg_start_backup('
> Incrementalbackup',true);"
>
> cp -r /var/lib/pgsql/data/* $dumpdir/data/
>
> /usr/bin/psql -U postgres template1 -c "SELECT pg_stop_backup();"
>
>
>
> Should it use rsync or pg_dump instead?
>
> Thanks
>
>
> --
>
> World Peace Through Nuclear Pacification
>
>
>Should it use rsync or pg_dump instead?

It is a matter of choice. What you are doing with the script is making a
backup of the entire PostgreSQL data file directory. That includes all
PostgreSQL system catalogs as well as user objects. A restore of your data
directory would be faster than a full restore of pg_dump as indexes and
constraints would not have to be recreated. However, it does not give you
the option to restore one or more selected objects.
pg_dump, on the other hand, gives you the flexibility of selecting what to
backup and what to restore. FWIW, I much prefer pg_dump.

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2017-10-09 14:09:39 Re: Using cp to back up a database?
Previous Message Larry Rosenman 2017-10-09 13:51:59 Re: Using cp to back up a database?