postgresql/src/bin/pg_dump/pg_backup.h

221 lines
5.8 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* pg_backup.h
*
* Public interface to the pg_dump archiver routines.
*
* See the headers to pg_restore for more details.
*
* Copyright (c) 2000, Philip Warner
2001-03-22 05:01:46 +01:00
* Rights are granted to use this software in any way so long
* as this notice is not removed.
*
* The author is not responsible for loss or damages that may
* result from it's use.
*
*
* IDENTIFICATION
2010-09-20 22:08:53 +02:00
* src/bin/pg_dump/pg_backup.h
*
*-------------------------------------------------------------------------
*/
#ifndef PG_BACKUP_H
#define PG_BACKUP_H
#include "postgres_fe.h"
#include "pg_dump.h"
#include "dumputils.h"
#include "libpq-fe.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
#define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
#define oideq(x,y) ( (x) == (y) )
#define oidle(x,y) ( (x) <= (y) )
#define oidge(x,y) ( (x) >= (y) )
#define oidzero(x) ( (x) == 0 )
enum trivalue
{
TRI_DEFAULT,
TRI_NO,
TRI_YES
};
2001-03-22 05:01:46 +01:00
typedef enum _archiveFormat
{
archUnknown = 0,
archCustom = 1,
archTar = 3,
archNull = 4,
archDirectory = 5
} ArchiveFormat;
typedef enum _archiveMode
{
archModeAppend,
archModeWrite,
archModeRead
} ArchiveMode;
typedef enum _teSection
{
SECTION_NONE = 1, /* COMMENTs, ACLs, etc; can be anywhere */
SECTION_PRE_DATA, /* stuff to be processed before data */
SECTION_DATA, /* TABLE DATA, BLOBS, BLOB COMMENTS */
SECTION_POST_DATA /* stuff to be processed after data */
} teSection;
/*
* We may want to have some more user-readable data, but in the mean
2001-03-22 05:01:46 +01:00
* time this gives us some abstraction and type checking.
*/
struct Archive
2001-03-22 05:01:46 +01:00
{
int verbose;
2005-10-15 04:49:52 +02:00
char *remoteVersionStr; /* server's version string */
int remoteVersion; /* same in numeric form */
2005-10-15 04:49:52 +02:00
int minRemoteVersion; /* allowable range */
int maxRemoteVersion;
int numWorkers; /* number of parallel processes */
char *sync_snapshot_id; /* sync snapshot id for parallel
* operation */
/* info needed for string escaping */
int encoding; /* libpq code for client_encoding */
bool std_strings; /* standard_conforming_strings */
char *use_role; /* Issue SET ROLE to this */
/* error handling */
bool exit_on_error; /* whether to exit on SQL errors... */
int n_errors; /* number of errors (if no die) */
2001-03-22 05:01:46 +01:00
/* The rest is private */
};
typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
2001-03-22 05:01:46 +01:00
typedef struct _restoreOptions
{
int createDB; /* Issue commands to create the database */
2005-10-15 04:49:52 +02:00
int noOwner; /* Don't try to match original object owner */
int noTablespace; /* Don't issue tablespace-related commands */
2005-10-15 04:49:52 +02:00
int disable_triggers; /* disable triggers during data-only
* restore */
2004-08-29 07:07:03 +02:00
int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
* instead of OWNER TO */
2011-06-09 20:32:50 +02:00
int no_security_labels; /* Skip security label entries */
2001-03-22 05:01:46 +01:00
char *superuser; /* Username to use as superuser */
char *use_role; /* Issue SET ROLE to this */
int dropSchema;
int if_exists;
2012-02-07 22:20:29 +01:00
const char *filename;
int dataOnly;
int schemaOnly;
int dumpSections;
int verbose;
int aclsSkip;
int tocSummary;
2001-03-22 05:01:46 +01:00
char *tocFile;
int format;
2001-03-22 05:01:46 +01:00
char *formatName;
int selTypes;
int selIndex;
int selFunction;
int selTrigger;
int selTable;
SimpleStringList indexNames;
SimpleStringList functionNames;
SimpleStringList schemaNames;
SimpleStringList triggerNames;
SimpleStringList tableNames;
int useDB;
2001-03-22 05:01:46 +01:00
char *dbname;
char *pgport;
char *pghost;
char *username;
int noDataForFailedTables;
enum trivalue promptPassword;
int exit_on_error;
int compression;
2005-10-15 04:49:52 +02:00
int suppressDumpWarnings; /* Suppress output of WARNING entries
* to stderr */
2006-10-04 02:30:14 +02:00
bool single_txn;
bool *idWanted; /* array showing which dump IDs to emit */
} RestoreOptions;
typedef void (*SetupWorkerPtr) (Archive *AH, RestoreOptions *ropt);
/*
* Main archiver interface.
*/
extern void ConnectDatabase(Archive *AH,
2001-03-22 05:01:46 +01:00
const char *dbname,
const char *pghost,
const char *pgport,
const char *username,
enum trivalue prompt_password);
extern void DisconnectDatabase(Archive *AHX);
extern PGconn *GetConnection(Archive *AHX);
/* Called to add a TOC entry */
extern void ArchiveEntry(Archive *AHX,
CatalogId catalogId, DumpId dumpId,
const char *tag,
const char *namespace, const char *tablespace,
const char *owner, bool withOids,
const char *desc, teSection section,
const char *defn,
const char *dropStmt, const char *copyStmt,
const DumpId *deps, int nDeps,
2002-09-04 22:31:48 +02:00
DataDumperPtr dumpFn, void *dumpArg);
/* Called to write *data* to the archive */
2002-09-04 22:31:48 +02:00
extern size_t WriteData(Archive *AH, const void *data, size_t dLen);
extern int StartBlob(Archive *AH, Oid oid);
extern int EndBlob(Archive *AH, Oid oid);
2001-03-22 05:01:46 +01:00
extern void CloseArchive(Archive *AH);
extern void SetArchiveRestoreOptions(Archive *AH, RestoreOptions *ropt);
extern void RestoreArchive(Archive *AH);
/* Open an existing archive */
2001-03-22 05:01:46 +01:00
extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
/* Create a new archive */
2001-03-22 05:01:46 +01:00
extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
const int compression, ArchiveMode mode,
SetupWorkerPtr setupDumpWorker);
/* The --list option */
2001-03-22 05:01:46 +01:00
extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
2001-03-22 05:01:46 +01:00
extern RestoreOptions *NewRestoreOptions(void);
/* Rearrange and filter TOC entries */
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
/* Convenience functions used only when writing DATA */
2001-03-22 05:01:46 +01:00
extern int archputs(const char *s, Archive *AH);
extern int
archprintf(Archive *AH, const char *fmt,...)
/* This extension allows gcc to check the format string */
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
#define appendStringLiteralAH(buf,str,AH) \
appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
2004-08-29 07:07:03 +02:00
#endif /* PG_BACKUP_H */