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