PostgreSQL Source Code  git master
pg_backup_archiver.h File Reference
#include <time.h>
#include "libpq-fe.h"
#include "pg_backup.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
 
struct  _archiveOpts
 

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_1_13
 
#define K_VERS_1_14   MAKE_ARCHIVE_VERSION(1, 14, 0) /* add tableam */
 
#define K_VERS_MAJOR   1
 
#define K_VERS_MINOR   14
 
#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_POST_ACL
 
#define REQ_SCHEMA   0x01 /* want schema */
 
#define REQ_DATA   0x02 /* want data */
 
#define REQ_SPECIAL   0x04 /* for special TOC entries */
 
#define ARCHIVE_OPTS(...)   &(ArchiveOpts){__VA_ARGS__}
 
#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(* 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(* PrepParallelRestorePtrType) (ArchiveHandle *AH)
 
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)
 
typedef void struct _archiveOpts ArchiveOpts
 

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 }
 

Functions

int parallel_restore (ArchiveHandle *AH, TocEntry *te)
 
void on_exit_close_archive (Archive *AHX)
 
void warn_or_exit_horribly (ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2
 
TocEntryArchiveEntry (Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
 
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)
 
int 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)
 
void ReconnectToServer (ArchiveHandle *AH, const char *dbname)
 
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
 

Macro Definition Documentation

◆ appendByteaLiteralAHX

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

Definition at line 443 of file pg_backup_archiver.h.

◆ appendStringLiteralAHX

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

Definition at line 440 of file pg_backup_archiver.h.

◆ ARCHIVE_MAJOR

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

Definition at line 66 of file pg_backup_archiver.h.

◆ ARCHIVE_MINOR

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

Definition at line 67 of file pg_backup_archiver.h.

◆ ARCHIVE_OPTS

#define ARCHIVE_OPTS (   ...)    &(ArchiveOpts){__VA_ARGS__}

Definition at line 422 of file pg_backup_archiver.h.

◆ ARCHIVE_REV

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

Definition at line 68 of file pg_backup_archiver.h.

◆ BLK_BLOBS

#define BLK_BLOBS   3

Definition at line 61 of file pg_backup_archiver.h.

◆ BLK_DATA

#define BLK_DATA   1

Definition at line 60 of file pg_backup_archiver.h.

◆ GZCLOSE

#define GZCLOSE (   fh)    fclose(fh)

Definition at line 42 of file pg_backup_archiver.h.

◆ GZEOF

#define GZEOF (   fh)    feof(fh)

Definition at line 45 of file pg_backup_archiver.h.

◆ GZREAD

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

Definition at line 44 of file pg_backup_archiver.h.

◆ GZWRITE

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

Definition at line 43 of file pg_backup_archiver.h.

◆ K_OFFSET_NO_DATA

#define K_OFFSET_NO_DATA   3

Definition at line 99 of file pg_backup_archiver.h.

◆ K_OFFSET_POS_NOT_SET

#define K_OFFSET_POS_NOT_SET   1

Definition at line 97 of file pg_backup_archiver.h.

◆ K_OFFSET_POS_SET

#define K_OFFSET_POS_SET   2

Definition at line 98 of file pg_backup_archiver.h.

◆ K_VERS_1_0

#define K_VERS_1_0   MAKE_ARCHIVE_VERSION(1, 0, 0)

Definition at line 71 of file pg_backup_archiver.h.

◆ K_VERS_1_10

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

Definition at line 80 of file pg_backup_archiver.h.

◆ K_VERS_1_11

#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 81 of file pg_backup_archiver.h.

◆ K_VERS_1_12

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

Definition at line 82 of file pg_backup_archiver.h.

◆ K_VERS_1_13

#define K_VERS_1_13
Value:
MAKE_ARCHIVE_VERSION(1, 13, 0) /* change search_path
* behavior */

Definition at line 83 of file pg_backup_archiver.h.

◆ K_VERS_1_14

#define K_VERS_1_14   MAKE_ARCHIVE_VERSION(1, 14, 0) /* add tableam */

Definition at line 84 of file pg_backup_archiver.h.

◆ K_VERS_1_2

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

Definition at line 72 of file pg_backup_archiver.h.

◆ K_VERS_1_3

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

Definition at line 73 of file pg_backup_archiver.h.

◆ K_VERS_1_4

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

Definition at line 74 of file pg_backup_archiver.h.

◆ K_VERS_1_5

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

Definition at line 75 of file pg_backup_archiver.h.

◆ K_VERS_1_6

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

Definition at line 76 of file pg_backup_archiver.h.

◆ K_VERS_1_7

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

Definition at line 77 of file pg_backup_archiver.h.

◆ K_VERS_1_8

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

Definition at line 78 of file pg_backup_archiver.h.

◆ K_VERS_1_9

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

Definition at line 79 of file pg_backup_archiver.h.

◆ K_VERS_MAJOR

#define K_VERS_MAJOR   1

Definition at line 87 of file pg_backup_archiver.h.

◆ K_VERS_MAX

#define K_VERS_MAX   MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, 255)

Definition at line 93 of file pg_backup_archiver.h.

◆ K_VERS_MINOR

#define K_VERS_MINOR   14

Definition at line 88 of file pg_backup_archiver.h.

◆ K_VERS_REV

#define K_VERS_REV   0

Definition at line 89 of file pg_backup_archiver.h.

◆ K_VERS_SELF

Definition at line 90 of file pg_backup_archiver.h.

◆ LOBBUFSIZE

#define LOBBUFSIZE   16384

Definition at line 33 of file pg_backup_archiver.h.

◆ MAKE_ARCHIVE_VERSION

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

Definition at line 64 of file pg_backup_archiver.h.

◆ READ_ERROR_EXIT

#define READ_ERROR_EXIT (   fd)
Value:
do { \
if (feof(fd)) \
fatal("could not read from input file: end of file"); \
fatal("could not read from input file: %m"); \
} while (0)
#define fatal(...)
static int fd(const char *x, int i)
Definition: preproc-init.c:105

Definition at line 114 of file pg_backup_archiver.h.

◆ REQ_DATA

#define REQ_DATA   0x02 /* want data */

Definition at line 222 of file pg_backup_archiver.h.

◆ REQ_SCHEMA

#define REQ_SCHEMA   0x01 /* want schema */

Definition at line 221 of file pg_backup_archiver.h.

◆ REQ_SPECIAL

#define REQ_SPECIAL   0x04 /* for special TOC entries */

Definition at line 223 of file pg_backup_archiver.h.

◆ RESTORE_PASS_LAST

#define RESTORE_PASS_LAST   RESTORE_PASS_POST_ACL

Definition at line 218 of file pg_backup_archiver.h.

◆ WORKER_CREATE_DONE

#define WORKER_CREATE_DONE   10

Definition at line 106 of file pg_backup_archiver.h.

◆ WORKER_IGNORED_ERRORS

#define WORKER_IGNORED_ERRORS   12

Definition at line 108 of file pg_backup_archiver.h.

◆ WORKER_INHIBIT_DATA

#define WORKER_INHIBIT_DATA   11

Definition at line 107 of file pg_backup_archiver.h.

◆ WORKER_OK

#define WORKER_OK   0

Definition at line 105 of file pg_backup_archiver.h.

◆ WRITE_ERROR_EXIT

#define WRITE_ERROR_EXIT
Value:
do { \
fatal("could not write to output file: %m"); \
} while (0)

Definition at line 122 of file pg_backup_archiver.h.

◆ Z_DEFAULT_COMPRESSION

#define Z_DEFAULT_COMPRESSION   (-1)

Definition at line 47 of file pg_backup_archiver.h.

Typedef Documentation

◆ ArchiveEntryPtrType

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

Definition at line 135 of file pg_backup_archiver.h.

◆ ArchiveHandle

typedef struct _archiveHandle ArchiveHandle

Definition at line 56 of file pg_backup_archiver.h.

◆ ArchiveOpts

typedef void struct _archiveOpts ArchiveOpts

◆ ClonePtrType

typedef void(* ClonePtrType) (ArchiveHandle *AH)

Definition at line 156 of file pg_backup_archiver.h.

◆ ClosePtrType

typedef void(* ClosePtrType) (ArchiveHandle *AH)

Definition at line 133 of file pg_backup_archiver.h.

◆ CustomOutPtrType

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

Definition at line 162 of file pg_backup_archiver.h.

◆ DeClonePtrType

typedef void(* DeClonePtrType) (ArchiveHandle *AH)

