Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_backup.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pg_backup.h
00004  *
00005  *  Public interface to the pg_dump archiver routines.
00006  *
00007  *  See the headers to pg_restore for more details.
00008  *
00009  * Copyright (c) 2000, Philip Warner
00010  *      Rights are granted to use this software in any way so long
00011  *      as this notice is not removed.
00012  *
00013  *  The author is not responsible for loss or damages that may
00014  *  result from it's use.
00015  *
00016  *
00017  * IDENTIFICATION
00018  *      src/bin/pg_dump/pg_backup.h
00019  *
00020  *-------------------------------------------------------------------------
00021  */
00022 
00023 #ifndef PG_BACKUP_H
00024 #define PG_BACKUP_H
00025 
00026 #include "postgres_fe.h"
00027 
00028 #include "pg_dump.h"
00029 #include "dumputils.h"
00030 
00031 #include "libpq-fe.h"
00032 
00033 
00034 #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
00035 #define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ?  1 : 0) )
00036 #define oideq(x,y) ( (x) == (y) )
00037 #define oidle(x,y) ( (x) <= (y) )
00038 #define oidge(x,y) ( (x) >= (y) )
00039 #define oidzero(x) ( (x) == 0 )
00040 
00041 enum trivalue
00042 {
00043     TRI_DEFAULT,
00044     TRI_NO,
00045     TRI_YES
00046 };
00047 
00048 typedef enum _archiveFormat
00049 {
00050     archUnknown = 0,
00051     archCustom = 1,
00052     archTar = 3,
00053     archNull = 4,
00054     archDirectory = 5
00055 } ArchiveFormat;
00056 
00057 typedef enum _archiveMode
00058 {
00059     archModeAppend,
00060     archModeWrite,
00061     archModeRead
00062 } ArchiveMode;
00063 
00064 typedef enum _teSection
00065 {
00066     SECTION_NONE = 1,           /* COMMENTs, ACLs, etc; can be anywhere */
00067     SECTION_PRE_DATA,           /* stuff to be processed before data */
00068     SECTION_DATA,               /* TABLE DATA, BLOBS, BLOB COMMENTS */
00069     SECTION_POST_DATA           /* stuff to be processed after data */
00070 } teSection;
00071 
00072 /*
00073  *  We may want to have some more user-readable data, but in the mean
00074  *  time this gives us some abstraction and type checking.
00075  */
00076 struct Archive
00077 {
00078     int         verbose;
00079     char       *remoteVersionStr;       /* server's version string */
00080     int         remoteVersion;  /* same in numeric form */
00081 
00082     int         minRemoteVersion;       /* allowable range */
00083     int         maxRemoteVersion;
00084 
00085     int         numWorkers;     /* number of parallel processes */
00086     char       *sync_snapshot_id;       /* sync snapshot id for parallel
00087                                          * operation */
00088 
00089     /* info needed for string escaping */
00090     int         encoding;       /* libpq code for client_encoding */
00091     bool        std_strings;    /* standard_conforming_strings */
00092     char       *use_role;       /* Issue SET ROLE to this */
00093 
00094     /* error handling */
00095     bool        exit_on_error;  /* whether to exit on SQL errors... */
00096     int         n_errors;       /* number of errors (if no die) */
00097 
00098     /* The rest is private */
00099 };
00100 
00101 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
00102 
00103 typedef struct _restoreOptions
00104 {
00105     int         createDB;       /* Issue commands to create the database */
00106     int         noOwner;        /* Don't try to match original object owner */
00107     int         noTablespace;   /* Don't issue tablespace-related commands */
00108     int         disable_triggers;       /* disable triggers during data-only
00109                                          * restore */
00110     int         use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
00111                                  * instead of OWNER TO */
00112     int         no_security_labels;     /* Skip security label entries */
00113     char       *superuser;      /* Username to use as superuser */
00114     char       *use_role;       /* Issue SET ROLE to this */
00115     int         dropSchema;
00116     const char *filename;
00117     int         dataOnly;
00118     int         schemaOnly;
00119     int         dumpSections;
00120     int         verbose;
00121     int         aclsSkip;
00122     int         tocSummary;
00123     char       *tocFile;
00124     int         format;
00125     char       *formatName;
00126 
00127     int         selTypes;
00128     int         selIndex;
00129     int         selFunction;
00130     int         selTrigger;
00131     int         selTable;
00132     char       *indexNames;
00133     char       *functionNames;
00134     char       *schemaNames;
00135     char       *triggerNames;
00136     SimpleStringList tableNames;
00137 
00138     int         useDB;
00139     char       *dbname;
00140     char       *pgport;
00141     char       *pghost;
00142     char       *username;
00143     int         noDataForFailedTables;
00144     enum trivalue promptPassword;
00145     int         exit_on_error;
00146     int         compression;
00147     int         suppressDumpWarnings;   /* Suppress output of WARNING entries
00148                                          * to stderr */
00149     bool        single_txn;
00150 
00151     bool       *idWanted;       /* array showing which dump IDs to emit */
00152 } RestoreOptions;
00153 
00154 typedef void (*SetupWorkerPtr) (Archive *AH, RestoreOptions *ropt);
00155 
00156 /*
00157  * Main archiver interface.
00158  */
00159 
00160 extern void ConnectDatabase(Archive *AH,
00161                 const char *dbname,
00162                 const char *pghost,
00163                 const char *pgport,
00164                 const char *username,
00165                 enum trivalue prompt_password);
00166 extern void DisconnectDatabase(Archive *AHX);
00167 extern PGconn *GetConnection(Archive *AHX);
00168 
00169 /* Called to add a TOC entry */
00170 extern void ArchiveEntry(Archive *AHX,
00171              CatalogId catalogId, DumpId dumpId,
00172              const char *tag,
00173              const char *namespace, const char *tablespace,
00174              const char *owner, bool withOids,
00175              const char *desc, teSection section,
00176              const char *defn,
00177              const char *dropStmt, const char *copyStmt,
00178              const DumpId *deps, int nDeps,
00179              DataDumperPtr dumpFn, void *dumpArg);
00180 
00181 /* Called to write *data* to the archive */
00182 extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
00183 
00184 extern int  StartBlob(Archive *AH, Oid oid);
00185 extern int  EndBlob(Archive *AH, Oid oid);
00186 
00187 extern void CloseArchive(Archive *AH);
00188 
00189 extern void SetArchiveRestoreOptions(Archive *AH, RestoreOptions *ropt);
00190 
00191 extern void RestoreArchive(Archive *AH);
00192 
00193 /* Open an existing archive */
00194 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
00195 
00196 /* Create a new archive */
00197 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
00198               const int compression, ArchiveMode mode,
00199               SetupWorkerPtr setupDumpWorker);
00200 
00201 /* The --list option */
00202 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
00203 
00204 extern RestoreOptions *NewRestoreOptions(void);
00205 
00206 /* Rearrange and filter TOC entries */
00207 extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
00208 
00209 /* Convenience functions used only when writing DATA */
00210 extern int  archputs(const char *s, Archive *AH);
00211 extern int
00212 archprintf(Archive *AH, const char *fmt,...)
00213 /* This extension allows gcc to check the format string */
00214 __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
00215 
00216 #define appendStringLiteralAH(buf,str,AH) \
00217     appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
00218 
00219 #endif   /* PG_BACKUP_H */