PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_backup_archiver.h File Reference
#include <time.h>
#include "pg_backup.h"
#include "libpq-fe.h"
#include "pqexpbuffer.h"
Include dependency graph for pg_backup_archiver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _z_stream
 
struct  sqlparseInfo
 
struct  _archiveHandle
 
struct  _tocEntry
 

Macros

#define LOBBUFSIZE   16384
 
#define GZCLOSE(fh)   fclose(fh)
 
#define GZWRITE(p, s, n, fh)   (fwrite(p, s, n, fh) * (s))
 
#define GZREAD(p, s, n, fh)   fread(p, s, n, fh)
 
#define GZEOF(fh)   feof(fh)
 
#define Z_DEFAULT_COMPRESSION   (-1)
 
#define BLK_DATA   1
 
#define BLK_BLOBS   3
 
#define MAKE_ARCHIVE_VERSION(major, minor, rev)   (((major) * 256 + (minor)) * 256 + (rev))
 
#define ARCHIVE_MAJOR(version)   (((version) >> 16) & 255)
 
#define ARCHIVE_MINOR(version)   (((version) >> 8) & 255)
 
#define ARCHIVE_REV(version)   (((version) ) & 255)
 
#define K_VERS_1_0   MAKE_ARCHIVE_VERSION(1, 0, 0)
 
#define K_VERS_1_2   MAKE_ARCHIVE_VERSION(1, 2, 0) /* Allow No ZLIB */
 
#define K_VERS_1_3   MAKE_ARCHIVE_VERSION(1, 3, 0) /* BLOBs */
 
#define K_VERS_1_4   MAKE_ARCHIVE_VERSION(1, 4, 0) /* Date & name in header */
 
#define K_VERS_1_5   MAKE_ARCHIVE_VERSION(1, 5, 0) /* Handle dependencies */
 
#define K_VERS_1_6   MAKE_ARCHIVE_VERSION(1, 6, 0) /* Schema field in TOCs */
 
#define K_VERS_1_7
 
#define K_VERS_1_8
 
#define K_VERS_1_9
 
#define K_VERS_1_10   MAKE_ARCHIVE_VERSION(1, 10, 0) /* add tablespace */
 
#define K_VERS_1_11
 
#define K_VERS_1_12
 
#define K_VERS_MAJOR   1
 
#define K_VERS_MINOR   12
 
#define K_VERS_REV   0
 
#define K_VERS_SELF   MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV);
 
#define K_VERS_MAX   MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, 255)
 
#define K_OFFSET_POS_NOT_SET   1
 
#define K_OFFSET_POS_SET   2
 
#define K_OFFSET_NO_DATA   3
 
#define WORKER_OK   0
 
#define WORKER_CREATE_DONE   10
 
#define WORKER_INHIBIT_DATA   11
 
#define WORKER_IGNORED_ERRORS   12
 
#define READ_ERROR_EXIT(fd)
 
#define WRITE_ERROR_EXIT
 
#define RESTORE_PASS_LAST   RESTORE_PASS_REFRESH
 
#define appendStringLiteralAHX(buf, str, AH)   appendStringLiteral(buf, str, (AH)->public.encoding, (AH)->public.std_strings)
 
#define appendByteaLiteralAHX(buf, str, len, AH)   appendByteaLiteral(buf, str, len, (AH)->public.std_strings)
 

Typedefs

typedef struct _z_stream z_stream
 
typedef z_streamz_streamp
 
typedef struct _archiveHandle ArchiveHandle
 
typedef struct _tocEntry TocEntry
 
typedef enum T_Action T_Action
 
typedef void(* ClosePtrType )(ArchiveHandle *AH)
 
typedef void(* ReopenPtrType )(ArchiveHandle *AH)
 
typedef void(* ArchiveEntryPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartDataPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* WriteDataPtrType )(ArchiveHandle *AH, const void *data, size_t dLen)
 
typedef void(* EndDataPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartBlobsPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartBlobPtrType )(ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndBlobPtrType )(ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndBlobsPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef int(* WriteBytePtrType )(ArchiveHandle *AH, const int i)
 
typedef int(* ReadBytePtrType )(ArchiveHandle *AH)
 
typedef void(* WriteBufPtrType )(ArchiveHandle *AH, const void *c, size_t len)
 
typedef void(* ReadBufPtrType )(ArchiveHandle *AH, void *buf, size_t len)
 
typedef void(* SaveArchivePtrType )(ArchiveHandle *AH)
 
typedef void(* WriteExtraTocPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* ReadExtraTocPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrintExtraTocPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrintTocDataPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* ClonePtrType )(ArchiveHandle *AH)
 
typedef void(* DeClonePtrType )(ArchiveHandle *AH)
 
typedef int(* WorkerJobDumpPtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef int(* WorkerJobRestorePtrType )(ArchiveHandle *AH, TocEntry *te)
 
typedef size_t(* CustomOutPtrType )(ArchiveHandle *AH, const void *buf, size_t len)
 

Enumerations

enum  T_Action { ACT_DUMP, ACT_RESTORE }
 
enum  sqlparseState { SQL_SCAN = 0, SQL_IN_SINGLE_QUOTE, SQL_IN_DOUBLE_QUOTE }
 
enum  ArchiverStage { STAGE_NONE = 0, STAGE_INITIALIZING, STAGE_PROCESSING, STAGE_FINALIZING }
 
enum  ArchiverOutput { OUTPUT_SQLCMDS = 0, OUTPUT_COPYDATA, OUTPUT_OTHERDATA }
 
enum  RestorePass { RESTORE_PASS_MAIN = 0, RESTORE_PASS_ACL }
 
enum  teReqs { REQ_SCHEMA = 0x01, REQ_DATA = 0x02, REQ_SPECIAL = 0x04 }
 

Functions

int parallel_restore (ArchiveHandle *AH, TocEntry *te)
 
void on_exit_close_archive (Archive *AHX)
 
void warn_or_exit_horribly (ArchiveHandle *AH, const char *modulename, const char *fmt,...) pg_attribute_printf(3
 
void void WriteTOC (ArchiveHandle *AH)
 
void ReadTOC (ArchiveHandle *AH)
 
void WriteHead (ArchiveHandle *AH)
 
void ReadHead (ArchiveHandle *AH)
 
void WriteToc (ArchiveHandle *AH)
 
void ReadToc (ArchiveHandle *AH)
 
void WriteDataChunks (ArchiveHandle *AH, struct ParallelState *pstate)
 
void WriteDataChunksForTocEntry (ArchiveHandle *AH, TocEntry *te)
 
ArchiveHandleCloneArchive (ArchiveHandle *AH)
 
void DeCloneArchive (ArchiveHandle *AH)
 
teReqs TocIDRequired (ArchiveHandle *AH, DumpId id)
 
TocEntrygetTocEntryByDumpId (ArchiveHandle *AH, DumpId id)
 
bool checkSeek (FILE *fp)
 
size_t WriteInt (ArchiveHandle *AH, int i)
 
int ReadInt (ArchiveHandle *AH)
 
char * ReadStr (ArchiveHandle *AH)
 
size_t WriteStr (ArchiveHandle *AH, const char *s)
 
int ReadOffset (ArchiveHandle *, pgoff_t *)
 
size_t WriteOffset (ArchiveHandle *, pgoff_t, int)
 
void StartRestoreBlobs (ArchiveHandle *AH)
 
void StartRestoreBlob (ArchiveHandle *AH, Oid oid, bool drop)
 
void EndRestoreBlob (ArchiveHandle *AH, Oid oid)
 
void EndRestoreBlobs (ArchiveHandle *AH)
 
void InitArchiveFmt_Custom (ArchiveHandle *AH)
 
void InitArchiveFmt_Null (ArchiveHandle *AH)
 
void InitArchiveFmt_Directory (ArchiveHandle *AH)
 
void InitArchiveFmt_Tar (ArchiveHandle *AH)
 
bool isValidTarHeader (char *header)
 
int ReconnectToServer (ArchiveHandle *AH, const char *dbname, const char *newUser)
 
void DropBlobIfExists (ArchiveHandle *AH, Oid oid)
 
void ahwrite (const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
 
int ahprintf (ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2
 
int void ahlog (ArchiveHandle *AH, int level, const char *fmt,...) pg_attribute_printf(3
 

Macro Definition Documentation

#define appendByteaLiteralAHX (   buf,
  str,
  len,
  AH 
)    appendByteaLiteral(buf, str, len, (AH)->public.std_strings)

Definition at line 424 of file pg_backup_archiver.h.

Referenced by _WriteBlobData(), and dump_lo_buf().

#define appendStringLiteralAHX (   buf,
  str,
  AH 
)    appendStringLiteral(buf, str, (AH)->public.encoding, (AH)->public.std_strings)

Definition at line 421 of file pg_backup_archiver.h.

Referenced by _doSetSessionAuth().

#define ARCHIVE_MAJOR (   version)    (((version) >> 16) & 255)

Definition at line 72 of file pg_backup_archiver.h.

Referenced by PrintTOCSummary(), and WriteHead().

#define ARCHIVE_MINOR (   version)    (((version) >> 8) & 255)

Definition at line 73 of file pg_backup_archiver.h.

Referenced by PrintTOCSummary(), and WriteHead().

#define ARCHIVE_REV (   version)    (((version) ) & 255)

Definition at line 74 of file pg_backup_archiver.h.

Referenced by PrintTOCSummary(), and WriteHead().

#define BLK_BLOBS   3

Definition at line 67 of file pg_backup_archiver.h.

Referenced by _PrintTocData(), and _StartBlobs().

#define BLK_DATA   1

Definition at line 66 of file pg_backup_archiver.h.

Referenced by _PrintTocData(), _readBlockHeader(), and _StartData().

#define GZCLOSE (   fh)    fclose(fh)

Definition at line 48 of file pg_backup_archiver.h.

Referenced by CloseArchive(), RestoreOutput(), and tarClose().

#define GZEOF (   fh)    feof(fh)

Definition at line 51 of file pg_backup_archiver.h.

Referenced by _tarReadRaw().

#define GZREAD (   p,
  s,
  n,
  fh 
)    fread(p, s, n, fh)

Definition at line 50 of file pg_backup_archiver.h.

Referenced by _tarReadRaw().

#define GZWRITE (   p,
  s,
  n,
  fh 
)    (fwrite(p, s, n, fh) * (s))

Definition at line 49 of file pg_backup_archiver.h.

Referenced by ahwrite(), and tarWrite().

#define K_OFFSET_NO_DATA   3

Definition at line 109 of file pg_backup_archiver.h.

Referenced by _ArchiveEntry(), _PrintTocData(), and ReadOffset().

#define K_OFFSET_POS_NOT_SET   1

Definition at line 107 of file pg_backup_archiver.h.

Referenced by _ArchiveEntry(), _PrintTocData(), and ReadOffset().

#define K_OFFSET_POS_SET   2

Definition at line 108 of file pg_backup_archiver.h.

Referenced by _StartBlobs(), _StartData(), and ReadOffset().

#define K_VERS_1_0   MAKE_ARCHIVE_VERSION(1, 0, 0)

Definition at line 77 of file pg_backup_archiver.h.

Referenced by ReadHead(), and ReadInt().

#define K_VERS_1_10   MAKE_ARCHIVE_VERSION(1, 10, 0) /* add tablespace */

Definition at line 90 of file pg_backup_archiver.h.

Referenced by ReadHead(), and ReadToc().

#define K_VERS_1_11
Value:
MAKE_ARCHIVE_VERSION(1, 11, 0) /* add toc section
* indicator */
#define MAKE_ARCHIVE_VERSION(major, minor, rev)

Definition at line 91 of file pg_backup_archiver.h.

Referenced by fix_dependencies(), and ReadToc().

#define K_VERS_1_12
Value:
MAKE_ARCHIVE_VERSION(1, 12, 0) /* add separate BLOB
* entries */
#define MAKE_ARCHIVE_VERSION(major, minor, rev)

Definition at line 93 of file pg_backup_archiver.h.

Referenced by _StartBlob(), and StartRestoreBlob().

#define K_VERS_1_2   MAKE_ARCHIVE_VERSION(1, 2, 0) /* Allow No ZLIB */

Definition at line 78 of file pg_backup_archiver.h.

Referenced by ReadHead().

#define K_VERS_1_3   MAKE_ARCHIVE_VERSION(1, 3, 0) /* BLOBs */

Definition at line 79 of file pg_backup_archiver.h.

Referenced by _readBlockHeader(), ReadToc(), and RestoreArchive().

#define K_VERS_1_4   MAKE_ARCHIVE_VERSION(1, 4, 0) /* Date & name in header */

Definition at line 80 of file pg_backup_archiver.h.

Referenced by ReadHead().

#define K_VERS_1_5   MAKE_ARCHIVE_VERSION(1, 5, 0) /* Handle dependencies */

Definition at line 81 of file pg_backup_archiver.h.

Referenced by ReadToc().

#define K_VERS_1_6   MAKE_ARCHIVE_VERSION(1, 6, 0) /* Schema field in TOCs */

Definition at line 82 of file pg_backup_archiver.h.

Referenced by ReadToc().

#define K_VERS_1_7
Value:
MAKE_ARCHIVE_VERSION(1, 7, 0) /* File Offset size in
* header */
#define MAKE_ARCHIVE_VERSION(major, minor, rev)

Definition at line 83 of file pg_backup_archiver.h.

Referenced by _discoverArchiveFormat(), _ReadExtraToc(), ReadHead(), and ReadOffset().

#define K_VERS_1_8
Value:
MAKE_ARCHIVE_VERSION(1, 8, 0) /* change interpretation
* of ID numbers and
* dependencies */
#define MAKE_ARCHIVE_VERSION(major, minor, rev)

Definition at line 85 of file pg_backup_archiver.h.

Referenced by ReadToc(), and RestoreArchive().

#define K_VERS_1_9
Value:
MAKE_ARCHIVE_VERSION(1, 9, 0) /* add default_with_oids
* tracking */
#define MAKE_ARCHIVE_VERSION(major, minor, rev)

Definition at line 88 of file pg_backup_archiver.h.

Referenced by ReadToc().

#define K_VERS_MAJOR   1

Definition at line 97 of file pg_backup_archiver.h.

#define K_VERS_MAX   MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, 255)

Definition at line 103 of file pg_backup_archiver.h.

Referenced by ReadHead().

#define K_VERS_MINOR   12

Definition at line 98 of file pg_backup_archiver.h.

#define K_VERS_REV   0

Definition at line 99 of file pg_backup_archiver.h.

Definition at line 100 of file pg_backup_archiver.h.

Referenced by _allocAH().

#define LOBBUFSIZE   16384
#define MAKE_ARCHIVE_VERSION (   major,
  minor,
  rev 
)    (((major) * 256 + (minor)) * 256 + (rev))

Definition at line 70 of file pg_backup_archiver.h.

Referenced by _discoverArchiveFormat(), and ReadHead().

#define READ_ERROR_EXIT (   fd)
Value:
do { \
if (feof(fd)) \
"could not read from input file: end of file\n"); \
"could not read from input file: %s\n", strerror(errno)); \
} while (0)
static const char * modulename
Definition: compress_io.c:78
static int fd(const char *x, int i)
Definition: preproc-init.c:105
void exit_horribly(const char *modulename, const char *fmt,...)
const char * strerror(int errnum)
Definition: strerror.c:19