Definition at line 157 of file pg_backup_archiver.h.

◆ EndBlobPtrType

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

Definition at line 143 of file pg_backup_archiver.h.

◆ EndBlobsPtrType

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

Definition at line 144 of file pg_backup_archiver.h.

◆ EndDataPtrType

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

Definition at line 139 of file pg_backup_archiver.h.

◆ PrepParallelRestorePtrType

typedef void(* PrepParallelRestorePtrType) (ArchiveHandle *AH)

Definition at line 155 of file pg_backup_archiver.h.

◆ PrintExtraTocPtrType

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

Definition at line 152 of file pg_backup_archiver.h.

◆ PrintTocDataPtrType

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

Definition at line 153 of file pg_backup_archiver.h.

◆ ReadBufPtrType

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

Definition at line 149 of file pg_backup_archiver.h.

◆ ReadBytePtrType

typedef int(* ReadBytePtrType) (ArchiveHandle *AH)

Definition at line 147 of file pg_backup_archiver.h.

◆ ReadExtraTocPtrType

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

Definition at line 151 of file pg_backup_archiver.h.

◆ ReopenPtrType

typedef void(* ReopenPtrType) (ArchiveHandle *AH)

Definition at line 134 of file pg_backup_archiver.h.

◆ StartBlobPtrType

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

Definition at line 142 of file pg_backup_archiver.h.

◆ StartBlobsPtrType

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

Definition at line 141 of file pg_backup_archiver.h.

◆ StartDataPtrType

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

Definition at line 137 of file pg_backup_archiver.h.

◆ T_Action

typedef enum T_Action T_Action

◆ TocEntry

typedef struct _tocEntry TocEntry

Definition at line 56 of file pg_backup_archiver.h.

◆ WorkerJobDumpPtrType

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

Definition at line 159 of file pg_backup_archiver.h.

◆ WorkerJobRestorePtrType

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

Definition at line 160 of file pg_backup_archiver.h.

◆ WriteBufPtrType

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

Definition at line 148 of file pg_backup_archiver.h.

◆ WriteBytePtrType

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

Definition at line 146 of file pg_backup_archiver.h.

◆ WriteDataPtrType

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

Definition at line 138 of file pg_backup_archiver.h.

◆ WriteExtraTocPtrType

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

Definition at line 150 of file pg_backup_archiver.h.

◆ z_stream

typedef struct _z_stream z_stream

◆ z_streamp

typedef z_stream* z_streamp

Definition at line 56 of file pg_backup_archiver.h.

Enumeration Type Documentation

◆ ArchiverOutput

Enumerator
OUTPUT_SQLCMDS 
OUTPUT_COPYDATA 
OUTPUT_OTHERDATA 

Definition at line 186 of file pg_backup_archiver.h.

