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 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(* ClosePtr )(ArchiveHandle *AH)
 
typedef void(* ReopenPtr )(ArchiveHandle *AH)
 
typedef void(* ArchiveEntryPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartDataPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* WriteDataPtr )(ArchiveHandle *AH, const void *data, size_t dLen)
 
typedef void(* EndDataPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartBlobsPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartBlobPtr )(ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndBlobPtr )(ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndBlobsPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef int(* WriteBytePtr )(ArchiveHandle *AH, const int i)
 
typedef int(* ReadBytePtr )(ArchiveHandle *AH)
 
typedef void(* WriteBufPtr )(ArchiveHandle *AH, const void *c, size_t len)
 
typedef void(* ReadBufPtr )(ArchiveHandle *AH, void *buf, size_t len)
 
typedef void(* SaveArchivePtr )(ArchiveHandle *AH)
 
typedef void(* WriteExtraTocPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* ReadExtraTocPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrintExtraTocPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrintTocDataPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef void(* ClonePtr )(ArchiveHandle *AH)
 
typedef void(* DeClonePtr )(ArchiveHandle *AH)
 
typedef int(* WorkerJobDumpPtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef int(* WorkerJobRestorePtr )(ArchiveHandle *AH, TocEntry *te)
 
typedef size_t(* CustomOutPtr )(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  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 398 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 395 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 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(* ArchiveEntryPtr)(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(* ClonePtr)(ArchiveHandle *AH)

Definition at line 169 of file pg_backup_archiver.h.

typedef void(* ClosePtr)(ArchiveHandle *AH)

Definition at line 146 of file pg_backup_archiver.h.

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

Definition at line 175 of file pg_backup_archiver.h.

typedef void(* DeClonePtr)(ArchiveHandle *AH)

Definition at line 170 of file pg_backup_archiver.h.

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

Definition at line 156 of file pg_backup_archiver.h.

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

Definition at line 157 of file pg_backup_archiver.h.

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

Definition at line 152 of file pg_backup_archiver.h.

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

Definition at line 166 of file pg_backup_archiver.h.

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

Definition at line 167 of file pg_backup_archiver.h.

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

Definition at line 162 of file pg_backup_archiver.h.

typedef int(* ReadBytePtr)(ArchiveHandle *AH)

Definition at line 160 of file pg_backup_archiver.h.

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

Definition at line 165 of file pg_backup_archiver.h.

typedef void(* ReopenPtr)(ArchiveHandle *AH)

Definition at line 147 of file pg_backup_archiver.h.

typedef void(* SaveArchivePtr)(ArchiveHandle *AH)

Definition at line 163 of file pg_backup_archiver.h.

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

Definition at line 155 of file pg_backup_archiver.h.

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

Definition at line 154 of file pg_backup_archiver.h.

typedef void(* StartDataPtr)(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(* WorkerJobDumpPtr)(ArchiveHandle *AH, TocEntry *te)

Definition at line 172 of file pg_backup_archiver.h.

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

Definition at line 173 of file pg_backup_archiver.h.

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

Definition at line 161 of file pg_backup_archiver.h.

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

Definition at line 159 of file pg_backup_archiver.h.

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

Definition at line 151 of file pg_backup_archiver.h.

typedef void(* WriteExtraTocPtr)(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
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 206 of file pg_backup_archiver.h.

207 {
208  REQ_SCHEMA = 0x01, /* want schema */
209  REQ_DATA = 0x02, /* want data */
210  REQ_SPECIAL = 0x04 /* for special TOC entries */
211 } 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 1658 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().

1659 {
1660  int bytes_written = 0;
1661 
1662  if (AH->writingBlob)
1663  {
1664  size_t remaining = size * nmemb;
1665 
1666  while (AH->lo_buf_used + remaining > AH->lo_buf_size)
1667  {
1668  size_t avail = AH->lo_buf_size - AH->lo_buf_used;
1669 
1670  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, avail);
1671  ptr = (const void *) ((const char *) ptr + avail);
1672  remaining -= avail;
1673  AH->lo_buf_used += avail;
1674  dump_lo_buf(AH);
1675  }
1676 
1677  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, remaining);
1678  AH->lo_buf_used += remaining;
1679 
1680  bytes_written = size * nmemb;
1681  }
1682  else if (AH->gzOut)
1683  bytes_written = GZWRITE(ptr, size, nmemb, AH->OF);
1684  else if (AH->CustomOutPtr)
1685  bytes_written = AH->CustomOutPtr (AH, ptr, size * nmemb);
1686 
1687  else
1688  {
1689  /*
1690  * If we're doing a restore, and it's direct to DB, and we're
1691  * connected then send it to the DB.
1692  */
1693  if (RestoringToDB(AH))
1694  bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
1695  else
1696  bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size;
1697  }
1698 
1699  if (bytes_written != size * nmemb)
1701 
1702  return;
1703 }
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:574
static void dump_lo_buf(ArchiveHandle *AH)
#define GZWRITE(p, s, n, fh)
CustomOutPtr CustomOutPtr
#define WRITE_ERROR_EXIT
bool checkSeek ( FILE *  fp)

Definition at line 3678 of file pg_backup_archiver.c.

References fseeko, ftello, and pgoff_t.

Referenced by InitArchiveFmt_Custom(), and InitArchiveFmt_Tar().

3679 {
3680  pgoff_t tpos;
3681 
3682  /*
3683  * If pgoff_t is wider than long, we must have "real" fseeko and not an
3684  * emulation using fseek. Otherwise report no seek capability.
3685  */
3686 #ifndef HAVE_FSEEKO
3687  if (sizeof(pgoff_t) > sizeof(long))
3688  return false;
3689 #endif
3690 
3691  /* Check that ftello works on this file */
3692  tpos = ftello(fp);
3693  if (tpos < 0)
3694  return false;
3695 
3696  /*
3697  * Check that fseeko(SEEK_SET) works, too. NB: we used to try to test
3698  * this with fseeko(fp, 0, SEEK_CUR). But some platforms treat that as a
3699  * successful no-op even on files that are otherwise unseekable.
3700  */
3701  if (fseeko(fp, tpos, SEEK_SET) != 0)
3702  return false;
3703 
3704  return true;
3705 }
#define fseeko(stream, offset, origin)
Definition: win32.h:247
#define pgoff_t
Definition: win32.h:241
#define ftello(stream)
Definition: win32.h:250
ArchiveHandle* CloneArchive ( ArchiveHandle AH)

Definition at line 4459 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, NULL, 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().

4460 {
4461  ArchiveHandle *clone;
4462 
4463  /* Make a "flat" copy */
4464  clone = (ArchiveHandle *) pg_malloc(sizeof(ArchiveHandle));
4465  memcpy(clone, AH, sizeof(ArchiveHandle));
4466 
4467  /* Handle format-independent fields */
4468  memset(&(clone->sqlparse), 0, sizeof(clone->sqlparse));
4469 
4470  /* The clone will have its own connection, so disregard connection state */
4471  clone->connection = NULL;
4472  clone->connCancel = NULL;
4473  clone->currUser = NULL;
4474  clone->currSchema = NULL;
4475  clone->currTablespace = NULL;
4476  clone->currWithOids = -1;
4477 
4478  /* savedPassword must be local in case we change it while connecting */
4479  if (clone->savedPassword)
4480  clone->savedPassword = pg_strdup(clone->savedPassword);
4481 
4482  /* clone has its own error count, too */
4483  clone->public.n_errors = 0;
4484 
4485  /*
4486  * Connect our new clone object to the database: In parallel restore the
4487  * parent is already disconnected, because we can connect the worker
4488  * processes independently to the database (no snapshot sync required). In
4489  * parallel backup we clone the parent's existing connection.
4490  */
4491  if (AH->mode == archModeRead)
4492  {
4493  RestoreOptions *ropt = AH->public.ropt;
4494 
4495  Assert(AH->connection == NULL);
4496 
4497  /* this also sets clone->connection */
4498  ConnectDatabase((Archive *) clone, ropt->dbname,
4499  ropt->pghost, ropt->pgport, ropt->username,
4500  ropt->promptPassword);
4501 
4502  /* re-establish fixed state */
4503  _doSetFixedOutputState(clone);
4504  }
4505  else
4506  {
4508  char *pghost;
4509  char *pgport;
4510  char *username;
4511 
4512  Assert(AH->connection != NULL);
4513 
4514  /*
4515  * Even though we are technically accessing the parent's database
4516  * object here, these functions are fine to be called like that
4517  * because all just return a pointer and do not actually send/receive
4518  * any data to/from the database.
4519  */
4520  initPQExpBuffer(&connstr);
4521  appendPQExpBuffer(&connstr, "dbname=");
4522  appendConnStrVal(&connstr, PQdb(AH->connection));
4523  pghost = PQhost(AH->connection);
4524  pgport = PQport(AH->connection);
4525  username = PQuser(AH->connection);
4526 
4527  /* this also sets clone->connection */
4528  ConnectDatabase((Archive *) clone, connstr.data,
4529  pghost, pgport, username, TRI_NO);
4530 
4531  termPQExpBuffer(&connstr);
4532  /* setupDumpWorker will fix up connection state */
4533  }
4534 
4535  /* Let the format-specific code have a chance too */
4536  (clone->ClonePtr) (clone);
4537 
4538  Assert(clone->connection != NULL);
4539  return clone;
4540 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
RestoreOptions * ropt
Definition: pg_backup.h:179
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
char * username
Definition: pg_backup.h:110
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:536
char * PQport(const PGconn *conn)
Definition: fe-connect.c:5881
int n_errors
Definition: pg_backup.h:200
PGcancel *volatile connCancel
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:5836
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:130
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:5861
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:5828
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
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:248
static char * connstr
Definition: pg_dumpall.c:67
trivalue promptPassword
Definition: pg_backup.h:112
void DeCloneArchive ( ArchiveHandle AH)

Definition at line 4548 of file pg_backup_archiver.c.

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

Referenced by RunWorker().

4549 {
4550  /* Should not have an open database connection */
4551  Assert(AH->connection == NULL);
4552 
4553  /* Clear format-specific state */
4554  (AH->DeClonePtr) (AH);
4555 
4556  /* Clear state allocated by CloneArchive */
4557  if (AH->sqlparse.curCmd)
4559 
4560  /* Clear any connection-local state */
4561  if (AH->currUser)
4562  free(AH->currUser);
4563  if (AH->currSchema)
4564  free(AH->currSchema);
4565  if (AH->currTablespace)
4566  free(AH->currTablespace);
4567  if (AH->savedPassword)
4568  free(AH->savedPassword);
4569 
4570  free(AH);
4571 }
PQExpBuffer curCmd
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
sqlparseInfo sqlparse
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
void DropBlobIfExists ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 674 of file pg_backup_db.c.

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

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

675 {
676  /*
677  * If we are not restoring to a direct database connection, we have to
678  * guess about how to detect whether the blob exists. Assume new-style.
679  */
680  if (AH->connection == NULL ||
681  PQserverVersion(AH->connection) >= 90000)
682  {
683  ahprintf(AH,
684  "SELECT pg_catalog.lo_unlink(oid) "
685  "FROM pg_catalog.pg_largeobject_metadata "
686  "WHERE oid = '%u';\n",
687  oid);
688  }
689  else
690  {
691  /* Restoring to pre-9.0 server, so do it the old way */
692  ahprintf(AH,
693  "SELECT CASE WHEN EXISTS("
694  "SELECT 1 FROM pg_catalog.pg_largeobject WHERE loid = '%u'"
695  ") THEN pg_catalog.lo_unlink('%u') END;\n",
696  oid, oid);
697  }
698 }
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:5950
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
#define NULL
Definition: c.h:226
void EndRestoreBlob ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 1294 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().

1295 {
1296  if (AH->lo_buf_used > 0)
1297  {
1298  /* Write remaining bytes from the LO buffer */
1299  dump_lo_buf(AH);
1300  }
1301 
1302  AH->writingBlob = 0;
1303 
1304  if (AH->connection)
1305  {
1306  lo_close(AH->connection, AH->loFd);
1307  AH->loFd = -1;
1308  }
1309  else
1310  {
1311  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
1312  }
1313 }
int lo_close(PGconn *conn, int fd)
Definition: fe-lobj.c:100
static void dump_lo_buf(ArchiveHandle *AH)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
void EndRestoreBlobs ( ArchiveHandle AH)

Definition at line 1227 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().

1228 {
1229  RestoreOptions *ropt = AH->public.ropt;
1230 
1231  if (!ropt->single_txn)
1232  {
1233  if (AH->connection)
1234  CommitTransaction(&AH->public);
1235  else
1236  ahprintf(AH, "COMMIT;\n\n");
1237  }
1238 
1239  ahlog(AH, 1, ngettext("restored %d large object\n",
1240  "restored %d large objects\n",
1241  AH->blobCount),
1242  AH->blobCount);
1243 }
RestoreOptions * ropt
Definition: pg_backup.h:179
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:1938
TocEntry* getTocEntryByDumpId ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1838 of file pg_backup_archiver.c.

References buildTocEntryArrays(), NULL, and _archiveHandle::tocsByDumpId.

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

1839 {
1840  /* build index arrays if we didn't already */
1841  if (AH->tocsByDumpId == NULL)
1842  buildTocEntryArrays(AH);
1843 
1844  if (id > 0 && id <= AH->maxDumpId)
1845  return AH->tocsByDumpId[id];
1846 
1847  return NULL;
1848 }
static void buildTocEntryArrays(ArchiveHandle *AH)
#define NULL
Definition: c.h:226
struct _tocEntry ** tocsByDumpId
void InitArchiveFmt_Custom ( ArchiveHandle AH)

Definition at line 107 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, NULL, 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().

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

Definition at line 109 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, NULL, 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().

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

Definition at line 128 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, NULL, PG_BINARY_R, PG_BINARY_W, pg_malloc(), pg_malloc0(), ReadHead(), ReadToc(), strerror(), tarClose(), lclContext::tarFH, lclContext::tarFHpos, and tarOpen().

Referenced by _allocAH().

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

Definition at line 1042 of file pg_backup_tar.c.

References read_tar_number(), and tarChecksum().

Referenced by _discoverArchiveFormat().

1043 {
1044  int sum;
1045  int chk = tarChecksum(header);
1046 
1047  sum = read_tar_number(&header[148], 8);
1048 
1049  if (sum != chk)
1050  return false;
1051 
1052  /* POSIX tar format */
1053  if (memcmp(&header[257], "ustar\0", 6) == 0 &&
1054  memcmp(&header[263], "00", 2) == 0)
1055  return true;
1056  /* GNU tar format */
1057  if (memcmp(&header[257], "ustar \0", 8) == 0)
1058  return true;
1059  /* not-quite-POSIX format written by pre-9.3 pg_dump */
1060  if (memcmp(&header[257], "ustar00\0", 8) == 0)
1061  return true;
1062 
1063  return false;
1064 }
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:205
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 4124 of file pg_backup_archiver.c.

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

Referenced by _WorkerJobRestoreCustom(), and _WorkerJobRestoreDirectory().

4125 {
4126  int status;
4127 
4128  Assert(AH->connection != NULL);
4129 
4130  /* Count only errors associated with this TOC entry */
4131  AH->public.n_errors = 0;
4132 
4133  /* Restore the TOC item */
4134  status = restore_toc_entry(AH, te, true);
4135 
4136  return status;
4137 }
int n_errors
Definition: pg_backup.h:200
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:222
void ReadHead ( ArchiveHandle AH)

Definition at line 3575 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().

3576 {
3577  char tmpMag[7];
3578  int fmt;
3579  struct tm crtm;
3580 
3581  /*
3582  * If we haven't already read the header, do so.
3583  *
3584  * NB: this code must agree with _discoverArchiveFormat(). Maybe find a
3585  * way to unify the cases?
3586  */
3587  if (!AH->readHeader)
3588  {
3589  char vmaj,
3590  vmin,
3591  vrev;
3592 
3593  (*AH->ReadBufPtr) (AH, tmpMag, 5);
3594 
3595  if (strncmp(tmpMag, "PGDMP", 5) != 0)
3596  exit_horribly(modulename, "did not find magic string in file header\n");
3597 
3598  vmaj = (*AH->ReadBytePtr) (AH);
3599  vmin = (*AH->ReadBytePtr) (AH);
3600 
3601  if (vmaj > 1 || (vmaj == 1 && vmin > 0)) /* Version > 1.0 */
3602  vrev = (*AH->ReadBytePtr) (AH);
3603  else
3604  vrev = 0;
3605 
3606  AH->version = MAKE_ARCHIVE_VERSION(vmaj, vmin, vrev);
3607 
3608  if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
3609  exit_horribly(modulename, "unsupported version (%d.%d) in file header\n",
3610  vmaj, vmin);
3611 
3612  AH->intSize = (*AH->ReadBytePtr) (AH);
3613  if (AH->intSize > 32)
3614  exit_horribly(modulename, "sanity check on integer size (%lu) failed\n",
3615  (unsigned long) AH->intSize);
3616 
3617  if (AH->intSize > sizeof(int))
3618  write_msg(modulename, "WARNING: archive was made on a machine with larger integers, some operations might fail\n");
3619 
3620  if (AH->version >= K_VERS_1_7)
3621  AH->offSize = (*AH->ReadBytePtr) (AH);
3622  else
3623  AH->offSize = AH->intSize;
3624 
3625  fmt = (*AH->ReadBytePtr) (AH);
3626 
3627  if (AH->format != fmt)
3628  exit_horribly(modulename, "expected format (%d) differs from format found in file (%d)\n",
3629  AH->format, fmt);
3630  }
3631 
3632  if (AH->version >= K_VERS_1_2)
3633  {
3634  if (AH->version < K_VERS_1_4)
3635  AH->compression = (*AH->ReadBytePtr) (AH);
3636  else
3637  AH->compression = ReadInt(AH);
3638  }
3639  else
3641 
3642 #ifndef HAVE_LIBZ
3643  if (AH->compression != 0)
3644  write_msg(modulename, "WARNING: archive is compressed, but this installation does not support compression -- no data will be available\n");
3645 #endif
3646 
3647  if (AH->version >= K_VERS_1_4)
3648  {
3649  crtm.tm_sec = ReadInt(AH);
3650  crtm.tm_min = ReadInt(AH);
3651  crtm.tm_hour = ReadInt(AH);
3652  crtm.tm_mday = ReadInt(AH);
3653  crtm.tm_mon = ReadInt(AH);
3654  crtm.tm_year = ReadInt(AH);
3655  crtm.tm_isdst = ReadInt(AH);
3656 
3657  AH->archdbname = ReadStr(AH);
3658 
3659  AH->createDate = mktime(&crtm);
3660 
3661  if (AH->createDate == (time_t) -1)
3662  write_msg(modulename, "WARNING: invalid creation date in header\n");
3663  }
3664 
3665  if (AH->version >= K_VERS_1_10)
3666  {
3667  AH->archiveRemoteVersion = ReadStr(AH);
3668  AH->archiveDumpVersion = ReadStr(AH);
3669  }
3670 }
#define Z_DEFAULT_COMPRESSION
#define K_VERS_1_0
int ReadInt(ArchiveHandle *AH)
#define K_VERS_1_4
static struct pg_tm tm
Definition: localtime.c:103
#define K_VERS_1_7
#define MAKE_ARCHIVE_VERSION(major, minor, rev)
#define K_VERS_1_2
#define K_VERS_1_10
ReadBytePtr ReadBytePtr
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 1974 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().

1975 {
1976  int res = 0;
1977  int bv,
1978  b;
1979  int sign = 0; /* Default positive */
1980  int bitShift = 0;
1981 
1982  if (AH->version > K_VERS_1_0)
1983  /* Read a sign byte */
1984  sign = (*AH->ReadBytePtr) (AH);
1985 
1986  for (b = 0; b < AH->intSize; b++)
1987  {
1988  bv = (*AH->ReadBytePtr) (AH) & 0xFF;
1989  if (bv != 0)
1990  res = res + (bv << bitShift);
1991  bitShift += 8;
1992  }
1993 
1994  if (sign)
1995  res = -res;
1996 
1997  return res;
1998 }
#define K_VERS_1_0
char sign
Definition: informix.c:693
ReadBytePtr ReadBytePtr
int ReadOffset ( ArchiveHandle ,
pgoff_t  
)

Definition at line 1879 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().

1880 {
1881  int i;
1882  int off;
1883  int offsetFlg;
1884 
1885  /* Initialize to zero */
1886  *o = 0;
1887 
1888  /* Check for old version */
1889  if (AH->version < K_VERS_1_7)
1890  {
1891  /* Prior versions wrote offsets using WriteInt */
1892  i = ReadInt(AH);
1893  /* -1 means not set */
1894  if (i < 0)
1895  return K_OFFSET_POS_NOT_SET;
1896  else if (i == 0)
1897  return K_OFFSET_NO_DATA;
1898 
1899  /* Cast to pgoff_t because it was written as an int. */
1900  *o = (pgoff_t) i;
1901  return K_OFFSET_POS_SET;
1902  }
1903 
1904  /*
1905  * Read the flag indicating the state of the data pointer. Check if valid
1906  * and die if not.
1907  *
1908  * This used to be handled by a negative or zero pointer, now we use an
1909  * extra byte specifically for the state.
1910  */
1911  offsetFlg = (*AH->ReadBytePtr) (AH) & 0xFF;
1912 
1913  switch (offsetFlg)
1914  {
1915  case K_OFFSET_POS_NOT_SET:
1916  case K_OFFSET_NO_DATA:
1917  case K_OFFSET_POS_SET:
1918 
1919  break;
1920 
1921  default:
1922  exit_horribly(modulename, "unexpected data offset flag %d\n", offsetFlg);
1923  }
1924 
1925  /*
1926  * Read the bytes
1927  */
1928  for (off = 0; off < AH->offSize; off++)
1929  {
1930  if (off < sizeof(pgoff_t))
1931  *o |= ((pgoff_t) ((*AH->ReadBytePtr) (AH))) << (off * 8);
1932  else
1933  {
1934  if ((*AH->ReadBytePtr) (AH) != 0)
1935  exit_horribly(modulename, "file offset in dump file is too large\n");
1936  }
1937  }
1938 
1939  return offsetFlg;
1940 }
int ReadInt(ArchiveHandle *AH)
#define K_VERS_1_7
#define K_OFFSET_NO_DATA
#define pgoff_t
Definition: win32.h:241
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 2020 of file pg_backup_archiver.c.

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

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

2021 {
2022  char *buf;
2023  int l;
2024 
2025  l = ReadInt(AH);
2026  if (l < 0)
2027  buf = NULL;
2028  else
2029  {
2030  buf = (char *) pg_malloc(l + 1);
2031  (*AH->ReadBufPtr) (AH, (void *) buf, l);
2032 
2033  buf[l] = '\0';
2034  }
2035 
2036  return buf;
2037 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int ReadInt(ArchiveHandle *AH)
static char * buf
Definition: pg_test_fsync.c:65
#define NULL
Definition: c.h:226
void ReadTOC ( ArchiveHandle AH)
void ReadToc ( ArchiveHandle AH)

Definition at line 2507 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, NULL, 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().

2508 {
2509  int i;
2510  char *tmp;
2511  DumpId *deps;
2512  int depIdx;
2513  int depSize;
2514  TocEntry *te;
2515 
2516  AH->tocCount = ReadInt(AH);
2517  AH->maxDumpId = 0;
2518 
2519  for (i = 0; i < AH->tocCount; i++)
2520  {
2521  te = (TocEntry *) pg_malloc0(sizeof(TocEntry));
2522  te->dumpId = ReadInt(AH);
2523 
2524  if (te->dumpId > AH->maxDumpId)
2525  AH->maxDumpId = te->dumpId;
2526 
2527  /* Sanity check */
2528  if (te->dumpId <= 0)
2530  "entry ID %d out of range -- perhaps a corrupt TOC\n",
2531  te->dumpId);
2532 
2533  te->hadDumper = ReadInt(AH);
2534 
2535  if (AH->version >= K_VERS_1_8)
2536  {
2537  tmp = ReadStr(AH);
2538  sscanf(tmp, "%u", &te->catalogId.tableoid);
2539  free(tmp);
2540  }
2541  else
2543  tmp = ReadStr(AH);
2544  sscanf(tmp, "%u", &te->catalogId.oid);
2545  free(tmp);
2546 
2547  te->tag = ReadStr(AH);
2548  te->desc = ReadStr(AH);
2549 
2550  if (AH->version >= K_VERS_1_11)
2551  {
2552  te->section = ReadInt(AH);
2553  }
2554  else
2555  {
2556  /*
2557  * Rules for pre-8.4 archives wherein pg_dump hasn't classified
2558  * the entries into sections. This list need not cover entry
2559  * types added later than 8.4.
2560  */
2561  if (strcmp(te->desc, "COMMENT") == 0 ||
2562  strcmp(te->desc, "ACL") == 0 ||
2563  strcmp(te->desc, "ACL LANGUAGE") == 0)
2564  te->section = SECTION_NONE;
2565  else if (strcmp(te->desc, "TABLE DATA") == 0 ||
2566  strcmp(te->desc, "BLOBS") == 0 ||
2567  strcmp(te->desc, "BLOB COMMENTS") == 0)
2568  te->section = SECTION_DATA;
2569  else if (strcmp(te->desc, "CONSTRAINT") == 0 ||
2570  strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
2571  strcmp(te->desc, "FK CONSTRAINT") == 0 ||
2572  strcmp(te->desc, "INDEX") == 0 ||
2573  strcmp(te->desc, "RULE") == 0 ||
2574  strcmp(te->desc, "TRIGGER") == 0)
2575  te->section = SECTION_POST_DATA;
2576  else
2577  te->section = SECTION_PRE_DATA;
2578  }
2579 
2580  te->defn = ReadStr(AH);
2581  te->dropStmt = ReadStr(AH);
2582 
2583  if (AH->version >= K_VERS_1_3)
2584  te->copyStmt = ReadStr(AH);
2585 
2586  if (AH->version >= K_VERS_1_6)
2587  te->namespace = ReadStr(AH);
2588 
2589  if (AH->version >= K_VERS_1_10)
2590  te->tablespace = ReadStr(AH);
2591 
2592  te->owner = ReadStr(AH);
2593  if (AH->version >= K_VERS_1_9)
2594  {
2595  if (strcmp(ReadStr(AH), "true") == 0)
2596  te->withOids = true;
2597  else
2598  te->withOids = false;
2599  }
2600  else
2601  te->withOids = true;
2602 
2603  /* Read TOC entry dependencies */
2604  if (AH->version >= K_VERS_1_5)
2605  {
2606  depSize = 100;
2607  deps = (DumpId *) pg_malloc(sizeof(DumpId) * depSize);
2608  depIdx = 0;
2609  for (;;)
2610  {
2611  tmp = ReadStr(AH);
2612  if (!tmp)
2613  break; /* end of list */
2614  if (depIdx >= depSize)
2615  {
2616  depSize *= 2;
2617  deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
2618  }
2619  sscanf(tmp, "%d", &deps[depIdx]);
2620  free(tmp);
2621  depIdx++;
2622  }
2623 
2624  if (depIdx > 0) /* We have a non-null entry */
2625  {
2626  deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depIdx);
2627  te->dependencies = deps;
2628  te->nDeps = depIdx;
2629  }
2630  else
2631  {
2632  free(deps);
2633  te->dependencies = NULL;
2634  te->nDeps = 0;
2635  }
2636  }
2637  else
2638  {
2639  te->dependencies = NULL;
2640  te->nDeps = 0;
2641  }
2642 
2643  if (AH->ReadExtraTocPtr)
2644  (*AH->ReadExtraTocPtr) (AH, te);
2645 
2646  ahlog(AH, 3, "read TOC entry %d (ID %d) for %s %s\n",
2647  i, te->dumpId, te->desc, te->tag);
2648 
2649  /* link completed entry into TOC circular list */
2650  te->prev = AH->toc->prev;
2651  AH->toc->prev->next = te;
2652  AH->toc->prev = te;
2653  te->next = AH->toc;
2654 
2655  /* special processing immediately upon read for some items */
2656  if (strcmp(te->desc, "ENCODING") == 0)
2657  processEncodingEntry(AH, te);
2658  else if (strcmp(te->desc, "STDSTRINGS") == 0)
2659  processStdStringsEntry(AH, te);
2660  }
2661 }
struct _tocEntry * next
static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
int DumpId
Definition: pg_backup.h:228
Oid tableoid
Definition: pg_backup.h:224
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:60
#define NULL
Definition: c.h:226
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
ReadExtraTocPtr ReadExtraTocPtr
int ReconnectToServer ( ArchiveHandle AH,
const char *  dbname,
const char *  newUser 
)

Definition at line 88 of file pg_backup_db.c.

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

Referenced by _reconnectToDB().

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

Definition at line 1250 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().

1251 {
1252  bool old_blob_style = (AH->version < K_VERS_1_12);
1253  Oid loOid;
1254 
1255  AH->blobCount++;
1256 
1257  /* Initialize the LO Buffer */
1258  AH->lo_buf_used = 0;
1259 
1260  ahlog(AH, 1, "restoring large object with OID %u\n", oid);
1261 
1262  /* With an old archive we must do drop and create logic here */
1263  if (old_blob_style && drop)
1264  DropBlobIfExists(AH, oid);
1265 
1266  if (AH->connection)
1267  {
1268  if (old_blob_style)
1269  {
1270  loOid = lo_create(AH->connection, oid);
1271  if (loOid == 0 || loOid != oid)
1272  exit_horribly(modulename, "could not create large object %u: %s",
1273  oid, PQerrorMessage(AH->connection));
1274  }
1275  AH->loFd = lo_open(AH->connection, oid, INV_WRITE);
1276  if (AH->loFd == -1)
1277  exit_horribly(modulename, "could not open large object %u: %s",
1278  oid, PQerrorMessage(AH->connection));
1279  }
1280  else
1281  {
1282  if (old_blob_style)
1283  ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1284  oid, INV_WRITE);
1285  else
1286  ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
1287  oid, INV_WRITE);
1288  }
1289 
1290  AH->writingBlob = 1;
1291 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:5960
void DropBlobIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:674
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:58
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
Oid lo_create(PGconn *conn, Oid lobjId)
Definition: fe-lobj.c:505
#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 1208 of file pg_backup_archiver.c.

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

Referenced by _LoadBlobs().

1209 {
1210  RestoreOptions *ropt = AH->public.ropt;
1211 
1212  if (!ropt->single_txn)
1213  {
1214  if (AH->connection)
1215  StartTransaction(&AH->public);
1216  else
1217  ahprintf(AH, "BEGIN;\n\n");
1218  }
1219 
1220  AH->blobCount = 0;
1221 }
RestoreOptions * ropt
Definition: pg_backup.h:179
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
static void StartTransaction(void)
Definition: xact.c:1800
teReqs TocIDRequired ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1851 of file pg_backup_archiver.c.

References getTocEntryByDumpId(), and _tocEntry::reqs.

Referenced by _tarPositionTo(), and findDumpableDependencies().

1852 {
1853  TocEntry *te = getTocEntryByDumpId(AH, id);
1854 
1855  if (!te)
1856  return 0;
1857 
1858  return te->reqs;
1859 }
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 2361 of file pg_backup_archiver.c.

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

Referenced by _CloseArchive().

2362 {
2363  TocEntry *te;
2364 
2365  for (te = AH->toc->next; te != AH->toc; te = te->next)
2366  {
2367  if (!te->dataDumper)
2368  continue;
2369 
2370  if ((te->reqs & REQ_DATA) == 0)
2371  continue;
2372 
2373  if (pstate && pstate->numWorkers > 1)
2374  {
2375  /*
2376  * If we are in a parallel backup, then we are always the master
2377  * process. Dispatch each data-transfer job to a worker.
2378  */
2379  DispatchJobForTocEntry(AH, pstate, te, ACT_DUMP,
2381  }
2382  else
2384  }
2385 
2386  /*
2387  * If parallel, wait for workers to finish.
2388  */
2389  if (pstate && pstate->numWorkers > 1)
2390  WaitForWorkers(AH, pstate, WFW_ALL_IDLE);
2391 }
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
#define NULL
Definition: c.h:226
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 2416 of file pg_backup_archiver.c.

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

Referenced by _WorkerJobDumpDirectory(), and WriteDataChunks().

2417 {
2418  StartDataPtr startPtr;
2419  EndDataPtr endPtr;
2420 
2421  AH->currToc = te;
2422 
2423  if (strcmp(te->desc, "BLOBS") == 0)
2424  {
2425  startPtr = AH->StartBlobsPtr;
2426  endPtr = AH->EndBlobsPtr;
2427  }
2428  else
2429  {
2430  startPtr = AH->StartDataPtr;
2431  endPtr = AH->EndDataPtr;
2432  }
2433 
2434  if (startPtr != NULL)
2435  (*startPtr) (AH, te);
2436 
2437  /*
2438  * The user-provided DataDumper routine needs to call AH->WriteData
2439  */
2440  (*te->dataDumper) ((Archive *) AH, te->dataDumperArg);
2441 
2442  if (endPtr != NULL)
2443  (*endPtr) (AH, te);
2444 
2445  AH->currToc = NULL;
2446 }
StartBlobsPtr StartBlobsPtr
DataDumperPtr dataDumper
struct _tocEntry * currToc
void(* EndDataPtr)(ArchiveHandle *AH, TocEntry *te)
#define NULL
Definition: c.h:226
void(* StartDataPtr)(ArchiveHandle *AH, TocEntry *te)
StartDataPtr StartDataPtr
EndBlobsPtr EndBlobsPtr
void WriteHead ( ArchiveHandle AH)

Definition at line 3549 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().

3550 {
3551  struct tm crtm;
3552 
3553  (*AH->WriteBufPtr) (AH, "PGDMP", 5); /* Magic code */
3554  (*AH->WriteBytePtr) (AH, ARCHIVE_MAJOR(AH->version));
3555  (*AH->WriteBytePtr) (AH, ARCHIVE_MINOR(AH->version));
3556  (*AH->WriteBytePtr) (AH, ARCHIVE_REV(AH->version));
3557  (*AH->WriteBytePtr) (AH, AH->intSize);
3558  (*AH->WriteBytePtr) (AH, AH->offSize);
3559  (*AH->WriteBytePtr) (AH, AH->format);
3560  WriteInt(AH, AH->compression);
3561  crtm = *localtime(&AH->createDate);
3562  WriteInt(AH, crtm.tm_sec);
3563  WriteInt(AH, crtm.tm_min);
3564  WriteInt(AH, crtm.tm_hour);
3565  WriteInt(AH, crtm.tm_mday);
3566  WriteInt(AH, crtm.tm_mon);
3567  WriteInt(AH, crtm.tm_year);
3568  WriteInt(AH, crtm.tm_isdst);
3569  WriteStr(AH, PQdb(AH->connection));
3570  WriteStr(AH, AH->public.remoteVersionStr);
3571  WriteStr(AH, PG_VERSION);
3572 }
WriteBufPtr WriteBufPtr
static struct pg_tm tm
Definition: localtime.c:103
WriteBytePtr WriteBytePtr
#define ARCHIVE_REV(version)
#define ARCHIVE_MINOR(version)
ArchiveFormat format
#define ARCHIVE_MAJOR(version)
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:5828
size_t WriteInt(ArchiveHandle *AH, int i)
char * remoteVersionStr
Definition: pg_backup.h:182
size_t WriteStr(ArchiveHandle *AH, const char *c)
size_t WriteInt ( ArchiveHandle AH,
int  i 
)

Definition at line 1943 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().

1944 {
1945  int b;
1946 
1947  /*
1948  * This is a bit yucky, but I don't want to make the binary format very
1949  * dependent on representation, and not knowing much about it, I write out
1950  * a sign byte. If you change this, don't forget to change the file
1951  * version #, and modify readInt to read the new format AS WELL AS the old
1952  * formats.
1953  */
1954 
1955  /* SIGN byte */
1956  if (i < 0)
1957  {
1958  (*AH->WriteBytePtr) (AH, 1);
1959  i = -i;
1960  }
1961  else
1962  (*AH->WriteBytePtr) (AH, 0);
1963 
1964  for (b = 0; b < AH->intSize; b++)
1965  {
1966  (*AH->WriteBytePtr) (AH, i & 0xFF);
1967  i >>= 8;
1968  }
1969 
1970  return AH->intSize + 1;
1971 }
WriteBytePtr WriteBytePtr
int i
size_t WriteOffset ( ArchiveHandle ,
pgoff_t  ,
int   
)

Definition at line 1862 of file pg_backup_archiver.c.

References pgoff_t, and _archiveHandle::WriteBytePtr.

Referenced by _WriteExtraToc().

1863 {
1864  int off;
1865 
1866  /* Save the flag */
1867  (*AH->WriteBytePtr) (AH, wasSet);
1868 
1869  /* Write out pgoff_t smallest byte first, prevents endian mismatch */
1870  for (off = 0; off < sizeof(pgoff_t); off++)
1871  {
1872  (*AH->WriteBytePtr) (AH, o & 0xFF);
1873  o >>= 8;
1874  }
1875  return sizeof(pgoff_t) + 1;
1876 }
#define pgoff_t
Definition: win32.h:241
size_t WriteStr ( ArchiveHandle AH,
const char *  s 
)

Definition at line 2001 of file pg_backup_archiver.c.

References _archiveHandle::WriteBufPtr, and WriteInt().

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

2002 {
2003  size_t res;
2004 
2005  if (c)
2006  {
2007  int len = strlen(c);
2008 
2009  res = WriteInt(AH, len);
2010  (*AH->WriteBufPtr) (AH, c, len);
2011  res += len;
2012  }
2013  else
2014  res = WriteInt(AH, -1);
2015 
2016  return res;
2017 }
WriteBufPtr WriteBufPtr
char * c
size_t WriteInt(ArchiveHandle *AH, int i)
void void WriteTOC ( ArchiveHandle AH)
void WriteToc ( ArchiveHandle AH)

Definition at line 2449 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, NULL, 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().

2450 {
2451  TocEntry *te;
2452  char workbuf[32];
2453  int tocCount;
2454  int i;
2455 
2456  /* count entries that will actually be dumped */
2457  tocCount = 0;
2458  for (te = AH->toc->next; te != AH->toc; te = te->next)
2459  {
2460  if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) != 0)
2461  tocCount++;
2462  }
2463 
2464  /* printf("%d TOC Entries to save\n", tocCount); */
2465 
2466  WriteInt(AH, tocCount);
2467 
2468  for (te = AH->toc->next; te != AH->toc; te = te->next)
2469  {
2470  if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) == 0)
2471  continue;
2472 
2473  WriteInt(AH, te->dumpId);
2474  WriteInt(AH, te->dataDumper ? 1 : 0);
2475 
2476  /* OID is recorded as a string for historical reasons */
2477  sprintf(workbuf, "%u", te->catalogId.tableoid);
2478  WriteStr(AH, workbuf);
2479  sprintf(workbuf, "%u", te->catalogId.oid);
2480  WriteStr(AH, workbuf);
2481 
2482  WriteStr(AH, te->tag);
2483  WriteStr(AH, te->desc);
2484  WriteInt(AH, te->section);
2485  WriteStr(AH, te->defn);
2486  WriteStr(AH, te->dropStmt);
2487  WriteStr(AH, te->copyStmt);
2488  WriteStr(AH, te->namespace);
2489  WriteStr(AH, te->tablespace);
2490  WriteStr(AH, te->owner);
2491  WriteStr(AH, te->withOids ? "true" : "false");
2492 
2493  /* Dump list of dependencies */
2494  for (i = 0; i < te->nDeps; i++)
2495  {
2496  sprintf(workbuf, "%d", te->dependencies[i]);
2497  WriteStr(AH, workbuf);
2498  }
2499  WriteStr(AH, NULL); /* Terminate List */
2500 
2501  if (AH->WriteExtraTocPtr)
2502  (*AH->WriteExtraTocPtr) (AH, te);
2503  }
2504 }
struct _tocEntry * next
Oid tableoid
Definition: pg_backup.h:224
CatalogId catalogId
WriteExtraTocPtr WriteExtraTocPtr
DataDumperPtr dataDumper
teSection section
struct _tocEntry * toc
DumpId * dependencies
#define NULL
Definition: c.h:226
size_t WriteInt(ArchiveHandle *AH, int i)
int i
size_t WriteStr(ArchiveHandle *AH, const char *c)