Definition at line 124 of file pg_backup_archiver.h.

Referenced by _discoverArchiveFormat(), _ReadBuf(), _ReadByte(), _tarAddFile(), _tarReadRaw(), cfgetc(), and cfread().

#define RESTORE_PASS_LAST   RESTORE_PASS_REFRESH

Definition at line 227 of file pg_backup_archiver.h.

Referenced by restore_toc_entries_parallel().

#define WORKER_CREATE_DONE   10

Definition at line 116 of file pg_backup_archiver.h.

Referenced by mark_restore_job_done(), and restore_toc_entry().

#define WORKER_IGNORED_ERRORS   12
#define WORKER_INHIBIT_DATA   11

Definition at line 117 of file pg_backup_archiver.h.

Referenced by mark_restore_job_done(), and restore_toc_entry().

#define WORKER_OK   0

Definition at line 115 of file pg_backup_archiver.h.

Referenced by restore_toc_entry().

#define WRITE_ERROR_EXIT
Value:
do { \
exit_horribly(modulename, "could not write to output file: %s\n", \
strerror(errno)); \
} while (0)
static const char * modulename
Definition: compress_io.c:78
void exit_horribly(const char *modulename, const char *fmt,...)
const char * strerror(int errnum)
Definition: strerror.c:19

Definition at line 134 of file pg_backup_archiver.h.

Referenced by _CloseArchive(), _tarAddFile(), _tarWriteHeader(), _WriteBuf(), _WriteByte(), _WriteData(), and ahwrite().

#define Z_DEFAULT_COMPRESSION   (-1)

Definition at line 53 of file pg_backup_archiver.h.

Referenced by cfopen(), main(), ParseCompressionOption(), and ReadHead().

Typedef Documentation