194 {

◆ ArchiverStage

Enumerator
STAGE_NONE 
STAGE_INITIALIZING 
STAGE_PROCESSING 
STAGE_FINALIZING 

Definition at line 178 of file pg_backup_archiver.h.

179 {
180  sqlparseState state; /* see above */
181  bool backSlash; /* next char is backslash quoted? */
182  PQExpBuffer curCmd; /* incomplete line (NULL if not created) */
183 } sqlparseInfo;
184 
sqlparseState
Definition: regguts.h:318

◆ RestorePass

Enumerator
RESTORE_PASS_MAIN 
RESTORE_PASS_ACL 

Definition at line 212 of file pg_backup_archiver.h.

220 {

◆ sqlparseState

Enumerator
SQL_SCAN 
SQL_IN_SINGLE_QUOTE 
SQL_IN_DOUBLE_QUOTE 

Definition at line 164 of file pg_backup_archiver.h.

172 {

◆ T_Action

enum T_Action
Enumerator
ACT_DUMP 
ACT_RESTORE 

Definition at line 127 of file pg_backup_archiver.h.

130  { \
131  fatal("could not write to output file: %m"); \

Function Documentation

◆ ahprintf()

int ahprintf ( ArchiveHandle AH,
const char *  fmt,
  ... 
)

◆ ahwrite()

void ahwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
ArchiveHandle AH 
)

Definition at line 1679 of file pg_backup_archiver.c.

1680 {
1681  int bytes_written = 0;
1682 
1683  if (AH->writingBlob)
1684  {
1685  size_t remaining = size * nmemb;
1686 
1687  while (AH->lo_buf_used + remaining > AH->lo_buf_size)
1688  {
1689  size_t avail = AH->lo_buf_size - AH->lo_buf_used;
1690 
1691  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, avail);
1692  ptr = (const void *) ((const char *) ptr + avail);
1693  remaining -= avail;
1694  AH->lo_buf_used += avail;
1695  dump_lo_buf(AH);
1696  }
1697 
1698  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, remaining);
1699  AH->lo_buf_used += remaining;
1700 
1701  bytes_written = size * nmemb;
1702  }
1703  else if (AH->gzOut)
1704  bytes_written = GZWRITE(ptr, size, nmemb, AH->OF);
1705  else if (AH->CustomOutPtr)
1706  bytes_written = AH->CustomOutPtr(AH, ptr, size * nmemb);
1707 
1708  else
1709  {
1710  /*
1711  * If we're doing a restore, and it's direct to DB, and we're
1712  * connected then send it to the DB.
1713  */
1714  if (RestoringToDB(AH))
1715  bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
1716  else
1717  bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size;
1718  }
1719 
1720  if (bytes_written != size * nmemb)
1722 }
int remaining
Definition: informix.c:667
static int RestoringToDB(ArchiveHandle *AH)
static void dump_lo_buf(ArchiveHandle *AH)
#define GZWRITE(p, s, n, fh)
#define WRITE_ERROR_EXIT
int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
Definition: pg_backup_db.c:444
CustomOutPtrType CustomOutPtr

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().

◆ ArchiveEntry()

TocEntry* ArchiveEntry ( Archive AHX,
CatalogId  catalogId,
DumpId  dumpId,
ArchiveOpts opts 
)

Definition at line 1056 of file pg_backup_archiver.c.

1058 {
1059  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1060  TocEntry *newToc;
1061 
1062  newToc = (TocEntry *) pg_malloc0(sizeof(TocEntry));
1063 
1064  AH->tocCount++;
1065  if (dumpId > AH->maxDumpId)
1066  AH->maxDumpId = dumpId;
1067 
1068  newToc->prev = AH->toc->prev;
1069  newToc->next = AH->toc;
1070  AH->toc->prev->next = newToc;
1071  AH->toc->prev = newToc;
1072 
1073  newToc->catalogId = catalogId;
1074  newToc->dumpId = dumpId;
1075  newToc->section = opts->section;
1076 
1077  newToc->tag = pg_strdup(opts->tag);
1078  newToc->namespace = opts->namespace ? pg_strdup(opts->namespace) : NULL;
1079  newToc->tablespace = opts->tablespace ? pg_strdup(opts->tablespace) : NULL;
1080  newToc->tableam = opts->tableam ? pg_strdup(opts->tableam) : NULL;
1081  newToc->owner = opts->owner ? pg_strdup(opts->owner) : NULL;
1082  newToc->desc = pg_strdup(opts->description);
1083  newToc->defn = opts->createStmt ? pg_strdup(opts->createStmt) : NULL;
1084  newToc->dropStmt = opts->dropStmt ? pg_strdup(opts->dropStmt) : NULL;
1085  newToc->copyStmt = opts->copyStmt ? pg_strdup(opts->copyStmt) : NULL;
1086 
1087  if (opts->nDeps > 0)
1088  {
1089  newToc->dependencies = (DumpId *) pg_malloc(opts->nDeps * sizeof(DumpId));
1090  memcpy(newToc->dependencies, opts->deps, opts->nDeps * sizeof(DumpId));
1091  newToc->nDeps = opts->nDeps;
1092  }
1093  else
1094  {
1095  newToc->dependencies = NULL;
1096  newToc->nDeps = 0;
1097  }
1098 
1099  newToc->dataDumper = opts->dumpFn;
1100  newToc->dataDumperArg = opts->dumpArg;
1101  newToc->hadDumper = opts->dumpFn ? true : false;
1102 
1103  newToc->formatData = NULL;
1104  newToc->dataLength = 0;
1105 
1106  if (AH->ArchiveEntryPtr != NULL)
1107  AH->ArchiveEntryPtr(AH, newToc);
1108 
1109  return newToc;
1110 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
return true
Definition: isn.c:126
static AmcheckOptions opts
Definition: pg_amcheck.c:110
int DumpId
Definition: pg_backup.h:265
struct _tocEntry * toc
ArchiveEntryPtrType ArchiveEntryPtr
struct _tocEntry * prev
teSection section
DataDumperPtr dataDumper
pgoff_t dataLength
CatalogId catalogId
struct _tocEntry * next
const void * dataDumperArg
DumpId * dependencies

References _archiveHandle::ArchiveEntryPtr, _tocEntry::catalogId, _tocEntry::copyStmt, _tocEntry::dataDumper, _tocEntry::dataDumperArg, _tocEntry::dataLength, _tocEntry::defn, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dropStmt, _tocEntry::dumpId, _tocEntry::formatData, _tocEntry::hadDumper, _archiveHandle::maxDumpId, _tocEntry::nDeps, _tocEntry::next, opts, _tocEntry::owner, pg_malloc(), pg_malloc0(), pg_strdup(), _tocEntry::prev, _tocEntry::section, _tocEntry::tableam, _tocEntry::tablespace, _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocCount, and true.

Referenced by dumpAccessMethod(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpBlob(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDefaultACL(), dumpDomain(), dumpDumpableObject(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpIndexAttach(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpPolicy(), dumpProcLang(), dumpPublication(), dumpPublicationNamespace(), dumpPublicationTable(), dumpRangeType(), dumpRule(), dumpSearchPath(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStatisticsExt(), dumpStdStrings(), dumpSubscription(), dumpTableAttach(), dumpTableComment(), dumpTableData(), dumpTableSchema(), dumpTableSecLabel(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUndefinedType(), dumpUserMappings(), and refreshMatViewData().

◆ checkSeek()

bool checkSeek ( FILE *  fp)

Definition at line 3844 of file pg_backup_archiver.c.

3845 {
3846  pgoff_t tpos;
3847 
3848  /* Check that ftello works on this file */
3849  tpos = ftello(fp);
3850  if (tpos < 0)
3851  return false;
3852 
3853  /*
3854  * Check that fseeko(SEEK_SET) works, too. NB: we used to try to test
3855  * this with fseeko(fp, 0, SEEK_CUR). But some platforms treat that as a
3856  * successful no-op even on files that are otherwise unseekable.
3857  */
3858  if (fseeko(fp, tpos, SEEK_SET) != 0)
3859  return false;
3860 
3861  return true;
3862 }
#define ftello(stream)
Definition: win32_port.h:218
#define fseeko(stream, offset, origin)
Definition: win32_port.h:215
#define pgoff_t
Definition: win32_port.h:208

References fseeko, ftello, and pgoff_t.

Referenced by InitArchiveFmt_Custom(), and InitArchiveFmt_Tar().

◆ CloneArchive()

ArchiveHandle* CloneArchive ( ArchiveHandle AH)

Definition at line 4768 of file pg_backup_archiver.c.

4769 {
4770  ArchiveHandle *clone;
4771 
4772  /* Make a "flat" copy */
4773  clone = (ArchiveHandle *) pg_malloc(sizeof(ArchiveHandle));
4774  memcpy(clone, AH, sizeof(ArchiveHandle));
4775 
4776  /* Handle format-independent fields */
4777  memset(&(clone->sqlparse), 0, sizeof(clone->sqlparse));
4778 
4779  /* The clone will have its own connection, so disregard connection state */
4780  clone->connection = NULL;
4781  clone->connCancel = NULL;
4782  clone->currUser = NULL;
4783  clone->currSchema = NULL;
4784  clone->currTableAm = NULL;
4785  clone->currTablespace = NULL;
4786 
4787  /* savedPassword must be local in case we change it while connecting */
4788  if (clone->savedPassword)
4789  clone->savedPassword = pg_strdup(clone->savedPassword);
4790 
4791  /* clone has its own error count, too */
4792  clone->public.n_errors = 0;
4793 
4794  /*
4795  * Connect our new clone object to the database, using the same connection
4796  * parameters used for the original connection.
4797  */
4798  ConnectDatabase((Archive *) clone, &clone->public.ropt->cparams, true);
4799 
4800  /* re-establish fixed state */
4801  if (AH->mode == archModeRead)
4802  _doSetFixedOutputState(clone);
4803  /* in write case, setupDumpWorker will fix up connection state */
4804 
4805  /* Let the format-specific code have a chance too */
4806  clone->ClonePtr(clone);
4807 
4808  Assert(clone->connection != NULL);
4809  return clone;
4810 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void ConnectDatabase(Archive *AHX, const ConnParams *cparams, bool isReconnect)
Definition: pg_backup_db.c:109
@ archModeRead
Definition: pg_backup.h:50
static void _doSetFixedOutputState(ArchiveHandle *AH)
int n_errors
Definition: pg_backup.h:233
RestoreOptions * ropt
Definition: pg_backup.h:210
PGcancel *volatile connCancel
ClonePtrType ClonePtr
sqlparseInfo sqlparse
ConnParams cparams
Definition: pg_backup.h:142

References _doSetFixedOutputState(), archModeRead, Assert(), _archiveHandle::ClonePtr, _archiveHandle::connCancel, ConnectDatabase(), _archiveHandle::connection, _restoreOptions::cparams, _archiveHandle::currSchema, _archiveHandle::currTableAm, _archiveHandle::currTablespace, _archiveHandle::currUser, _archiveHandle::mode, Archive::n_errors, pg_malloc(), pg_strdup(), _archiveHandle::public, Archive::ropt, _archiveHandle::savedPassword, and _archiveHandle::sqlparse.

Referenced by RunWorker().

◆ DeCloneArchive()

void DeCloneArchive ( ArchiveHandle AH)

Definition at line 4818 of file pg_backup_archiver.c.

4819 {
4820  /* Should not have an open database connection */
4821  Assert(AH->connection == NULL);
4822 
4823  /* Clear format-specific state */
4824  AH->DeClonePtr(AH);
4825 
4826  /* Clear state allocated by CloneArchive */
4827  if (AH->sqlparse.curCmd)
4829 
4830  /* Clear any connection-local state */
4831  if (AH->currUser)
4832  free(AH->currUser);
4833  if (AH->currSchema)
4834  free(AH->currSchema);
4835  if (AH->currTablespace)
4836  free(AH->currTablespace);
4837  if (AH->currTableAm)
4838  free(AH->currTableAm);
4839  if (AH->savedPassword)
4840  free(AH->savedPassword);
4841 
4842  free(AH);
4843 }
#define free(a)
Definition: header.h:65
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DeClonePtrType DeClonePtr
PQExpBuffer curCmd

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

Referenced by RunWorker().

◆ DropBlobIfExists()

void DropBlobIfExists ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 544 of file pg_backup_db.c.

545 {
546  /*
547  * If we are not restoring to a direct database connection, we have to
548  * guess about how to detect whether the blob exists. Assume new-style.
549  */
550  if (AH->connection == NULL ||
551  PQserverVersion(AH->connection) >= 90000)
552  {
553  ahprintf(AH,
554  "SELECT pg_catalog.lo_unlink(oid) "
555  "FROM pg_catalog.pg_largeobject_metadata "
556  "WHERE oid = '%u';\n",
557  oid);
558  }
559  else
560  {
561  /* Restoring to pre-9.0 server, so do it the old way */
562  ahprintf(AH,
563  "SELECT CASE WHEN EXISTS("
564  "SELECT 1 FROM pg_catalog.pg_largeobject WHERE loid = '%u'"
565  ") THEN pg_catalog.lo_unlink('%u') END;\n",
566  oid, oid);
567  }
568 }
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6905
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

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

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

◆ EndRestoreBlob()

void EndRestoreBlob ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 1336 of file pg_backup_archiver.c.

1337 {
1338  if (AH->lo_buf_used > 0)
1339  {
1340  /* Write remaining bytes from the LO buffer */
1341  dump_lo_buf(AH);
1342  }
1343 
1344  AH->writingBlob = 0;
1345 
1346  if (AH->connection)
1347  {
1348  lo_close(AH->connection, AH->loFd);
1349  AH->loFd = -1;
1350  }
1351  else
1352  {
1353  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
1354  }
1355 }
int lo_close(PGconn *conn, int fd)
Definition: fe-lobj.c:96

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

Referenced by _LoadBlobs().

◆ EndRestoreBlobs()

void EndRestoreBlobs ( ArchiveHandle AH)

Definition at line 1269 of file pg_backup_archiver.c.

1270 {
1271  RestoreOptions *ropt = AH->public.ropt;
1272 
1273  if (!ropt->single_txn)
1274  {
1275  if (AH->connection)
1276  CommitTransaction(&AH->public);
1277  else
1278  ahprintf(AH, "COMMIT;\n\n");
1279  }
1280 
1281  pg_log_info(ngettext("restored %d large object",
1282  "restored %d large objects",
1283  AH->blobCount),
1284  AH->blobCount);
1285 }
#define ngettext(s, p, n)
Definition: c.h:1179
#define pg_log_info(...)
Definition: logging.h:88
static void CommitTransaction(void)
Definition: xact.c:2125

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

Referenced by _LoadBlobs().

◆ getTocEntryByDumpId()

TocEntry* getTocEntryByDumpId ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1859 of file pg_backup_archiver.c.

1860 {
1861  /* build index arrays if we didn't already */
1862  if (AH->tocsByDumpId == NULL)
1863  buildTocEntryArrays(AH);
1864 
1865  if (id > 0 && id <= AH->maxDumpId)
1866  return AH->tocsByDumpId[id];
1867 
1868  return NULL;
1869 }
static void buildTocEntryArrays(ArchiveHandle *AH)
struct _tocEntry ** tocsByDumpId

References buildTocEntryArrays(), and _archiveHandle::tocsByDumpId.

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

◆ InitArchiveFmt_Custom()

void InitArchiveFmt_Custom ( ArchiveHandle AH)

Definition at line 106 of file pg_backup_custom.c.

107 {
108  lclContext *ctx;
109 
110  /* Assuming static functions, this can be copied for each format. */
112  AH->StartDataPtr = _StartData;
113  AH->WriteDataPtr = _WriteData;
114  AH->EndDataPtr = _EndData;
115  AH->WriteBytePtr = _WriteByte;
116  AH->ReadBytePtr = _ReadByte;
117  AH->WriteBufPtr = _WriteBuf;
118  AH->ReadBufPtr = _ReadBuf;
119  AH->ClosePtr = _CloseArchive;
125 
127  AH->StartBlobPtr = _StartBlob;
128  AH->EndBlobPtr = _EndBlob;
129  AH->EndBlobsPtr = _EndBlobs;
130 
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  /*
148  * Now open the file
149  */
150  if (AH->mode == archModeWrite)
151  {
152  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
153  {
154  AH->FH = fopen(AH->fSpec, PG_BINARY_W);
155  if (!AH->FH)
156  fatal("could not open output file \"%s\": %m", AH->fSpec);
157  }
158  else
159  {
160  AH->FH = stdout;
161  if (!AH->FH)
162  fatal("could not open output file: %m");
163  }
164 
165  ctx->hasSeek = checkSeek(AH->FH);
166  }
167  else
168  {
169  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
170  {
171  AH->FH = fopen(AH->fSpec, PG_BINARY_R);
172  if (!AH->FH)
173  fatal("could not open input file \"%s\": %m", AH->fSpec);
174  }
175  else
176  {
177  AH->FH = stdin;
178  if (!AH->FH)
179  fatal("could not open input file: %m");
180  }
181 
182  ctx->hasSeek = checkSeek(AH->FH);
183 
184  ReadHead(AH);
185  ReadToc(AH);
186 
187  /*
188  * Remember location of first data block (i.e., the point after TOC)
189  * in case we have to search for desired data blocks.
190  */
191  ctx->lastFilePos = _getFilePos(AH, ctx);
192  }
193 }
#define PG_BINARY_R
Definition: c.h:1270
#define PG_BINARY_W
Definition: c.h:1271
@ archModeWrite
Definition: pg_backup.h:49
bool checkSeek(FILE *fp)
void ReadHead(ArchiveHandle *AH)
void ReadToc(ArchiveHandle *AH)
#define LOBBUFSIZE
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static pgoff_t _getFilePos(ArchiveHandle *AH, lclContext *ctx)
static void _DeClone(ArchiveHandle *AH)
static void _ReopenArchive(ArchiveHandle *AH)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
static int _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
static int _ReadByte(ArchiveHandle *)
static void _Clone(ArchiveHandle *AH)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
ReadExtraTocPtrType ReadExtraTocPtr
WorkerJobDumpPtrType WorkerJobDumpPtr
EndBlobPtrType EndBlobPtr
WriteDataPtrType WriteDataPtr
StartBlobsPtrType StartBlobsPtr
WriteBufPtrType WriteBufPtr
PrepParallelRestorePtrType PrepParallelRestorePtr
StartBlobPtrType StartBlobPtr
WriteExtraTocPtrType WriteExtraTocPtr
ReadBytePtrType ReadBytePtr
WorkerJobRestorePtrType WorkerJobRestorePtr
PrintTocDataPtrType PrintTocDataPtr
WriteBytePtrType WriteBytePtr
ReadBufPtrType ReadBufPtr
PrintExtraTocPtrType PrintExtraTocPtr
EndBlobsPtrType EndBlobsPtr
StartDataPtrType StartDataPtr
ReopenPtrType ReopenPtr
EndDataPtrType EndDataPtr
ClosePtrType ClosePtr
pgoff_t lastFilePos

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

Referenced by _allocAH().

◆ InitArchiveFmt_Directory()

void InitArchiveFmt_Directory ( ArchiveHandle AH)

Definition at line 108 of file pg_backup_directory.c.

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 
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  fatal("no output directory specified");
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  fatal("could not read directory \"%s\": %m",
186  ctx->directory);
187 
188  if (closedir(dir))
189  fatal("could not close directory \"%s\": %m",
190  ctx->directory);
191  }
192  }
193 
194  if (!is_empty && mkdir(ctx->directory, 0700) < 0)
195  fatal("could not create directory \"%s\": %m",
196  ctx->directory);
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)
207  fatal("could not open input file \"%s\": %m", fname);
208 
209  ctx->dataFH = tocFH;
210 
211  /*
212  * The TOC of a directory format dump shares the format code of the
213  * tar format.
214  */
215  AH->format = archTar;
216  ReadHead(AH);
217  AH->format = archDirectory;
218  ReadToc(AH);
219 
220  /* Nothing else in the file, so close it again... */
221  if (cfclose(tocFH) != 0)
222  fatal("could not close TOC file: %m");
223  ctx->dataFH = NULL;
224  }
225 }
int cfclose(cfp *fp)
Definition: compress_io.c:649
cfp * cfopen_read(const char *path, const char *mode)
Definition: compress_io.c:452
int closedir(DIR *)
Definition: dirent.c:123
struct dirent * readdir(DIR *)
Definition: dirent.c:78
DIR * opendir(const char *)
Definition: dirent.c:33
@ archTar
Definition: pg_backup.h:41
@ archDirectory
Definition: pg_backup.h:43
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static void _DeClone(ArchiveHandle *AH)
static void _ReopenArchive(ArchiveHandle *AH)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
static int _ReadByte(ArchiveHandle *)
static void _Clone(ArchiveHandle *AH)
static int _WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te)
static void setFilePath(ArchiveHandle *AH, char *buf, const char *relativeFilename)
static int _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
#define MAXPGPATH
Definition: dirent.c:26
ArchiveFormat format
Definition: dirent.h:10
char d_name[MAX_PATH]
Definition: dirent.h:15
#define stat
Definition: win32_port.h:283
#define S_ISDIR(m)
Definition: win32_port.h:324
#define mkdir(a, b)
Definition: win32_port.h:71

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndBlob(), _EndBlobs(), _EndData(), _PrepParallelRestore(), _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, fatal, _archiveHandle::format, _archiveHandle::formatData, _archiveHandle::fSpec, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, MAXPGPATH, mkdir, _archiveHandle::mode, opendir(), PG_BINARY_R, pg_malloc(), pg_malloc0(), _archiveHandle::PrepParallelRestorePtr, _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, readdir(), _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, S_ISDIR, setFilePath(), stat::st_mode, _archiveHandle::StartBlobPtr, _archiveHandle::StartBlobsPtr, _archiveHandle::StartDataPtr, stat, _archiveHandle::WorkerJobDumpPtr, _archiveHandle::WorkerJobRestorePtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, _archiveHandle::WriteDataPtr, and _archiveHandle::WriteExtraTocPtr.

Referenced by _allocAH().

◆ InitArchiveFmt_Null()

void InitArchiveFmt_Null ( ArchiveHandle AH)

Definition at line 48 of file pg_backup_null.c.

49 {
50  /* Assuming static functions, this can be copied for each format. */
52  AH->EndDataPtr = _EndData;
54  AH->WriteBufPtr = _WriteBuf;
55  AH->ClosePtr = _CloseArchive;
56  AH->ReopenPtr = NULL;
58 
61  AH->EndBlobPtr = _EndBlob;
62  AH->EndBlobsPtr = _EndBlobs;
63  AH->ClonePtr = NULL;
64  AH->DeClonePtr = NULL;
65 
66  /* Initialize LO buffering */
67  AH->lo_buf_size = LOBBUFSIZE;
68  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
69 
70  /*
71  * Now prevent reading...
72  */
73  if (AH->mode == archModeRead)
74  fatal("this format cannot be read");
75 }
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _CloseArchive(ArchiveHandle *AH)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)

References _CloseArchive(), _EndBlob(), _EndBlobs(), _EndData(), _PrintTocData(), _StartBlob(), _StartBlobs(), _WriteBuf(), _WriteByte(), _WriteData(), archModeRead, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndBlobPtr, _archiveHandle::EndBlobsPtr, _archiveHandle::EndDataPtr, fatal, _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().

◆ InitArchiveFmt_Tar()

void InitArchiveFmt_Tar ( ArchiveHandle AH)

Definition at line 126 of file pg_backup_tar.c.

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

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

Referenced by _allocAH().

◆ isValidTarHeader()

bool isValidTarHeader ( char *  header)

Definition at line 1042 of file pg_backup_tar.c.

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 }
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:212
uint64 read_tar_number(const char *s, int len)
Definition: tar.c:58
int tarChecksum(char *header)
Definition: tar.c:90

References header(), read_tar_number(), and tarChecksum().

Referenced by _discoverArchiveFormat().

◆ on_exit_close_archive()

void on_exit_close_archive ( Archive AHX)

Definition at line 333 of file parallel.c.

334 {
335  shutdown_info.AHX = AHX;
337 }
static void archive_close_connection(int code, void *arg)
Definition: parallel.c:344
static ShutdownInformation shutdown_info
Definition: parallel.c:154
void on_exit_nicely(on_exit_nicely_callback function, void *arg)

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

Referenced by main().

◆ parallel_restore()

int parallel_restore ( ArchiveHandle AH,
TocEntry te 
)

Definition at line 4401 of file pg_backup_archiver.c.

4402 {
4403  int status;
4404 
4405  Assert(AH->connection != NULL);
4406 
4407  /* Count only errors associated with this TOC entry */
4408  AH->public.n_errors = 0;
4409 
4410  /* Restore the TOC item */
4411  status = restore_toc_entry(AH, te, true);
4412 
4413  return status;
4414 }
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229

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

Referenced by _WorkerJobRestoreCustom(), and _WorkerJobRestoreDirectory().

◆ ReadHead()

void ReadHead ( ArchiveHandle AH)

Definition at line 3720 of file pg_backup_archiver.c.

3721 {
3722  char vmaj,
3723  vmin,
3724  vrev;
3725  int fmt;
3726 
3727  /*
3728  * If we haven't already read the header, do so.
3729  *
3730  * NB: this code must agree with _discoverArchiveFormat(). Maybe find a
3731  * way to unify the cases?
3732  */
3733  if (!AH->readHeader)
3734  {
3735  char tmpMag[7];
3736 
3737  AH->ReadBufPtr(AH, tmpMag, 5);
3738 
3739  if (strncmp(tmpMag, "PGDMP", 5) != 0)
3740  fatal("did not find magic string in file header");
3741  }
3742 
3743  vmaj = AH->ReadBytePtr(AH);
3744  vmin = AH->ReadBytePtr(AH);
3745 
3746  if (vmaj > 1 || (vmaj == 1 && vmin > 0)) /* Version > 1.0 */
3747  vrev = AH->ReadBytePtr(AH);
3748  else
3749  vrev = 0;
3750 
3751  AH->version = MAKE_ARCHIVE_VERSION(vmaj, vmin, vrev);
3752 
3753  if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
3754  fatal("unsupported version (%d.%d) in file header",
3755  vmaj, vmin);
3756 
3757  AH->intSize = AH->ReadBytePtr(AH);
3758  if (AH->intSize > 32)
3759  fatal("sanity check on integer size (%lu) failed",
3760  (unsigned long) AH->intSize);
3761 
3762  if (AH->intSize > sizeof(int))
3763  pg_log_warning("archive was made on a machine with larger integers, some operations might fail");
3764 
3765  if (AH->version >= K_VERS_1_7)
3766  AH->offSize = AH->ReadBytePtr(AH);
3767  else
3768  AH->offSize = AH->intSize;
3769 
3770  fmt = AH->ReadBytePtr(AH);
3771 
3772  if (AH->format != fmt)
3773  fatal("expected format (%d) differs from format found in file (%d)",
3774  AH->format, fmt);
3775 
3776  if (AH->version >= K_VERS_1_2)
3777  {
3778  if (AH->version < K_VERS_1_4)
3779  AH->compression = AH->ReadBytePtr(AH);
3780  else
3781  AH->compression = ReadInt(AH);
3782  }
3783  else
3785 
3786 #ifndef HAVE_LIBZ
3787  if (AH->compression != 0)
3788  pg_log_warning("archive is compressed, but this installation does not support compression -- no data will be available");
3789 #endif
3790 
3791  if (AH->version >= K_VERS_1_4)
3792  {
3793  struct tm crtm;
3794 
3795  crtm.tm_sec = ReadInt(AH);
3796  crtm.tm_min = ReadInt(AH);
3797  crtm.tm_hour = ReadInt(AH);
3798  crtm.tm_mday = ReadInt(AH);
3799  crtm.tm_mon = ReadInt(AH);
3800  crtm.tm_year = ReadInt(AH);
3801  crtm.tm_isdst = ReadInt(AH);
3802 
3803  /*
3804  * Newer versions of glibc have mktime() report failure if tm_isdst is
3805  * inconsistent with the prevailing timezone, e.g. tm_isdst = 1 when
3806  * TZ=UTC. This is problematic when restoring an archive under a
3807  * different timezone setting. If we get a failure, try again with
3808  * tm_isdst set to -1 ("don't know").
3809  *
3810  * XXX with or without this hack, we reconstruct createDate
3811  * incorrectly when the prevailing timezone is different from
3812  * pg_dump's. Next time we bump the archive version, we should flush
3813  * this representation and store a plain seconds-since-the-Epoch
3814  * timestamp instead.
3815  */
3816  AH->createDate = mktime(&crtm);
3817  if (AH->createDate == (time_t) -1)
3818  {
3819  crtm.tm_isdst = -1;
3820  AH->createDate = mktime(&crtm);
3821  if (AH->createDate == (time_t) -1)
3822  pg_log_warning("invalid creation date in header");
3823  }
3824  }
3825 
3826  if (AH->version >= K_VERS_1_4)
3827  {
3828  AH->archdbname = ReadStr(AH);
3829  }
3830 
3831  if (AH->version >= K_VERS_1_10)
3832  {
3833  AH->archiveRemoteVersion = ReadStr(AH);
3834  AH->archiveDumpVersion = ReadStr(AH);
3835  }
3836 }
static void const char * fmt
static struct pg_tm tm
Definition: localtime.c:102
char * ReadStr(ArchiveHandle *AH)
int ReadInt(ArchiveHandle *AH)
#define K_VERS_1_10
#define K_VERS_1_2
#define K_VERS_1_4
#define K_VERS_1_0
#define K_VERS_MAX
#define Z_DEFAULT_COMPRESSION
#define K_VERS_1_7
#define pg_log_warning(...)
Definition: pgfnames.c:24
int tm_sec
Definition: pgtime.h:34

References _archiveHandle::archdbname, _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, _archiveHandle::compression, _archiveHandle::createDate, fatal, fmt, _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, _archiveHandle::offSize, pg_log_warning, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::readHeader, ReadInt(), ReadStr(), tm, pg_tm::tm_sec, _archiveHandle::version, and Z_DEFAULT_COMPRESSION.

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

◆ ReadInt()

int ReadInt ( ArchiveHandle AH)

Definition at line 1995 of file pg_backup_archiver.c.

1996 {
1997  int res = 0;
1998  int bv,
1999  b;
2000  int sign = 0; /* Default positive */
2001  int bitShift = 0;
2002 
2003  if (AH->version > K_VERS_1_0)
2004  /* Read a sign byte */
2005  sign = AH->ReadBytePtr(AH);
2006 
2007  for (b = 0; b < AH->intSize; b++)
2008  {
2009  bv = AH->ReadBytePtr(AH) & 0xFF;
2010  if (bv != 0)
2011  res = res + (bv << bitShift);
2012  bitShift += 8;
2013  }
2014 
2015  if (sign)
2016  res = -res;
2017 
2018  return res;
2019 }
char sign
Definition: informix.c:668
int b
Definition: isn.c:70

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

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

◆ ReadOffset()

int ReadOffset ( ArchiveHandle AH,
pgoff_t o 
)

Definition at line 1900 of file pg_backup_archiver.c.

1901 {
1902  int i;
1903  int off;
1904  int offsetFlg;
1905 
1906  /* Initialize to zero */
1907  *o = 0;
1908 
1909  /* Check for old version */
1910  if (AH->version < K_VERS_1_7)
1911  {
1912  /* Prior versions wrote offsets using WriteInt */
1913  i = ReadInt(AH);
1914  /* -1 means not set */
1915  if (i < 0)
1916  return K_OFFSET_POS_NOT_SET;
1917  else if (i == 0)
1918  return K_OFFSET_NO_DATA;
1919 
1920  /* Cast to pgoff_t because it was written as an int. */
1921  *o = (pgoff_t) i;
1922  return K_OFFSET_POS_SET;
1923  }
1924 
1925  /*
1926  * Read the flag indicating the state of the data pointer. Check if valid
1927  * and die if not.
1928  *
1929  * This used to be handled by a negative or zero pointer, now we use an
1930  * extra byte specifically for the state.
1931  */
1932  offsetFlg = AH->ReadBytePtr(AH) & 0xFF;
1933 
1934  switch (offsetFlg)
1935  {
1936  case K_OFFSET_POS_NOT_SET:
1937  case K_OFFSET_NO_DATA:
1938  case K_OFFSET_POS_SET:
1939 
1940  break;
1941 
1942  default:
1943  fatal("unexpected data offset flag %d", offsetFlg);
1944  }
1945 
1946  /*
1947  * Read the bytes
1948  */
1949  for (off = 0; off < AH->offSize; off++)
1950  {
1951  if (off < sizeof(pgoff_t))
1952  *o |= ((pgoff_t) (AH->ReadBytePtr(AH))) << (off * 8);
1953  else
1954  {
1955  if (AH->ReadBytePtr(AH) != 0)
1956  fatal("file offset in dump file is too large");
1957  }
1958  }
1959 
1960  return offsetFlg;
1961 }
int i
Definition: isn.c:73
#define K_OFFSET_NO_DATA
#define K_OFFSET_POS_NOT_SET
#define K_OFFSET_POS_SET

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

Referenced by _ReadExtraToc().

◆ ReadStr()

char* ReadStr ( ArchiveHandle AH)

Definition at line 2041 of file pg_backup_archiver.c.

2042 {
2043  char *buf;
2044  int l;
2045 
2046  l = ReadInt(AH);
2047  if (l < 0)
2048  buf = NULL;
2049  else
2050  {
2051  buf = (char *) pg_malloc(l + 1);
2052  AH->ReadBufPtr(AH, (void *) buf, l);
2053 
2054  buf[l] = '\0';
2055  }
2056 
2057  return buf;
2058 }
static char * buf
Definition: pg_test_fsync.c:70

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

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

◆ ReadToc()

void ReadToc ( ArchiveHandle AH)

Definition at line 2489 of file pg_backup_archiver.c.

2490 {
2491  int i;
2492  char *tmp;
2493  DumpId *deps;
2494  int depIdx;
2495  int depSize;
2496  TocEntry *te;
2497 
2498  AH->tocCount = ReadInt(AH);
2499  AH->maxDumpId = 0;
2500 
2501  for (i = 0; i < AH->tocCount; i++)
2502  {
2503  te = (TocEntry *) pg_malloc0(sizeof(TocEntry));
2504  te->dumpId = ReadInt(AH);
2505 
2506  if (te->dumpId > AH->maxDumpId)
2507  AH->maxDumpId = te->dumpId;
2508 
2509  /* Sanity check */
2510  if (te->dumpId <= 0)
2511  fatal("entry ID %d out of range -- perhaps a corrupt TOC",
2512  te->dumpId);
2513 
2514  te->hadDumper = ReadInt(AH);
2515 
2516  if (AH->version >= K_VERS_1_8)
2517  {
2518  tmp = ReadStr(AH);
2519  sscanf(tmp, "%u", &te->catalogId.tableoid);
2520  free(tmp);
2521  }
2522  else
2524  tmp = ReadStr(AH);
2525  sscanf(tmp, "%u", &te->catalogId.oid);
2526  free(tmp);
2527 
2528  te->tag = ReadStr(AH);
2529  te->desc = ReadStr(AH);
2530 
2531  if (AH->version >= K_VERS_1_11)
2532  {
2533  te->section = ReadInt(AH);
2534  }
2535  else
2536  {
2537  /*
2538  * Rules for pre-8.4 archives wherein pg_dump hasn't classified
2539  * the entries into sections. This list need not cover entry
2540  * types added later than 8.4.
2541  */
2542  if (strcmp(te->desc, "COMMENT") == 0 ||
2543  strcmp(te->desc, "ACL") == 0 ||
2544  strcmp(te->desc, "ACL LANGUAGE") == 0)
2545  te->section = SECTION_NONE;
2546  else if (strcmp(te->desc, "TABLE DATA") == 0 ||
2547  strcmp(te->desc, "BLOBS") == 0 ||
2548  strcmp(te->desc, "BLOB COMMENTS") == 0)
2549  te->section = SECTION_DATA;
2550  else if (strcmp(te->desc, "CONSTRAINT") == 0 ||
2551  strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
2552  strcmp(te->desc, "FK CONSTRAINT") == 0 ||
2553  strcmp(te->desc, "INDEX") == 0 ||
2554  strcmp(te->desc, "RULE") == 0 ||
2555  strcmp(te->desc, "TRIGGER") == 0)
2556  te->section = SECTION_POST_DATA;
2557  else
2558  te->section = SECTION_PRE_DATA;
2559  }
2560 
2561  te->defn = ReadStr(AH);
2562  te->dropStmt = ReadStr(AH);
2563 
2564  if (AH->version >= K_VERS_1_3)
2565  te->copyStmt = ReadStr(AH);
2566 
2567  if (AH->version >= K_VERS_1_6)
2568  te->namespace = ReadStr(AH);
2569 
2570  if (AH->version >= K_VERS_1_10)
2571  te->tablespace = ReadStr(AH);
2572 
2573  if (AH->version >= K_VERS_1_14)
2574  te->tableam = ReadStr(AH);
2575 
2576  te->owner = ReadStr(AH);
2577  if (AH->version < K_VERS_1_9 || strcmp(ReadStr(AH), "true") == 0)
2578  pg_log_warning("restoring tables WITH OIDS is not supported anymore");
2579 
2580  /* Read TOC entry dependencies */
2581  if (AH->version >= K_VERS_1_5)
2582  {
2583  depSize = 100;
2584  deps = (DumpId *) pg_malloc(sizeof(DumpId) * depSize);
2585  depIdx = 0;
2586  for (;;)
2587  {
2588  tmp = ReadStr(AH);
2589  if (!tmp)
2590  break; /* end of list */
2591  if (depIdx >= depSize)
2592  {
2593  depSize *= 2;
2594  deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
2595  }
2596  sscanf(tmp, "%d", &deps[depIdx]);
2597  free(tmp);
2598  depIdx++;
2599  }
2600 
2601  if (depIdx > 0) /* We have a non-null entry */
2602  {
2603  deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depIdx);
2604  te->dependencies = deps;
2605  te->nDeps = depIdx;
2606  }
2607  else
2608  {
2609  free(deps);
2610  te->dependencies = NULL;
2611  te->nDeps = 0;
2612  }
2613  }
2614  else
2615  {
2616  te->dependencies = NULL;
2617  te->nDeps = 0;
2618  }
2619  te->dataLength = 0;
2620 
2621  if (AH->ReadExtraTocPtr)
2622  AH->ReadExtraTocPtr(AH, te);
2623 
2624  pg_log_debug("read TOC entry %d (ID %d) for %s %s",
2625  i, te->dumpId, te->desc, te->tag);
2626 
2627  /* link completed entry into TOC circular list */
2628  te->prev = AH->toc->prev;
2629  AH->toc->prev->next = te;
2630  AH->toc->prev = te;
2631  te->next = AH->toc;
2632 
2633  /* special processing immediately upon read for some items */
2634  if (strcmp(te->desc, "ENCODING") == 0)
2635  processEncodingEntry(AH, te);
2636  else if (strcmp(te->desc, "STDSTRINGS") == 0)
2637  processStdStringsEntry(AH, te);
2638  else if (strcmp(te->desc, "SEARCHPATH") == 0)
2639  processSearchPathEntry(AH, te);
2640  }
2641 }
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
#define pg_log_debug(...)
Definition: logging.h:92
@ SECTION_NONE
Definition: pg_backup.h:55
@ SECTION_POST_DATA
Definition: pg_backup.h:58
@ SECTION_PRE_DATA
Definition: pg_backup.h:56
@ SECTION_DATA
Definition: pg_backup.h:57
static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te)
static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te)
#define K_VERS_1_14
#define K_VERS_1_5
#define K_VERS_1_6
#define K_VERS_1_8
#define K_VERS_1_11
#define K_VERS_1_9
#define K_VERS_1_3
#define InvalidOid
Definition: postgres_ext.h:36
Oid tableoid
Definition: pg_backup.h:261

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

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

