1
/*-------------------------------------------------------------------------
5
* Public interface to the pg_dump archiver routines.
7
* See the headers to pg_restore for more details.
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.
13
* The author is not responsible for loss or damages that may
14
* result from it's use.
20
*-------------------------------------------------------------------------
26
#include "postgres_fe.h"
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 )
47
typedef enum _archiveFormat
56
typedef enum _archiveMode
63
typedef enum _teSection
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 */
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.
75
typedef struct _Archive
78
char *remoteVersionStr; /* server's version string */
79
int remoteVersion; /* same in numeric form */
81
int minRemoteVersion; /* allowable range */
84
/* info needed for string escaping */
85
int encoding; /* libpq code for client_encoding */
86
bool std_strings; /* standard_conforming_strings */
89
bool exit_on_error; /* whether to exit on SQL errors... */
90
int n_errors; /* number of errors (if no die) */
92
/* The rest is private */
95
typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
97
typedef struct _restoreOptions
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
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 */
135
int noDataForFailedTables;
136
enum trivalue promptPassword;
139
int suppressDumpWarnings; /* Suppress output of WARNING entries
144
bool *idWanted; /* array showing which dump IDs to emit */
148
* Main archiver interface.
152
exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
153
__attribute__((format(printf, 3, 4)));
156
/* Lets the archive know we have a DB connection to shutdown if it dies */
158
PGconn *ConnectDatabase(Archive *AH,
162
const char *username,
163
enum trivalue prompt_password);
165
/* Called to add a TOC entry */
166
extern void ArchiveEntry(Archive *AHX,
167
CatalogId catalogId, DumpId dumpId,
169
const char *namespace, const char *tablespace,
170
const char *owner, bool withOids,
171
const char *desc, teSection section,
173
const char *dropStmt, const char *copyStmt,
174
const DumpId *deps, int nDeps,
175
DataDumperPtr dumpFn, void *dumpArg);
177
/* Called to write *data* to the archive */
178
extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
180
extern int StartBlob(Archive *AH, Oid oid);
181
extern int EndBlob(Archive *AH, Oid oid);
183
extern void CloseArchive(Archive *AH);
185
extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
187
/* Open an existing archive */
188
extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
190
/* Create a new archive */
191
extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
192
const int compression, ArchiveMode mode);
194
/* The --list option */
195
extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
197
extern RestoreOptions *NewRestoreOptions(void);
199
/* Rearrange and filter TOC entries */
200
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
201
extern void InitDummyWantedList(Archive *AHX, RestoreOptions *ropt);
203
/* Convenience functions used only when writing DATA */
204
extern int archputs(const char *s, Archive *AH);
206
archprintf(Archive *AH, const char *fmt,...)
207
/* This extension allows gcc to check the format string */
208
__attribute__((format(printf, 2, 3)));
210
#define appendStringLiteralAH(buf,str,AH) \
211
appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
213
#endif /* PG_BACKUP_H */