typedef void(* ArchiveEntryPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 148 of file pg_backup_archiver.h.

Definition at line 120 of file pg_backup_archiver.h.

typedef void(* ClonePtrType)(ArchiveHandle *AH)

Definition at line 169 of file pg_backup_archiver.h.

typedef void(* ClosePtrType)(ArchiveHandle *AH)

Definition at line 146 of file pg_backup_archiver.h.

typedef size_t(* CustomOutPtrType)(ArchiveHandle *AH, const void *buf, size_t len)

Definition at line 175 of file pg_backup_archiver.h.

typedef void(* DeClonePtrType)(ArchiveHandle *AH)

Definition at line 170 of file pg_backup_archiver.h.

typedef void(* EndBlobPtrType)(ArchiveHandle *AH, TocEntry *te, Oid oid)

Definition at line 156 of file pg_backup_archiver.h.

typedef void(* EndBlobsPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 157 of file pg_backup_archiver.h.

typedef void(* EndDataPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 152 of file pg_backup_archiver.h.

typedef void(* PrintExtraTocPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 166 of file pg_backup_archiver.h.

typedef void(* PrintTocDataPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 167 of file pg_backup_archiver.h.

typedef void(* ReadBufPtrType)(ArchiveHandle *AH, void *buf, size_t len)

Definition at line 162 of file pg_backup_archiver.h.

typedef int(* ReadBytePtrType)(ArchiveHandle *AH)

Definition at line 160 of file pg_backup_archiver.h.

typedef void(* ReadExtraTocPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 165 of file pg_backup_archiver.h.

typedef void(* ReopenPtrType)(ArchiveHandle *AH)

Definition at line 147 of file pg_backup_archiver.h.

typedef void(* SaveArchivePtrType)(ArchiveHandle *AH)

Definition at line 163 of file pg_backup_archiver.h.

typedef void(* StartBlobPtrType)(ArchiveHandle *AH, TocEntry *te, Oid oid)

Definition at line 155 of file pg_backup_archiver.h.

typedef void(* StartBlobsPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 154 of file pg_backup_archiver.h.

typedef void(* StartDataPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 150 of file pg_backup_archiver.h.

Definition at line 121 of file pg_backup_archiver.h.

typedef int(* WorkerJobDumpPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 172 of file pg_backup_archiver.h.

typedef int(* WorkerJobRestorePtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 173 of file pg_backup_archiver.h.

typedef void(* WriteBufPtrType)(ArchiveHandle *AH, const void *c, size_t len)

Definition at line 161 of file pg_backup_archiver.h.

typedef int(* WriteBytePtrType)(ArchiveHandle *AH, const int i)

Definition at line 159 of file pg_backup_archiver.h.

typedef void(* WriteDataPtrType)(ArchiveHandle *AH, const void *data, size_t dLen)

Definition at line 151 of file pg_backup_archiver.h.

typedef void(* WriteExtraTocPtrType)(ArchiveHandle *AH, TocEntry *te)

Definition at line 164 of file pg_backup_archiver.h.

Definition at line 62 of file pg_backup_archiver.h.

Enumeration Type Documentation

Enumerator
OUTPUT_SQLCMDS 
OUTPUT_COPYDATA 
OUTPUT_OTHERDATA 

Definition at line 199 of file pg_backup_archiver.h.

200 {
201  OUTPUT_SQLCMDS = 0, /* emitting general SQL commands */
202  OUTPUT_COPYDATA, /* writing COPY data */
203  OUTPUT_OTHERDATA /* writing data as INSERT commands */
ArchiverOutput
Enumerator
STAGE_NONE 
STAGE_INITIALIZING 
STAGE_PROCESSING 
STAGE_FINALIZING 

Definition at line 191 of file pg_backup_archiver.h.

Enumerator
RESTORE_PASS_MAIN 
RESTORE_PASS_ACL 

Definition at line 221 of file pg_backup_archiver.h.

222 {
223  RESTORE_PASS_MAIN = 0, /* Main pass (most TOC item types) */
224  RESTORE_PASS_ACL, /* ACL item types */
225  RESTORE_PASS_REFRESH /* Matview REFRESH items */
226 
227 #define RESTORE_PASS_LAST RESTORE_PASS_REFRESH
228 } RestorePass;
Enumerator
SQL_SCAN 
SQL_IN_SINGLE_QUOTE 
SQL_IN_DOUBLE_QUOTE 

Definition at line 177 of file pg_backup_archiver.h.

178 {
179  SQL_SCAN = 0, /* normal */
180  SQL_IN_SINGLE_QUOTE, /* '...' literal */
181  SQL_IN_DOUBLE_QUOTE /* "..." identifier */
182 } sqlparseState;
sqlparseState
enum T_Action
Enumerator
ACT_DUMP 
ACT_RESTORE 

Definition at line 140 of file pg_backup_archiver.h.

enum teReqs
Enumerator
REQ_SCHEMA 
REQ_DATA 
REQ_SPECIAL 

Definition at line 230 of file pg_backup_archiver.h.

231 {
232  REQ_SCHEMA = 0x01, /* want schema */
233  REQ_DATA = 0x02, /* want data */
234  REQ_SPECIAL = 0x04 /* for special TOC entries */
235 } teReqs;

Function Documentation

int void ahlog ( ArchiveHandle AH,
int  level,
const char *  fmt,
  ... 
)
int ahprintf ( ArchiveHandle AH,
const char *  fmt,
  ... 
)
void ahwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
ArchiveHandle AH 
)

Definition at line 1714 of file pg_backup_archiver.c.

References _archiveHandle::CustomOutPtr, dump_lo_buf(), ExecuteSqlCommandBuf(), _archiveHandle::gzOut, GZWRITE, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, _archiveHandle::lo_buf_used, _archiveHandle::OF, _archiveHandle::public, remaining, RestoringToDB(), WRITE_ERROR_EXIT, and _archiveHandle::writingBlob.

Referenced by _LoadBlobs(), _PrintFileData(), _PrintTocData(), _WriteData(), ahprintf(), and ReadDataFromArchiveNone().

1715 {
1716  int bytes_written = 0;
1717 
1718  if (AH->writingBlob)
1719  {
1720  size_t remaining = size * nmemb;
1721 
1722  while (AH->lo_buf_used + remaining > AH->lo_buf_size)
1723  {
1724  size_t avail = AH->lo_buf_size - AH->lo_buf_used;
1725 
1726  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, avail);
1727  ptr = (const void *) ((const char *) ptr + avail);
1728  remaining -= avail;
1729  AH->lo_buf_used += avail;
1730  dump_lo_buf(AH);
1731  }
1732 
1733  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, remaining);
1734  AH->lo_buf_used += remaining;
1735 
1736  bytes_written = size * nmemb;
1737  }
1738  else if (AH->gzOut)
1739  bytes_written = GZWRITE(ptr, size, nmemb, AH->OF);
1740  else if (AH->CustomOutPtr)
1741  bytes_written = AH->CustomOutPtr(AH, ptr, size * nmemb);
1742 
1743  else
1744  {
1745  /*
1746  * If we're doing a restore, and it's direct to DB, and we're
1747  * connected then send it to the DB.
1748  */
1749  if (RestoringToDB(AH))
1750  bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
1751  else
1752  bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size;
1753  }
1754 
1755  if (bytes_written != size * nmemb)
1757 
1758  return;
1759 }
int remaining
Definition: informix.c:692
static int RestoringToDB(ArchiveHandle *AH)
int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
Definition: pg_backup_db.c:563
static void dump_lo_buf(ArchiveHandle *AH)
#define GZWRITE(p, s, n, fh)
CustomOutPtrType CustomOutPtr
#define WRITE_ERROR_EXIT
bool checkSeek ( FILE *  fp)

Definition at line 3776 of file pg_backup_archiver.c.

References fseeko, ftello, and pgoff_t.

Referenced by InitArchiveFmt_Custom(), and InitArchiveFmt_Tar().

3777 {
3778  pgoff_t tpos;
3779 
3780  /*
3781  * If pgoff_t is wider than long, we must have "real" fseeko and not an
3782  * emulation using fseek. Otherwise report no seek capability.
3783  */
3784 #ifndef HAVE_FSEEKO
3785  if (sizeof(pgoff_t) > sizeof(long))
3786  return false;
3787 #endif
3788 
3789  /* Check that ftello works on this file */
3790  tpos = ftello(fp);
3791  if (tpos < 0)
3792  return false;
3793 
3794  /*
3795  * Check that fseeko(SEEK_SET) works, too. NB: we used to try to test
3796  * this with fseeko(fp, 0, SEEK_CUR). But some platforms treat that as a
3797  * successful no-op even on files that are otherwise unseekable.
3798  */
3799  if (fseeko(fp, tpos, SEEK_SET) != 0)
3800  return false;
3801 
3802  return true;
3803 }
#define fseeko(stream, offset, origin)
Definition: win32.h:237
#define pgoff_t
Definition: win32.h:231
#define ftello(stream)
Definition: win32.h:240
ArchiveHandle* CloneArchive ( ArchiveHandle AH)

Definition at line 4626 of file pg_backup_archiver.c.

References _doSetFixedOutputState(), appendConnStrVal(), appendPQExpBuffer(), archModeRead, Assert, _archiveHandle::ClonePtr, _archiveHandle::connCancel, ConnectDatabase(), _archiveHandle::connection, connstr, _archiveHandle::currSchema, _archiveHandle::currTablespace, _archiveHandle::currUser, _archiveHandle::currWithOids, PQExpBufferData::data, _restoreOptions::dbname, initPQExpBuffer(), _archiveHandle::mode, Archive::n_errors, pg_malloc(), pg_strdup(), _restoreOptions::pghost, pghost, _restoreOptions::pgport, pgport, PQdb(), PQhost(), PQport(), PQuser(), _restoreOptions::promptPassword, _archiveHandle::public, Archive::ropt, _archiveHandle::savedPassword, _archiveHandle::sqlparse, termPQExpBuffer(), TRI_NO, _restoreOptions::username, and username.

Referenced by RunWorker().

4627 {
4628  ArchiveHandle *clone;
4629 
4630  /* Make a "flat" copy */
4631  clone = (ArchiveHandle *) pg_malloc(sizeof(ArchiveHandle));
4632  memcpy(clone, AH, sizeof(ArchiveHandle));
4633 
4634  /* Handle format-independent fields */
4635  memset(&(clone->sqlparse), 0, sizeof(clone->sqlparse));
4636 
4637  /* The clone will have its own connection, so disregard connection state */
4638  clone->connection = NULL;
4639  clone->connCancel = NULL;
4640  clone->currUser = NULL;
4641  clone->currSchema = NULL;
4642  clone->currTablespace = NULL;
4643  clone->currWithOids = -1;
4644 
4645  /* savedPassword must be local in case we change it while connecting */
4646  if (clone->savedPassword)
4647  clone->savedPassword = pg_strdup(clone->savedPassword);
4648 
4649  /* clone has its own error count, too */
4650  clone->public.n_errors = 0;
4651 
4652  /*
4653  * Connect our new clone object to the database: In parallel restore the
4654  * parent is already disconnected, because we can connect the worker
4655  * processes independently to the database (no snapshot sync required). In
4656  * parallel backup we clone the parent's existing connection.
4657  */
4658  if (AH->mode == archModeRead)
4659  {
4660  RestoreOptions *ropt = AH->public.ropt;
4661 
4662  Assert(AH->connection == NULL);
4663 
4664  /* this also sets clone->connection */
4665  ConnectDatabase((Archive *) clone, ropt->dbname,
4666  ropt->pghost, ropt->pgport, ropt->username,
4667  ropt->promptPassword);
4668 
4669  /* re-establish fixed state */
4670  _doSetFixedOutputState(clone);
4671  }
4672  else
4673  {
4675  char *pghost;
4676  char *pgport;
4677  char *username;
4678 
4679  Assert(AH->connection != NULL);
4680 
4681  /*
4682  * Even though we are technically accessing the parent's database
4683  * object here, these functions are fine to be called like that
4684  * because all just return a pointer and do not actually send/receive
4685  * any data to/from the database.
4686  */
4687  initPQExpBuffer(&connstr);
4688  appendPQExpBuffer(&connstr, "dbname=");
4689  appendConnStrVal(&connstr, PQdb(AH->connection));
4690  pghost = PQhost(AH->connection);
4691  pgport = PQport(AH->connection);
4692  username = PQuser(AH->connection);
4693 
4694  /* this also sets clone->connection */
4695  ConnectDatabase((Archive *) clone, connstr.data,
4696  pghost, pgport, username, TRI_NO);
4697 
4698  termPQExpBuffer(&connstr);
4699  /* setupDumpWorker will fix up connection state */
4700  }
4701 
4702  /* Let the format-specific code have a chance too */
4703  clone->ClonePtr(clone);
4704 
4705  Assert(clone->connection != NULL);
4706  return clone;
4707 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
RestoreOptions * ropt
Definition: pg_backup.h:182
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
char * username
Definition: pg_backup.h:112
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:551
char * PQport(const PGconn *conn)
Definition: fe-connect.c:6018
int n_errors
Definition: pg_backup.h:202
PGcancel *volatile connCancel
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:5973
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void _doSetFixedOutputState(ArchiveHandle *AH)
sqlparseInfo sqlparse
char * pghost
Definition: pgbench.c:180
static char * username
Definition: initdb.c:132
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:5998
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:5965
#define Assert(condition)
Definition: c.h:681
ClonePtrType ClonePtr
char * pgport
Definition: pgbench.c:181
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
void ConnectDatabase(Archive *AH, const char *dbname, const char *pghost, const char *pgport, const char *username, trivalue prompt_password)
Definition: pg_backup_db.c:246
static char * connstr
Definition: pg_dumpall.c:64
trivalue promptPassword
Definition: pg_backup.h:114
void DeCloneArchive ( ArchiveHandle AH)

Definition at line 4715 of file pg_backup_archiver.c.

References Assert, _archiveHandle::connection, sqlparseInfo::curCmd, _archiveHandle::currSchema, _archiveHandle::currTablespace, _archiveHandle::currUser, _archiveHandle::DeClonePtr, destroyPQExpBuffer(), free, _archiveHandle::savedPassword, and _archiveHandle::sqlparse.

Referenced by RunWorker().

4716 {
4717  /* Should not have an open database connection */
4718  Assert(AH->connection == NULL);
4719 
4720  /* Clear format-specific state */
4721  AH->DeClonePtr(AH);
4722 
4723  /* Clear state allocated by CloneArchive */
4724  if (AH->sqlparse.curCmd)
4726 
4727  /* Clear any connection-local state */
4728  if (AH->currUser)
4729  free(AH->currUser);
4730  if (AH->currSchema)
4731  free(AH->currSchema);
4732  if (AH->currTablespace)
4733  free(AH->currTablespace);
4734  if (AH->savedPassword)
4735  free(AH->savedPassword);
4736 
4737  free(AH);
4738 }
PQExpBuffer curCmd
DeClonePtrType DeClonePtr
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
sqlparseInfo sqlparse
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:681
void DropBlobIfExists ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 663 of file pg_backup_db.c.

References ahprintf(), _archiveHandle::connection, and PQserverVersion().

Referenced by _StartBlob(), RestoreArchive(), and StartRestoreBlob().

664 {
665  /*
666  * If we are not restoring to a direct database connection, we have to
667  * guess about how to detect whether the blob exists. Assume new-style.
668  */
669  if (AH->connection == NULL ||
670  PQserverVersion(AH->connection) >= 90000)
671  {
672  ahprintf(AH,
673  "SELECT pg_catalog.lo_unlink(oid) "
674  "FROM pg_catalog.pg_largeobject_metadata "
675  "WHERE oid = '%u';\n",
676  oid);
677  }
678  else
679  {
680  /* Restoring to pre-9.0 server, so do it the old way */
681  ahprintf(AH,
682  "SELECT CASE WHEN EXISTS("
683  "SELECT 1 FROM pg_catalog.pg_largeobject WHERE loid = '%u'"
684  ") THEN pg_catalog.lo_unlink('%u') END;\n",
685  oid, oid);
686  }
687 }
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6087
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
void EndRestoreBlob ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 1350 of file pg_backup_archiver.c.

References ahprintf(), _archiveHandle::connection, dump_lo_buf(), _archiveHandle::lo_buf_used, lo_close(), _archiveHandle::loFd, and _archiveHandle::writingBlob.

Referenced by _LoadBlobs().

1351 {
1352  if (AH->lo_buf_used > 0)
1353  {
1354  /* Write remaining bytes from the LO buffer */
1355  dump_lo_buf(AH);
1356  }
1357 
1358  AH->writingBlob = 0;
1359 
1360  if (AH->connection)
1361  {
1362  lo_close(AH->connection, AH->loFd);
1363  AH->loFd = -1;
1364  }
1365  else
1366  {
1367  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
1368  }
1369 }
int lo_close(PGconn *conn, int fd)
Definition: fe-lobj.c:99
static void dump_lo_buf(ArchiveHandle *AH)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
void EndRestoreBlobs ( ArchiveHandle AH)

Definition at line 1283 of file pg_backup_archiver.c.

References ahlog(), ahprintf(), _archiveHandle::blobCount, CommitTransaction(), _archiveHandle::connection, ngettext, _archiveHandle::public, Archive::ropt, and _restoreOptions::single_txn.

Referenced by _LoadBlobs().

1284 {
1285  RestoreOptions *ropt = AH->public.ropt;
1286 
1287  if (!ropt->single_txn)
1288  {
1289  if (AH->connection)
1290  CommitTransaction(&AH->public);
1291  else
1292  ahprintf(AH, "COMMIT;\n\n");
1293  }
1294 
1295  ahlog(AH, 1, ngettext("restored %d large object\n",
1296  "restored %d large objects\n",
1297  AH->blobCount),
1298  AH->blobCount);
1299 }
RestoreOptions * ropt
Definition: pg_backup.h:182
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
#define ngettext(s, p, n)
Definition: c.h:127
void ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
static void CommitTransaction(void)
Definition: xact.c:1933
TocEntry* getTocEntryByDumpId ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1894 of file pg_backup_archiver.c.

References buildTocEntryArrays(), and _archiveHandle::tocsByDumpId.

Referenced by parseWorkerCommand(), SortTocFromFile(), and TocIDRequired().

1895 {
1896  /* build index arrays if we didn't already */
1897  if (AH->tocsByDumpId == NULL)
1898  buildTocEntryArrays(AH);
1899 
1900  if (id > 0 && id <= AH->maxDumpId)
1901  return AH->tocsByDumpId[id];
1902 
1903  return NULL;
1904 }
static void buildTocEntryArrays(ArchiveHandle *AH)
struct _tocEntry ** tocsByDumpId
void InitArchiveFmt_Custom ( ArchiveHandle AH)

Definition at line 108 of file pg_backup_custom.c.

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndBlob(), _EndBlobs(), _EndData(), _getFilePos(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartBlob(), _StartBlobs(), _StartData(), _WorkerJobRestoreCustom(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), _archiveHandle::ArchiveEntryPtr, archModeWrite, checkSeek(), _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, lclContext::dataStart, _archiveHandle::DeClonePtr, _archiveHandle::EndBlobPtr, _archiveHandle::EndBlobsPtr, _archiveHandle::EndDataPtr, exit_horribly(), _archiveHandle::FH, lclContext::filePos, _archiveHandle::formatData, _archiveHandle::fSpec, lclContext::hasSeek, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, _archiveHandle::mode, modulename, PG_BINARY_R, PG_BINARY_W, pg_malloc(), pg_malloc0(), _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, _archiveHandle::StartBlobPtr, _archiveHandle::StartBlobsPtr, _archiveHandle::StartDataPtr, strerror(), _archiveHandle::WorkerJobDumpPtr, _archiveHandle::WorkerJobRestorePtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, _archiveHandle::WriteDataPtr, and _archiveHandle::WriteExtraTocPtr.

Referenced by _allocAH().

109 {
110  lclContext *ctx;
111 
112  /* Assuming static functions, this can be copied for each format. */
114  AH->StartDataPtr = _StartData;
115  AH->WriteDataPtr = _WriteData;
116  AH->EndDataPtr = _EndData;
117  AH->WriteBytePtr = _WriteByte;
118  AH->ReadBytePtr = _ReadByte;
119  AH->WriteBufPtr = _WriteBuf;
120  AH->ReadBufPtr = _ReadBuf;
121  AH->ClosePtr = _CloseArchive;
127 
129  AH->StartBlobPtr = _StartBlob;
130  AH->EndBlobPtr = _EndBlob;
131  AH->EndBlobsPtr = _EndBlobs;
132  AH->ClonePtr = _Clone;
133  AH->DeClonePtr = _DeClone;
134 
135  /* no parallel dump in the custom archive, only parallel restore */
136  AH->WorkerJobDumpPtr = NULL;
138 
139  /* Set up a private area. */
140  ctx = (lclContext *) pg_malloc0(sizeof(lclContext));
141  AH->formatData = (void *) ctx;
142 
143  /* Initialize LO buffering */
144  AH->lo_buf_size = LOBBUFSIZE;
145  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
146 
147  ctx->filePos = 0;
148 
149  /*
150  * Now open the file
151  */
152  if (AH->mode == archModeWrite)
153  {
154  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
155  {
156  AH->FH = fopen(AH->fSpec, PG_BINARY_W);
157  if (!AH->FH)
158  exit_horribly(modulename, "could not open output file \"%s\": %s\n",
159  AH->fSpec, strerror(errno));
160  }
161  else
162  {
163  AH->FH = stdout;
164  if (!AH->FH)
165  exit_horribly(modulename, "could not open output file: %s\n",
166  strerror(errno));
167  }
168 
169  ctx->hasSeek = checkSeek(AH->FH);
170  }
171  else
172  {
173  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
174  {
175  AH->FH = fopen(AH->fSpec, PG_BINARY_R);
176  if (!AH->FH)
177  exit_horribly(modulename, "could not open input file \"%s\": %s\n",
178  AH->fSpec, strerror(errno));
179  }
180  else
181  {
182  AH->FH = stdin;
183  if (!AH->FH)
184  exit_horribly(modulename, "could not open input file: %s\n",
185  strerror(errno));
186  }
187 
188  ctx->hasSeek = checkSeek(AH->FH);
189 
190  ReadHead(AH);
191  ReadToc(AH);
192  ctx->dataStart = _getFilePos(AH, ctx);
193  }
194 
195 }
static void _ReopenArchive(ArchiveHandle *AH)
ReopenPtrType ReopenPtr
ReadBufPtrType ReadBufPtr
void ReadToc(ArchiveHandle *AH)
void ReadHead(ArchiveHandle *AH)
DeClonePtrType DeClonePtr
static void _Clone(ArchiveHandle *AH)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
WriteBufPtrType WriteBufPtr
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
StartBlobPtrType StartBlobPtr
static int _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
EndDataPtrType EndDataPtr
#define PG_BINARY_W
Definition: c.h:1047
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
StartBlobsPtrType StartBlobsPtr
#define PG_BINARY_R
Definition: c.h:1046
ReadBytePtrType ReadBytePtr
EndBlobPtrType EndBlobPtr
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
StartDataPtrType StartDataPtr
WriteBytePtrType WriteBytePtr
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static int _ReadByte(ArchiveHandle *)
PrintTocDataPtrType PrintTocDataPtr
static const char * modulename
WriteDataPtrType WriteDataPtr
static pgoff_t _getFilePos(ArchiveHandle *AH, lclContext *ctx)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
EndBlobsPtrType EndBlobsPtr
ArchiveEntryPtrType ArchiveEntryPtr
void exit_horribly(const char *modulename, const char *fmt,...)
pgoff_t dataStart
ClonePtrType ClonePtr
const char * strerror(int errnum)
Definition: strerror.c:19
WorkerJobRestorePtrType WorkerJobRestorePtr
static void _DeClone(ArchiveHandle *AH)
bool checkSeek(FILE *fp)
ClosePtrType ClosePtr
PrintExtraTocPtrType PrintExtraTocPtr
pgoff_t filePos
static int _WriteByte(ArchiveHandle *AH, const int i)
WriteExtraTocPtrType WriteExtraTocPtr
#define LOBBUFSIZE
ReadExtraTocPtrType ReadExtraTocPtr
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
WorkerJobDumpPtrType WorkerJobDumpPtr
void InitArchiveFmt_Directory ( ArchiveHandle AH)

Definition at line 110 of file pg_backup_directory.c.

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndBlob(), _EndBlobs(), _EndData(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartBlob(), _StartBlobs(), _StartData(), _WorkerJobDumpDirectory(), _WorkerJobRestoreDirectory(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archDirectory, _archiveHandle::ArchiveEntryPtr, archModeWrite, archTar, lclContext::blobsTocFH, cfclose(), cfopen_read(), _archiveHandle::ClonePtr, closedir(), _archiveHandle::ClosePtr, dirent::d_name, lclContext::dataFH, _archiveHandle::DeClonePtr, lclContext::directory, _archiveHandle::EndBlobPtr, _archiveHandle::EndBlobsPtr, _archiveHandle::EndDataPtr, exit_horribly(), _archiveHandle::format, _archiveHandle::formatData, _archiveHandle::fSpec, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, MAXPGPATH, mkdir, _archiveHandle::mode, modulename, opendir(), PG_BINARY_R, pg_malloc(), pg_malloc0(), _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, readdir(), _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, setFilePath(), _archiveHandle::StartBlobPtr, _archiveHandle::StartBlobsPtr, _archiveHandle::StartDataPtr, strerror(), _archiveHandle::WorkerJobDumpPtr, _archiveHandle::WorkerJobRestorePtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, _archiveHandle::WriteDataPtr, and _archiveHandle::WriteExtraTocPtr.

Referenced by _allocAH().

111 {
112  lclContext *ctx;
113 
114  /* Assuming static functions, this can be copied for each format. */
116  AH->StartDataPtr = _StartData;
117  AH->WriteDataPtr = _WriteData;
118  AH->EndDataPtr = _EndData;
119  AH->WriteBytePtr = _WriteByte;
120  AH->ReadBytePtr = _ReadByte;
121  AH->WriteBufPtr = _WriteBuf;
122  AH->ReadBufPtr = _ReadBuf;
123  AH->ClosePtr = _CloseArchive;
129 
131  AH->StartBlobPtr = _StartBlob;
132  AH->EndBlobPtr = _EndBlob;
133  AH->EndBlobsPtr = _EndBlobs;
134 
135  AH->ClonePtr = _Clone;
136  AH->DeClonePtr = _DeClone;
137 
140 
141  /* Set up our private context */
142  ctx = (lclContext *) pg_malloc0(sizeof(lclContext));
143  AH->formatData = (void *) ctx;
144 
145  ctx->dataFH = NULL;
146  ctx->blobsTocFH = NULL;
147 
148  /* Initialize LO buffering */
149  AH->lo_buf_size = LOBBUFSIZE;
150  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
151 
152  /*
153  * Now open the TOC file
154  */
155 
156  if (!AH->fSpec || strcmp(AH->fSpec, "") == 0)
157  exit_horribly(modulename, "no output directory specified\n");
158 
159  ctx->directory = AH->fSpec;
160 
161  if (AH->mode == archModeWrite)
162  {
163  struct stat st;
164  bool is_empty = false;
165 
166  /* we accept an empty existing directory */
167  if (stat(ctx->directory, &st) == 0 && S_ISDIR(st.st_mode))
168  {
169  DIR *dir = opendir(ctx->directory);
170 
171  if (dir)
172  {
173  struct dirent *d;
174 
175  is_empty = true;
176  while (errno = 0, (d = readdir(dir)))
177  {
178  if (strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0)
179  {
180  is_empty = false;
181  break;
182  }
183  }
184 
185  if (errno)
186  exit_horribly(modulename, "could not read directory \"%s\": %s\n",
187  ctx->directory, strerror(errno));
188 
189  if (closedir(dir))
190  exit_horribly(modulename, "could not close directory \"%s\": %s\n",
191  ctx->directory, strerror(errno));
192  }
193  }
194 
195  if (!is_empty && mkdir(ctx->directory, 0700) < 0)
196  exit_horribly(modulename, "could not create directory \"%s\": %s\n",
197  ctx->directory, strerror(errno));
198  }
199  else
200  { /* Read Mode */
201  char fname[MAXPGPATH];
202  cfp *tocFH;
203 
204  setFilePath(AH, fname, "toc.dat");
205 
206  tocFH = cfopen_read(fname, PG_BINARY_R);
207  if (tocFH == NULL)
209  "could not open input file \"%s\": %s\n",
210  fname, strerror(errno));
211 
212  ctx->dataFH = tocFH;
213 
214  /*
215  * The TOC of a directory format dump shares the format code of the
216  * tar format.
217  */
218  AH->format = archTar;
219  ReadHead(AH);
220  AH->format = archDirectory;
221  ReadToc(AH);
222 
223  /* Nothing else in the file, so close it again... */
224  if (cfclose(tocFH) != 0)
225  exit_horribly(modulename, "could not close TOC file: %s\n",
226  strerror(errno));
227  ctx->dataFH = NULL;
228  }
229 }
ReopenPtrType ReopenPtr
static void _StartData(ArchiveHandle *AH, TocEntry *te)
ReadBufPtrType ReadBufPtr
void ReadToc(ArchiveHandle *AH)
void ReadHead(ArchiveHandle *AH)
DeClonePtrType DeClonePtr
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
WriteBufPtrType WriteBufPtr
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static int _WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
#define mkdir(a, b)
Definition: win32.h:57
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void setFilePath(ArchiveHandle *AH, char *buf, const char *relativeFilename)
StartBlobPtrType StartBlobPtr
EndDataPtrType EndDataPtr
int closedir(DIR *)
Definition: dirent.c:111
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static const char * modulename
StartBlobsPtrType StartBlobsPtr
int cfclose(cfp *fp)
Definition: compress_io.c:667
Definition: dirent.h:9
#define PG_BINARY_R
Definition: c.h:1046
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
ReadBytePtrType ReadBytePtr
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
EndBlobPtrType EndBlobPtr
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
Definition: dirent.c:25
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
#define MAXPGPATH
DIR * opendir(const char *)
Definition: dirent.c:33
static void _Clone(ArchiveHandle *AH)
StartDataPtrType StartDataPtr
WriteBytePtrType WriteBytePtr
ArchiveFormat format
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
PrintTocDataPtrType PrintTocDataPtr
WriteDataPtrType WriteDataPtr
static void _DeClone(ArchiveHandle *AH)
static int _ReadByte(ArchiveHandle *)
EndBlobsPtrType EndBlobsPtr
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
ArchiveEntryPtrType ArchiveEntryPtr
struct dirent * readdir(DIR *)
Definition: dirent.c:77
void exit_horribly(const char *modulename, const char *fmt,...)
static void _CloseArchive(ArchiveHandle *AH)
ClonePtrType ClonePtr
cfp * cfopen_read(const char *path, const char *mode)
Definition: compress_io.c:467
const char * strerror(int errnum)
Definition: strerror.c:19
WorkerJobRestorePtrType WorkerJobRestorePtr
static int _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te)
static void _ReopenArchive(ArchiveHandle *AH)
ClosePtrType ClosePtr
char d_name[MAX_PATH]
Definition: dirent.h:14
PrintExtraTocPtrType PrintExtraTocPtr
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
WriteExtraTocPtrType WriteExtraTocPtr
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
#define LOBBUFSIZE
ReadExtraTocPtrType ReadExtraTocPtr
WorkerJobDumpPtrType WorkerJobDumpPtr
void InitArchiveFmt_Null ( ArchiveHandle AH)

Definition at line 49 of file pg_backup_null.c.

References _CloseArchive(), _EndBlob(), _EndBlobs(), _EndData(), _PrintTocData(), _StartBlob(), _StartBlobs(), _WriteBuf(), _WriteByte(), _WriteData(), archModeRead, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndBlobPtr, _archiveHandle::EndBlobsPtr, _archiveHandle::EndDataPtr, exit_horribly(), _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, _archiveHandle::mode, pg_malloc(), _archiveHandle::PrintTocDataPtr, _archiveHandle::ReopenPtr, _archiveHandle::StartBlobPtr, _archiveHandle::StartBlobsPtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, and _archiveHandle::WriteDataPtr.

Referenced by _allocAH().

50 {
51  /* Assuming static functions, this can be copied for each format. */
53  AH->EndDataPtr = _EndData;
55  AH->WriteBufPtr = _WriteBuf;
56  AH->ClosePtr = _CloseArchive;
57  AH->ReopenPtr = NULL;
59 
62  AH->EndBlobPtr = _EndBlob;
63  AH->EndBlobsPtr = _EndBlobs;
64  AH->ClonePtr = NULL;
65  AH->DeClonePtr = NULL;
66 
67  /* Initialize LO buffering */
68  AH->lo_buf_size = LOBBUFSIZE;
69  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
70 
71  /*
72  * Now prevent reading...
73  */
74  if (AH->mode == archModeRead)
75  exit_horribly(NULL, "this format cannot be read\n");
76 }
ReopenPtrType ReopenPtr
DeClonePtrType DeClonePtr
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
WriteBufPtrType WriteBufPtr
StartBlobPtrType StartBlobPtr
EndDataPtrType EndDataPtr
StartBlobsPtrType StartBlobsPtr
EndBlobPtrType EndBlobPtr
static void _CloseArchive(ArchiveHandle *AH)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
WriteBytePtrType WriteBytePtr
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
PrintTocDataPtrType PrintTocDataPtr
WriteDataPtrType WriteDataPtr
static void _EndData(ArchiveHandle *AH, TocEntry *te)
EndBlobsPtrType EndBlobsPtr
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
void exit_horribly(const char *modulename, const char *fmt,...)
ClonePtrType ClonePtr
ClosePtrType ClosePtr
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
#define LOBBUFSIZE
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
void InitArchiveFmt_Tar ( ArchiveHandle AH)

Definition at line 129 of file pg_backup_tar.c.

References _ArchiveEntry(), _CloseArchive(), _EndBlob(), _EndBlobs(), _EndData(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _StartBlob(), _StartBlobs(), _StartData(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archModeWrite, checkSeek(), exit_horribly(), lclContext::FH, lclContext::filePos, lclContext::hasSeek, lclContext::isSpecialScript, LOBBUFSIZE, modulename, PG_BINARY_R, PG_BINARY_W, pg_malloc(), pg_malloc0(), ReadHead(), ReadToc(), strerror(), tarClose(), lclContext::tarFH, lclContext::tarFHpos, and tarOpen().

Referenced by _allocAH().

130 {
131  lclContext *ctx;
132 
133  /* Assuming static functions, this can be copied for each format. */
135  AH->StartDataPtr = _StartData;
136  AH->WriteDataPtr = _WriteData;
137  AH->EndDataPtr = _EndData;
138  AH->WriteBytePtr = _WriteByte;
139  AH->ReadBytePtr = _ReadByte;
140  AH->WriteBufPtr = _WriteBuf;
141  AH->ReadBufPtr = _ReadBuf;
142  AH->ClosePtr = _CloseArchive;
143  AH->ReopenPtr = NULL;
148 
150  AH->StartBlobPtr = _StartBlob;
151  AH->EndBlobPtr = _EndBlob;
152  AH->EndBlobsPtr = _EndBlobs;
153  AH->ClonePtr = NULL;
154  AH->DeClonePtr = NULL;
155 
156  AH->WorkerJobDumpPtr = NULL;
157  AH->WorkerJobRestorePtr = NULL;
158 
159  /*
160  * Set up some special context used in compressing data.
161  */
162  ctx = (lclContext *) pg_malloc0(sizeof(lclContext));
163  AH->formatData = (void *) ctx;
164  ctx->filePos = 0;
165  ctx->isSpecialScript = 0;
166 
167  /* Initialize LO buffering */
168  AH->lo_buf_size = LOBBUFSIZE;
169  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
170 
171  /*
172  * Now open the tar file, and load the TOC if we're in read mode.
173  */
174  if (AH->mode == archModeWrite)
175  {
176  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
177  {
178  ctx->tarFH = fopen(AH->fSpec, PG_BINARY_W);
179  if (ctx->tarFH == NULL)
181  "could not open TOC file \"%s\" for output: %s\n",
182  AH->fSpec, strerror(errno));
183  }
184  else
185  {
186  ctx->tarFH = stdout;
187  if (ctx->tarFH == NULL)
189  "could not open TOC file for output: %s\n",
190  strerror(errno));
191  }
192 
193  ctx->tarFHpos = 0;
194 
195  /*
196  * Make unbuffered since we will dup() it, and the buffers screw each
197  * other
198  */
199  /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
200 
201  ctx->hasSeek = checkSeek(ctx->tarFH);
202 
203  /*
204  * We don't support compression because reading the files back is not
205  * possible since gzdopen uses buffered IO which totally screws file
206  * positioning.
207  */
208  if (AH->compression != 0)
210  "compression is not supported by tar archive format\n");
211  }
212  else
213  { /* Read Mode */
214  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
215  {
216  ctx->tarFH = fopen(AH->fSpec, PG_BINARY_R);
217  if (ctx->tarFH == NULL)
218  exit_horribly(modulename, "could not open TOC file \"%s\" for input: %s\n",
219  AH->fSpec, strerror(errno));
220  }
221  else
222  {
223  ctx->tarFH = stdin;
224  if (ctx->tarFH == NULL)
225  exit_horribly(modulename, "could not open TOC file for input: %s\n",
226  strerror(errno));
227  }
228 
229  /*
230  * Make unbuffered since we will dup() it, and the buffers screw each
231  * other
232  */
233  /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
234 
235  ctx->tarFHpos = 0;
236 
237  ctx->hasSeek = checkSeek(ctx->tarFH);
238 
239  /*
240  * Forcibly unmark the header as read since we use the lookahead
241  * buffer
242  */
243  AH->readHeader = 0;
244 
245  ctx->FH = (void *) tarOpen(AH, "toc.dat", 'r');
246  ReadHead(AH);
247  ReadToc(AH);
248  tarClose(AH, ctx->FH); /* Nothing else in the file... */
249  }
250 }
TAR_MEMBER * FH
Definition: pg_backup_tar.c:91
ReopenPtrType ReopenPtr
ReadBufPtrType ReadBufPtr
void ReadToc(ArchiveHandle *AH)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
void ReadHead(ArchiveHandle *AH)
DeClonePtrType DeClonePtr
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
WriteBufPtrType WriteBufPtr
static TAR_MEMBER * tarOpen(ArchiveHandle *AH, const char *filename, char mode)
pgoff_t tarFHpos
Definition: pg_backup_tar.c:89
StartBlobPtrType StartBlobPtr
EndDataPtrType EndDataPtr
#define PG_BINARY_W
Definition: c.h:1047
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
StartBlobsPtrType StartBlobsPtr
#define PG_BINARY_R
Definition: c.h:1046
ReadBytePtrType ReadBytePtr
EndBlobPtrType EndBlobPtr
int isSpecialScript
Definition: pg_backup_tar.c:92
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
FILE * tarFH
Definition: pg_backup_tar.c:88
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
StartDataPtrType StartDataPtr
static void tarClose(ArchiveHandle *AH, TAR_MEMBER *TH)
WriteBytePtrType WriteBytePtr
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
static const char * modulename
PrintTocDataPtrType PrintTocDataPtr
WriteDataPtrType WriteDataPtr
static void _EndData(ArchiveHandle *AH, TocEntry *te)
EndBlobsPtrType EndBlobsPtr
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
ArchiveEntryPtrType ArchiveEntryPtr
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
void exit_horribly(const char *modulename, const char *fmt,...)
ClonePtrType ClonePtr
static void _CloseArchive(ArchiveHandle *AH)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
const char * strerror(int errnum)
Definition: strerror.c:19
WorkerJobRestorePtrType WorkerJobRestorePtr
bool checkSeek(FILE *fp)
ClosePtrType ClosePtr
PrintExtraTocPtrType PrintExtraTocPtr
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
pgoff_t filePos
static int _ReadByte(ArchiveHandle *)
WriteExtraTocPtrType WriteExtraTocPtr
#define LOBBUFSIZE
static int _WriteByte(ArchiveHandle *AH, const int i)
ReadExtraTocPtrType ReadExtraTocPtr
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
WorkerJobDumpPtrType WorkerJobDumpPtr
bool isValidTarHeader ( char *  header)

Definition at line 1059 of file pg_backup_tar.c.

References read_tar_number(), and tarChecksum().

Referenced by _discoverArchiveFormat().

1060 {
1061  int sum;
1062  int chk = tarChecksum(header);
1063 
1064  sum = read_tar_number(&header[148], 8);
1065 
1066  if (sum != chk)
1067  return false;
1068 
1069  /* POSIX tar format */
1070  if (memcmp(&header[257], "ustar\0", 6) == 0 &&
1071  memcmp(&header[263], "00", 2) == 0)
1072  return true;
1073  /* GNU tar format */
1074  if (memcmp(&header[257], "ustar \0", 8) == 0)
1075  return true;
1076  /* not-quite-POSIX format written by pre-9.3 pg_dump */
1077  if (memcmp(&header[257], "ustar00\0", 8) == 0)
1078  return true;
1079 
1080  return false;
1081 }
uint64 read_tar_number(const char *s, int len)
Definition: tar.c:56
int tarChecksum(char *header)
Definition: tar.c:88
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:208
void on_exit_close_archive ( Archive AHX)

Definition at line 347 of file parallel.c.

References ShutdownInformation::AHX, archive_close_connection(), and on_exit_nicely().

Referenced by main().

348 {
349  shutdown_info.AHX = AHX;
351 }
void on_exit_nicely(on_exit_nicely_callback function, void *arg)
static ShutdownInformation shutdown_info
Definition: parallel.c:150
static void archive_close_connection(int code, void *arg)
Definition: parallel.c:358
int parallel_restore ( ArchiveHandle AH,
TocEntry te 
)

Definition at line 4278 of file pg_backup_archiver.c.

References Assert, _archiveHandle::connection, Archive::n_errors, _archiveHandle::public, restore_toc_entry(), and status().

Referenced by _WorkerJobRestoreCustom(), and _WorkerJobRestoreDirectory().

4279 {
4280  int status;
4281 
4282  Assert(AH->connection != NULL);
4283 
4284  /* Count only errors associated with this TOC entry */
4285  AH->public.n_errors = 0;
4286 
4287  /* Restore the TOC item */
4288  status = restore_toc_entry(AH, te, true);
4289 
4290  return status;
4291 }
int n_errors
Definition: pg_backup.h:202
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
#define Assert(condition)
Definition: c.h:681
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
void ReadHead ( ArchiveHandle AH)

Definition at line 3673 of file pg_backup_archiver.c.

References _archiveHandle::archdbname, _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, _archiveHandle::compression, _archiveHandle::createDate, exit_horribly(), _archiveHandle::format, _archiveHandle::intSize, K_VERS_1_0, K_VERS_1_10, K_VERS_1_2, K_VERS_1_4, K_VERS_1_7, K_VERS_MAX, MAKE_ARCHIVE_VERSION, modulename, _archiveHandle::offSize, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::readHeader, ReadInt(), ReadStr(), tm, _archiveHandle::version, write_msg(), and Z_DEFAULT_COMPRESSION.

Referenced by InitArchiveFmt_Custom(), InitArchiveFmt_Directory(), and InitArchiveFmt_Tar().

3674 {
3675  char tmpMag[7];
3676  int fmt;
3677  struct tm crtm;
3678 
3679  /*
3680  * If we haven't already read the header, do so.
3681  *
3682  * NB: this code must agree with _discoverArchiveFormat(). Maybe find a
3683  * way to unify the cases?
3684  */
3685  if (!AH->readHeader)
3686  {
3687  char vmaj,
3688  vmin,
3689  vrev;
3690 
3691  AH->ReadBufPtr(AH, tmpMag, 5);
3692 
3693  if (strncmp(tmpMag, "PGDMP", 5) != 0)
3694  exit_horribly(modulename, "did not find magic string in file header\n");
3695 
3696  vmaj = AH->ReadBytePtr(AH);
3697  vmin = AH->ReadBytePtr(AH);
3698 
3699  if (vmaj > 1 || (vmaj == 1 && vmin > 0)) /* Version > 1.0 */
3700  vrev = AH->ReadBytePtr(AH);
3701  else
3702  vrev = 0;
3703 
3704  AH->version = MAKE_ARCHIVE_VERSION(vmaj, vmin, vrev);
3705 
3706  if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
3707  exit_horribly(modulename, "unsupported version (%d.%d) in file header\n",
3708  vmaj, vmin);
3709 
3710  AH->intSize = AH->ReadBytePtr(AH);
3711  if (AH->intSize > 32)
3712  exit_horribly(modulename, "sanity check on integer size (%lu) failed\n",
3713  (unsigned long) AH->intSize);
3714 
3715  if (AH->intSize > sizeof(int))
3716  write_msg(modulename, "WARNING: archive was made on a machine with larger integers, some operations might fail\n");
3717 
3718  if (AH->version >= K_VERS_1_7)
3719  AH->offSize = AH->ReadBytePtr(AH);
3720  else
3721  AH->offSize = AH->intSize;
3722 
3723  fmt = AH->ReadBytePtr(AH);
3724 
3725  if (AH->format != fmt)
3726  exit_horribly(modulename, "expected format (%d) differs from format found in file (%d)\n",
3727  AH->format, fmt);
3728  }
3729 
3730  if (AH->version >= K_VERS_1_2)
3731  {
3732  if (AH->version < K_VERS_1_4)
3733  AH->compression = AH->ReadBytePtr(AH);
3734  else
3735  AH->compression = ReadInt(AH);
3736  }
3737  else
3739 
3740 #ifndef HAVE_LIBZ
3741  if (AH->compression != 0)
3742  write_msg(modulename, "WARNING: archive is compressed, but this installation does not support compression -- no data will be available\n");
3743 #endif
3744 
3745  if (AH->version >= K_VERS_1_4)
3746  {
3747  crtm.tm_sec = ReadInt(AH);
3748  crtm.tm_min = ReadInt(AH);
3749  crtm.tm_hour = ReadInt(AH);
3750  crtm.tm_mday = ReadInt(AH);
3751  crtm.tm_mon = ReadInt(AH);
3752  crtm.tm_year = ReadInt(AH);
3753  crtm.tm_isdst = ReadInt(AH);
3754 
3755  AH->archdbname = ReadStr(AH);
3756 
3757  AH->createDate = mktime(&crtm);
3758 
3759  if (AH->createDate == (time_t) -1)
3760  write_msg(modulename, "WARNING: invalid creation date in header\n");
3761  }
3762 
3763  if (AH->version >= K_VERS_1_10)
3764  {
3765  AH->archiveRemoteVersion = ReadStr(AH);
3766  AH->archiveDumpVersion = ReadStr(AH);
3767  }
3768 }
ReadBufPtrType ReadBufPtr
#define Z_DEFAULT_COMPRESSION
#define K_VERS_1_0
int ReadInt(ArchiveHandle *AH)
#define K_VERS_1_4
ReadBytePtrType ReadBytePtr
static struct pg_tm tm
Definition: localtime.c:107
#define K_VERS_1_7
#define MAKE_ARCHIVE_VERSION(major, minor, rev)
#define K_VERS_1_2
#define K_VERS_1_10
ArchiveFormat format
#define K_VERS_MAX
void write_msg(const char *modulename, const char *fmt,...)
char * ReadStr(ArchiveHandle *AH)
void exit_horribly(const char *modulename, const char *fmt,...)
static const char * modulename
int ReadInt ( ArchiveHandle AH)

Definition at line 2030 of file pg_backup_archiver.c.

References _archiveHandle::intSize, K_VERS_1_0, _archiveHandle::ReadBytePtr, sign, and _archiveHandle::version.

Referenced by _CustomReadFunc(), _LoadBlobs(), _readBlockHeader(), _ReadExtraToc(), _skipBlobs(), _skipData(), ReadHead(), ReadOffset(), ReadStr(), and ReadToc().

2031 {
2032  int res = 0;
2033  int bv,
2034  b;
2035  int sign = 0; /* Default positive */
2036  int bitShift = 0;
2037 
2038  if (AH->version > K_VERS_1_0)
2039  /* Read a sign byte */
2040  sign = AH->ReadBytePtr(AH);
2041 
2042  for (b = 0; b < AH->intSize; b++)
2043  {
2044  bv = AH->ReadBytePtr(AH) & 0xFF;
2045  if (bv != 0)
2046  res = res + (bv << bitShift);
2047  bitShift += 8;
2048  }
2049 
2050  if (sign)
2051  res = -res;
2052 
2053  return res;
2054 }
#define K_VERS_1_0
ReadBytePtrType ReadBytePtr
char sign
Definition: informix.c:693
int ReadOffset ( ArchiveHandle ,
pgoff_t  
)

Definition at line 1935 of file pg_backup_archiver.c.

References exit_horribly(), i, K_OFFSET_NO_DATA, K_OFFSET_POS_NOT_SET, K_OFFSET_POS_SET, K_VERS_1_7, modulename, _archiveHandle::offSize, pgoff_t, _archiveHandle::ReadBytePtr, ReadInt(), and _archiveHandle::version.

Referenced by _ReadExtraToc().

1936 {
1937  int i;
1938  int off;
1939  int offsetFlg;
1940 
1941  /* Initialize to zero */
1942  *o = 0;
1943 
1944  /* Check for old version */
1945  if (AH->version < K_VERS_1_7)
1946  {
1947  /* Prior versions wrote offsets using WriteInt */
1948  i = ReadInt(AH);
1949  /* -1 means not set */
1950  if (i < 0)
1951  return K_OFFSET_POS_NOT_SET;
1952  else if (i == 0)
1953  return K_OFFSET_NO_DATA;
1954 
1955  /* Cast to pgoff_t because it was written as an int. */
1956  *o = (pgoff_t) i;
1957  return K_OFFSET_POS_SET;
1958  }
1959 
1960  /*
1961  * Read the flag indicating the state of the data pointer. Check if valid
1962  * and die if not.
1963  *
1964  * This used to be handled by a negative or zero pointer, now we use an
1965  * extra byte specifically for the state.
1966  */
1967  offsetFlg = AH->ReadBytePtr(AH) & 0xFF;
1968 
1969  switch (offsetFlg)
1970  {
1971  case K_OFFSET_POS_NOT_SET:
1972  case K_OFFSET_NO_DATA:
1973  case K_OFFSET_POS_SET:
1974 
1975  break;
1976 
1977  default:
1978  exit_horribly(modulename, "unexpected data offset flag %d\n", offsetFlg);
1979  }
1980 
1981  /*
1982  * Read the bytes
1983  */
1984  for (off = 0; off < AH->offSize; off++)
1985  {
1986  if (off < sizeof(pgoff_t))
1987  *o |= ((pgoff_t) (AH->ReadBytePtr(AH))) << (off * 8);
1988  else
1989  {
1990  if (AH->ReadBytePtr(AH) != 0)
1991  exit_horribly(modulename, "file offset in dump file is too large\n");
1992  }
1993  }
1994 
1995  return offsetFlg;
1996 }
int ReadInt(ArchiveHandle *AH)
#define K_VERS_1_7
#define K_OFFSET_NO_DATA
#define pgoff_t
Definition: win32.h:231
void exit_horribly(const char *modulename, const char *fmt,...)
#define K_OFFSET_POS_SET
int i
static const char * modulename
#define K_OFFSET_POS_NOT_SET
char* ReadStr ( ArchiveHandle AH)

Definition at line 2076 of file pg_backup_archiver.c.

References buf, pg_malloc(), _archiveHandle::ReadBufPtr, and ReadInt().

Referenced by _ReadExtraToc(), ReadHead(), and ReadToc().

2077 {
2078  char *buf;
2079  int l;
2080 
2081  l = ReadInt(AH);
2082  if (l < 0)
2083  buf = NULL;
2084  else
2085  {
2086  buf = (char *) pg_malloc(l + 1);
2087  AH->ReadBufPtr(AH, (void *) buf, l);
2088 
2089  buf[l] = '\0';
2090  }
2091 
2092  return buf;
2093 }
ReadBufPtrType ReadBufPtr
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int ReadInt(ArchiveHandle *AH)
static char * buf
Definition: pg_test_fsync.c:67
void ReadTOC ( ArchiveHandle AH)
void ReadToc ( ArchiveHandle AH)

Definition at line 2565 of file pg_backup_archiver.c.

References ahlog(), _tocEntry::catalogId, _tocEntry::copyStmt, _tocEntry::defn, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dropStmt, _tocEntry::dumpId, exit_horribly(), free, _tocEntry::hadDumper, i, InvalidOid, K_VERS_1_10, K_VERS_1_11, K_VERS_1_3, K_VERS_1_5, K_VERS_1_6, K_VERS_1_8, K_VERS_1_9, _archiveHandle::maxDumpId, modulename, _tocEntry::nDeps, _tocEntry::next, CatalogId::oid, _tocEntry::owner, pg_malloc(), pg_malloc0(), pg_realloc(), _tocEntry::prev, processEncodingEntry(), processStdStringsEntry(), _archiveHandle::ReadExtraTocPtr, ReadInt(), ReadStr(), _tocEntry::section, SECTION_DATA, SECTION_NONE, SECTION_POST_DATA, SECTION_PRE_DATA, CatalogId::tableoid, _tocEntry::tablespace, _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocCount, _archiveHandle::version, and _tocEntry::withOids.

Referenced by InitArchiveFmt_Custom(), InitArchiveFmt_Directory(), and InitArchiveFmt_Tar().

2566 {
2567  int i;
2568  char *tmp;
2569  DumpId *deps;
2570  int depIdx;
2571  int depSize;
2572  TocEntry *te;
2573 
2574  AH->tocCount = ReadInt(AH);
2575  AH->maxDumpId = 0;
2576 
2577  for (i = 0; i < AH->tocCount; i++)
2578  {
2579  te = (TocEntry *) pg_malloc0(sizeof(TocEntry));
2580  te->dumpId = ReadInt(AH);
2581 
2582  if (te->dumpId > AH->maxDumpId)
2583  AH->maxDumpId = te->dumpId;
2584 
2585  /* Sanity check */
2586  if (te->dumpId <= 0)
2588  "entry ID %d out of range -- perhaps a corrupt TOC\n",
2589  te->dumpId);
2590 
2591  te->hadDumper = ReadInt(AH);
2592 
2593  if (AH->version >= K_VERS_1_8)
2594  {
2595  tmp = ReadStr(AH);
2596  sscanf(tmp, "%u", &te->catalogId.tableoid);
2597  free(tmp);
2598  }
2599  else
2601  tmp = ReadStr(AH);
2602  sscanf(tmp, "%u", &te->catalogId.oid);
2603  free(tmp);
2604 
2605  te->tag = ReadStr(AH);
2606  te->desc = ReadStr(AH);
2607 
2608  if (AH->version >= K_VERS_1_11)
2609  {
2610  te->section = ReadInt(AH);
2611  }
2612  else
2613  {
2614  /*
2615  * Rules for pre-8.4 archives wherein pg_dump hasn't classified
2616  * the entries into sections. This list need not cover entry
2617  * types added later than 8.4.
2618  */
2619  if (strcmp(te->desc, "COMMENT") == 0 ||
2620  strcmp(te->desc, "ACL") == 0 ||
2621  strcmp(te->desc, "ACL LANGUAGE") == 0)
2622  te->section = SECTION_NONE;
2623  else if (strcmp(te->desc, "TABLE DATA") == 0 ||
2624  strcmp(te->desc, "BLOBS") == 0 ||
2625  strcmp(te->desc, "BLOB COMMENTS") == 0)
2626  te->section = SECTION_DATA;
2627  else if (strcmp(te->desc, "CONSTRAINT") == 0 ||
2628  strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
2629  strcmp(te->desc, "FK CONSTRAINT") == 0 ||
2630  strcmp(te->desc, "INDEX") == 0 ||
2631  strcmp(te->desc, "RULE") == 0 ||
2632  strcmp(te->desc, "TRIGGER") == 0)
2633  te->section = SECTION_POST_DATA;
2634  else
2635  te->section = SECTION_PRE_DATA;
2636  }
2637 
2638  te->defn = ReadStr(AH);
2639  te->dropStmt = ReadStr(AH);
2640 
2641  if (AH->version >= K_VERS_1_3)
2642  te->copyStmt = ReadStr(AH);
2643 
2644  if (AH->version >= K_VERS_1_6)
2645  te->namespace = ReadStr(AH);
2646 
2647  if (AH->version >= K_VERS_1_10)
2648  te->tablespace = ReadStr(AH);
2649 
2650  te->owner = ReadStr(AH);
2651  if (AH->version >= K_VERS_1_9)
2652  {
2653  if (strcmp(ReadStr(AH), "true") == 0)
2654  te->withOids = true;
2655  else
2656  te->withOids = false;
2657  }
2658  else
2659  te->withOids = true;
2660 
2661  /* Read TOC entry dependencies */
2662  if (AH->version >= K_VERS_1_5)
2663  {
2664  depSize = 100;
2665  deps = (DumpId *) pg_malloc(sizeof(DumpId) * depSize);
2666  depIdx = 0;
2667  for (;;)
2668  {
2669  tmp = ReadStr(AH);
2670  if (!tmp)
2671  break; /* end of list */
2672  if (depIdx >= depSize)
2673  {
2674  depSize *= 2;
2675  deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
2676  }
2677  sscanf(tmp, "%d", &deps[depIdx]);
2678  free(tmp);
2679  depIdx++;
2680  }
2681 
2682  if (depIdx > 0) /* We have a non-null entry */
2683  {
2684  deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depIdx);
2685  te->dependencies = deps;
2686  te->nDeps = depIdx;
2687  }
2688  else
2689  {
2690  free(deps);
2691  te->dependencies = NULL;
2692  te->nDeps = 0;
2693  }
2694  }
2695  else
2696  {
2697  te->dependencies = NULL;
2698  te->nDeps = 0;
2699  }
2700 
2701  if (AH->ReadExtraTocPtr)
2702  AH->ReadExtraTocPtr(AH, te);
2703 
2704  ahlog(AH, 3, "read TOC entry %d (ID %d) for %s %s\n",
2705  i, te->dumpId, te->desc, te->tag);
2706 
2707  /* link completed entry into TOC circular list */
2708  te->prev = AH->toc->prev;
2709  AH->toc->prev->next = te;
2710  AH->toc->prev = te;
2711  te->next = AH->toc;
2712 
2713  /* special processing immediately upon read for some items */
2714  if (strcmp(te->desc, "ENCODING") == 0)
2715  processEncodingEntry(AH, te);
2716  else if (strcmp(te->desc, "STDSTRINGS") == 0)
2717  processStdStringsEntry(AH, te);
2718  }
2719 }
struct _tocEntry * next
static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
int DumpId
Definition: pg_backup.h:230
Oid tableoid
Definition: pg_backup.h:226
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
CatalogId catalogId
#define K_VERS_1_9
int ReadInt(ArchiveHandle *AH)
static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te)
teSection section
#define K_VERS_1_5
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
struct _tocEntry * toc
DumpId * dependencies
#define K_VERS_1_8
#define K_VERS_1_10
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
#define K_VERS_1_3
struct _tocEntry * prev
#define InvalidOid
Definition: postgres_ext.h:36
#define free(a)
Definition: header.h:65
char * ReadStr(ArchiveHandle *AH)
void exit_horribly(const char *modulename, const char *fmt,...)
#define K_VERS_1_6
void ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
int i
#define K_VERS_1_11
static const char * modulename
ReadExtraTocPtrType ReadExtraTocPtr
int ReconnectToServer ( ArchiveHandle AH,
const char *  dbname,
const char *  newUser 
)

Definition at line 86 of file pg_backup_db.c.

References _connectDB(), _archiveHandle::connection, dbname, PQdb(), PQfinish(), PQuser(), set_archive_cancel_info(), and username.

Referenced by _reconnectToDB().

87 {
88  PGconn *newConn;
89  const char *newdbname;
90  const char *newusername;
91 
92  if (!dbname)
93  newdbname = PQdb(AH->connection);
94  else
95  newdbname = dbname;
96 
97  if (!username)
98  newusername = PQuser(AH->connection);
99  else
100  newusername = username;
101 
102  /* Let's see if the request is already satisfied */
103  if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
104  strcmp(newusername, PQuser(AH->connection)) == 0)
105  return 1;
106 
107  newConn = _connectDB(AH, newdbname, newusername);
108 
109  /* Update ArchiveHandle's connCancel before closing old connection */
110  set_archive_cancel_info(AH, newConn);
111 
112  PQfinish(AH->connection);
113  AH->connection = newConn;
114 
115  return 1;
116 }
static PGconn * _connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser)
Definition: pg_backup_db.c:128
void PQfinish(PGconn *conn)
Definition: fe-connect.c:3630
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:5973
static char * username
Definition: initdb.c:132
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:5965
char * dbname
Definition: streamutil.c:42
void set_archive_cancel_info(ArchiveHandle *AH, PGconn *conn)
Definition: parallel.c:744
void StartRestoreBlob ( ArchiveHandle AH,
Oid  oid,
bool  drop 
)

Definition at line 1306 of file pg_backup_archiver.c.

References ahlog(), ahprintf(), _archiveHandle::blobCount, _archiveHandle::connection, DropBlobIfExists(), exit_horribly(), INV_WRITE, K_VERS_1_12, _archiveHandle::lo_buf_used, lo_create(), lo_open(), _archiveHandle::loFd, modulename, PQerrorMessage(), _archiveHandle::version, and _archiveHandle::writingBlob.

Referenced by _LoadBlobs().

1307 {
1308  bool old_blob_style = (AH->version < K_VERS_1_12);
1309  Oid loOid;
1310 
1311  AH->blobCount++;
1312 
1313  /* Initialize the LO Buffer */
1314  AH->lo_buf_used = 0;
1315 
1316  ahlog(AH, 1, "restoring large object with OID %u\n", oid);
1317 
1318  /* With an old archive we must do drop and create logic here */
1319  if (old_blob_style && drop)
1320  DropBlobIfExists(AH, oid);
1321 
1322  if (AH->connection)
1323  {
1324  if (old_blob_style)
1325  {
1326  loOid = lo_create(AH->connection, oid);
1327  if (loOid == 0 || loOid != oid)
1328  exit_horribly(modulename, "could not create large object %u: %s",
1329  oid, PQerrorMessage(AH->connection));
1330  }
1331  AH->loFd = lo_open(AH->connection, oid, INV_WRITE);
1332  if (AH->loFd == -1)
1333  exit_horribly(modulename, "could not open large object %u: %s",
1334  oid, PQerrorMessage(AH->connection));
1335  }
1336  else
1337  {
1338  if (old_blob_style)
1339  ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1340  oid, INV_WRITE);
1341  else
1342  ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
1343  oid, INV_WRITE);
1344  }
1345 
1346  AH->writingBlob = 1;
1347 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6097
void DropBlobIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:663
unsigned int Oid
Definition: postgres_ext.h:31
#define K_VERS_1_12
int lo_open(PGconn *conn, Oid lobjId, int mode)
Definition: fe-lobj.c:57
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
Oid lo_create(PGconn *conn, Oid lobjId)
Definition: fe-lobj.c:504
#define INV_WRITE
Definition: libpq-fs.h:21
void exit_horribly(const char *modulename, const char *fmt,...)
void ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
static const char * modulename
void StartRestoreBlobs ( ArchiveHandle AH)

Definition at line 1264 of file pg_backup_archiver.c.

References ahprintf(), _archiveHandle::blobCount, _archiveHandle::connection, _archiveHandle::public, Archive::ropt, _restoreOptions::single_txn, and StartTransaction().

Referenced by _LoadBlobs().

1265 {
1266  RestoreOptions *ropt = AH->public.ropt;
1267 
1268  if (!ropt->single_txn)
1269  {
1270  if (AH->connection)
1271  StartTransaction(&AH->public);
1272  else
1273  ahprintf(AH, "BEGIN;\n\n");
1274  }
1275 
1276  AH->blobCount = 0;
1277 }
RestoreOptions * ropt
Definition: pg_backup.h:182
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
static void StartTransaction(void)
Definition: xact.c:1795
teReqs TocIDRequired ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1907 of file pg_backup_archiver.c.

References getTocEntryByDumpId(), and _tocEntry::reqs.

Referenced by _tarPositionTo(), and findDumpableDependencies().

1908 {
1909  TocEntry *te = getTocEntryByDumpId(AH, id);
1910 
1911  if (!te)
1912  return 0;
1913 
1914  return te->reqs;
1915 }
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
void warn_or_exit_horribly ( ArchiveHandle AH,
const char *  modulename,
const char *  fmt,
  ... 
)
void WriteDataChunks ( ArchiveHandle AH,
struct ParallelState pstate 
)

Definition at line 2419 of file pg_backup_archiver.c.

References ACT_DUMP, _tocEntry::dataDumper, DispatchJobForTocEntry(), mark_dump_job_done(), _tocEntry::next, ParallelState::numWorkers, REQ_DATA, _tocEntry::reqs, _archiveHandle::toc, WaitForWorkers(), WFW_ALL_IDLE, and WriteDataChunksForTocEntry().

Referenced by _CloseArchive().

2420 {
2421  TocEntry *te;
2422 
2423  for (te = AH->toc->next; te != AH->toc; te = te->next)
2424  {
2425  if (!te->dataDumper)
2426  continue;
2427 
2428  if ((te->reqs & REQ_DATA) == 0)
2429  continue;
2430 
2431  if (pstate && pstate->numWorkers > 1)
2432  {
2433  /*
2434  * If we are in a parallel backup, then we are always the master
2435  * process. Dispatch each data-transfer job to a worker.
2436  */
2437  DispatchJobForTocEntry(AH, pstate, te, ACT_DUMP,
2438  mark_dump_job_done, NULL);
2439  }
2440  else
2442  }
2443 
2444  /*
2445  * If parallel, wait for workers to finish.
2446  */
2447  if (pstate && pstate->numWorkers > 1)
2448  WaitForWorkers(AH, pstate, WFW_ALL_IDLE);
2449 }
struct _tocEntry * next
void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, TocEntry *te, T_Action act, ParallelCompletionPtr callback, void *callback_data)
Definition: parallel.c:1229
DataDumperPtr dataDumper
struct _tocEntry * toc
void WaitForWorkers(ArchiveHandle *AH, ParallelState *pstate, WFW_WaitOption mode)
Definition: parallel.c:1477
void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
static void mark_dump_job_done(ArchiveHandle *AH, TocEntry *te, int status, void *callback_data)
int numWorkers
Definition: parallel.h:42
void WriteDataChunksForTocEntry ( ArchiveHandle AH,
TocEntry te 
)

Definition at line 2474 of file pg_backup_archiver.c.

References _archiveHandle::currToc, _tocEntry::dataDumper, _tocEntry::dataDumperArg, _tocEntry::desc, _archiveHandle::EndBlobsPtr, _archiveHandle::EndDataPtr, _archiveHandle::StartBlobsPtr, and _archiveHandle::StartDataPtr.

Referenced by _WorkerJobDumpDirectory(), and WriteDataChunks().

2475 {
2476  StartDataPtrType startPtr;
2477  EndDataPtrType endPtr;
2478 
2479  AH->currToc = te;
2480 
2481  if (strcmp(te->desc, "BLOBS") == 0)
2482  {
2483  startPtr = AH->StartBlobsPtr;
2484  endPtr = AH->EndBlobsPtr;
2485  }
2486  else
2487  {
2488  startPtr = AH->StartDataPtr;
2489  endPtr = AH->EndDataPtr;
2490  }
2491 
2492  if (startPtr != NULL)
2493  (*startPtr) (AH, te);
2494 
2495  /*
2496  * The user-provided DataDumper routine needs to call AH->WriteData
2497  */
2498  te->dataDumper((Archive *) AH, te->dataDumperArg);
2499 
2500  if (endPtr != NULL)
2501  (*endPtr) (AH, te);
2502 
2503  AH->currToc = NULL;
2504 }
void * dataDumperArg
EndDataPtrType EndDataPtr
DataDumperPtr dataDumper
StartBlobsPtrType StartBlobsPtr
struct _tocEntry * currToc
StartDataPtrType StartDataPtr
void(* StartDataPtrType)(ArchiveHandle *AH, TocEntry *te)
EndBlobsPtrType EndBlobsPtr
void(* EndDataPtrType)(ArchiveHandle *AH, TocEntry *te)
void WriteHead ( ArchiveHandle AH)

Definition at line 3647 of file pg_backup_archiver.c.

References ARCHIVE_MAJOR, ARCHIVE_MINOR, ARCHIVE_REV, _archiveHandle::compression, _archiveHandle::connection, _archiveHandle::createDate, _archiveHandle::format, _archiveHandle::intSize, _archiveHandle::offSize, PQdb(), _archiveHandle::public, Archive::remoteVersionStr, tm, _archiveHandle::version, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, WriteInt(), and WriteStr().

Referenced by _CloseArchive().

3648 {
3649  struct tm crtm;
3650 
3651  AH->WriteBufPtr(AH, "PGDMP", 5); /* Magic code */
3652  AH->WriteBytePtr(AH, ARCHIVE_MAJOR(AH->version));
3653  AH->WriteBytePtr(AH, ARCHIVE_MINOR(AH->version));
3654  AH->WriteBytePtr(AH, ARCHIVE_REV(AH->version));
3655  AH->WriteBytePtr(AH, AH->intSize);
3656  AH->WriteBytePtr(AH, AH->offSize);
3657  AH->WriteBytePtr(AH, AH->format);
3658  WriteInt(AH, AH->compression);
3659  crtm = *localtime(&AH->createDate);
3660  WriteInt(AH, crtm.tm_sec);
3661  WriteInt(AH, crtm.tm_min);
3662  WriteInt(AH, crtm.tm_hour);
3663  WriteInt(AH, crtm.tm_mday);
3664  WriteInt(AH, crtm.tm_mon);
3665  WriteInt(AH, crtm.tm_year);
3666  WriteInt(AH, crtm.tm_isdst);
3667  WriteStr(AH, PQdb(AH->connection));
3668  WriteStr(AH, AH->public.remoteVersionStr);
3669  WriteStr(AH, PG_VERSION);
3670 }
WriteBufPtrType WriteBufPtr
static struct pg_tm tm
Definition: localtime.c:107
#define ARCHIVE_REV(version)
WriteBytePtrType WriteBytePtr
#define ARCHIVE_MINOR(version)
ArchiveFormat format
#define ARCHIVE_MAJOR(version)
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:5965
size_t WriteInt(ArchiveHandle *AH, int i)
char * remoteVersionStr
Definition: pg_backup.h:185
size_t WriteStr(ArchiveHandle *AH, const char *c)
size_t WriteInt ( ArchiveHandle AH,
int  i 
)

Definition at line 1999 of file pg_backup_archiver.c.

References i, _archiveHandle::intSize, and _archiveHandle::WriteBytePtr.

Referenced by _CustomWriteFunc(), _EndBlob(), _EndBlobs(), _EndData(), _StartBlob(), _StartBlobs(), _StartData(), WriteHead(), WriteStr(), and WriteToc().

2000 {
2001  int b;
2002 
2003  /*
2004  * This is a bit yucky, but I don't want to make the binary format very
2005  * dependent on representation, and not knowing much about it, I write out
2006  * a sign byte. If you change this, don't forget to change the file
2007  * version #, and modify readInt to read the new format AS WELL AS the old
2008  * formats.
2009  */
2010 
2011  /* SIGN byte */
2012  if (i < 0)
2013  {
2014  AH->WriteBytePtr(AH, 1);
2015  i = -i;
2016  }
2017  else
2018  AH->WriteBytePtr(AH, 0);
2019 
2020  for (b = 0; b < AH->intSize; b++)
2021  {
2022  AH->WriteBytePtr(AH, i & 0xFF);
2023  i >>= 8;
2024  }
2025 
2026  return AH->intSize + 1;
2027 }
WriteBytePtrType WriteBytePtr
int i
size_t WriteOffset ( ArchiveHandle ,
pgoff_t  ,
int   
)

Definition at line 1918 of file pg_backup_archiver.c.

References pgoff_t, and _archiveHandle::WriteBytePtr.

Referenced by _WriteExtraToc().

1919 {
1920  int off;
1921 
1922  /* Save the flag */
1923  AH->WriteBytePtr(AH, wasSet);
1924 
1925  /* Write out pgoff_t smallest byte first, prevents endian mismatch */
1926  for (off = 0; off < sizeof(pgoff_t); off++)
1927  {
1928  AH->WriteBytePtr(AH, o & 0xFF);
1929  o >>= 8;
1930  }
1931  return sizeof(pgoff_t) + 1;
1932 }
#define pgoff_t
Definition: win32.h:231
size_t WriteStr ( ArchiveHandle AH,
const char *  s 
)

Definition at line 2057 of file pg_backup_archiver.c.

References _archiveHandle::WriteBufPtr, and WriteInt().

Referenced by _WriteExtraToc(), WriteHead(), and WriteToc().

2058 {
2059  size_t res;
2060 
2061  if (c)
2062  {
2063  int len = strlen(c);
2064 
2065  res = WriteInt(AH, len);
2066  AH->WriteBufPtr(AH, c, len);
2067  res += len;
2068  }
2069  else
2070  res = WriteInt(AH, -1);
2071 
2072  return res;
2073 }
WriteBufPtrType WriteBufPtr
char * c
size_t WriteInt(ArchiveHandle *AH, int i)
void void WriteTOC ( ArchiveHandle AH)
void WriteToc ( ArchiveHandle AH)

Definition at line 2507 of file pg_backup_archiver.c.

References _tocEntry::catalogId, _tocEntry::copyStmt, _tocEntry::dataDumper, _tocEntry::defn, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dropStmt, _tocEntry::dumpId, i, _tocEntry::nDeps, _tocEntry::next, CatalogId::oid, _tocEntry::owner, REQ_DATA, REQ_SCHEMA, REQ_SPECIAL, _tocEntry::reqs, _tocEntry::section, CatalogId::tableoid, _tocEntry::tablespace, _tocEntry::tag, _archiveHandle::toc, _tocEntry::withOids, _archiveHandle::WriteExtraTocPtr, WriteInt(), and WriteStr().

Referenced by _CloseArchive().

2508 {
2509  TocEntry *te;
2510  char workbuf[32];
2511  int tocCount;
2512  int i;
2513 
2514  /* count entries that will actually be dumped */
2515  tocCount = 0;
2516  for (te = AH->toc->next; te != AH->toc; te = te->next)
2517  {
2518  if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) != 0)
2519  tocCount++;
2520  }
2521 
2522  /* printf("%d TOC Entries to save\n", tocCount); */
2523 
2524  WriteInt(AH, tocCount);
2525 
2526  for (te = AH->toc->next; te != AH->toc; te = te->next)
2527  {
2528  if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) == 0)
2529  continue;
2530 
2531  WriteInt(AH, te->dumpId);
2532  WriteInt(AH, te->dataDumper ? 1 : 0);
2533 
2534  /* OID is recorded as a string for historical reasons */
2535  sprintf(workbuf, "%u", te->catalogId.tableoid);
2536  WriteStr(AH, workbuf);
2537  sprintf(workbuf, "%u", te->catalogId.oid);
2538  WriteStr(AH, workbuf);
2539 
2540  WriteStr(AH, te->tag);
2541  WriteStr(AH, te->desc);
2542  WriteInt(AH, te->section);
2543  WriteStr(AH, te->defn);
2544  WriteStr(AH, te->dropStmt);
2545  WriteStr(AH, te->copyStmt);
2546  WriteStr(AH, te->namespace);
2547  WriteStr(AH, te->tablespace);
2548  WriteStr(AH, te->owner);
2549  WriteStr(AH, te->withOids ? "true" : "false");
2550 
2551  /* Dump list of dependencies */
2552  for (i = 0; i < te->nDeps; i++)
2553  {
2554  sprintf(workbuf, "%d", te->dependencies[i]);
2555  WriteStr(AH, workbuf);
2556  }
2557  WriteStr(AH, NULL); /* Terminate List */
2558 
2559  if (AH->WriteExtraTocPtr)
2560  AH->WriteExtraTocPtr(AH, te);
2561  }
2562 }
struct _tocEntry * next
Oid tableoid
Definition: pg_backup.h:226
CatalogId catalogId
DataDumperPtr dataDumper
teSection section
struct _tocEntry * toc
DumpId * dependencies
size_t WriteInt(ArchiveHandle *AH, int i)
int i
size_t WriteStr(ArchiveHandle *AH, const char *c)
WriteExtraTocPtrType WriteExtraTocPtr