◆ ReconnectToServer()

void ReconnectToServer ( ArchiveHandle AH,
const char *  dbname 
)

Definition at line 73 of file pg_backup_db.c.

74 {
75  PGconn *oldConn = AH->connection;
76  RestoreOptions *ropt = AH->public.ropt;
77 
78  /*
79  * Save the dbname, if given, in override_dbname so that it will also
80  * affect any later reconnection attempt.
81  */
82  if (dbname)
84 
85  /*
86  * Note: we want to establish the new connection, and in particular update
87  * ArchiveHandle's connCancel, before closing old connection. Otherwise
88  * an ill-timed SIGINT could try to access a dead connection.
89  */
90  AH->connection = NULL; /* dodge error check in ConnectDatabase */
91 
92  ConnectDatabase((Archive *) AH, &ropt->cparams, true);
93 
94  PQfinish(oldConn);
95 }
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4256
void ConnectDatabase(Archive *AHX, const ConnParams *cparams, bool isReconnect)
Definition: pg_backup_db.c:109
char * dbname
Definition: streamutil.c:51
char * override_dbname
Definition: pg_backup.h:89

References ConnectDatabase(), _archiveHandle::connection, _restoreOptions::cparams, dbname, _connParams::override_dbname, pg_strdup(), PQfinish(), _archiveHandle::public, and Archive::ropt.

