pg_backup.h 4.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*-------------------------------------------------------------------------
 *
 * 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
 *      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
 *
 * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
 *
 *	Initial version. 
 *
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *
 * Modifications - 28-Jul-2000 - pjw@rhyme.com.au (1.45)
 *
 * 		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).
 *
39 40 41 42 43 44
 *-------------------------------------------------------------------------
 */

#ifndef PG_BACKUP__
#define PG_BACKUP__

45 46
#include "postgres_fe.h"

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include "libpq-fe.h"

typedef enum _archiveFormat {
    archUnknown = 0,
    archCustom = 1,
    archFiles = 2,
    archTar = 3,
    archNull = 4
} ArchiveFormat;

/*
 *  We may want to have so user-readbale data, but in the mean
 *  time this gives us some abstraction and type checking.
 */
typedef struct _Archive {
	int			verbose;
    /* The rest is private */
} Archive;

typedef int     (*DataDumperPtr)(Archive* AH, char* oid, void* userArg);

typedef struct _restoreOptions {
69 70 71 72
	int			create;			/* Issue commands to create the database */
	int			noOwner;		/* Don't reconnect to database to match original object owner */
	int			noReconnect;	/* Don't reconnect to database under any cirsumstances */
	char		*superuser;		/* Username to use as superuser */
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	int			dataOnly;
	int			dropSchema;
	char		*filename;
	int			schemaOnly;
	int			verbose;
	int			aclsSkip;
	int			tocSummary;
	char		*tocFile;
	int			oidOrder;
	int			origOrder;
	int			rearrange;
	int			format;
	char		*formatName;

	int			selTypes;
	int			selIndex;
	int			selFunction;
	int			selTrigger;
	int			selTable;
	char		*indexNames;
	char		*functionNames;
	char		*tableNames;
	char		*triggerNames;

	int			useDB;
	char		*dbname;
99
	char		*pgport;
100
	char		*pghost;
101 102 103
	int			ignoreVersion;
	int			requirePassword;

104 105 106
	int			*idWanted;
	int			limitToList;
	int			compression;
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

} RestoreOptions;

/*
 * Main archiver interface.
 */

extern void exit_horribly(Archive *AH, const char *fmt, ...);

/* Lets the archibe know we have a DB connection to shutdown if it dies */

PGconn* ConnectDatabase(Archive *AH,
		const char* 	dbname,
		const char*	pghost,
		const char*	pgport,
		const int	reqPwd,
		const int	ignoreVersion);


/* Called to add a TOC entry */
extern void	ArchiveEntry(Archive* AH, const char* oid, const char* name,
			const char* desc, const char* (deps[]), const char* defn,
			const char* dropStmt, const char* copyStmt, const char* owner, 
			DataDumperPtr dumpFn, void* dumpArg);

/* Called to write *data* to the archive */
extern int	WriteData(Archive* AH, const void* data, int dLen);

135 136 137 138
/* 
extern int 	StartBlobs(Archive* AH);
extern int	EndBlobs(Archive* AH);
*/
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
extern int	StartBlob(Archive* AH, int oid);
extern int	EndBlob(Archive* AH, int oid);

extern void	CloseArchive(Archive* AH);

extern void	RestoreArchive(Archive* AH, RestoreOptions *ropt);

/* Open an existing archive */
extern Archive* OpenArchive(const char* FileSpec, const ArchiveFormat fmt);

/* Create a new archive */
extern Archive* CreateArchive(const char* FileSpec, const ArchiveFormat fmt, 
								const int compression);

/* The --list option */
extern void	PrintTOCSummary(Archive* AH, RestoreOptions *ropt);

extern RestoreOptions*		NewRestoreOptions(void);

/* Rearrange TOC entries */
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 */
extern int archputs(const char *s, Archive* AH);
extern int archputc(const char c, Archive* AH);
extern int archprintf(Archive* AH, const char *fmt, ...);

#endif