Just somewhere to keep my notes while I'm playing.

Friday, October 24, 2008

Backup and Recovery Part 2

To Perform a simple recovery of a single database table from your previous backup.

Perform the backup!
timj@dell-desktop:~$ pg_dump -i -h localhost -U timj -F c -b -v -f /var/tmp/mybackup testdb
pg_dump: reading schemas
pg_dump: reading user-defined functions
pg_dump: reading user-defined types
pg_dump: reading procedural languages
pg_dump: reading user-defined aggregate functions
pg_dump: reading user-defined operators
pg_dump: reading user-defined operator classes
pg_dump: reading user-defined text search parsers
pg_dump: reading user-defined text search templates
pg_dump: reading user-defined text search dictionaries
pg_dump: reading user-defined text search configurations
pg_dump: reading user-defined operator families
pg_dump: reading user-defined conversions
pg_dump: reading user-defined tables
pg_dump: reading table inheritance information
pg_dump: reading rewrite rules
pg_dump: reading type casts
pg_dump: finding inheritance relationships
pg_dump: reading column info for interesting tables
pg_dump: finding the columns and types of table "numbers"
pg_dump: finding the columns and types of table "myuser"
pg_dump: flagging inherited columns in subtables
pg_dump: reading indexes
pg_dump: reading constraints
pg_dump: reading triggers
pg_dump: reading dependency data
pg_dump: saving encoding = UTF8
pg_dump: saving standard_conforming_strings = off
pg_dump: saving database definition
pg_dump: dumping contents of table myuser
pg_dump: dumping contents of table numbers
timj@dell-desktop:~$ ls -trl /var/tmp/mybackup
-rw-r--r-- 1 timj timj 2261 2008-10-24 17:11 /var/tmp/mybackup
timj@dell-desktop:~$

At this stage we lost the 'numbers' table.
drop table number;

So we need to recover it

timj@dell-desktop:~$ pg_restore -c -h localhost -U timj -v /var/tmp/mybackup -d testdb -t numbers
pg_restore: connecting to database for restore
pg_restore: dropping TABLE numbers
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 1466; 1259 24589 TABLE numbers timj
pg_restore: [archiver (db)] could not execute query: ERROR: table "numbers" does not exist
Command was:
DROP TABLE public.numbers;
pg_restore: creating TABLE numbers
pg_restore: restoring data for table "numbers"
pg_restore: setting owner and privileges for TABLE numbers
WARNING: errors ignored on restore: 1
timj@dell-desktop:~$

No comments: