Thread: Restoring selected records from backup file

Restoring selected records from backup file

From
Piyush Lenka
Date:
hi,

1. How can we restore selected records from a plain text backup (backup.sql).
2. Is it possible using psql. If yes how

Thanks & Regards 
Piyush

Re: Restoring selected records from backup file

From
Daniel Staal
Date:
--As of March 2, 2012 3:44:46 PM +0530, Piyush Lenka is alleged to have
said:

> hi,
>
> 1. How can we restore selected records from a plain text backup
> (backup.sql).
> 2. Is it possible using psql. If yes how

--As for the rest, it is mine.

A plain text backup will just be a set of SQL commands.  You'll need to
isolate those commands that have the selected records, copy them out into a
new file, and then feed that file to psql.

If you are on a unix-like box, `grep` will be useful for this.

Note that there will probably be some SQL editing involved: the backup is
optimized for full-table restores, and therefore has multiple records per
statement, usually.  (Depending on options specified at the backup creation
time: If you are expecting this to be a common type of restore, it might be
a good idea to use the `--inserts` or even `--column-inserts` switch.
Either will slow down a full restore considerably, but would make this type
of restore easy.  See the docs for full details.)

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------