Referenced by _reconnectToDB().

◆ StartRestoreBlob()

void StartRestoreBlob ( ArchiveHandle AH,
Oid  oid,
bool  drop 
)

Definition at line 1292 of file pg_backup_archiver.c.

1293 {
1294  bool old_blob_style = (AH->version < K_VERS_1_12);
1295  Oid loOid;
1296 
1297  AH->blobCount++;
1298 
1299  /* Initialize the LO Buffer */
1300  AH->lo_buf_used = 0;
1301 
1302  pg_log_info("restoring large object with OID %u", oid);
1303 
1304  /* With an old archive we must do drop and create logic here */
1305  if (old_blob_style && drop)
1306  DropBlobIfExists(AH, oid);
1307 
1308  if (AH->connection)
1309  {
1310  if (old_blob_style)
1311  {
1312  loOid = lo_create(AH->connection, oid);
1313  if (loOid == 0 || loOid != oid)
1314  fatal("could not create large object %u: %s",
1315  oid, PQerrorMessage(AH->connection));
1316  }
1317  AH->loFd = lo_open(AH->connection, oid, INV_WRITE);
1318  if (AH->loFd == -1)
1319  fatal("could not open large object %u: %s",
1320  oid, PQerrorMessage(AH->connection));
1321  }
1322  else
1323  {
1324  if (old_blob_style)
1325  ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1326  oid, INV_WRITE);
1327  else
1328  ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
1329  oid, INV_WRITE);
1330  }
1331 
1332  AH->writingBlob = 1;
1333 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6915
int lo_open(PGconn *conn, Oid lobjId, int mode)
Definition: fe-lobj.c:57
Oid lo_create(PGconn *conn, Oid lobjId)
Definition: fe-lobj.c:480
#define INV_WRITE
Definition: libpq-fs.h:21
void DropBlobIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:544
#define K_VERS_1_12
unsigned int Oid
Definition: postgres_ext.h:31

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

