postgresql/src/bin/pg_dump/pg_backup.h

200 lines
5.5 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
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.16 2001/10/25 05:49:52 momjian Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
2001-03-22 05:01:46 +01:00
* Initial version.
*
*
* Modifications - 28-Jul-2000 - pjw@rhyme.com.au (1.45)
*
2001-03-22 05:01:46 +01:00
* Added --create, --no-owner, --superuser, --no-reconnect (pg_dump & pg_restore)
* Added code to dump 'Create Schema' statement (pg_dump)
* Don't bother to disable/enable triggers if we don't have a superuser (pg_restore)
* Cleaned up code for reconnecting to database.
* Force a reconnect as superuser before enabling/disabling triggers.
*
* Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
* Added & Removed --throttle (pg_dump)
* Fixed minor bug in language dumping code: expbuffres were not being reset.
* Fixed version number initialization in _allocAH (pg_backup_archiver.c)
* Added second connection when restoring BLOBs to allow temp. table to survive
* (db reconnection causes temp tables to be lost).
*
*-------------------------------------------------------------------------
*/
#ifndef PG_BACKUP__
#define PG_BACKUP__
#include "postgres_fe.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 )
2001-03-22 05:01:46 +01:00
typedef enum _archiveFormat
{
archUnknown = 0,
archCustom = 1,
archFiles = 2,
archTar = 3,
archNull = 4
} ArchiveFormat;
/*
2001-03-22 05:01:46 +01:00
* We may want to have so user-readbale data, but in the mean
* time this gives us some abstraction and type checking.
*/
2001-03-22 05:01:46 +01:00
typedef struct _Archive
{
int verbose;
int remoteVersion;
int minRemoteVersion;
int maxRemoteVersion;
2001-03-22 05:01:46 +01:00
/* The rest is private */
} Archive;
2001-03-22 05:01:46 +01:00
typedef int (*DataDumperPtr) (Archive *AH, char *oid, void *userArg);
2001-03-22 05:01:46 +01:00
typedef struct _restoreOptions
{
int create; /* Issue commands to create the database */
2001-03-22 05:01:46 +01:00
int noOwner; /* Don't reconnect to database to match
* original object owner */
int noReconnect; /* Don't reconnect to database under any
* cirsumstances */
int use_setsessauth;/* use SET SESSSION AUTHORIZATION instead
* of \connect */
2001-03-22 05:01:46 +01:00
char *superuser; /* Username to use as superuser */
int dataOnly;
int dropSchema;
2001-03-22 05:01:46 +01:00
char *filename;
int schemaOnly;
int verbose;
int aclsSkip;
int tocSummary;
2001-03-22 05:01:46 +01:00
char *tocFile;
int oidOrder;
int origOrder;
int rearrange;
int format;
2001-03-22 05:01:46 +01:00
char *formatName;
int selTypes;
int selIndex;
int selFunction;
int selTrigger;
int selTable;
2001-03-22 05:01:46 +01:00
char *indexNames;
char *functionNames;
char *tableNames;
char *triggerNames;
int useDB;
2001-03-22 05:01:46 +01:00
char *dbname;
char *pgport;
char *pghost;
char *username;
int ignoreVersion;
int requirePassword;
2001-03-22 05:01:46 +01:00
int *idWanted;
int limitToList;
int compression;
int suppressDumpWarnings; /* Suppress output of WARNING
* entries to stderr */
} RestoreOptions;
/*
* Main archiver interface.
*/
extern void
exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
__attribute__((format(printf, 3, 4)));
extern char *
simple_prompt(const char *prompt, int maxlen, bool echo);
/* Lets the archibe know we have a DB connection to shutdown if it dies */
2001-03-22 05:01:46 +01:00
PGconn *ConnectDatabase(Archive *AH,
const char *dbname,
const char *pghost,
const char *pgport,
const char *username,
2001-03-22 05:01:46 +01:00
const int reqPwd,
const int ignoreVersion);
/* Called to add a TOC entry */
2001-03-22 05:01:46 +01:00
extern void ArchiveEntry(Archive *AH, const char *oid, const char *name,
const char *desc, const char *((*deps)[]), const char *defn,
2001-03-22 05:01:46 +01:00
const char *dropStmt, const char *copyStmt, const char *owner,
DataDumperPtr dumpFn, void *dumpArg);
/* Called to write *data* to the archive */
2001-03-22 05:01:46 +01:00
extern int WriteData(Archive *AH, const void *data, int dLen);
2001-03-22 05:01:46 +01:00
/*
extern int StartBlobs(Archive* AH);
extern int EndBlobs(Archive* AH);
*/
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);
2001-03-22 05:01:46 +01:00
extern void RestoreArchive(Archive *AH, RestoreOptions *ropt);
/* 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);
/* 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 TOC entries */
2001-03-22 05:01:46 +01:00
extern void MoveToStart(Archive *AH, char *oType);
extern void MoveToEnd(Archive *AH, char *oType);
extern void SortTocByOID(Archive *AH);
extern void SortTocByID(Archive *AH);
extern void SortTocFromFile(Archive *AH, 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 archputc(const char c, Archive *AH);
extern int
archprintf(Archive *AH, const char *fmt,...)
/* This extension allows gcc to check the format string */
__attribute__((format(printf, 2, 3)));
#endif