00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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,
00067 SECTION_PRE_DATA,
00068 SECTION_DATA,
00069 SECTION_POST_DATA
00070 } teSection;
00071
00072
00073
00074
00075
00076 struct Archive
00077 {
00078 int verbose;
00079 char *remoteVersionStr;
00080 int remoteVersion;
00081
00082 int minRemoteVersion;
00083 int maxRemoteVersion;
00084
00085 int numWorkers;
00086 char *sync_snapshot_id;
00087
00088
00089
00090 int encoding;
00091 bool std_strings;
00092 char *use_role;
00093
00094
00095 bool exit_on_error;
00096 int n_errors;
00097
00098
00099 };
00100
00101 typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
00102
00103 typedef struct _restoreOptions
00104 {
00105 int createDB;
00106 int noOwner;
00107 int noTablespace;
00108 int disable_triggers;
00109
00110 int use_setsessauth;
00111
00112 int no_security_labels;
00113 char *superuser;
00114 char *use_role;
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;
00148
00149 bool single_txn;
00150
00151 bool *idWanted;
00152 } RestoreOptions;
00153
00154 typedef void (*SetupWorkerPtr) (Archive *AH, RestoreOptions *ropt);
00155
00156
00157
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
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
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
00194 extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
00195
00196
00197 extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
00198 const int compression, ArchiveMode mode,
00199 SetupWorkerPtr setupDumpWorker);
00200
00201
00202 extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
00203
00204 extern RestoreOptions *NewRestoreOptions(void);
00205
00206
00207 extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
00208
00209
00210 extern int archputs(const char *s, Archive *AH);
00211 extern int
00212 archprintf(Archive *AH, const char *fmt,...)
00213
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