Referenced by _LoadBlobs().

◆ StartRestoreBlobs()

void StartRestoreBlobs ( ArchiveHandle AH)

Definition at line 1250 of file pg_backup_archiver.c.

1251 {
1252  RestoreOptions *ropt = AH->public.ropt;
1253 
1254  if (!ropt->single_txn)
1255  {
1256  if (AH->connection)
1257  StartTransaction(&AH->public);
1258  else
1259  ahprintf(AH, "BEGIN;\n\n");
1260  }
1261 
1262  AH->blobCount = 0;
1263 }
static void StartTransaction(void)
Definition: xact.c:1966

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

Referenced by _LoadBlobs().

◆ TocIDRequired()

int TocIDRequired ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1872 of file pg_backup_archiver.c.

1873 {
1874  TocEntry *te = getTocEntryByDumpId(AH, id);
1875 
1876  if (!te)
1877  return 0;
1878 
1879  return te->reqs;
1880 }
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)

References getTocEntryByDumpId(), and _tocEntry::reqs.

Referenced by _tarPositionTo(), _tocEntryRequired(), and findDumpableDependencies().

◆ warn_or_exit_horribly()

void warn_or_exit_horribly ( ArchiveHandle AH,
const char *  fmt,
  ... 
)

◆ WriteDataChunks()

