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(* StartLOsPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartLOPtrType) (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndLOPtrType) (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndLOsPtrType) (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 *c)
 
int ReadOffset (ArchiveHandle *, pgoff_t *)
 
size_t WriteOffset (ArchiveHandle *, pgoff_t, int)
 
void StartRestoreLOs (ArchiveHandle *AH)
 
void StartRestoreLO (ArchiveHandle *AH, Oid oid, bool drop)
 
void EndRestoreLO (ArchiveHandle *AH, Oid oid)
 
void EndRestoreLOs (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 DropLOIfExists (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 437 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 434 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 416 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)) \
pg_fatal("could not read from input file: end of file"); \
pg_fatal("could not read from input file: %m"); \
} while (0)
#define pg_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 { \
pg_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.

◆ EndDataPtrType

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

Definition at line 139 of file pg_backup_archiver.h.

◆ EndLOPtrType

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

Definition at line 143 of file pg_backup_archiver.h.

◆ EndLOsPtrType

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

Definition at line 144 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.

◆ StartDataPtrType

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

Definition at line 137 of file pg_backup_archiver.h.

◆ StartLOPtrType

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

Definition at line 142 of file pg_backup_archiver.h.

◆ StartLOsPtrType

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

Definition at line 141 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  pg_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 1699 of file pg_backup_archiver.c.

1700 {
1701  int bytes_written = 0;
1702 
1703  if (AH->writingLO)
1704  {
1705  size_t remaining = size * nmemb;
1706 
1707  while (AH->lo_buf_used + remaining > AH->lo_buf_size)
1708  {
1709  size_t avail = AH->lo_buf_size - AH->lo_buf_used;
1710 
1711  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, avail);
1712  ptr = (const void *) ((const char *) ptr + avail);
1713  remaining -= avail;
1714  AH->lo_buf_used += avail;
1715  dump_lo_buf(AH);
1716  }
1717 
1718  memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, remaining);
1719  AH->lo_buf_used += remaining;
1720 
1721  bytes_written = size * nmemb;
1722  }
1723  else if (AH->gzOut)
1724  bytes_written = GZWRITE(ptr, size, nmemb, AH->OF);
1725  else if (AH->CustomOutPtr)
1726  bytes_written = AH->CustomOutPtr(AH, ptr, size * nmemb);
1727 
1728  else
1729  {
1730  /*
1731  * If we're doing a restore, and it's direct to DB, and we're
1732  * connected then send it to the DB.
1733  */
1734  if (RestoringToDB(AH))
1735  bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
1736  else
1737  bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size;
1738  }
1739 
1740  if (bytes_written != size * nmemb)
1742 }
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:445
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::writingLO.

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

◆ ArchiveEntry()

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

Definition at line 1071 of file pg_backup_archiver.c.

