Skip to content

Commit 500b62b

Browse files
committed
pg_dump patch from Philip Warner
1 parent 20c01ef commit 500b62b

File tree

14 files changed

+3882
-388
lines changed

14 files changed

+3882
-388
lines changed

doc/TODO.detail/function

Lines changed: 519 additions & 0 deletions
Large diffs are not rendered by default.

src/bin/pg_dump/Makefile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.17 2000/07/03 16:35:39 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.18 2000/07/04 14:25:26 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/bin/pg_dump
1212
top_builddir = ../../..
1313
include ../../Makefile.global
1414

15-
OBJS= pg_dump.o common.o $(STRDUP)
15+
OBJS= pg_backup_archiver.o pg_backup_custom.o pg_backup_files.o \
16+
pg_backup_plain_text.o $(STRDUP)
1617

1718
CFLAGS+= -I$(LIBPQDIR)
19+
LDFLAGS+= -lz
1820

21+
all: submake pg_dump$(X) pg_restore$(X)
1922

20-
all: submake pg_dump pg_dumpall
23+
pg_dump$(X): pg_dump.o common.o $(OBJS) $(LIBPQDIR)/libpq.a
24+
$(CC) $(CFLAGS) -o $@ pg_dump.o common.o $(OBJS) $(LIBPQ) $(LDFLAGS)
2125

22-
pg_dump: $(OBJS) $(LIBPQDIR)/libpq.a
23-
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBPQ) $(LDFLAGS)
24-
25-
pg_dumpall: pg_dumpall.sh
26-
sed -e 's:__VERSION__:$(VERSION):g' \
27-
-e 's:__MULTIBYTE__:$(MULTIBYTE):g' \
28-
-e 's:__bindir__:$(bindir):g' \
29-
< $< > $@
26+
pg_restore$(X): pg_restore.o $(OBJS) $(LIBPQDIR)/libpq.a
27+
$(CC) $(CFLAGS) -o $@ pg_restore.o $(OBJS) $(LIBPQ) $(LDFLAGS)
3028

3129
../../utils/strdup.o:
3230
$(MAKE) -C ../../utils strdup.o
@@ -37,6 +35,7 @@ submake:
3735

3836
install: all installdirs
3937
$(INSTALL_PROGRAM) pg_dump$(X) $(bindir)/pg_dump$(X)
38+
$(INSTALL_PROGRAM) pg_restore$(X) $(bindir)/pg_restore$(X)
4039
$(INSTALL_SCRIPT) pg_dumpall $(bindir)/pg_dumpall
4140
$(INSTALL_SCRIPT) pg_upgrade $(bindir)/pg_upgrade
4241

@@ -50,7 +49,7 @@ depend dep:
5049
$(CC) -MM $(CFLAGS) *.c >depend
5150

5251
clean distclean maintainer-clean:
53-
rm -f pg_dump$(X) $(OBJS) pg_dumpall
52+
rm -f pg_dump$(X) pg_restore$(X) $(OBJS) pg_dump.o common.o pg_restore.o
5453

5554
ifeq (depend,$(wildcard depend))
5655
include depend

src/bin/pg_dump/README

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Notes on pg_dump
2+
================
3+
4+
pg_dump, by default, still outputs text files.
5+
6+
pg_dumpall forces all pg_dump output to be text, since it also outputs text into the same output stream.
7+
8+
The plain text output format can not be used as input into pg_restore.
9+
10+
11+
To dump a database into the next custom format, type:
12+
13+
pg_dump <db-name> -Fc > <backup-file>
14+
15+
To restore, try
16+
17+
To list contents:
18+
19+
pg_restore -l <backup-file> | less
20+
21+
or to list tables:
22+
23+
pg_restore <backup-file> --table | less
24+
25+
or to list in a differnet orderL
26+
27+
pg_restore <backup-file> -l --oid --rearrange | less
28+
29+
Once you are happy with the list, just remove the '-l', and an SQL script will be output.
30+
31+
32+
You can also dump a listing:
33+
34+
pg_restore -l <backup-file> > toc.lis
35+
or
36+
pg_restore -l <backup-file> -f toc.lis
37+
38+
edit it, and rearrange the lines (or delete some):
39+
40+
vi toc.lis
41+
42+
then use it to restore selected items:
43+
44+
pg_restore <backup-file> --use=toc.lis -l | less
45+
46+
When you like the list, type
47+
48+
pg_restore backup.bck --use=toc.lis > script.sql
49+
50+
or, simply:
51+
52+
createdb newdbname
53+
pg_restore backup.bck --use=toc.lis | psql newdbname
54+
55+
56+
Philip Warner, 3-Jul-2000
57+
pjw@rhyme.com.au
58+
59+
60+