void WriteDataChunks ( ArchiveHandle AH,
struct ParallelState pstate 
)

Definition at line 2315 of file pg_backup_archiver.c.

2316 {
2317  TocEntry *te;
2318 
2319  if (pstate && pstate->numWorkers > 1)
2320  {
2321  /*
2322  * In parallel mode, this code runs in the leader process. We
2323  * construct an array of candidate TEs, then sort it into decreasing
2324  * size order, then dispatch each TE to a data-transfer worker. By
2325  * dumping larger tables first, we avoid getting into a situation
2326  * where we're down to one job and it's big, losing parallelism.
2327  */
2328  TocEntry **tes;
2329  int ntes;
2330 
2331  tes = (TocEntry **) pg_malloc(AH->tocCount * sizeof(TocEntry *));
2332  ntes = 0;
2333  for (te = AH->toc->next; te != AH->toc; te = te->next)
2334  {
2335  /* Consider only TEs with dataDumper functions ... */
2336  if (!te->dataDumper)
2337  continue;
2338  /* ... and ignore ones not enabled for dump */
2339  if ((te->reqs & REQ_DATA) == 0)
2340  continue;
2341 
2342  tes[ntes++] = te;
2343  }
2344 
2345  if (ntes > 1)
2346  qsort((void *) tes, ntes, sizeof(TocEntry *),
2348 
2349  for (int i = 0; i < ntes; i++)
2350  DispatchJobForTocEntry(AH, pstate, tes[i], ACT_DUMP,
2351  mark_dump_job_done, NULL);
2352 
2353  pg_free(tes);
2354 
2355  /* Now wait for workers to finish. */
2356  WaitForWorkers(AH, pstate, WFW_ALL_IDLE);
2357  }
2358  else
2359  {
2360  /* Non-parallel mode: just dump all candidate TEs sequentially. */
2361  for (te = AH->toc->next; te != AH->toc; te = te->next)
2362  {
2363  /* Must have same filter conditions as above */
2364  if (!te->dataDumper)
2365  continue;
2366  if ((te->reqs & REQ_DATA) == 0)
2367  continue;
2368 
2370  }
2371  }
2372 }
void WaitForWorkers(ArchiveHandle *AH, ParallelState *pstate, WFW_WaitOption mode)
Definition: parallel.c:1456
void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, TocEntry *te, T_Action act, ParallelCompletionPtr callback, void *callback_data)
Definition: parallel.c:1210
@ WFW_ALL_IDLE
Definition: parallel.h:35
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
static void mark_dump_job_done(ArchiveHandle *AH, TocEntry *te, int status, void *callback_data)
static int TocEntrySizeCompare(const void *p1, const void *p2)
@ ACT_DUMP
#define REQ_DATA
#define qsort(a, b, c, d)
Definition: port.h:495
int numWorkers
Definition: parallel.h:57

