~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/bin/pg_dump/pg_backup.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *              $PostgreSQL$
 
19
 *
 
20
 *-------------------------------------------------------------------------
 
21
 */
 
22
 
 
23
#ifndef PG_BACKUP_H
 
24
#define PG_BACKUP_H
 
25
 
 
26
#include "postgres_fe.h"
 
27
 
 
28
#include "pg_dump.h"
 
29
 
 
30
#include "libpq-fe.h"
 
31
 
 
32
 
 
33
#define atooid(x)  ((Oid) strtoul((x), NULL, 10))
 
34
#define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ?  1 : 0) )
 
35
#define oideq(x,y) ( (x) == (y) )
 
36
#define oidle(x,y) ( (x) <= (y) )
 
37
#define oidge(x,y) ( (x) >= (y) )
 
38
#define oidzero(x) ( (x) == 0 )
 
39
 
 
40
enum trivalue
 
41
{
 
42
        TRI_DEFAULT,
 
43
        TRI_NO,
 
44
        TRI_YES
 
45
};
 
46
 
 
47
typedef enum _archiveFormat
 
48
{
 
49
        archUnknown = 0,
 
50
        archCustom = 1,
 
51
        archFiles = 2,
 
52
        archTar = 3,
 
53
        archNull = 4
 
54
} ArchiveFormat;
 
55
 
 
56
typedef enum _archiveMode
 
57
{
 
58
        archModeAppend,
 
59
        archModeWrite,
 
60
        archModeRead
 
61
} ArchiveMode;
 
62
 
 
63
typedef enum _teSection
 
64
{
 
65
        SECTION_NONE = 1,                       /* COMMENTs, ACLs, etc; can be anywhere */
 
66
        SECTION_PRE_DATA,                       /* stuff to be processed before data */
 
67
        SECTION_DATA,                           /* TABLE DATA, BLOBS, BLOB COMMENTS */
 
68
        SECTION_POST_DATA                       /* stuff to be processed after data */
 
69
} teSection;
 
70
 
 
71
/*
 
72
 *      We may want to have some more user-readable data, but in the mean
 
73
 *      time this gives us some abstraction and type checking.
 
74
 */
 
75
typedef struct _Archive
 
76
{
 
77
        int                     verbose;
 
78
        char       *remoteVersionStr;           /* server's version string */
 
79
        int                     remoteVersion;  /* same in numeric form */
 
80
 
 
81
        int                     minRemoteVersion;               /* allowable range */
 
82
        int                     maxRemoteVersion;
 
83
 
 
84
        /* info needed for string escaping */
 
85
        int                     encoding;               /* libpq code for client_encoding */
 
86
        bool            std_strings;    /* standard_conforming_strings */
 
87
 
 
88
        /* error handling */
 
89
        bool            exit_on_error;  /* whether to exit on SQL errors... */
 
90
        int                     n_errors;               /* number of errors (if no die) */
 
91
 
 
92
        /* The rest is private */
 
93
} Archive;
 
94
 
 
95
typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
 
96
 
 
97
typedef struct _restoreOptions
 
98
{
 
99
        int                     create;                 /* Issue commands to create the database */
 
100
        int                     noOwner;                /* Don't try to match original object owner */
 
101
        int                     noTablespace;   /* Don't issue tablespace-related commands */
 
102
        int                     disable_triggers;               /* disable triggers during data-only
 
103
                                                                                 * restore */
 
104
        int                     use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
 
105
                                                                 * instead of OWNER TO */
 
106
        char       *superuser;          /* Username to use as superuser */
 
107
        char       *use_role;           /* Issue SET ROLE to this */
 
108
        int                     dataOnly;
 
109
        int                     dropSchema;
 
110
        char       *filename;
 
111
        int                     schemaOnly;
 
112
        int                     verbose;
 
113
        int                     aclsSkip;
 
114
        int                     tocSummary;
 
115
        char       *tocFile;
 
116
        int                     format;
 
117
        char       *formatName;
 
118
 
 
119
        int                     selTypes;
 
120
        int                     selIndex;
 
121
        int                     selFunction;
 
122
        int                     selTrigger;
 
123
        int                     selTable;
 
124
        char       *indexNames;
 
125
        char       *functionNames;
 
126
        char       *tableNames;
 
127
        char       *schemaNames;
 
128
        char       *triggerNames;
 
129
 
 
130
        int                     useDB;
 
131
        char       *dbname;
 
132
        char       *pgport;
 
133
        char       *pghost;
 
134
        char       *username;
 
135
        int                     noDataForFailedTables;
 
136
        enum trivalue promptPassword;
 
137
        int                     exit_on_error;
 
138
        int                     compression;
 
139
        int                     suppressDumpWarnings;   /* Suppress output of WARNING entries
 
140
                                                                                 * to stderr */
 
141
        bool            single_txn;
 
142
        int                     number_of_jobs;
 
143
 
 
144
        bool       *idWanted;           /* array showing which dump IDs to emit */
 
145
} RestoreOptions;
 
146
 
 
147
/*
 
148
 * Main archiver interface.
 
149
 */
 
150
 
 
151
extern void
 
152
exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
 
153
__attribute__((format(printf, 3, 4)));
 
154
 
 
155
 
 
156
/* Lets the archive know we have a DB connection to shutdown if it dies */
 
157
 
 
158
PGconn *ConnectDatabase(Archive *AH,
 
159
                                const char *dbname,
 
160
                                const char *pghost,
 
161
                                const char *pgport,
 
162
                                const char *username,
 
163
                                enum trivalue prompt_password);
 
164
 
 
165
/* Called to add a TOC entry */
 
166
extern void ArchiveEntry(Archive *AHX,
 
167
                         CatalogId catalogId, DumpId dumpId,
 
168
                         const char *tag,
 
169
                         const char *namespace, const char *tablespace,
 
170
                         const char *owner, bool withOids,
 
171
                         const char *desc, teSection section,
 
172
                         const char *defn,
 
173
                         const char *dropStmt, const char *copyStmt,
 
174
                         const DumpId *deps, int nDeps,
 
175
                         DataDumperPtr dumpFn, void *dumpArg);
 
176
 
 
177
/* Called to write *data* to the archive */
 
178
extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
 
179
 
 
180
extern int      StartBlob(Archive *AH, Oid oid);
 
181
extern int      EndBlob(Archive *AH, Oid oid);
 
182
 
 
183
extern void CloseArchive(Archive *AH);
 
184
 
 
185
extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
 
186
 
 
187
/* Open an existing archive */
 
188
extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
 
189
 
 
190
/* Create a new archive */
 
191
extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
 
192
                          const int compression, ArchiveMode mode);
 
193
 
 
194
/* The --list option */
 
195
extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
 
196
 
 
197
extern RestoreOptions *NewRestoreOptions(void);
 
198
 
 
199
/* Rearrange and filter TOC entries */
 
200
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
 
201
extern void InitDummyWantedList(Archive *AHX, RestoreOptions *ropt);
 
202
 
 
203
/* Convenience functions used only when writing DATA */
 
204
extern int      archputs(const char *s, Archive *AH);
 
205
extern int
 
206
archprintf(Archive *AH, const char *fmt,...)
 
207
/* This extension allows gcc to check the format string */
 
208
__attribute__((format(printf, 2, 3)));
 
209
 
 
210
#define appendStringLiteralAH(buf,str,AH) \
 
211
        appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
 
212
 
 
213
#endif   /* PG_BACKUP_H */