]> granicus.if.org Git - postgresql/blob - src/bin/pg_dump/pg_backup.h
Add pg_dump -X no-data-for-failed-tables option to suppress loading data
[postgresql] / src / bin / pg_dump / pg_backup.h
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: pgsql/src/bin/pg_dump/pg_backup.h,v 1.42 2006/08/01 18:21:44 momjian Exp $
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 typedef enum _archiveFormat
41 {
42         archUnknown = 0,
43         archCustom = 1,
44         archFiles = 2,
45         archTar = 3,
46         archNull = 4
47 } ArchiveFormat;
48
49 /*
50  *      We may want to have some more user-readable data, but in the mean
51  *      time this gives us some abstraction and type checking.
52  */
53 typedef struct _Archive
54 {
55         int                     verbose;
56         char       *remoteVersionStr;           /* server's version string */
57         int                     remoteVersion;  /* same in numeric form */
58
59         int                     minRemoteVersion;               /* allowable range */
60         int                     maxRemoteVersion;
61
62         /* info needed for string escaping */
63         int                     encoding;               /* libpq code for client_encoding */
64         bool            std_strings;    /* standard_conforming_strings */
65
66         /* error handling */
67         bool            exit_on_error;  /* whether to exit on SQL errors... */
68         int                     n_errors;               /* number of errors (if no die) */
69
70         /* The rest is private */
71 } Archive;
72
73 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
74
75 typedef struct _restoreOptions
76 {
77         int                     create;                 /* Issue commands to create the database */
78         int                     noOwner;                /* Don't try to match original object owner */
79         int                     disable_triggers;               /* disable triggers during data-only
80                                                                                  * restore */
81         int                     use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
82                                                                  * instead of OWNER TO */
83         char       *superuser;          /* Username to use as superuser */
84         int                     dataOnly;
85         int                     dropSchema;
86         char       *filename;
87         int                     schemaOnly;
88         int                     verbose;
89         int                     aclsSkip;
90         int                     tocSummary;
91         char       *tocFile;
92         int                     format;
93         char       *formatName;
94
95         int                     selTypes;
96         int                     selIndex;
97         int                     selFunction;
98         int                     selTrigger;
99         int                     selTable;
100         char       *indexNames;
101         char       *functionNames;
102         char       *tableNames;
103         char       *schemaNames;
104         char       *triggerNames;
105
106         int                     useDB;
107         char       *dbname;
108         char       *pgport;
109         char       *pghost;
110         char       *username;
111         int                     ignoreVersion;
112         int                     noDataForFailedTables;
113         int                     requirePassword;
114         int                     exit_on_error;
115
116         bool       *idWanted;
117         bool            limitToList;
118         int                     compression;
119
120         int                     suppressDumpWarnings;   /* Suppress output of WARNING entries
121                                                                                  * to stderr */
122     bool        single_txn;
123
124 } RestoreOptions;
125
126 /*
127  * Main archiver interface.
128  */
129
130 extern void
131 exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
132 __attribute__((format(printf, 3, 4)));
133
134
135 /* Lets the archive know we have a DB connection to shutdown if it dies */
136
137 PGconn *ConnectDatabase(Archive *AH,
138                                 const char *dbname,
139                                 const char *pghost,
140                                 const char *pgport,
141                                 const char *username,
142                                 const int reqPwd,
143                                 const int ignoreVersion);
144
145
146 /* Called to add a TOC entry */
147 extern void ArchiveEntry(Archive *AHX,
148                          CatalogId catalogId, DumpId dumpId,
149                          const char *tag,
150                          const char *namespace, const char *tablespace,
151                          const char *owner, bool withOids,
152                          const char *desc, const char *defn,
153                          const char *dropStmt, const char *copyStmt,
154                          const DumpId *deps, int nDeps,
155                          DataDumperPtr dumpFn, void *dumpArg);
156
157 /* Called to write *data* to the archive */
158 extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
159
160 extern int      StartBlob(Archive *AH, Oid oid);
161 extern int      EndBlob(Archive *AH, Oid oid);
162
163 extern void CloseArchive(Archive *AH);
164
165 extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
166
167 /* Open an existing archive */
168 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
169
170 /* Create a new archive */
171 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
172                           const int compression);
173
174 /* The --list option */
175 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
176
177 extern RestoreOptions *NewRestoreOptions(void);
178
179 /* Rearrange TOC entries */
180 extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
181
182 /* Convenience functions used only when writing DATA */
183 extern int      archputs(const char *s, Archive *AH);
184 extern int
185 archprintf(Archive *AH, const char *fmt,...)
186 /* This extension allows gcc to check the format string */
187 __attribute__((format(printf, 2, 3)));
188
189 #define appendStringLiteralAH(buf,str,AH) \
190         appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
191
192 #endif   /* PG_BACKUP_H */