References ACT_DUMP, _tocEntry::dataDumper, DispatchJobForTocEntry(), i, mark_dump_job_done(), _tocEntry::next, ParallelState::numWorkers, pg_free(), pg_malloc(), qsort, REQ_DATA, _tocEntry::reqs, _archiveHandle::toc, _archiveHandle::tocCount, TocEntrySizeCompare(), WaitForWorkers(), WFW_ALL_IDLE, and WriteDataChunksForTocEntry().

Referenced by _CloseArchive().

◆ WriteDataChunksForTocEntry()

void WriteDataChunksForTocEntry ( ArchiveHandle AH,
TocEntry te 
)

Definition at line 2397 of file pg_backup_archiver.c.

2398 {
2399  StartDataPtrType startPtr;
2400  EndDataPtrType endPtr;
2401 
2402  AH->currToc = te;
2403 
2404  if (strcmp(te->desc, "BLOBS") == 0)
2405  {
2406  startPtr = AH->StartBlobsPtr;
2407  endPtr = AH->EndBlobsPtr;
2408  }
2409  else
2410  {
2411  startPtr = AH->StartDataPtr;
2412  endPtr = AH->EndDataPtr;
2413  }
2414 
2415  if (startPtr != NULL)
2416  (*startPtr) (AH, te);
2417 
2418  /*
2419  * The user-provided DataDumper routine needs to call AH->WriteData
2420  */
2421  te->dataDumper((Archive *) AH, te->dataDumperArg);
2422 
2423  if (endPtr != NULL)
2424  (*endPtr) (AH, te);
2425 
2426  AH->currToc = NULL;
2427 }
void(* EndDataPtrType)(ArchiveHandle *AH, TocEntry *te)
void(* StartDataPtrType)(ArchiveHandle *AH, TocEntry *te)
struct _tocEntry * currToc

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

Referenced by _WorkerJobDumpDirectory(), and WriteDataChunks().

◆ WriteHead()

void WriteHead ( ArchiveHandle AH)

Definition at line 3694 of file pg_backup_archiver.c.

3695 {
3696  struct tm crtm;
3697 
3698  AH->WriteBufPtr(AH, "PGDMP", 5); /* Magic code */
3699  AH->WriteBytePtr(AH, ARCHIVE_MAJOR(AH->version));
3700  AH->WriteBytePtr(AH, ARCHIVE_MINOR(AH->version));
3701  AH->WriteBytePtr(AH, ARCHIVE_REV(AH->version));
3702  AH->WriteBytePtr(AH, AH->intSize);
3703  AH->WriteBytePtr(AH, AH->offSize);
3704  AH->WriteBytePtr(AH, AH->format);
3705  WriteInt(AH, AH->compression);
3706  crtm = *localtime(&AH->createDate);
3707  WriteInt(AH, crtm.tm_sec);
3708  WriteInt(AH, crtm.tm_min);
3709  WriteInt(AH, crtm.tm_hour);
3710  WriteInt(AH, crtm.tm_mday);
3711  WriteInt(AH, crtm.tm_mon);
3712  WriteInt(AH, crtm.tm_year);
3713  WriteInt(AH, crtm.tm_isdst);
3714  WriteStr(AH, PQdb(AH->connection));
3715  WriteStr(AH, AH->public.remoteVersionStr);
3716  WriteStr(AH, PG_VERSION);
3717 }
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:6761
size_t WriteInt(ArchiveHandle *AH, int i)
size_t WriteStr(ArchiveHandle *AH, const char *c)
#define ARCHIVE_MAJOR(version)
#define ARCHIVE_MINOR(version)
#define ARCHIVE_REV(version)
char * remoteVersionStr
Definition: pg_backup.h:213

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().

◆ WriteInt()

size_t WriteInt ( ArchiveHandle AH,
int  i 
)

Definition at line 1964 of file pg_backup_archiver.c.

1965 {
1966  int b;
1967 
1968  /*
1969  * This is a bit yucky, but I don't want to make the binary format very
1970  * dependent on representation, and not knowing much about it, I write out
1971  * a sign byte. If you change this, don't forget to change the file
1972  * version #, and modify ReadInt to read the new format AS WELL AS the old
1973  * formats.
1974  */
1975 
1976  /* SIGN byte */
1977  if (i < 0)
1978  {
1979  AH->WriteBytePtr(AH, 1);
1980  i = -i;
1981  }
1982  else
1983  AH->WriteBytePtr(AH, 0);
1984 
1985  for (b = 0; b < AH->intSize; b++)
1986  {
1987  AH->WriteBytePtr(AH, i & 0xFF);
1988  i >>= 8;
1989  }
1990 
1991  return AH->intSize + 1;
1992 }

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

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

◆ WriteOffset()

size_t WriteOffset ( ArchiveHandle AH,
pgoff_t  o,
int  wasSet 
)

Definition at line 1883 of file pg_backup_archiver.c.

1884 {
1885  int off;
1886 
1887  /* Save the flag */
1888  AH->WriteBytePtr(AH, wasSet);
1889 
1890  /* Write out pgoff_t smallest byte first, prevents endian mismatch */
1891  for (off = 0; off < sizeof(pgoff_t); off++)
1892  {
1893  AH->WriteBytePtr(AH, o & 0xFF);
1894  o >>= 8;
1895  }
1896  return sizeof(pgoff_t) + 1;
1897 }

References pgoff_t, and _archiveHandle::WriteBytePtr.

Referenced by _WriteExtraToc().

◆ WriteStr()

size_t WriteStr ( ArchiveHandle AH,
const char *  s 
)

Definition at line 2022 of file pg_backup_archiver.c.

2023 {
2024  size_t res;
2025 
2026  if (c)
2027  {
2028  int len = strlen(c);
2029 
2030  res = WriteInt(AH, len);
2031  AH->WriteBufPtr(AH, c, len);
2032  res += len;
2033  }
2034  else
2035  res = WriteInt(AH, -1);
2036 
2037  return res;
2038 }
const void size_t len
char * c

References len, res, _archiveHandle::WriteBufPtr, and WriteInt().

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

◆ WriteToc()

void WriteToc ( ArchiveHandle AH)

Definition at line 2430 of file pg_backup_archiver.c.

2431 {
2432  TocEntry *te;
2433  char workbuf[32];
2434  int tocCount;
2435  int i;
2436 
2437  /* count entries that will actually be dumped */
2438  tocCount = 0;
2439  for (te = AH->toc->next; te != AH->toc; te = te->next)
2440  {
2441  if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) != 0)
2442  tocCount++;
2443  }
2444 
2445  /* printf("%d TOC Entries to save\n", tocCount); */
2446 
2447  WriteInt(AH, tocCount);
2448 
2449  for (te = AH->toc->next; te != AH->toc; te = te->next)
2450  {
2451  if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_SPECIAL)) == 0)
2452  continue;
2453 
2454  WriteInt(AH, te->dumpId);
2455  WriteInt(AH, te->dataDumper ? 1 : 0);
2456 
2457  /* OID is recorded as a string for historical reasons */
2458  sprintf(workbuf, "%u", te->catalogId.tableoid);
2459  WriteStr(AH, workbuf);
2460  sprintf(workbuf, "%u", te->catalogId.oid);
2461  WriteStr(AH, workbuf);
2462 
2463  WriteStr(AH, te->tag);
2464  WriteStr(AH, te->desc);
2465  WriteInt(AH, te->section);
2466  WriteStr(AH, te->defn);
2467  WriteStr(AH, te->dropStmt);
2468  WriteStr(AH, te->copyStmt);
2469  WriteStr(AH, te->namespace);
2470  WriteStr(AH, te->tablespace);
2471  WriteStr(AH, te->tableam);
2472  WriteStr(AH, te->owner);
2473  WriteStr(AH, "false");
2474 
2475  /* Dump list of dependencies */
2476  for (i = 0; i < te->nDeps; i++)
2477  {
2478  sprintf(workbuf, "%d", te->dependencies[i]);
2479  WriteStr(AH, workbuf);
2480  }
2481  WriteStr(AH, NULL); /* Terminate List */
2482 
2483  if (AH->WriteExtraTocPtr)
2484  AH->WriteExtraTocPtr(AH, te);
2485  }
2486 }
#define REQ_SCHEMA
#define REQ_SPECIAL
#define sprintf
Definition: port.h:227

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, sprintf, _tocEntry::tableam, CatalogId::tableoid, _tocEntry::tablespace, _tocEntry::tag, _archiveHandle::toc, _archiveHandle::WriteExtraTocPtr, WriteInt(), and WriteStr().

Referenced by _CloseArchive().