1073 {
1074  ArchiveHandle *AH = (ArchiveHandle *) AHX;
1075  TocEntry *newToc;
1076 
1077  newToc = (TocEntry *) pg_malloc0(sizeof(TocEntry));
1078 
1079  AH->tocCount++;
1080  if (dumpId > AH->maxDumpId)
1081  AH->maxDumpId = dumpId;
1082 
1083  newToc->prev = AH->toc->prev;
1084  newToc->next = AH->toc;
1085  AH->toc->prev->next = newToc;
1086  AH->toc->prev = newToc;
1087 
1088  newToc->catalogId = catalogId;
1089  newToc->dumpId = dumpId;
1090  newToc->section = opts->section;
1091 
1092  newToc->tag = pg_strdup(opts->tag);
1093  newToc->namespace = opts->namespace ? pg_strdup(opts->namespace) : NULL;
1094  newToc->tablespace = opts->tablespace ? pg_strdup(opts->tablespace) : NULL;
1095  newToc->tableam = opts->tableam ? pg_strdup(opts->tableam) : NULL;
1096  newToc->owner = opts->owner ? pg_strdup(opts->owner) : NULL;
1097  newToc->desc = pg_strdup(opts->description);
1098  newToc->defn = opts->createStmt ? pg_strdup(opts->createStmt) : NULL;
1099  newToc->dropStmt = opts->dropStmt ? pg_strdup(opts->dropStmt) : NULL;
1100  newToc->copyStmt = opts->copyStmt ? pg_strdup(opts->copyStmt) : NULL;
1101 
1102  if (opts->nDeps > 0)
1103  {
1104  newToc->dependencies = (DumpId *) pg_malloc(opts->nDeps * sizeof(DumpId));
1105  memcpy(newToc->dependencies, opts->deps, opts->nDeps * sizeof(DumpId));
1106  newToc->nDeps = opts->nDeps;
1107  }
1108  else
1109  {
1110  newToc->dependencies = NULL;
1111  newToc->nDeps = 0;
1112  }
1113 
1114  newToc->dataDumper = opts->dumpFn;
1115  newToc->dataDumperArg = opts->dumpArg;
1116  newToc->hadDumper = opts->dumpFn ? true : false;
1117 
1118  newToc->formatData = NULL;
1119  newToc->dataLength = 0;
1120 
1121  if (AH->ArchiveEntryPtr != NULL)
1122  AH->ArchiveEntryPtr(AH, newToc);
1123 
1124  return newToc;
1125 }
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:267
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(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDefaultACL(), dumpDomain(), dumpDumpableObject(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpIndexAttach(), dumpLO(), 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 3843 of file pg_backup_archiver.c.

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

References fseeko, ftello, and pgoff_t.

Referenced by InitArchiveFmt_Custom(), and InitArchiveFmt_Tar().

◆ CloneArchive()

ArchiveHandle* CloneArchive ( ArchiveHandle AH)

Definition at line 4763 of file pg_backup_archiver.c.

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

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 4813 of file pg_backup_archiver.c.

4814 {
4815  /* Should not have an open database connection */
4816  Assert(AH->connection == NULL);
4817 
4818  /* Clear format-specific state */
4819  AH->DeClonePtr(AH);
4820 
4821  /* Clear state allocated by CloneArchive */
4822  if (AH->sqlparse.curCmd)
4824 
4825  /* Clear any connection-local state */
4826  free(AH->currUser);
4827  free(AH->currSchema);
4828  free(AH->currTablespace);
4829  free(AH->currTableAm);
4830  free(AH->savedPassword);
4831 
4832  free(AH);
4833 }
#define free(a)
Definition: header.h:65
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
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().

◆ DropLOIfExists()

void DropLOIfExists ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 545 of file pg_backup_db.c.

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

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

Referenced by _StartLO(), RestoreArchive(), and StartRestoreLO().

◆ EndRestoreLO()

void EndRestoreLO ( ArchiveHandle AH,
Oid  oid 
)

Definition at line 1355 of file pg_backup_archiver.c.

1356 {
1357  if (AH->lo_buf_used > 0)
1358  {
1359  /* Write remaining bytes from the LO buffer */
1360  dump_lo_buf(AH);
1361  }
1362 
1363  AH->writingLO = false;
1364 
1365  if (AH->connection)
1366  {
1367  lo_close(AH->connection, AH->loFd);
1368  AH->loFd = -1;
1369  }
1370  else
1371  {
1372  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
1373  }
1374 }
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::writingLO.

Referenced by _LoadLOs().

◆ EndRestoreLOs()

void EndRestoreLOs ( ArchiveHandle AH)

Definition at line 1288 of file pg_backup_archiver.c.

1289 {
1290  RestoreOptions *ropt = AH->public.ropt;
1291 
1292  if (!ropt->single_txn)
1293  {
1294  if (AH->connection)
1295  CommitTransaction(&AH->public);
1296  else
1297  ahprintf(AH, "COMMIT;\n\n");
1298  }
1299 
1300  pg_log_info(ngettext("restored %d large object",
1301  "restored %d large objects",
1302  AH->loCount),
1303  AH->loCount);
1304 }
#define ngettext(s, p, n)
Definition: c.h:1171
#define pg_log_info(...)
Definition: logging.h:124
static void CommitTransaction(void)
Definition: xact.c:2155

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

Referenced by _LoadLOs().

◆ getTocEntryByDumpId()

TocEntry* getTocEntryByDumpId ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1879 of file pg_backup_archiver.c.

1880 {
1881  /* build index arrays if we didn't already */
1882  if (AH->tocsByDumpId == NULL)
1883  buildTocEntryArrays(AH);
1884 
1885  if (id > 0 && id <= AH->maxDumpId)
1886  return AH->tocsByDumpId[id];
1887 
1888  return NULL;
1889 }
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 
126  AH->StartLOsPtr = _StartLOs;
127  AH->StartLOPtr = _StartLO;
128  AH->EndLOPtr = _EndLO;
129  AH->EndLOsPtr = _EndLOs;
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  pg_fatal("could not open output file \"%s\": %m", AH->fSpec);
157  }
158  else
159  {
160  AH->FH = stdout;
161  if (!AH->FH)
162  pg_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  pg_fatal("could not open input file \"%s\": %m", AH->fSpec);
174  }
175  else
176  {
177  AH->FH = stdin;
178  if (!AH->FH)
179  pg_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:1262
#define PG_BINARY_W
Definition: c.h:1263
@ archModeWrite
Definition: pg_backup.h:50
bool checkSeek(FILE *fp)
void ReadHead(ArchiveHandle *AH)
void ReadToc(ArchiveHandle *AH)
#define LOBBUFSIZE
static void _PrintTocData(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 _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static int _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
static void _Clone(ArchiveHandle *AH)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
EndLOsPtrType EndLOsPtr
ReadExtraTocPtrType ReadExtraTocPtr
WorkerJobDumpPtrType WorkerJobDumpPtr
StartLOsPtrType StartLOsPtr
WriteDataPtrType WriteDataPtr
StartLOPtrType StartLOPtr
WriteBufPtrType WriteBufPtr
PrepParallelRestorePtrType PrepParallelRestorePtr
EndLOPtrType EndLOPtr
WriteExtraTocPtrType WriteExtraTocPtr
ReadBytePtrType ReadBytePtr
WorkerJobRestorePtrType WorkerJobRestorePtr
PrintTocDataPtrType PrintTocDataPtr
WriteBytePtrType WriteBytePtr
ReadBufPtrType ReadBufPtr
PrintExtraTocPtrType PrintExtraTocPtr
StartDataPtrType StartDataPtr
ReopenPtrType ReopenPtr
EndDataPtrType EndDataPtr
ClosePtrType ClosePtr
pgoff_t lastFilePos

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndData(), _EndLO(), _EndLOs(), _getFilePos(), _PrepParallelRestore(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartData(), _StartLO(), _StartLOs(), _WorkerJobRestoreCustom(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), _archiveHandle::ArchiveEntryPtr, archModeWrite, checkSeek(), _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, _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_fatal, pg_malloc(), pg_malloc0(), _archiveHandle::PrepParallelRestorePtr, _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, _archiveHandle::StartDataPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, 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 
128  AH->StartLOsPtr = _StartLOs;
129  AH->StartLOPtr = _StartLO;
130  AH->EndLOPtr = _EndLO;
131  AH->EndLOsPtr = _EndLOs;
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->LOsTocFH = 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  pg_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  pg_fatal("could not read directory \"%s\": %m",
186  ctx->directory);
187 
188  if (closedir(dir))
189  pg_fatal("could not close directory \"%s\": %m",
190  ctx->directory);
191  }
192  }
193 
194  if (!is_empty && mkdir(ctx->directory, 0700) < 0)
195  pg_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  pg_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  pg_fatal("could not close TOC file: %m");
223  ctx->dataFH = NULL;
224  }
225 }
int cfclose(cfp *fp)
Definition: compress_io.c:631
cfp * cfopen_read(const char *path, const char *mode)
Definition: compress_io.c:425
int closedir(DIR *)
Definition: dirent.c:127
struct dirent * readdir(DIR *)
Definition: dirent.c:78
DIR * opendir(const char *)
Definition: dirent.c:33
@ archTar
Definition: pg_backup.h:42
@ archDirectory
Definition: pg_backup.h:44
static void _PrintTocData(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 _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
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:286
#define S_ISDIR(m)
Definition: win32_port.h:327
#define mkdir(a, b)
Definition: win32_port.h:80

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndData(), _EndLO(), _EndLOs(), _PrepParallelRestore(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartData(), _StartLO(), _StartLOs(), _WorkerJobDumpDirectory(), _WorkerJobRestoreDirectory(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archDirectory, _archiveHandle::ArchiveEntryPtr, archModeWrite, archTar, cfclose(), cfopen_read(), _archiveHandle::ClonePtr, closedir(), _archiveHandle::ClosePtr, dirent::d_name, lclContext::dataFH, _archiveHandle::DeClonePtr, lclContext::directory, _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, _archiveHandle::format, _archiveHandle::formatData, _archiveHandle::fSpec, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, lclContext::LOsTocFH, MAXPGPATH, mkdir, _archiveHandle::mode, opendir(), PG_BINARY_R, pg_fatal, 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::StartDataPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, 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 
59  AH->StartLOsPtr = _StartLOs;
60  AH->StartLOPtr = _StartLO;
61  AH->EndLOPtr = _EndLO;
62  AH->EndLOsPtr = _EndLOs;
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  pg_fatal("this format cannot be read");
75 }
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _CloseArchive(ArchiveHandle *AH)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)

References _CloseArchive(), _EndData(), _EndLO(), _EndLOs(), _PrintTocData(), _StartLO(), _StartLOs(), _WriteBuf(), _WriteByte(), _WriteData(), archModeRead, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, _archiveHandle::mode, pg_fatal, pg_malloc(), _archiveHandle::PrintTocDataPtr, _archiveHandle::ReopenPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, and _archiveHandle::WriteDataPtr.

Referenced by _allocAH().

◆ InitArchiveFmt_Tar()

void InitArchiveFmt_Tar ( ArchiveHandle AH)

Definition at line 121 of file pg_backup_tar.c.

122 {
123  lclContext *ctx;
124 
125  /* Assuming static functions, this can be copied for each format. */
127  AH->StartDataPtr = _StartData;
128  AH->WriteDataPtr = _WriteData;
129  AH->EndDataPtr = _EndData;
130  AH->WriteBytePtr = _WriteByte;
131  AH->ReadBytePtr = _ReadByte;
132  AH->WriteBufPtr = _WriteBuf;
133  AH->ReadBufPtr = _ReadBuf;
134  AH->ClosePtr = _CloseArchive;
135  AH->ReopenPtr = NULL;
140 
141  AH->StartLOsPtr = _StartLOs;
142  AH->StartLOPtr = _StartLO;
143  AH->EndLOPtr = _EndLO;
144  AH->EndLOsPtr = _EndLOs;
145  AH->ClonePtr = NULL;
146  AH->DeClonePtr = NULL;
147 
148  AH->WorkerJobDumpPtr = NULL;
149  AH->WorkerJobRestorePtr = NULL;
150 
151  /*
152  * Set up some special context used in compressing data.
153  */
155  AH->formatData = (void *) ctx;
156  ctx->filePos = 0;
157  ctx->isSpecialScript = 0;
158 
159  /* Initialize LO buffering */
160  AH->lo_buf_size = LOBBUFSIZE;
161  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
162 
163  /*
164  * Now open the tar file, and load the TOC if we're in read mode.
165  */
166  if (AH->mode == archModeWrite)
167  {
168  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
169  {
170  ctx->tarFH = fopen(AH->fSpec, PG_BINARY_W);
171  if (ctx->tarFH == NULL)
172  pg_fatal("could not open TOC file \"%s\" for output: %m",
173  AH->fSpec);
174  }
175  else
176  {
177  ctx->tarFH = stdout;
178  if (ctx->tarFH == NULL)
179  pg_fatal("could not open TOC file for output: %m");
180  }
181 
182  ctx->tarFHpos = 0;
183 
184  /*
185  * Make unbuffered since we will dup() it, and the buffers screw each
186  * other
187  */
188  /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
189 
190  ctx->hasSeek = checkSeek(ctx->tarFH);
191 
192  /*
193  * We don't support compression because reading the files back is not
194  * possible since gzdopen uses buffered IO which totally screws file
195  * positioning.
196  */
198  pg_fatal("compression is not supported by tar archive format");
199  }
200  else
201  { /* Read Mode */
202  if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
203  {
204  ctx->tarFH = fopen(AH->fSpec, PG_BINARY_R);
205  if (ctx->tarFH == NULL)
206  pg_fatal("could not open TOC file \"%s\" for input: %m",
207  AH->fSpec);
208  }
209  else
210  {
211  ctx->tarFH = stdin;
212  if (ctx->tarFH == NULL)
213  pg_fatal("could not open TOC file for input: %m");
214  }
215 
216  /*
217  * Make unbuffered since we will dup() it, and the buffers screw each
218  * other
219  */
220  /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
221 
222  ctx->tarFHpos = 0;
223 
224  ctx->hasSeek = checkSeek(ctx->tarFH);
225 
226  ctx->FH = (void *) tarOpen(AH, "toc.dat", 'r');
227  ReadHead(AH);
228  ReadToc(AH);
229  tarClose(AH, ctx->FH); /* Nothing else in the file... */
230  }
231 }
@ PG_COMPRESSION_NONE
Definition: compression.h:19
#define pg_malloc0_object(type)
Definition: fe_memutils.h:39
static void _PrintTocData(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 _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
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 _EndData(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
static void tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
pg_compress_specification compression_spec
FILE * tarFH
Definition: pg_backup_tar.c:83
pgoff_t filePos
Definition: pg_backup_tar.c:81
pgoff_t tarFHpos
Definition: pg_backup_tar.c:84
TAR_MEMBER * FH
Definition: pg_backup_tar.c:86
int isSpecialScript
Definition: pg_backup_tar.c:87
pg_compress_algorithm algorithm
Definition: compression.h:29

References _ArchiveEntry(), _CloseArchive(), _EndData(), _EndLO(), _EndLOs(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _StartData(), _StartLO(), _StartLOs(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archModeWrite, checkSeek(), lclContext::FH, lclContext::filePos, lclContext::hasSeek, lclContext::isSpecialScript, LOBBUFSIZE, PG_BINARY_R, PG_BINARY_W, PG_COMPRESSION_NONE, pg_fatal, pg_malloc(), pg_malloc0_object, ReadHead(), ReadToc(), generate_unaccent_rules::stdout, tarClose(), lclContext::tarFH, lclContext::tarFHpos, and tarOpen().

Referenced by _allocAH().

◆ isValidTarHeader()

bool isValidTarHeader ( char *  header)

Definition at line 973 of file pg_backup_tar.c.

974 {
975  int sum;
976  int chk = tarChecksum(header);
977 
978  sum = read_tar_number(&header[148], 8);
979 
980  if (sum != chk)
981  return false;
982 
983  /* POSIX tar format */
984  if (memcmp(&header[257], "ustar\0", 6) == 0 &&
985  memcmp(&header[263], "00", 2) == 0)
986  return true;
987  /* GNU tar format */
988  if (memcmp(&header[257], "ustar \0", 8) == 0)
989  return true;
990  /* not-quite-POSIX format written by pre-9.3 pg_dump */
991  if (memcmp(&header[257], "ustar00\0", 8) == 0)
992  return true;
993 
994  return false;
995 }
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:207
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 328 of file parallel.c.

329 {
330  shutdown_info.AHX = AHX;
332 }
static void archive_close_connection(int code, void *arg)
Definition: parallel.c:339
static ShutdownInformation shutdown_info
Definition: parallel.c:152
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 4396 of file pg_backup_archiver.c.

4397 {
4398  int status;
4399 
4400  Assert(AH->connection != NULL);
4401 
4402  /* Count only errors associated with this TOC entry */
4403  AH->public.n_errors = 0;
4404 
4405  /* Restore the TOC item */
4406  status = restore_toc_entry(AH, te, true);
4407 
4408  return status;
4409 }
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:224

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 3714 of file pg_backup_archiver.c.

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

References pg_compress_specification::algorithm, _archiveHandle::archdbname, _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, _archiveHandle::compression_spec, _archiveHandle::createDate, 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, pg_compress_specification::level, MAKE_ARCHIVE_VERSION, _archiveHandle::offSize, PG_COMPRESSION_GZIP, PG_COMPRESSION_NONE, pg_fatal, pg_log_warning, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::readHeader, ReadInt(), ReadStr(), tm, pg_tm::tm_sec, and _archiveHandle::version.

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

◆ ReadInt()

int ReadInt ( ArchiveHandle AH)

Definition at line 2015 of file pg_backup_archiver.c.

2016 {
2017  int res = 0;
2018  int bv,
2019  b;
2020  int sign = 0; /* Default positive */
2021  int bitShift = 0;
2022 
2023  if (AH->version > K_VERS_1_0)
2024  /* Read a sign byte */
2025  sign = AH->ReadBytePtr(AH);
2026 
2027  for (b = 0; b < AH->intSize; b++)
2028  {
2029  bv = AH->ReadBytePtr(AH) & 0xFF;
2030  if (bv != 0)
2031  res = res + (bv << bitShift);
2032  bitShift += 8;
2033  }
2034 
2035  if (sign)
2036  res = -res;
2037 
2038  return res;
2039 }
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(), _LoadLOs(), _readBlockHeader(), _ReadExtraToc(), _skipData(), _skipLOs(), ReadHead(), ReadOffset(), ReadStr(), and ReadToc().

◆ ReadOffset()

int ReadOffset ( ArchiveHandle AH,
pgoff_t o 
)

Definition at line 1920 of file pg_backup_archiver.c.

1921 {
1922  int i;
1923  int off;
1924  int offsetFlg;
1925 
1926  /* Initialize to zero */
1927  *o = 0;
1928 
1929  /* Check for old version */
1930  if (AH->version < K_VERS_1_7)
1931  {
1932  /* Prior versions wrote offsets using WriteInt */
1933  i = ReadInt(AH);
1934  /* -1 means not set */
1935  if (i < 0)
1936  return K_OFFSET_POS_NOT_SET;
1937  else if (i == 0)
1938  return K_OFFSET_NO_DATA;
1939 
1940  /* Cast to pgoff_t because it was written as an int. */
1941  *o = (pgoff_t) i;
1942  return K_OFFSET_POS_SET;
1943  }
1944 
1945  /*
1946  * Read the flag indicating the state of the data pointer. Check if valid
1947  * and die if not.
1948  *
1949  * This used to be handled by a negative or zero pointer, now we use an
1950  * extra byte specifically for the state.
1951  */
1952  offsetFlg = AH->ReadBytePtr(AH) & 0xFF;
1953 
1954  switch (offsetFlg)
1955  {
1956  case K_OFFSET_POS_NOT_SET:
1957  case K_OFFSET_NO_DATA:
1958  case K_OFFSET_POS_SET:
1959 
1960  break;
1961 
1962  default:
1963  pg_fatal("unexpected data offset flag %d", offsetFlg);
1964  }
1965 
1966  /*
1967  * Read the bytes
1968  */
1969  for (off = 0; off < AH->offSize; off++)
1970  {
1971  if (off < sizeof(pgoff_t))
1972  *o |= ((pgoff_t) (AH->ReadBytePtr(AH))) << (off * 8);
1973  else
1974  {
1975  if (AH->ReadBytePtr(AH) != 0)
1976  pg_fatal("file offset in dump file is too large");
1977  }
1978  }
1979 
1980  return offsetFlg;
1981 }
int i
Definition: isn.c:73
#define K_OFFSET_NO_DATA
#define K_OFFSET_POS_NOT_SET
#define K_OFFSET_POS_SET

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

Referenced by _ReadExtraToc().

◆ ReadStr()

char* ReadStr ( ArchiveHandle AH)

Definition at line 2061 of file pg_backup_archiver.c.

2062 {
2063  char *buf;
2064  int l;
2065 
2066  l = ReadInt(AH);
2067  if (l < 0)
2068  buf = NULL;
2069  else
2070  {
2071  buf = (char *) pg_malloc(l + 1);
2072  AH->ReadBufPtr(AH, (void *) buf, l);
2073 
2074  buf[l] = '\0';
2075  }
2076 
2077  return buf;
2078 }
static char * buf
Definition: pg_test_fsync.c:67

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

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

◆ ReadToc()

void ReadToc ( ArchiveHandle AH)

Definition at line 2509 of file pg_backup_archiver.c.

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

References _tocEntry::catalogId, _tocEntry::copyStmt, _tocEntry::dataLength, _tocEntry::defn, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dropStmt, _tocEntry::dumpId, 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_fatal, 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 74 of file pg_backup_db.c.

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

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

Referenced by _reconnectToDB().

◆ StartRestoreLO()

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

Definition at line 1311 of file pg_backup_archiver.c.

1312 {
1313  bool old_lo_style = (AH->version < K_VERS_1_12);
1314  Oid loOid;
1315 
1316  AH->loCount++;
1317 
1318  /* Initialize the LO Buffer */
1319  AH->lo_buf_used = 0;
1320 
1321  pg_log_info("restoring large object with OID %u", oid);
1322 
1323  /* With an old archive we must do drop and create logic here */
1324  if (old_lo_style && drop)
1325  DropLOIfExists(AH, oid);
1326 
1327  if (AH->connection)
1328  {
1329  if (old_lo_style)
1330  {
1331  loOid = lo_create(AH->connection, oid);
1332  if (loOid == 0 || loOid != oid)
1333  pg_fatal("could not create large object %u: %s",
1334  oid, PQerrorMessage(AH->connection));
1335  }
1336  AH->loFd = lo_open(AH->connection, oid, INV_WRITE);
1337  if (AH->loFd == -1)
1338  pg_fatal("could not open large object %u: %s",
1339  oid, PQerrorMessage(AH->connection));
1340  }
1341  else
1342  {
1343  if (old_lo_style)
1344  ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1345  oid, INV_WRITE);
1346  else
1347  ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
1348  oid, INV_WRITE);
1349  }
1350 
1351  AH->writingLO = true;
1352 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6743
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:474
#define INV_WRITE
Definition: libpq-fs.h:21
void DropLOIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:545
#define K_VERS_1_12
unsigned int Oid
Definition: postgres_ext.h:31

References ahprintf(), _archiveHandle::connection, DropLOIfExists(), INV_WRITE, K_VERS_1_12, _archiveHandle::lo_buf_used, lo_create(), lo_open(), _archiveHandle::loCount, _archiveHandle::loFd, pg_fatal, pg_log_info, PQerrorMessage(), _archiveHandle::version, and _archiveHandle::writingLO.

Referenced by _LoadLOs().

◆ StartRestoreLOs()

void StartRestoreLOs ( 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  StartTransaction(&AH->public);
1277  else
1278  ahprintf(AH, "BEGIN;\n\n");
1279  }
1280 
1281  AH->loCount = 0;
1282 }
static void StartTransaction(void)
Definition: xact.c:1996

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

Referenced by _LoadLOs().

◆ TocIDRequired()

int TocIDRequired ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 1892 of file pg_backup_archiver.c.

1893 {
1894  TocEntry *te = getTocEntryByDumpId(AH, id);
1895 
1896  if (!te)
1897  return 0;
1898 
1899  return te->reqs;
1900 }
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 2335 of file pg_backup_archiver.c.

2336 {
2337  TocEntry *te;
2338 
2339  if (pstate && pstate->numWorkers > 1)
2340  {
2341  /*
2342  * In parallel mode, this code runs in the leader process. We
2343  * construct an array of candidate TEs, then sort it into decreasing
2344  * size order, then dispatch each TE to a data-transfer worker. By
2345  * dumping larger tables first, we avoid getting into a situation
2346  * where we're down to one job and it's big, losing parallelism.
2347  */
2348  TocEntry **tes;
2349  int ntes;
2350 
2351  tes = (TocEntry **) pg_malloc(AH->tocCount * sizeof(TocEntry *));
2352  ntes = 0;
2353  for (te = AH->toc->next; te != AH->toc; te = te->next)
2354  {
2355  /* Consider only TEs with dataDumper functions ... */
2356  if (!te->dataDumper)
2357  continue;
2358  /* ... and ignore ones not enabled for dump */
2359  if ((te->reqs & REQ_DATA) == 0)
2360  continue;
2361 
2362  tes[ntes++] = te;
2363  }
2364 
2365  if (ntes > 1)
2366  qsort((void *) tes, ntes, sizeof(TocEntry *),
2368 
2369  for (int i = 0; i < ntes; i++)
2370  DispatchJobForTocEntry(AH, pstate, tes[i], ACT_DUMP,
2371  mark_dump_job_done, NULL);
2372 
2373  pg_free(tes);
2374 
2375  /* Now wait for workers to finish. */
2376  WaitForWorkers(AH, pstate, WFW_ALL_IDLE);
2377  }
2378  else
2379  {
2380  /* Non-parallel mode: just dump all candidate TEs sequentially. */
2381  for (te = AH->toc->next; te != AH->toc; te = te->next)
2382  {
2383  /* Must have same filter conditions as above */
2384  if (!te->dataDumper)
2385  continue;
2386  if ((te->reqs & REQ_DATA) == 0)
2387  continue;
2388 
2390  }
2391  }
2392 }
void WaitForWorkers(ArchiveHandle *AH, ParallelState *pstate, WFW_WaitOption mode)
Definition: parallel.c:1451
void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, TocEntry *te, T_Action act, ParallelCompletionPtr callback, void *callback_data)
Definition: parallel.c:1205
@ 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:445
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 2417 of file pg_backup_archiver.c.

2418 {
2419  StartDataPtrType startPtr;
2420  EndDataPtrType endPtr;
2421 
2422  AH->currToc = te;
2423 
2424  if (strcmp(te->desc, "BLOBS") == 0)
2425  {
2426  startPtr = AH->StartLOsPtr;
2427  endPtr = AH->EndLOsPtr;
2428  }
2429  else
2430  {
2431  startPtr = AH->StartDataPtr;
2432  endPtr = AH->EndDataPtr;
2433  }
2434 
2435  if (startPtr != NULL)
2436  (*startPtr) (AH, te);
2437 
2438  /*
2439  * The user-provided DataDumper routine needs to call AH->WriteData
2440  */
2441  te->dataDumper((Archive *) AH, te->dataDumperArg);
2442 
2443  if (endPtr != NULL)
2444  (*endPtr) (AH, te);
2445 
2446  AH->currToc = NULL;
2447 }
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::EndDataPtr, _archiveHandle::EndLOsPtr, _archiveHandle::StartDataPtr, and _archiveHandle::StartLOsPtr.

Referenced by _WorkerJobDumpDirectory(), and WriteDataChunks().

◆ WriteHead()

void WriteHead ( ArchiveHandle AH)

Definition at line 3683 of file pg_backup_archiver.c.

3684 {
3685  struct tm crtm;
3686 
3687  AH->WriteBufPtr(AH, "PGDMP", 5); /* Magic code */
3688  AH->WriteBytePtr(AH, ARCHIVE_MAJOR(AH->version));
3689  AH->WriteBytePtr(AH, ARCHIVE_MINOR(AH->version));
3690  AH->WriteBytePtr(AH, ARCHIVE_REV(AH->version));
3691  AH->WriteBytePtr(AH, AH->intSize);
3692  AH->WriteBytePtr(AH, AH->offSize);
3693  AH->WriteBytePtr(AH, AH->format);
3694  /*
3695  * For now the compression type is implied by the level. This will need
3696  * to change once support for more compression algorithms is added,
3697  * requiring a format bump.
3698  */
3699  WriteInt(AH, AH->compression_spec.level);
3700  crtm = *localtime(&AH->createDate);
3701  WriteInt(AH, crtm.tm_sec);
3702  WriteInt(AH, crtm.tm_min);
3703  WriteInt(AH, crtm.tm_hour);
3704  WriteInt(AH, crtm.tm_mday);
3705  WriteInt(AH, crtm.tm_mon);
3706  WriteInt(AH, crtm.tm_year);
3707  WriteInt(AH, crtm.tm_isdst);
3708  WriteStr(AH, PQdb(AH->connection));
3709  WriteStr(AH, AH->public.remoteVersionStr);
3710  WriteStr(AH, PG_VERSION);
3711 }
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:6589
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:215

References ARCHIVE_MAJOR, ARCHIVE_MINOR, ARCHIVE_REV, _archiveHandle::compression_spec, _archiveHandle::connection, _archiveHandle::createDate, _archiveHandle::format, _archiveHandle::intSize, pg_compress_specification::level, _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 1984 of file pg_backup_archiver.c.

1985 {
1986  int b;
1987 
1988  /*
1989  * This is a bit yucky, but I don't want to make the binary format very
1990  * dependent on representation, and not knowing much about it, I write out
1991  * a sign byte. If you change this, don't forget to change the file
1992  * version #, and modify ReadInt to read the new format AS WELL AS the old
1993  * formats.
1994  */
1995 
1996  /* SIGN byte */
1997  if (i < 0)
1998  {
1999  AH->WriteBytePtr(AH, 1);
2000  i = -i;
2001  }
2002  else
2003  AH->WriteBytePtr(AH, 0);
2004 
2005  for (b = 0; b < AH->intSize; b++)
2006  {
2007  AH->WriteBytePtr(AH, i & 0xFF);
2008  i >>= 8;
2009  }
2010 
2011  return AH->intSize + 1;
2012 }

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

Referenced by _CustomWriteFunc(), _EndData(), _EndLO(), _EndLOs(), _StartData(), _StartLO(), _StartLOs(), WriteHead(), WriteStr(), and WriteToc().

◆ WriteOffset()

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

Definition at line 1903 of file pg_backup_archiver.c.

1904 {
1905  int off;
1906 
1907  /* Save the flag */
1908  AH->WriteBytePtr(AH, wasSet);
1909 
1910  /* Write out pgoff_t smallest byte first, prevents endian mismatch */
1911  for (off = 0; off < sizeof(pgoff_t); off++)
1912  {
1913  AH->WriteBytePtr(AH, o & 0xFF);
1914  o >>= 8;
1915  }
1916  return sizeof(pgoff_t) + 1;
1917 }

References pgoff_t, and _archiveHandle::WriteBytePtr.

Referenced by _WriteExtraToc().

◆ WriteStr()

size_t WriteStr ( ArchiveHandle AH,
const char *  c 
)

Definition at line 2042 of file pg_backup_archiver.c.

2043 {
2044  size_t res;
2045 
2046  if (c)
2047  {
2048  int len = strlen(c);
2049 
2050  res = WriteInt(AH, len);
2051  AH->WriteBufPtr(AH, c, len);
2052  res += len;
2053  }
2054  else
2055  res = WriteInt(AH, -1);
2056 
2057  return res;
2058 }
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 2450 of file pg_backup_archiver.c.

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

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