src/bin/pg_dump/common.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.43 2000/06/14 18:17:50 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.44 2000/07/04 14:25:27 momjian Exp $
1212
*
1313
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1414
*
@@ -232,10 +232,13 @@ strInArray(const char *pattern, char **arr, int arr_size)
232232
*/
233233

234234
TableInfo *
235-
dumpSchema(FILE *fout,
236-
int *numTablesPtr,
237-
const char *tablename,
238-
const bool aclsSkip)
235+
dumpSchema(Archive *fout,
236+
int *numTablesPtr,
237+
const char *tablename,
238+
const bool aclsSkip,
239+
const bool oids,
240+
const bool schemaOnly,
241+
const bool dataOnly)
239242
{
240243
int numTypes;
241244
int numFuncs;
@@ -290,7 +293,7 @@ dumpSchema(FILE *fout,
290293
g_comment_start, g_comment_end);
291294
flagInhAttrs(tblinfo, numTables, inhinfo, numInherits);
292295

293-
if (!tablename && fout)
296+
if (!tablename && !dataOnly)
294297
{
295298
if (g_verbose)
296299
fprintf(stderr, "%s dumping out database comment %s\n",
@@ -306,40 +309,37 @@ dumpSchema(FILE *fout,
306309
dumpTypes(fout, finfo, numFuncs, tinfo, numTypes);
307310
}
308311

309-
if (fout)
310-
{
311-
if (g_verbose)
312-
fprintf(stderr, "%s dumping out tables %s\n",
313-
g_comment_start, g_comment_end);
314-
dumpTables(fout, tblinfo, numTables, inhinfo, numInherits,
315-
tinfo, numTypes, tablename, aclsSkip);
316-
}
312+
if (g_verbose)
313+
fprintf(stderr, "%s dumping out tables %s\n",
314+
g_comment_start, g_comment_end);
315+
dumpTables(fout, tblinfo, numTables, inhinfo, numInherits,
316+
tinfo, numTypes, tablename, aclsSkip, oids, schemaOnly, dataOnly);
317317

318-
if (!tablename && fout)
318+
if (!tablename && !dataOnly)
319319
{
320320
if (g_verbose)
321321
fprintf(stderr, "%s dumping out user-defined procedural languages %s\n",
322322
g_comment_start, g_comment_end);
323323
dumpProcLangs(fout, finfo, numFuncs, tinfo, numTypes);
324324
}
325325

326-
if (!tablename && fout)
326+
if (!tablename && !dataOnly)
327327
{
328328
if (g_verbose)
329329
fprintf(stderr, "%s dumping out user-defined functions %s\n",
330330
g_comment_start, g_comment_end);
331331
dumpFuncs(fout, finfo, numFuncs, tinfo, numTypes);
332332
}
333333

334-
if (!tablename && fout)
334+
if (!tablename && !dataOnly)
335335
{
336336
if (g_verbose)
337337
fprintf(stderr, "%s dumping out user-defined aggregates %s\n",
338338
g_comment_start, g_comment_end);
339339
dumpAggs(fout, agginfo, numAggregates, tinfo, numTypes);
340340
}
341341

342-
if (!tablename && fout)
342+
if (!tablename && !dataOnly)
343343
{
344344
if (g_verbose)
345345
fprintf(stderr, "%s dumping out user-defined operators %s\n",
@@ -363,7 +363,7 @@ dumpSchema(FILE *fout,
363363
*/
364364

365365
extern void
366-
dumpSchemaIdx(FILE *fout, const char *tablename,
366+
dumpSchemaIdx(Archive *fout, const char *tablename,
367367
TableInfo *tblinfo, int numTables)
368368
{
369369
int numIndices;

src/bin/pg_dump/pg_backup.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_backup.h
4+
*
5+
* Public interface to the pg_dump archiver routines.
6+
*
7+
* See the headers to pg_restore for more details.
8+
*
9+
* Copyright (c) 2000, Philip Warner
10+
* Rights are granted to use this software in any way so long
11+
* as this notice is not removed.
12+
*
13+
* The author is not responsible for loss or damages that may
14+
* result from it's use.
15+
*
16+
*
17+
* IDENTIFICATION
18+
*
19+
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
20+
*
21+
* Initial version.
22+
*
23+
*-------------------------------------------------------------------------
24+
*/
25+
26+
#ifndef PG_BACKUP__
27+
28+
#include "config.h"
29+
#include "c.h"
30+
31+
#define PG_BACKUP__
32+
33+
typedef enum _archiveFormat {
34+
archUnknown = 0,
35+
archCustom = 1,
36+
archFiles = 2,
37+
archTar = 3,
38+
archPlainText = 4
39+
} ArchiveFormat;
40+
41+
/*
42+
* We may want to have so user-readbale data, but in the mean
43+
* time this gives us some abstraction and type checking.
44+
*/
45+
typedef struct _Archive {
46+
/* Nothing here */
47+
} Archive;
48+
49+
typedef int (*DataDumperPtr)(Archive* AH, char* oid, void* userArg);
50+
51+
typedef struct _restoreOptions {
52+
int dataOnly;
53+
int dropSchema;
54+
char *filename;
55+
int schemaOnly;
56+
int verbose;
57+
int aclsSkip;
58+
int tocSummary;
59+
char *tocFile;
60+
int oidOrder;
61+
int origOrder;
62+
int rearrange;
63+
int format;
64+
char *formatName;
65+
66+
int selTypes;
67+
int selIndex;
68+
int selFunction;
69+
int selTrigger;
70+
int selTable;
71+
char *indexNames;
72+
char *functionNames;
73+
char *tableNames;
74+
char *triggerNames;
75+
76+
int *idWanted;
77+
int limitToList;
78+
int compression;
79+
80+
} RestoreOptions;
81+
82+
/*
83+
* Main archiver interface.
84+
*/
85+
86+
/* Called to add a TOC entry */
87+
extern void ArchiveEntry(Archive* AH, const char* oid, const char* name,
88+
const char* desc, const char* (deps[]), const char* defn,
89+
const char* dropStmt, const char* owner,
90+
DataDumperPtr dumpFn, void* dumpArg);
91+
92+
/* Called to write *data* to the archive */
93+
extern int WriteData(Archive* AH, const void* data, int dLen);
94+
95+
extern void CloseArchive(Archive* AH);
96+
97+
extern void RestoreArchive(Archive* AH, RestoreOptions *ropt);
98+
99+
/* Open an existing archive */
100+
extern Archive* OpenArchive(const char* FileSpec, ArchiveFormat fmt);
101+
102+
/* Create a new archive */
103+
extern Archive* CreateArchive(const char* FileSpec, ArchiveFormat fmt, int compression);
104+
105+
/* The --list option */
106+
extern void PrintTOCSummary(Archive* AH, RestoreOptions *ropt);
107+
108+
extern RestoreOptions* NewRestoreOptions(void);
109+
110+
/* Rearrange TOC entries */
111+
extern void MoveToStart(Archive* AH, char *oType);
112+
extern void MoveToEnd(Archive* AH, char *oType);
113+
extern void SortTocByOID(Archive* AH);
114+
extern void SortTocByID(Archive* AH);
115+
extern void SortTocFromFile(Archive* AH, RestoreOptions *ropt);
116+
117+
/* Convenience functions used only when writing DATA */
118+
extern int archputs(const char *s, Archive* AH);
119+
extern int archputc(const char c, Archive* AH);
120+
extern int archprintf(Archive* AH, const char *fmt, ...);
121+
122+
#endif
123+
124+
125+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy