]> granicus.if.org Git - postgresql/blob - src/bin/pg_dump/pg_backup.h
Another pgindent run. Fixes enum indenting, and improves #endif
[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  *              $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.17 2001/10/28 06:25:58 momjian Exp $
19  *
20  * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
21  *
22  *      Initial version.
23  *
24  *
25  * Modifications - 28-Jul-2000 - pjw@rhyme.com.au (1.45)
26  *
27  *              Added --create, --no-owner, --superuser, --no-reconnect (pg_dump & pg_restore)
28  *              Added code to dump 'Create Schema' statement (pg_dump)
29  *              Don't bother to disable/enable triggers if we don't have a superuser (pg_restore)
30  *              Cleaned up code for reconnecting to database.
31  *              Force a reconnect as superuser before enabling/disabling triggers.
32  *
33  * Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
34  *              Added & Removed --throttle (pg_dump)
35  *              Fixed minor bug in language dumping code: expbuffres were not being reset.
36  *              Fixed version number initialization in _allocAH (pg_backup_archiver.c)
37  *              Added second connection when restoring BLOBs to allow temp. table to survive
38  *              (db reconnection causes temp tables to be lost).
39  *
40  *-------------------------------------------------------------------------
41  */
42
43 #ifndef PG_BACKUP__
44 #define PG_BACKUP__
45
46 #include "postgres_fe.h"
47
48 #include "libpq-fe.h"
49
50 #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
51 #define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ?  1 : 0) )
52 #define oideq(x,y) ( (x) == (y) )
53 #define oidle(x,y) ( (x) <= (y) )
54 #define oidge(x,y) ( (x) >= (y) )
55 #define oidzero(x) ( (x) == 0 )
56
57 typedef enum _archiveFormat
58 {
59         archUnknown = 0,
60         archCustom = 1,
61         archFiles = 2,
62         archTar = 3,
63         archNull = 4
64 } ArchiveFormat;
65
66 /*
67  *      We may want to have so user-readbale data, but in the mean
68  *      time this gives us some abstraction and type checking.
69  */
70 typedef struct _Archive
71 {
72         int                     verbose;
73         int                     remoteVersion;
74         int                     minRemoteVersion;
75         int                     maxRemoteVersion;
76         /* The rest is private */
77 } Archive;
78
79 typedef int (*DataDumperPtr) (Archive *AH, char *oid, void *userArg);
80
81 typedef struct _restoreOptions
82 {
83         int                     create;                 /* Issue commands to create the database */
84         int                     noOwner;                /* Don't reconnect to database to match
85                                                                  * original object owner */
86         int                     noReconnect;    /* Don't reconnect to database under any
87                                                                  * cirsumstances */
88         int                     use_setsessauth;/* use SET SESSSION AUTHORIZATION instead
89                                                                  * of \connect */
90         char       *superuser;          /* Username to use as superuser */
91         int                     dataOnly;
92         int                     dropSchema;
93         char       *filename;
94         int                     schemaOnly;
95         int                     verbose;
96         int                     aclsSkip;
97         int                     tocSummary;
98         char       *tocFile;
99         int                     oidOrder;
100         int                     origOrder;
101         int                     rearrange;
102         int                     format;
103         char       *formatName;
104
105         int                     selTypes;
106         int                     selIndex;
107         int                     selFunction;
108         int                     selTrigger;
109         int                     selTable;
110         char       *indexNames;
111         char       *functionNames;
112         char       *tableNames;
113         char       *triggerNames;
114
115         int                     useDB;
116         char       *dbname;
117         char       *pgport;
118         char       *pghost;
119         char       *username;
120         int                     ignoreVersion;
121         int                     requirePassword;
122
123         int                *idWanted;
124         int                     limitToList;
125         int                     compression;
126
127         int                     suppressDumpWarnings;   /* Suppress output of WARNING
128                                                                                  * entries to stderr */
129 } RestoreOptions;
130
131 /*
132  * Main archiver interface.
133  */
134
135 extern void
136 exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
137 __attribute__((format(printf, 3, 4)));
138
139 extern char *
140                         simple_prompt(const char *prompt, int maxlen, bool echo);
141
142 /* Lets the archibe know we have a DB connection to shutdown if it dies */
143
144 PGconn *ConnectDatabase(Archive *AH,
145                                 const char *dbname,
146                                 const char *pghost,
147                                 const char *pgport,
148                                 const char *username,
149                                 const int reqPwd,
150                                 const int ignoreVersion);
151
152
153 /* Called to add a TOC entry */
154 extern void ArchiveEntry(Archive *AH, const char *oid, const char *name,
155                          const char *desc, const char *((*deps)[]), const char *defn,
156                    const char *dropStmt, const char *copyStmt, const char *owner,
157                          DataDumperPtr dumpFn, void *dumpArg);
158
159 /* Called to write *data* to the archive */
160 extern int      WriteData(Archive *AH, const void *data, int dLen);
161
162 /*
163 extern int      StartBlobs(Archive* AH);
164 extern int      EndBlobs(Archive* AH);
165 */
166 extern int      StartBlob(Archive *AH, Oid oid);
167 extern int      EndBlob(Archive *AH, Oid oid);
168
169 extern void CloseArchive(Archive *AH);
170
171 extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
172
173 /* Open an existing archive */
174 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
175
176 /* Create a new archive */
177 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
178                           const int compression);
179
180 /* The --list option */
181 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
182
183 extern RestoreOptions *NewRestoreOptions(void);
184
185 /* Rearrange TOC entries */
186 extern void MoveToStart(Archive *AH, char *oType);
187 extern void MoveToEnd(Archive *AH, char *oType);
188 extern void SortTocByOID(Archive *AH);
189 extern void SortTocByID(Archive *AH);
190 extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
191
192 /* Convenience functions used only when writing DATA */
193 extern int      archputs(const char *s, Archive *AH);
194 extern int      archputc(const char c, Archive *AH);
195 extern int
196 archprintf(Archive *AH, const char *fmt,...)
197 /* This extension allows gcc to check the format string */
198 __attribute__((format(printf, 2, 3)));
199
200 #endif