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 "fe_utils/simple_list.h" 27 #include "libpq-fe.h" 28 29 30 typedef enum trivalue 31 { 32 TRI_DEFAULT, 33 TRI_NO, 34 TRI_YES 35 } trivalue; 36 37 typedef enum _archiveFormat 38 { 39 archUnknown = 0, 40 archCustom = 1, 41 archTar = 3, 42 archNull = 4, 43 archDirectory = 5 44 } ArchiveFormat; 45 46 typedef enum _archiveMode 47 { 48 archModeAppend, 49 archModeWrite, 50 archModeRead 51 } ArchiveMode; 52 53 typedef enum _teSection 54 { 55 SECTION_NONE = 1, /* COMMENTs, ACLs, etc; can be anywhere */ 56 SECTION_PRE_DATA, /* stuff to be processed before data */ 57 SECTION_DATA, /* TABLE DATA, BLOBS, BLOB COMMENTS */ 58 SECTION_POST_DATA /* stuff to be processed after data */ 59 } teSection; 60 61 /* Parameters needed by ConnectDatabase; same for dump and restore */ 62 typedef struct _connParams 63 { 64 /* These fields record the actual command line parameters */ 65 char *dbname; /* this may be a connstring! */ 66 char *pgport; 67 char *pghost; 68 char *username; 69 trivalue promptPassword; 70 /* If not NULL, this overrides the dbname obtained from command line */ 71 /* (but *only* the DB name, not anything else in the connstring) */ 72 char *override_dbname; 73 } ConnParams; 74 75 typedef struct _restoreOptions 76 { 77 int createDB; /* Issue commands to create the database */ 78 int noOwner; /* Don't try to match original object owner */ 79 int noTablespace; /* Don't issue tablespace-related commands */ 80 int disable_triggers; /* disable triggers during data-only 81 * restore */ 82 int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands 83 * instead of OWNER TO */ 84 char *superuser; /* Username to use as superuser */ 85 char *use_role; /* Issue SET ROLE to this */ 86 int dropSchema; 87 int disable_dollar_quoting; 88 int dump_inserts; 89 int column_inserts; 90 int if_exists; 91 int no_security_labels; /* Skip security label entries */ 92 int strict_names; 93 94 const char *filename; 95 int dataOnly; 96 int schemaOnly; 97 int dumpSections; 98 int verbose; 99 int aclsSkip; 100 const char *lockWaitTimeout; 101 int include_everything; 102 103 int tocSummary; 104 char *tocFile; 105 int format; 106 char *formatName; 107 108 int selTypes; 109 int selIndex; 110 int selFunction; 111 int selTrigger; 112 int selTable; 113 SimpleStringList indexNames; 114 SimpleStringList functionNames; 115 SimpleStringList schemaNames; 116 SimpleStringList triggerNames; 117 SimpleStringList tableNames; 118 119 int useDB; 120 ConnParams cparams; /* parameters to use if useDB */ 121 122 int noDataForFailedTables; 123 int exit_on_error; 124 int compression; 125 int suppressDumpWarnings; /* Suppress output of WARNING entries 126 * to stderr */ 127 bool single_txn; 128 129 bool *idWanted; /* array showing which dump IDs to emit */ 130 int enable_row_security; 131 int binary_upgrade; 132 } RestoreOptions; 133 134 typedef struct _dumpOptions 135 { 136 ConnParams cparams; 137 138 bool oids; 139 140 int binary_upgrade; 141 142 /* various user-settable parameters */ 143 bool schemaOnly; 144 bool dataOnly; 145 int dumpSections; /* bitmask of chosen sections */ 146 bool aclsSkip; 147 const char *lockWaitTimeout; 148 149 /* flags for various command-line long options */ 150 int disable_dollar_quoting; 151 int dump_inserts; 152 int column_inserts; 153 int if_exists; 154 int no_security_labels; 155 int no_synchronized_snapshots; 156 int no_unlogged_table_data; 157 int serializable_deferrable; 158 int quote_all_identifiers; 159 int disable_triggers; 160 int outputNoTablespaces; 161 int use_setsessauth; 162 int enable_row_security; 163 164 /* default, if no "inclusion" switches appear, is to dump everything */ 165 bool include_everything; 166 167 int outputClean; 168 int outputCreateDB; 169 bool outputBlobs; 170 int outputNoOwner; 171 char *outputSuperuser; 172 } DumpOptions; 173 174 /* 175 * We may want to have some more user-readable data, but in the mean 176 * time this gives us some abstraction and type checking. 177 */ 178 typedef struct Archive 179 { 180 DumpOptions *dopt; /* options, if dumping */ 181 RestoreOptions *ropt; /* options, if restoring */ 182 183 int verbose; 184 char *remoteVersionStr; /* server's version string */ 185 int remoteVersion; /* same in numeric form */ 186 bool isStandby; /* is server a standby node */ 187 188 int minRemoteVersion; /* allowable range */ 189 int maxRemoteVersion; 190 191 int numWorkers; /* number of parallel processes */ 192 char *sync_snapshot_id; /* sync snapshot id for parallel 193 * operation */ 194 195 /* info needed for string escaping */ 196 int encoding; /* libpq code for client_encoding */ 197 bool std_strings; /* standard_conforming_strings */ 198 199 /* other important stuff */ 200 char *searchpath; /* search_path to set during restore */ 201 char *use_role; /* Issue SET ROLE to this */ 202 203 /* error handling */ 204 bool exit_on_error; /* whether to exit on SQL errors... */ 205 int n_errors; /* number of errors (if no die) */ 206 207 /* The rest is private */ 208 } Archive; 209 210 211 /* 212 * pg_dump uses two different mechanisms for identifying database objects: 213 * 214 * CatalogId represents an object by the tableoid and oid of its defining 215 * entry in the system catalogs. We need this to interpret pg_depend entries, 216 * for instance. 217 * 218 * DumpId is a simple sequential integer counter assigned as dumpable objects 219 * are identified during a pg_dump run. We use DumpId internally in preference 220 * to CatalogId for two reasons: it's more compact, and we can assign DumpIds 221 * to "objects" that don't have a separate CatalogId. For example, it is 222 * convenient to consider a table, its data, and its ACL as three separate 223 * dumpable "objects" with distinct DumpIds --- this lets us reason about the 224 * order in which to dump these things. 225 */ 226 227 typedef struct 228 { 229 Oid tableoid; 230 Oid oid; 231 } CatalogId; 232 233 typedef int DumpId; 234 235 #define InvalidDumpId 0 236 237 /* 238 * Function pointer prototypes for assorted callback methods. 239 */ 240 241 typedef int (*DataDumperPtr) (Archive *AH, void *userArg); 242 243 typedef void (*SetupWorkerPtr) (Archive *AH); 244 245 /* 246 * Main archiver interface. 247 */ 248 249 extern void ConnectDatabase(Archive *AHX, 250 const ConnParams *cparams, 251 bool isReconnect); 252 extern void DisconnectDatabase(Archive *AHX); 253 extern PGconn *GetConnection(Archive *AHX); 254 255 /* Called to add a TOC entry */ 256 extern void ArchiveEntry(Archive *AHX, 257 CatalogId catalogId, DumpId dumpId, 258 const char *tag, 259 const char *namespace, const char *tablespace, 260 const char *owner, bool withOids, 261 const char *desc, teSection section, 262 const char *defn, 263 const char *dropStmt, const char *copyStmt, 264 const DumpId *deps, int nDeps, 265 DataDumperPtr dumpFn, void *dumpArg); 266 267 /* Called to write *data* to the archive */ 268 extern void WriteData(Archive *AH, const void *data, size_t dLen); 269 270 extern int StartBlob(Archive *AH, Oid oid); 271 extern int EndBlob(Archive *AH, Oid oid); 272 273 extern void CloseArchive(Archive *AH); 274 275 extern void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt); 276 277 extern void ProcessArchiveRestoreOptions(Archive *AH); 278 279 extern void RestoreArchive(Archive *AH); 280 281 /* Open an existing archive */ 282 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt); 283 284 /* Create a new archive */ 285 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt, 286 const int compression, ArchiveMode mode, 287 SetupWorkerPtr setupDumpWorker); 288 289 /* The --list option */ 290 extern void PrintTOCSummary(Archive *AH); 291 292 extern RestoreOptions *NewRestoreOptions(void); 293 294 extern DumpOptions *NewDumpOptions(void); 295 extern void InitDumpOptions(DumpOptions *opts); 296 extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt); 297 298 /* Rearrange and filter TOC entries */ 299 extern void SortTocFromFile(Archive *AHX); 300 301 /* Convenience functions used only when writing DATA */ 302 extern void archputs(const char *s, Archive *AH); 303 extern int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2, 3); 304 305 #define appendStringLiteralAH(buf,str,AH) \ 306 appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings) 307 308 #endif /* PG_BACKUP_H */ 309