PostgreSQL Source Code  git master
pg_basebackup.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
#include "access/xlog_internal.h"
#include "backup/basebackup.h"
#include "bbstreamer.h"
#include "common/compression.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/logging.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/recovery_gen.h"
#include "getopt_long.h"
#include "receivelog.h"
#include "streamutil.h"
Include dependency graph for pg_basebackup.c:

Go to the source code of this file.

Data Structures

struct  TablespaceListCell
 
struct  TablespaceList
 
struct  ArchiveStreamState
 
struct  WriteTarState
 
struct  WriteManifestState
 
struct  logstreamer_param
 

Macros

#define ERRCODE_DATA_CORRUPTED   "XX001"
 
#define MINIMUM_VERSION_FOR_PG_WAL   100000
 
#define MINIMUM_VERSION_FOR_TEMP_SLOTS   100000
 
#define MINIMUM_VERSION_FOR_MANIFESTS   130000
 
#define MINIMUM_VERSION_FOR_TERMINATED_TARFILE   150000
 
#define VERBOSE_FILENAME_LENGTH   35
 

Typedefs

typedef struct TablespaceListCell TablespaceListCell
 
typedef struct TablespaceList TablespaceList
 
typedef struct ArchiveStreamState ArchiveStreamState
 
typedef struct WriteTarState WriteTarState
 
typedef struct WriteManifestState WriteManifestState
 
typedef void(* WriteDataCallback) (size_t nbytes, char *buf, void *callback_data)
 

Enumerations

enum  IncludeWal { NO_WAL , FETCH_WAL , STREAM_WAL }
 
enum  CompressionLocation { COMPRESS_LOCATION_UNSPECIFIED , COMPRESS_LOCATION_CLIENT , COMPRESS_LOCATION_SERVER }
 

Functions

static void usage (void)
 
static void verify_dir_is_empty_or_create (char *dirname, bool *created, bool *found)
 
static void progress_update_filename (const char *filename)
 
static void progress_report (int tablespacenum, bool force, bool finished)
 
static bbstreamerCreateBackupStreamer (char *archive_name, char *spclocation, bbstreamer **manifest_inject_streamer_p, bool is_recovery_guc_supported, bool expect_unterminated_tarfile, pg_compress_specification *compress)
 
static void ReceiveArchiveStreamChunk (size_t r, char *copybuf, void *callback_data)
 
static char GetCopyDataByte (size_t r, char *copybuf, size_t *cursor)
 
static char * GetCopyDataString (size_t r, char *copybuf, size_t *cursor)
 
static uint64 GetCopyDataUInt64 (size_t r, char *copybuf, size_t *cursor)
 
static void GetCopyDataEnd (size_t r, char *copybuf, size_t cursor)
 
static void ReportCopyDataParseError (size_t r, char *copybuf)
 
static void ReceiveTarFile (PGconn *conn, char *archive_name, char *spclocation, bool tablespacenum, pg_compress_specification *compress)
 
static void ReceiveTarCopyChunk (size_t r, char *copybuf, void *callback_data)
 
static void ReceiveBackupManifest (PGconn *conn)
 
static void ReceiveBackupManifestChunk (size_t r, char *copybuf, void *callback_data)
 
static void ReceiveBackupManifestInMemory (PGconn *conn, PQExpBuffer buf)
 
static void ReceiveBackupManifestInMemoryChunk (size_t r, char *copybuf, void *callback_data)
 
static void BaseBackup (char *compression_algorithm, char *compression_detail, CompressionLocation compressloc, pg_compress_specification *client_compress)
 
static bool reached_end_position (XLogRecPtr segendpos, uint32 timeline, bool segment_finished)
 
static const char * get_tablespace_mapping (const char *dir)
 
static void tablespace_list_append (const char *arg)
 
static void cleanup_directories_atexit (void)
 
static void disconnect_atexit (void)
 
static void sigchld_handler (SIGNAL_ARGS)
 
static void kill_bgchild_atexit (void)
 
static int LogStreamerMain (logstreamer_param *param)
 
static void StartLogStreamer (char *startpos, uint32 timeline, char *sysidentifier, pg_compress_algorithm wal_compress_algorithm, int wal_compress_level)
 
static int32 parse_max_rate (char *src)
 
static void backup_parse_compress_options (char *option, char **algorithm, char **detail, CompressionLocation *locationres)
 
static void ReceiveCopyData (PGconn *conn, WriteDataCallback callback, void *callback_data)
 
static void ReceiveArchiveStream (PGconn *conn, pg_compress_specification *compress)
 
int main (int argc, char **argv)
 

Variables

static char * basedir = NULL
 
static TablespaceList tablespace_dirs = {NULL, NULL}
 
static char * xlog_dir = NULL
 
static char format = '\0'
 
static char * label = "pg_basebackup base backup"
 
static bool noclean = false
 
static bool checksum_failure = false
 
static bool showprogress = false
 
static bool estimatesize = true
 
static int verbose = 0
 
static IncludeWal includewal = STREAM_WAL
 
static bool fastcheckpoint = false
 
static bool writerecoveryconf = false
 
static bool do_sync = true
 
static int standby_message_timeout = 10 * 1000
 
static pg_time_t last_progress_report = 0
 
static int32 maxrate = 0
 
static char * replication_slot = NULL
 
static bool temp_replication_slot = true
 
static char * backup_target = NULL
 
static bool create_slot = false
 
static bool no_slot = false
 
static bool verify_checksums = true
 
static bool manifest = true
 
static bool manifest_force_encode = false
 
static char * manifest_checksums = NULL
 
static bool success = false
 
static bool made_new_pgdata = false
 
static bool found_existing_pgdata = false
 
static bool made_new_xlogdir = false
 
static bool found_existing_xlogdir = false
 
static bool made_tablespace_dirs = false
 
static bool found_tablespace_dirs = false
 
static uint64 totalsize_kb
 
static uint64 totaldone
 
static int tablespacecount
 
static char * progress_filename = NULL
 
static int bgpipe [2] = {-1, -1}
 
static pid_t bgchild = -1
 
static bool in_log_streamer = false
 
static volatile sig_atomic_t bgchild_exited = false
 
static XLogRecPtr xlogendptr
 
static int has_xlogendptr = 0
 
static PQExpBuffer recoveryconfcontents = NULL
 

Macro Definition Documentation

◆ ERRCODE_DATA_CORRUPTED

#define ERRCODE_DATA_CORRUPTED   "XX001"

Definition at line 41 of file pg_basebackup.c.

◆ MINIMUM_VERSION_FOR_MANIFESTS

#define MINIMUM_VERSION_FOR_MANIFESTS   130000

Definition at line 96 of file pg_basebackup.c.

◆ MINIMUM_VERSION_FOR_PG_WAL

#define MINIMUM_VERSION_FOR_PG_WAL   100000

Definition at line 86 of file pg_basebackup.c.

◆ MINIMUM_VERSION_FOR_TEMP_SLOTS

#define MINIMUM_VERSION_FOR_TEMP_SLOTS   100000

Definition at line 91 of file pg_basebackup.c.

◆ MINIMUM_VERSION_FOR_TERMINATED_TARFILE

#define MINIMUM_VERSION_FOR_TERMINATED_TARFILE   150000

Definition at line 102 of file pg_basebackup.c.

◆ VERBOSE_FILENAME_LENGTH

#define VERBOSE_FILENAME_LENGTH   35

Typedef Documentation

◆ ArchiveStreamState

◆ TablespaceList

◆ TablespaceListCell

◆ WriteDataCallback

typedef void(* WriteDataCallback) (size_t nbytes, char *buf, void *callback_data)

Definition at line 79 of file pg_basebackup.c.

◆ WriteManifestState

◆ WriteTarState

typedef struct WriteTarState WriteTarState

Enumeration Type Documentation

◆ CompressionLocation

Enumerator
COMPRESS_LOCATION_UNSPECIFIED 
COMPRESS_LOCATION_CLIENT 
COMPRESS_LOCATION_SERVER 

Definition at line 117 of file pg_basebackup.c.

118 {
CompressionLocation
@ COMPRESS_LOCATION_UNSPECIFIED
@ COMPRESS_LOCATION_CLIENT
@ COMPRESS_LOCATION_SERVER

◆ IncludeWal

enum IncludeWal
Enumerator
NO_WAL 
FETCH_WAL 
STREAM_WAL 

Definition at line 107 of file pg_basebackup.c.

108 {
109  NO_WAL,
110  FETCH_WAL,
111  STREAM_WAL
112 } IncludeWal;
IncludeWal
@ STREAM_WAL
@ FETCH_WAL
@ NO_WAL

Function Documentation

◆ backup_parse_compress_options()

static void backup_parse_compress_options ( char *  option,
char **  algorithm,
char **  detail,
CompressionLocation locationres 
)
static

Definition at line 959 of file pg_basebackup.c.

961 {
962  /*
963  * Strip off any "client-" or "server-" prefix, calculating the location.
964  */
965  if (strncmp(option, "server-", 7) == 0)
966  {
967  *locationres = COMPRESS_LOCATION_SERVER;
968  option += 7;
969  }
970  else if (strncmp(option, "client-", 7) == 0)
971  {
972  *locationres = COMPRESS_LOCATION_CLIENT;
973  option += 7;
974  }
975  else
976  *locationres = COMPRESS_LOCATION_UNSPECIFIED;
977 
978  /* fallback to the common parsing for the algorithm and detail */
979  parse_compress_options(option, algorithm, detail);
980 }
void parse_compress_options(const char *option, char **algorithm, char **detail)

References COMPRESS_LOCATION_CLIENT, COMPRESS_LOCATION_SERVER, COMPRESS_LOCATION_UNSPECIFIED, and parse_compress_options().

Referenced by main().

◆ BaseBackup()

static void BaseBackup ( char *  compression_algorithm,
char *  compression_detail,
CompressionLocation  compressloc,
pg_compress_specification client_compress 
)
static

Definition at line 1718 of file pg_basebackup.c.

1720 {
1721  PGresult *res;
1722  char *sysidentifier;
1723  TimeLineID latesttli;
1724  TimeLineID starttli;
1725  char *basebkp;
1726  int i;
1727  char xlogstart[64];
1728  char xlogend[64] = {0};
1729  int minServerMajor,
1730  maxServerMajor;
1731  int serverVersion,
1732  serverMajor;
1733  int writing_to_stdout;
1734  bool use_new_option_syntax = false;
1736 
1737  Assert(conn != NULL);
1738  initPQExpBuffer(&buf);
1739 
1740  /*
1741  * Check server version. BASE_BACKUP command was introduced in 9.1, so we
1742  * can't work with servers older than 9.1.
1743  */
1744  minServerMajor = 901;
1745  maxServerMajor = PG_VERSION_NUM / 100;
1746  serverVersion = PQserverVersion(conn);
1747  serverMajor = serverVersion / 100;
1748  if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
1749  {
1750  const char *serverver = PQparameterStatus(conn, "server_version");
1751 
1752  pg_fatal("incompatible server version %s",
1753  serverver ? serverver : "'unknown'");
1754  }
1755  if (serverMajor >= 1500)
1756  use_new_option_syntax = true;
1757 
1758  /*
1759  * If WAL streaming was requested, also check that the server is new
1760  * enough for that.
1761  */
1763  {
1764  /*
1765  * Error message already written in CheckServerVersionForStreaming(),
1766  * but add a hint about using -X none.
1767  */
1768  pg_log_error_hint("Use -X none or -X fetch to disable log streaming.");
1769  exit(1);
1770  }
1771 
1772  /*
1773  * Build contents of configuration file if requested
1774  */
1775  if (writerecoveryconf)
1777 
1778  /*
1779  * Run IDENTIFY_SYSTEM so we can get the timeline
1780  */
1781  if (!RunIdentifySystem(conn, &sysidentifier, &latesttli, NULL, NULL))
1782  exit(1);
1783 
1784  /*
1785  * Start the actual backup
1786  */
1787  AppendStringCommandOption(&buf, use_new_option_syntax, "LABEL", label);
1788  if (estimatesize)
1789  AppendPlainCommandOption(&buf, use_new_option_syntax, "PROGRESS");
1790  if (includewal == FETCH_WAL)
1791  AppendPlainCommandOption(&buf, use_new_option_syntax, "WAL");
1792  if (fastcheckpoint)
1793  {
1794  if (use_new_option_syntax)
1795  AppendStringCommandOption(&buf, use_new_option_syntax,
1796  "CHECKPOINT", "fast");
1797  else
1798  AppendPlainCommandOption(&buf, use_new_option_syntax, "FAST");
1799  }
1800  if (includewal != NO_WAL)
1801  {
1802  if (use_new_option_syntax)
1803  AppendIntegerCommandOption(&buf, use_new_option_syntax, "WAIT", 0);
1804  else
1805  AppendPlainCommandOption(&buf, use_new_option_syntax, "NOWAIT");
1806  }
1807  if (maxrate > 0)
1808  AppendIntegerCommandOption(&buf, use_new_option_syntax, "MAX_RATE",
1809  maxrate);
1810  if (format == 't')
1811  AppendPlainCommandOption(&buf, use_new_option_syntax, "TABLESPACE_MAP");
1812  if (!verify_checksums)
1813  {
1814  if (use_new_option_syntax)
1815  AppendIntegerCommandOption(&buf, use_new_option_syntax,
1816  "VERIFY_CHECKSUMS", 0);
1817  else
1818  AppendPlainCommandOption(&buf, use_new_option_syntax,
1819  "NOVERIFY_CHECKSUMS");
1820  }
1821 
1822  if (manifest)
1823  {
1824  AppendStringCommandOption(&buf, use_new_option_syntax, "MANIFEST",
1825  manifest_force_encode ? "force-encode" : "yes");
1826  if (manifest_checksums != NULL)
1827  AppendStringCommandOption(&buf, use_new_option_syntax,
1828  "MANIFEST_CHECKSUMS", manifest_checksums);
1829  }
1830 
1831  if (backup_target != NULL)
1832  {
1833  char *colon;
1834 
1835  if (serverMajor < 1500)
1836  pg_fatal("backup targets are not supported by this server version");
1837 
1838  if (writerecoveryconf)
1839  pg_fatal("recovery configuration cannot be written when a backup target is used");
1840 
1841  AppendPlainCommandOption(&buf, use_new_option_syntax, "TABLESPACE_MAP");
1842 
1843  if ((colon = strchr(backup_target, ':')) == NULL)
1844  {
1845  AppendStringCommandOption(&buf, use_new_option_syntax,
1846  "TARGET", backup_target);
1847  }
1848  else
1849  {
1850  char *target;
1851 
1853  AppendStringCommandOption(&buf, use_new_option_syntax,
1854  "TARGET", target);
1855  AppendStringCommandOption(&buf, use_new_option_syntax,
1856  "TARGET_DETAIL", colon + 1);
1857  }
1858  }
1859  else if (serverMajor >= 1500)
1860  AppendStringCommandOption(&buf, use_new_option_syntax,
1861  "TARGET", "client");
1862 
1863  if (compressloc == COMPRESS_LOCATION_SERVER)
1864  {
1865  if (!use_new_option_syntax)
1866  pg_fatal("server does not support server-side compression");
1867  AppendStringCommandOption(&buf, use_new_option_syntax,
1868  "COMPRESSION", compression_algorithm);
1869  if (compression_detail != NULL)
1870  AppendStringCommandOption(&buf, use_new_option_syntax,
1871  "COMPRESSION_DETAIL",
1872  compression_detail);
1873  }
1874 
1875  if (verbose)
1876  pg_log_info("initiating base backup, waiting for checkpoint to complete");
1877 
1878  if (showprogress && !verbose)
1879  {
1880  fprintf(stderr, _("waiting for checkpoint"));
1881  if (isatty(fileno(stderr)))
1882  fprintf(stderr, "\r");
1883  else
1884  fprintf(stderr, "\n");
1885  }
1886 
1887  if (use_new_option_syntax && buf.len > 0)
1888  basebkp = psprintf("BASE_BACKUP (%s)", buf.data);
1889  else
1890  basebkp = psprintf("BASE_BACKUP %s", buf.data);
1891 
1892  if (PQsendQuery(conn, basebkp) == 0)
1893  pg_fatal("could not send replication command \"%s\": %s",
1894  "BASE_BACKUP", PQerrorMessage(conn));
1895 
1896  /*
1897  * Get the starting WAL location
1898  */
1899  res = PQgetResult(conn);
1901  pg_fatal("could not initiate base backup: %s",
1902  PQerrorMessage(conn));
1903  if (PQntuples(res) != 1)
1904  pg_fatal("server returned unexpected response to BASE_BACKUP command; got %d rows and %d fields, expected %d rows and %d fields",
1905  PQntuples(res), PQnfields(res), 1, 2);
1906 
1907  strlcpy(xlogstart, PQgetvalue(res, 0, 0), sizeof(xlogstart));
1908 
1909  if (verbose)
1910  pg_log_info("checkpoint completed");
1911 
1912  /*
1913  * 9.3 and later sends the TLI of the starting point. With older servers,
1914  * assume it's the same as the latest timeline reported by
1915  * IDENTIFY_SYSTEM.
1916  */
1917  if (PQnfields(res) >= 2)
1918  starttli = atoi(PQgetvalue(res, 0, 1));
1919  else
1920  starttli = latesttli;
1921  PQclear(res);
1922 
1923  if (verbose && includewal != NO_WAL)
1924  pg_log_info("write-ahead log start point: %s on timeline %u",
1925  xlogstart, starttli);
1926 
1927  /*
1928  * Get the header
1929  */
1930  res = PQgetResult(conn);
1932  pg_fatal("could not get backup header: %s",
1933  PQerrorMessage(conn));
1934  if (PQntuples(res) < 1)
1935  pg_fatal("no data returned from server");
1936 
1937  /*
1938  * Sum up the total size, for progress reporting
1939  */
1940  totalsize_kb = totaldone = 0;
1942  for (i = 0; i < PQntuples(res); i++)
1943  {
1944  totalsize_kb += atol(PQgetvalue(res, i, 2));
1945 
1946  /*
1947  * Verify tablespace directories are empty. Don't bother with the
1948  * first once since it can be relocated, and it will be checked before
1949  * we do anything anyway.
1950  *
1951  * Note that this is skipped for tar format backups and backups that
1952  * the server is storing to a target location, since in that case we
1953  * won't be storing anything into these directories and thus should
1954  * not create them.
1955  */
1956  if (backup_target == NULL && format == 'p' && !PQgetisnull(res, i, 1))
1957  {
1958  char *path = unconstify(char *, get_tablespace_mapping(PQgetvalue(res, i, 1)));
1959 
1961  }
1962  }
1963 
1964  /*
1965  * When writing to stdout, require a single tablespace
1966  */
1967  writing_to_stdout = format == 't' && basedir != NULL &&
1968  strcmp(basedir, "-") == 0;
1969  if (writing_to_stdout && PQntuples(res) > 1)
1970  pg_fatal("can only write single tablespace to stdout, database has %d",
1971  PQntuples(res));
1972 
1973  /*
1974  * If we're streaming WAL, start the streaming session before we start
1975  * receiving the actual data chunks.
1976  */
1977  if (includewal == STREAM_WAL)
1978  {
1979  pg_compress_algorithm wal_compress_algorithm;
1980  int wal_compress_level;
1981 
1982  if (verbose)
1983  pg_log_info("starting background WAL receiver");
1984 
1985  if (client_compress->algorithm == PG_COMPRESSION_GZIP)
1986  {
1987  wal_compress_algorithm = PG_COMPRESSION_GZIP;
1988  wal_compress_level = client_compress->level;
1989  }
1990  else
1991  {
1992  wal_compress_algorithm = PG_COMPRESSION_NONE;
1993  wal_compress_level = 0;
1994  }
1995 
1996  StartLogStreamer(xlogstart, starttli, sysidentifier,
1997  wal_compress_algorithm,
1998  wal_compress_level);
1999  }
2000 
2001  if (serverMajor >= 1500)
2002  {
2003  /* Receive a single tar stream with everything. */
2004  ReceiveArchiveStream(conn, client_compress);
2005  }
2006  else
2007  {
2008  /* Receive a tar file for each tablespace in turn */
2009  for (i = 0; i < PQntuples(res); i++)
2010  {
2011  char archive_name[MAXPGPATH];
2012  char *spclocation;
2013 
2014  /*
2015  * If we write the data out to a tar file, it will be named
2016  * base.tar if it's the main data directory or <tablespaceoid>.tar
2017  * if it's for another tablespace. CreateBackupStreamer() will
2018  * arrange to add an extension to the archive name if
2019  * pg_basebackup is performing compression, depending on the
2020  * compression type.
2021  */
2022  if (PQgetisnull(res, i, 0))
2023  {
2024  strlcpy(archive_name, "base.tar", sizeof(archive_name));
2025  spclocation = NULL;
2026  }
2027  else
2028  {
2029  snprintf(archive_name, sizeof(archive_name),
2030  "%s.tar", PQgetvalue(res, i, 0));
2031  spclocation = PQgetvalue(res, i, 1);
2032  }
2033 
2034  ReceiveTarFile(conn, archive_name, spclocation, i,
2035  client_compress);
2036  }
2037 
2038  /*
2039  * Now receive backup manifest, if appropriate.
2040  *
2041  * If we're writing a tarfile to stdout, ReceiveTarFile will have
2042  * already processed the backup manifest and included it in the output
2043  * tarfile. Such a configuration doesn't allow for writing multiple
2044  * files.
2045  *
2046  * If we're talking to an older server, it won't send a backup
2047  * manifest, so don't try to receive one.
2048  */
2049  if (!writing_to_stdout && manifest)
2051  }
2052 
2053  if (showprogress)
2054  {
2056  progress_report(PQntuples(res), true, true);
2057  }
2058 
2059  PQclear(res);
2060 
2061  /*
2062  * Get the stop position
2063  */
2064  res = PQgetResult(conn);
2066  pg_fatal("backup failed: %s",
2067  PQerrorMessage(conn));
2068  if (PQntuples(res) != 1)
2069  pg_fatal("no write-ahead log end position returned from server");
2070  strlcpy(xlogend, PQgetvalue(res, 0, 0), sizeof(xlogend));
2071  if (verbose && includewal != NO_WAL)
2072  pg_log_info("write-ahead log end point: %s", xlogend);
2073  PQclear(res);
2074 
2075  res = PQgetResult(conn);
2077  {
2078  const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
2079 
2080  if (sqlstate &&
2081  strcmp(sqlstate, ERRCODE_DATA_CORRUPTED) == 0)
2082  {
2083  pg_log_error("checksum error occurred");
2084  checksum_failure = true;
2085  }
2086  else
2087  {
2088  pg_log_error("final receive failed: %s",
2089  PQerrorMessage(conn));
2090  }
2091  exit(1);
2092  }
2093 
2094  if (bgchild > 0)
2095  {
2096 #ifndef WIN32
2097  int status;
2098  pid_t r;
2099 #else
2100  DWORD status;
2101 
2102  /*
2103  * get a pointer sized version of bgchild to avoid warnings about
2104  * casting to a different size on WIN64.
2105  */
2106  intptr_t bgchild_handle = bgchild;
2107  uint32 hi,
2108  lo;
2109 #endif
2110 
2111  if (verbose)
2112  pg_log_info("waiting for background process to finish streaming ...");
2113 
2114 #ifndef WIN32
2115  if (write(bgpipe[1], xlogend, strlen(xlogend)) != strlen(xlogend))
2116  pg_fatal("could not send command to background pipe: %m");
2117 
2118  /* Just wait for the background process to exit */
2119  r = waitpid(bgchild, &status, 0);
2120  if (r == (pid_t) -1)
2121  pg_fatal("could not wait for child process: %m");
2122  if (r != bgchild)
2123  pg_fatal("child %d died, expected %d", (int) r, (int) bgchild);
2124  if (status != 0)
2125  pg_fatal("%s", wait_result_to_str(status));
2126  /* Exited normally, we're happy! */
2127 #else /* WIN32 */
2128 
2129  /*
2130  * On Windows, since we are in the same process, we can just store the
2131  * value directly in the variable, and then set the flag that says
2132  * it's there.
2133  */
2134  if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
2135  pg_fatal("could not parse write-ahead log location \"%s\"",
2136  xlogend);
2137  xlogendptr = ((uint64) hi) << 32 | lo;
2138  InterlockedIncrement(&has_xlogendptr);
2139 
2140  /* First wait for the thread to exit */
2141  if (WaitForSingleObjectEx((HANDLE) bgchild_handle, INFINITE, FALSE) !=
2142  WAIT_OBJECT_0)
2143  {
2144  _dosmaperr(GetLastError());
2145  pg_fatal("could not wait for child thread: %m");
2146  }
2147  if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
2148  {
2149  _dosmaperr(GetLastError());
2150  pg_fatal("could not get child thread exit status: %m");
2151  }
2152  if (status != 0)
2153  pg_fatal("child thread exited with error %u",
2154  (unsigned int) status);
2155  /* Exited normally, we're happy */
2156 #endif
2157  }
2158 
2159  /* Free the configuration file contents */
2161 
2162  /*
2163  * End of copy data. Final result is already checked inside the loop.
2164  */
2165  PQclear(res);
2166  PQfinish(conn);
2167  conn = NULL;
2168 
2169  /*
2170  * Make data persistent on disk once backup is completed. For tar format
2171  * sync the parent directory and all its contents as each tar file was not
2172  * synced after being completed. In plain format, all the data of the
2173  * base directory is synced, taking into account all the tablespaces.
2174  * Errors are not considered fatal.
2175  *
2176  * If, however, there's a backup target, we're not writing anything
2177  * locally, so in that case we skip this step.
2178  */
2179  if (do_sync && backup_target == NULL)
2180  {
2181  if (verbose)
2182  pg_log_info("syncing data to disk ...");
2183  if (format == 't')
2184  {
2185  if (strcmp(basedir, "-") != 0)
2186  (void) fsync_dir_recurse(basedir);
2187  }
2188  else
2189  {
2190  (void) fsync_pgdata(basedir, serverVersion);
2191  }
2192  }
2193 
2194  /*
2195  * After synchronizing data to disk, perform a durable rename of
2196  * backup_manifest.tmp to backup_manifest, if we wrote such a file. This
2197  * way, a failure or system crash before we reach this point will leave us
2198  * without a backup_manifest file, decreasing the chances that a directory
2199  * we leave behind will be mistaken for a valid backup.
2200  */
2201  if (!writing_to_stdout && manifest && backup_target == NULL)
2202  {
2203  char tmp_filename[MAXPGPATH];
2204  char filename[MAXPGPATH];
2205 
2206  if (verbose)
2207  pg_log_info("renaming backup_manifest.tmp to backup_manifest");
2208 
2209  snprintf(tmp_filename, MAXPGPATH, "%s/backup_manifest.tmp", basedir);
2210  snprintf(filename, MAXPGPATH, "%s/backup_manifest", basedir);
2211 
2212  if (do_sync)
2213  {
2214  /* durable_rename emits its own log message in case of failure */
2215  if (durable_rename(tmp_filename, filename) != 0)
2216  exit(1);
2217  }
2218  else
2219  {
2220  if (rename(tmp_filename, filename) != 0)
2221  pg_fatal("could not rename file \"%s\" to \"%s\": %m",
2222  tmp_filename, filename);
2223  }
2224  }
2225 
2226  if (verbose)
2227  pg_log_info("base backup completed");
2228 }
#define unconstify(underlying_type, expr)
Definition: c.h:1232
unsigned int uint32
Definition: c.h:490
pg_compress_algorithm
Definition: compression.h:22
@ PG_COMPRESSION_GZIP
Definition: compression.h:24
@ PG_COMPRESSION_NONE
Definition: compression.h:23
#define _(x)
Definition: elog.c:91
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:688
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:7138
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:7163
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:7173
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4560
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3244
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3314
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3709
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3734
int PQsendQuery(PGconn *conn, const char *query)
Definition: fe-exec.c:1422
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:3299
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3322
PGresult * PQgetResult(PGconn *conn)
Definition: fe-exec.c:2035
#define colon
Definition: indent_codes.h:43
#define write(a, b, c)
Definition: win32.h:14
int i
Definition: isn.c:73
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:97
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:100
Assert(fmt[strlen(fmt) - 1] !='\n')
exit(1)
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_hint(...)
Definition: logging.h:112
#define pg_log_info(...)
Definition: logging.h:124
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1635
#define pg_fatal(...)
static int verbose
static bool checksum_failure
static bool estimatesize
static bool manifest
static int32 maxrate
static void ReceiveTarFile(PGconn *conn, char *archive_name, char *spclocation, bool tablespacenum, pg_compress_specification *compress)
static char * backup_target
static char format
static void StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier, pg_compress_algorithm wal_compress_algorithm, int wal_compress_level)
static int bgpipe[2]
static void ReceiveArchiveStream(PGconn *conn, pg_compress_specification *compress)
static PQExpBuffer recoveryconfcontents
static int tablespacecount
static void progress_update_filename(const char *filename)
static pid_t bgchild
static int has_xlogendptr
static void verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found)
static uint64 totalsize_kb
static bool verify_checksums
static char * replication_slot
static void ReceiveBackupManifest(PGconn *conn)
static uint64 totaldone
static void progress_report(int tablespacenum, bool force, bool finished)
static bool manifest_force_encode
static char * manifest_checksums
static bool found_tablespace_dirs
static IncludeWal includewal
static bool do_sync
static bool writerecoveryconf
static bool made_tablespace_dirs
static bool fastcheckpoint
#define ERRCODE_DATA_CORRUPTED
Definition: pg_basebackup.c:41
static char * label
static bool showprogress
static const char * get_tablespace_mapping(const char *dir)
static char * basedir
static XLogRecPtr xlogendptr
#define MAXPGPATH
static char * filename
Definition: pg_dumpall.c:119
static pg_compress_algorithm compression_algorithm
Definition: pg_receivewal.c:55
static char * buf
Definition: pg_test_fsync.c:67
#define snprintf
Definition: port.h:238
#define fprintf
Definition: port.h:242
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:56
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
bool CheckServerVersionForStreaming(PGconn *conn)
Definition: receivelog.c:375
PQExpBuffer GenerateRecoveryConfig(PGconn *pgconn, char *replication_slot)
Definition: recovery_gen.c:23
void AppendIntegerCommandOption(PQExpBuffer buf, bool use_new_option_syntax, char *option_name, int32 option_value)
Definition: streamutil.c:776
void AppendPlainCommandOption(PQExpBuffer buf, bool use_new_option_syntax, char *option_name)
Definition: streamutil.c:732
void AppendStringCommandOption(PQExpBuffer buf, bool use_new_option_syntax, char *option_name, char *option_value)
Definition: streamutil.c:753
PGconn * conn
Definition: streamutil.c:54
bool RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, XLogRecPtr *startpos, char **db_name)
Definition: streamutil.c:400
pg_compress_algorithm algorithm
Definition: compression.h:33
char * wait_result_to_str(int exitstatus)
Definition: wait_error.c:33
void _dosmaperr(unsigned long)
Definition: win32error.c:177
uint32 TimeLineID
Definition: xlogdefs.h:59

References _, _dosmaperr(), pg_compress_specification::algorithm, AppendIntegerCommandOption(), AppendPlainCommandOption(), AppendStringCommandOption(), Assert(), backup_target, basedir, bgchild, bgpipe, buf, CheckServerVersionForStreaming(), checksum_failure, colon, COMPRESS_LOCATION_SERVER, compression_algorithm, conn, destroyPQExpBuffer(), do_sync, durable_rename(), ERRCODE_DATA_CORRUPTED, estimatesize, exit(), fastcheckpoint, FETCH_WAL, filename, format, found_tablespace_dirs, fprintf, GenerateRecoveryConfig(), get_tablespace_mapping(), has_xlogendptr, i, includewal, initPQExpBuffer(), label, pg_compress_specification::level, made_tablespace_dirs, manifest, manifest_checksums, manifest_force_encode, MAXPGPATH, maxrate, NO_WAL, PG_COMPRESSION_GZIP, PG_COMPRESSION_NONE, PG_DIAG_SQLSTATE, pg_fatal, pg_log_error, pg_log_error_hint, pg_log_info, PGRES_COMMAND_OK, PGRES_TUPLES_OK, pnstrdup(), PQclear(), PQerrorMessage(), PQfinish(), PQgetisnull(), PQgetResult(), PQgetvalue(), PQnfields(), PQntuples(), PQparameterStatus(), PQresultErrorField(), PQresultStatus(), PQsendQuery(), PQserverVersion(), progress_report(), progress_update_filename(), psprintf(), ReceiveArchiveStream(), ReceiveBackupManifest(), ReceiveTarFile(), recoveryconfcontents, replication_slot, res, RunIdentifySystem(), showprogress, snprintf, StartLogStreamer(), STREAM_WAL, strlcpy(), tablespacecount, totaldone, totalsize_kb, unconstify, verbose, verify_checksums, verify_dir_is_empty_or_create(), wait_result_to_str(), write, writerecoveryconf, and xlogendptr.

Referenced by main().

◆ cleanup_directories_atexit()

static void cleanup_directories_atexit ( void  )
static

Definition at line 229 of file pg_basebackup.c.

230 {
231  if (success || in_log_streamer)
232  return;
233 
234  if (!noclean && !checksum_failure)
235  {
236  if (made_new_pgdata)
237  {
238  pg_log_info("removing data directory \"%s\"", basedir);
239  if (!rmtree(basedir, true))
240  pg_log_error("failed to remove data directory");
241  }
242  else if (found_existing_pgdata)
243  {
244  pg_log_info("removing contents of data directory \"%s\"", basedir);
245  if (!rmtree(basedir, false))
246  pg_log_error("failed to remove contents of data directory");
247  }
248 
249  if (made_new_xlogdir)
250  {
251  pg_log_info("removing WAL directory \"%s\"", xlog_dir);
252  if (!rmtree(xlog_dir, true))
253  pg_log_error("failed to remove WAL directory");
254  }
255  else if (found_existing_xlogdir)
256  {
257  pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
258  if (!rmtree(xlog_dir, false))
259  pg_log_error("failed to remove contents of WAL directory");
260  }
261  }
262  else
263  {
265  pg_log_info("data directory \"%s\" not removed at user's request", basedir);
266 
268  pg_log_info("WAL directory \"%s\" not removed at user's request", xlog_dir);
269  }
270 
272  pg_log_info("changes to tablespace directories will not be undone");
273 }
static bool noclean
static bool found_existing_pgdata
static bool found_existing_xlogdir
static char * xlog_dir
static bool success
static bool in_log_streamer
static bool made_new_xlogdir
static bool made_new_pgdata
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:50

References basedir, checksum_failure, found_existing_pgdata, found_existing_xlogdir, found_tablespace_dirs, in_log_streamer, made_new_pgdata, made_new_xlogdir, made_tablespace_dirs, noclean, pg_log_error, pg_log_info, rmtree(), success, and xlog_dir.

Referenced by main().

◆ CreateBackupStreamer()

static bbstreamer * CreateBackupStreamer ( char *  archive_name,
char *  spclocation,
bbstreamer **  manifest_inject_streamer_p,
bool  is_recovery_guc_supported,
bool  expect_unterminated_tarfile,
pg_compress_specification compress 
)
static

Definition at line 1034 of file pg_basebackup.c.

1039 {
1040  bbstreamer *streamer = NULL;
1041  bbstreamer *manifest_inject_streamer = NULL;
1042  bool inject_manifest;
1043  bool is_tar,
1044  is_tar_gz,
1045  is_tar_lz4,
1046  is_tar_zstd,
1047  is_compressed_tar;
1048  bool must_parse_archive;
1049  int archive_name_len = strlen(archive_name);
1050 
1051  /*
1052  * Normally, we emit the backup manifest as a separate file, but when
1053  * we're writing a tarfile to stdout, we don't have that option, so
1054  * include it in the one tarfile we've got.
1055  */
1056  inject_manifest = (format == 't' && strcmp(basedir, "-") == 0 && manifest);
1057 
1058  /* Is this a tar archive? */
1059  is_tar = (archive_name_len > 4 &&
1060  strcmp(archive_name + archive_name_len - 4, ".tar") == 0);
1061 
1062  /* Is this a .tar.gz archive? */
1063  is_tar_gz = (archive_name_len > 7 &&
1064  strcmp(archive_name + archive_name_len - 7, ".tar.gz") == 0);
1065 
1066  /* Is this a .tar.lz4 archive? */
1067  is_tar_lz4 = (archive_name_len > 8 &&
1068  strcmp(archive_name + archive_name_len - 8, ".tar.lz4") == 0);
1069 
1070  /* Is this a .tar.zst archive? */
1071  is_tar_zstd = (archive_name_len > 8 &&
1072  strcmp(archive_name + archive_name_len - 8, ".tar.zst") == 0);
1073 
1074  /* Is this any kind of compressed tar? */
1075  is_compressed_tar = is_tar_gz || is_tar_lz4 || is_tar_zstd;
1076 
1077  /*
1078  * Injecting the manifest into a compressed tar file would be possible if
1079  * we decompressed it, parsed the tarfile, generated a new tarfile, and
1080  * recompressed it, but compressing and decompressing multiple times just
1081  * to inject the manifest seems inefficient enough that it's probably not
1082  * what the user wants. So, instead, reject the request and tell the user
1083  * to specify something more reasonable.
1084  */
1085  if (inject_manifest && is_compressed_tar)
1086  {
1087  pg_log_error("cannot inject manifest into a compressed tar file");
1088  pg_log_error_hint("Use client-side compression, send the output to a directory rather than standard output, or use %s.",
1089  "--no-manifest");
1090  exit(1);
1091  }
1092 
1093  /*
1094  * We have to parse the archive if (1) we're suppose to extract it, or if
1095  * (2) we need to inject backup_manifest or recovery configuration into
1096  * it. However, we only know how to parse tar archives.
1097  */
1098  must_parse_archive = (format == 'p' || inject_manifest ||
1099  (spclocation == NULL && writerecoveryconf));
1100 
1101  /* At present, we only know how to parse tar archives. */
1102  if (must_parse_archive && !is_tar && !is_compressed_tar)
1103  {
1104  pg_log_error("cannot parse archive \"%s\"", archive_name);
1105  pg_log_error_detail("Only tar archives can be parsed.");
1106  if (format == 'p')
1107  pg_log_error_detail("Plain format requires pg_basebackup to parse the archive.");
1108  if (inject_manifest)
1109  pg_log_error_detail("Using - as the output directory requires pg_basebackup to parse the archive.");
1110  if (writerecoveryconf)
1111  pg_log_error_detail("The -R option requires pg_basebackup to parse the archive.");
1112  exit(1);
1113  }
1114 
1115  if (format == 'p')
1116  {
1117  const char *directory;
1118 
1119  /*
1120  * In plain format, we must extract the archive. The data for the main
1121  * tablespace will be written to the base directory, and the data for
1122  * other tablespaces will be written to the directory where they're
1123  * located on the server, after applying any user-specified tablespace
1124  * mappings.
1125  */
1126  directory = spclocation == NULL ? basedir
1127  : get_tablespace_mapping(spclocation);
1131  }
1132  else
1133  {
1134  FILE *archive_file;
1135  char archive_filename[MAXPGPATH];
1136 
1137  /*
1138  * In tar format, we just write the archive without extracting it.
1139  * Normally, we write it to the archive name provided by the caller,
1140  * but when the base directory is "-" that means we need to write to
1141  * standard output.
1142  */
1143  if (strcmp(basedir, "-") == 0)
1144  {
1145  snprintf(archive_filename, sizeof(archive_filename), "-");
1146  archive_file = stdout;
1147  }
1148  else
1149  {
1150  snprintf(archive_filename, sizeof(archive_filename),
1151  "%s/%s", basedir, archive_name);
1152  archive_file = NULL;
1153  }
1154 
1155  if (compress->algorithm == PG_COMPRESSION_NONE)
1156  streamer = bbstreamer_plain_writer_new(archive_filename,
1157  archive_file);
1158  else if (compress->algorithm == PG_COMPRESSION_GZIP)
1159  {
1160  strlcat(archive_filename, ".gz", sizeof(archive_filename));
1161  streamer = bbstreamer_gzip_writer_new(archive_filename,
1162  archive_file, compress);
1163  }
1164  else if (compress->algorithm == PG_COMPRESSION_LZ4)
1165  {
1166  strlcat(archive_filename, ".lz4", sizeof(archive_filename));
1167  streamer = bbstreamer_plain_writer_new(archive_filename,
1168  archive_file);
1169  streamer = bbstreamer_lz4_compressor_new(streamer, compress);
1170  }
1171  else if (compress->algorithm == PG_COMPRESSION_ZSTD)
1172  {
1173  strlcat(archive_filename, ".zst", sizeof(archive_filename));
1174  streamer = bbstreamer_plain_writer_new(archive_filename,
1175  archive_file);
1176  streamer = bbstreamer_zstd_compressor_new(streamer, compress);
1177  }
1178  else
1179  {
1180  Assert(false); /* not reachable */
1181  }
1182 
1183  /*
1184  * If we need to parse the archive for whatever reason, then we'll
1185  * also need to re-archive, because, if the output format is tar, the
1186  * only point of parsing the archive is to be able to inject stuff
1187  * into it.
1188  */
1189  if (must_parse_archive)
1190  streamer = bbstreamer_tar_archiver_new(streamer);
1191  progress_update_filename(archive_filename);
1192  }
1193 
1194  /*
1195  * If we're supposed to inject the backup manifest into the results, it
1196  * should be done here, so that the file content can be injected directly,
1197  * without worrying about the details of the tar format.
1198  */
1199  if (inject_manifest)
1200  manifest_inject_streamer = streamer;
1201 
1202  /*
1203  * If this is the main tablespace and we're supposed to write recovery
1204  * information, arrange to do that.
1205  */
1206  if (spclocation == NULL && writerecoveryconf)
1207  {
1208  Assert(must_parse_archive);
1209  streamer = bbstreamer_recovery_injector_new(streamer,
1210  is_recovery_guc_supported,
1212  }
1213 
1214  /*
1215  * If we're doing anything that involves understanding the contents of the
1216  * archive, we'll need to parse it. If not, we can skip parsing it, but
1217  * old versions of the server send improperly terminated tarfiles, so if
1218  * we're talking to such a server we'll need to add the terminator here.
1219  */
1220  if (must_parse_archive)
1221  streamer = bbstreamer_tar_parser_new(streamer);
1222  else if (expect_unterminated_tarfile)
1223  streamer = bbstreamer_tar_terminator_new(streamer);
1224 
1225  /*
1226  * If the user has requested a server compressed archive along with
1227  * archive extraction at client then we need to decompress it.
1228  */
1229  if (format == 'p')
1230  {
1231  if (is_tar_gz)
1232  streamer = bbstreamer_gzip_decompressor_new(streamer);
1233  else if (is_tar_lz4)
1234  streamer = bbstreamer_lz4_decompressor_new(streamer);
1235  else if (is_tar_zstd)
1236  streamer = bbstreamer_zstd_decompressor_new(streamer);
1237  }
1238 
1239  /* Return the results. */
1240  *manifest_inject_streamer_p = manifest_inject_streamer;
1241  return streamer;
1242 }
bbstreamer * bbstreamer_gzip_writer_new(char *pathname, FILE *file, pg_compress_specification *compress)
bbstreamer * bbstreamer_zstd_compressor_new(bbstreamer *next, pg_compress_specification *compress)
bbstreamer * bbstreamer_tar_terminator_new(bbstreamer *next)
bbstreamer * bbstreamer_lz4_compressor_new(bbstreamer *next, pg_compress_specification *compress)
bbstreamer * bbstreamer_tar_parser_new(bbstreamer *next)
bbstreamer * bbstreamer_lz4_decompressor_new(bbstreamer *next)
bbstreamer * bbstreamer_recovery_injector_new(bbstreamer *next, bool is_recovery_guc_supported, PQExpBuffer recoveryconfcontents)
bbstreamer * bbstreamer_tar_archiver_new(bbstreamer *next)
bbstreamer * bbstreamer_zstd_decompressor_new(bbstreamer *next)
bbstreamer * bbstreamer_plain_writer_new(char *pathname, FILE *file)
bbstreamer * bbstreamer_extractor_new(const char *basepath, const char *(*link_map)(const char *), void(*report_output_file)(const char *))
bbstreamer * bbstreamer_gzip_decompressor_new(bbstreamer *next)
@ PG_COMPRESSION_LZ4
Definition: compression.h:25
@ PG_COMPRESSION_ZSTD
Definition: compression.h:26
#define pg_log_error_detail(...)
Definition: logging.h:109
size_t strlcat(char *dst, const char *src, size_t siz)
Definition: strlcat.c:33
static const char * directory
Definition: zic.c:634

References pg_compress_specification::algorithm, Assert(), basedir, bbstreamer_extractor_new(), bbstreamer_gzip_decompressor_new(), bbstreamer_gzip_writer_new(), bbstreamer_lz4_compressor_new(), bbstreamer_lz4_decompressor_new(), bbstreamer_plain_writer_new(), bbstreamer_recovery_injector_new(), bbstreamer_tar_archiver_new(), bbstreamer_tar_parser_new(), bbstreamer_tar_terminator_new(), bbstreamer_zstd_compressor_new(), bbstreamer_zstd_decompressor_new(), directory, exit(), format, get_tablespace_mapping(), manifest, MAXPGPATH, PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, pg_log_error, pg_log_error_detail, pg_log_error_hint, progress_update_filename(), recoveryconfcontents, snprintf, generate_unaccent_rules::stdout, strlcat(), and writerecoveryconf.

Referenced by ReceiveArchiveStreamChunk(), and ReceiveTarFile().

◆ disconnect_atexit()

static void disconnect_atexit ( void  )
static

Definition at line 276 of file pg_basebackup.c.

277 {
278  if (conn != NULL)
279  PQfinish(conn);
280 }

References conn, and PQfinish().

Referenced by main().

◆ get_tablespace_mapping()

static const char * get_tablespace_mapping ( const char *  dir)
static

Definition at line 1643 of file pg_basebackup.c.

1644 {
1645  TablespaceListCell *cell;
1646  char canon_dir[MAXPGPATH];
1647 
1648  /* Canonicalize path for comparison consistency */
1649  strlcpy(canon_dir, dir, sizeof(canon_dir));
1650  canonicalize_path(canon_dir);
1651 
1652  for (cell = tablespace_dirs.head; cell; cell = cell->next)
1653  if (strcmp(canon_dir, cell->old_dir) == 0)
1654  return cell->new_dir;
1655 
1656  return dir;
1657 }
static TablespaceList tablespace_dirs
void canonicalize_path(char *path)
Definition: path.c:264
struct TablespaceListCell * next
Definition: pg_basebackup.c:45
char old_dir[MAXPGPATH]
Definition: pg_basebackup.c:46
char new_dir[MAXPGPATH]
Definition: pg_basebackup.c:47
TablespaceListCell * head
Definition: pg_basebackup.c:52

References canonicalize_path(), TablespaceList::head, MAXPGPATH, TablespaceListCell::new_dir, TablespaceListCell::next, TablespaceListCell::old_dir, strlcpy(), and tablespace_dirs.

Referenced by BaseBackup(), and CreateBackupStreamer().

◆ GetCopyDataByte()

static char GetCopyDataByte ( size_t  r,
char *  copybuf,
size_t *  cursor 
)
static

Definition at line 1481 of file pg_basebackup.c.

1482 {
1483  if (*cursor >= r)
1485 
1486  return copybuf[(*cursor)++];
1487 }
static void ReportCopyDataParseError(size_t r, char *copybuf)
Definition: type.h:137
static StringInfo copybuf
Definition: tablesync.c:128

References copybuf, and ReportCopyDataParseError().

Referenced by ReceiveArchiveStreamChunk().

◆ GetCopyDataEnd()

static void GetCopyDataEnd ( size_t  r,
char *  copybuf,
size_t  cursor 
)
static

Definition at line 1534 of file pg_basebackup.c.

1535 {
1536  if (r != cursor)
1538 }

References copybuf, and ReportCopyDataParseError().

Referenced by ReceiveArchiveStreamChunk().

◆ GetCopyDataString()

static char * GetCopyDataString ( size_t  r,
char *  copybuf,
size_t *  cursor 
)
static

Definition at line 1495 of file pg_basebackup.c.

1496 {
1497  size_t startpos = *cursor;
1498  size_t endpos = startpos;
1499 
1500  while (1)
1501  {
1502  if (endpos >= r)
1504  if (copybuf[endpos] == '\0')
1505  break;
1506  ++endpos;
1507  }
1508 
1509  *cursor = endpos + 1;
1510  return &copybuf[startpos];
1511 }
static XLogRecPtr endpos
Definition: pg_receivewal.c:56
static XLogRecPtr startpos

References copybuf, endpos, ReportCopyDataParseError(), and startpos.

Referenced by ReceiveArchiveStreamChunk().

◆ GetCopyDataUInt64()

static uint64 GetCopyDataUInt64 ( size_t  r,
char *  copybuf,
size_t *  cursor 
)
static

Definition at line 1519 of file pg_basebackup.c.

1520 {
1521  uint64 result;
1522 
1523  if (*cursor + sizeof(uint64) > r)
1525  memcpy(&result, &copybuf[*cursor], sizeof(uint64));
1526  *cursor += sizeof(uint64);
1527  return pg_ntoh64(result);
1528 }
#define pg_ntoh64(x)
Definition: pg_bswap.h:126

References copybuf, pg_ntoh64, and ReportCopyDataParseError().

Referenced by ReceiveArchiveStreamChunk().

◆ kill_bgchild_atexit()

static void kill_bgchild_atexit ( void  )
static

Definition at line 301 of file pg_basebackup.c.

302 {
303  if (bgchild > 0 && !bgchild_exited)
304  kill(bgchild, SIGTERM);
305 }
static volatile sig_atomic_t bgchild_exited
#define kill(pid, sig)
Definition: win32_port.h:489

References bgchild, bgchild_exited, and kill.

Referenced by StartLogStreamer().

◆ LogStreamerMain()

static int LogStreamerMain ( logstreamer_param param)
static

Definition at line 534 of file pg_basebackup.c.

535 {
536  StreamCtl stream = {0};
537 
538  in_log_streamer = true;
539 
540  stream.startpos = param->startptr;
541  stream.timeline = param->timeline;
542  stream.sysidentifier = param->sysidentifier;
544 #ifndef WIN32
545  stream.stop_socket = bgpipe[0];
546 #else
547  stream.stop_socket = PGINVALID_SOCKET;
548 #endif
550  stream.synchronous = false;
551  /* fsync happens at the end of pg_basebackup for all data */
552  stream.do_sync = false;
553  stream.mark_done = true;
554  stream.partial_suffix = NULL;
556  if (format == 'p')
557  stream.walmethod = CreateWalDirectoryMethod(param->xlog,
559  stream.do_sync);
560  else
561  stream.walmethod = CreateWalTarMethod(param->xlog,
562  param->wal_compress_algorithm,
563  param->wal_compress_level,
564  stream.do_sync);
565 
566  if (!ReceiveXlogStream(param->bgconn, &stream))
567  {
568  /*
569  * Any errors will already have been reported in the function process,
570  * but we need to tell the parent that we didn't shutdown in a nice
571  * way.
572  */
573 #ifdef WIN32
574  /*
575  * In order to signal the main thread of an ungraceful exit we set the
576  * same flag that we use on Unix to signal SIGCHLD.
577  */
578  bgchild_exited = true;
579 #endif
580  return 1;
581  }
582 
583  if (!stream.walmethod->ops->finish(stream.walmethod))
584  {
585  pg_log_error("could not finish writing WAL files: %m");
586 #ifdef WIN32
587  bgchild_exited = true;
588 #endif
589  return 1;
590  }
591 
592  PQfinish(param->bgconn);
593 
594  stream.walmethod->ops->free(stream.walmethod);
595 
596  return 0;
597 }
static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline, bool segment_finished)
static int standby_message_timeout
#define PGINVALID_SOCKET
Definition: port.h:31
bool ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
Definition: receivelog.c:453
char * sysidentifier
Definition: receivelog.h:33
TimeLineID timeline
Definition: receivelog.h:32
stream_stop_callback stream_stop
Definition: receivelog.h:41
char * replication_slot
Definition: receivelog.h:48
XLogRecPtr startpos
Definition: receivelog.h:31
bool do_sync
Definition: receivelog.h:38
pgsocket stop_socket
Definition: receivelog.h:43
int standby_message_timeout
Definition: receivelog.h:35
WalWriteMethod * walmethod
Definition: receivelog.h:46
bool mark_done
Definition: receivelog.h:37
char * partial_suffix
Definition: receivelog.h:47
bool synchronous
Definition: receivelog.h:36
void(* free)(WalWriteMethod *wwmethod)
Definition: walmethods.h:91
bool(* finish)(WalWriteMethod *wwmethod)
Definition: walmethods.h:85
const WalWriteMethodOps * ops
Definition: walmethods.h:104
XLogRecPtr startptr
pg_compress_algorithm wal_compress_algorithm
char xlog[MAXPGPATH]
WalWriteMethod * CreateWalDirectoryMethod(const char *basedir, pg_compress_algorithm compression_algorithm, int compression_level, bool sync)
Definition: walmethods.c:635
WalWriteMethod * CreateWalTarMethod(const char *tarbase, pg_compress_algorithm compression_algorithm, int compression_level, bool sync)
Definition: walmethods.c:1350

References bgchild_exited, logstreamer_param::bgconn, bgpipe, CreateWalDirectoryMethod(), CreateWalTarMethod(), StreamCtl::do_sync, WalWriteMethodOps::finish, format, WalWriteMethodOps::free, in_log_streamer, StreamCtl::mark_done, WalWriteMethod::ops, StreamCtl::partial_suffix, PG_COMPRESSION_NONE, pg_log_error, PGINVALID_SOCKET, PQfinish(), reached_end_position(), ReceiveXlogStream(), replication_slot, StreamCtl::replication_slot, standby_message_timeout, StreamCtl::standby_message_timeout, StreamCtl::startpos, logstreamer_param::startptr, StreamCtl::stop_socket, StreamCtl::stream_stop, StreamCtl::synchronous, logstreamer_param::sysidentifier, StreamCtl::sysidentifier, logstreamer_param::timeline, StreamCtl::timeline, logstreamer_param::wal_compress_algorithm, logstreamer_param::wal_compress_level, StreamCtl::walmethod, and logstreamer_param::xlog.

Referenced by StartLogStreamer().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 2232 of file pg_basebackup.c.

2233 {
2234  static struct option long_options[] = {
2235  {"help", no_argument, NULL, '?'},
2236  {"version", no_argument, NULL, 'V'},
2237  {"pgdata", required_argument, NULL, 'D'},
2238  {"format", required_argument, NULL, 'F'},
2239  {"checkpoint", required_argument, NULL, 'c'},
2240  {"create-slot", no_argument, NULL, 'C'},
2241  {"max-rate", required_argument, NULL, 'r'},
2242  {"write-recovery-conf", no_argument, NULL, 'R'},
2243  {"slot", required_argument, NULL, 'S'},
2244  {"target", required_argument, NULL, 't'},
2245  {"tablespace-mapping", required_argument, NULL, 'T'},
2246  {"wal-method", required_argument, NULL, 'X'},
2247  {"gzip", no_argument, NULL, 'z'},
2248  {"compress", required_argument, NULL, 'Z'},
2249  {"label", required_argument, NULL, 'l'},
2250  {"no-clean", no_argument, NULL, 'n'},
2251  {"no-sync", no_argument, NULL, 'N'},
2252  {"dbname", required_argument, NULL, 'd'},
2253  {"host", required_argument, NULL, 'h'},
2254  {"port", required_argument, NULL, 'p'},
2255  {"username", required_argument, NULL, 'U'},
2256  {"no-password", no_argument, NULL, 'w'},
2257  {"password", no_argument, NULL, 'W'},
2258  {"status-interval", required_argument, NULL, 's'},
2259  {"verbose", no_argument, NULL, 'v'},
2260  {"progress", no_argument, NULL, 'P'},
2261  {"waldir", required_argument, NULL, 1},
2262  {"no-slot", no_argument, NULL, 2},
2263  {"no-verify-checksums", no_argument, NULL, 3},
2264  {"no-estimate-size", no_argument, NULL, 4},
2265  {"no-manifest", no_argument, NULL, 5},
2266  {"manifest-force-encode", no_argument, NULL, 6},
2267  {"manifest-checksums", required_argument, NULL, 7},
2268  {NULL, 0, NULL, 0}
2269  };
2270  int c;
2271 
2272  int option_index;
2273  char *compression_algorithm = "none";
2274  char *compression_detail = NULL;
2276  pg_compress_specification client_compress;
2277 
2278  pg_logging_init(argv[0]);
2279  progname = get_progname(argv[0]);
2280  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
2281 
2282  if (argc > 1)
2283  {
2284  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
2285  {
2286  usage();
2287  exit(0);
2288  }
2289  else if (strcmp(argv[1], "-V") == 0
2290  || strcmp(argv[1], "--version") == 0)
2291  {
2292  puts("pg_basebackup (PostgreSQL) " PG_VERSION);
2293  exit(0);
2294  }
2295  }
2296 
2298 
2299  while ((c = getopt_long(argc, argv, "c:Cd:D:F:h:l:nNp:Pr:Rs:S:t:T:U:vwWX:zZ:",
2300  long_options, &option_index)) != -1)
2301  {
2302  switch (c)
2303  {
2304  case 'c':
2305  if (pg_strcasecmp(optarg, "fast") == 0)
2306  fastcheckpoint = true;
2307  else if (pg_strcasecmp(optarg, "spread") == 0)
2308  fastcheckpoint = false;
2309  else
2310  pg_fatal("invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"",
2311  optarg);
2312  break;
2313  case 'C':
2314  create_slot = true;
2315  break;
2316  case 'd':
2318  break;
2319  case 'D':
2321  break;
2322  case 'F':
2323  if (strcmp(optarg, "p") == 0 || strcmp(optarg, "plain") == 0)
2324  format = 'p';
2325  else if (strcmp(optarg, "t") == 0 || strcmp(optarg, "tar") == 0)
2326  format = 't';
2327  else
2328  pg_fatal("invalid output format \"%s\", must be \"plain\" or \"tar\"",
2329  optarg);
2330  break;
2331  case 'h':
2332  dbhost = pg_strdup(optarg);
2333  break;
2334  case 'l':
2335  label = pg_strdup(optarg);
2336  break;
2337  case 'n':
2338  noclean = true;
2339  break;
2340  case 'N':
2341  do_sync = false;
2342  break;
2343  case 'p':
2344  dbport = pg_strdup(optarg);
2345  break;
2346  case 'P':
2347  showprogress = true;
2348  break;
2349  case 'r':
2351  break;
2352  case 'R':
2353  writerecoveryconf = true;
2354  break;
2355  case 's':
2356  if (!option_parse_int(optarg, "-s/--status-interval", 0,
2357  INT_MAX / 1000,
2359  exit(1);
2360  standby_message_timeout *= 1000;
2361  break;
2362  case 'S':
2363 
2364  /*
2365  * When specifying replication slot name, use a permanent
2366  * slot.
2367  */
2369  temp_replication_slot = false;
2370  break;
2371  case 't':
2373  break;
2374  case 'T':
2376  break;
2377  case 'U':
2378  dbuser = pg_strdup(optarg);
2379  break;
2380  case 'v':
2381  verbose++;
2382  break;
2383  case 'w':
2384  dbgetpassword = -1;
2385  break;
2386  case 'W':
2387  dbgetpassword = 1;
2388  break;
2389  case 'X':
2390  if (strcmp(optarg, "n") == 0 ||
2391  strcmp(optarg, "none") == 0)
2392  {
2393  includewal = NO_WAL;
2394  }
2395  else if (strcmp(optarg, "f") == 0 ||
2396  strcmp(optarg, "fetch") == 0)
2397  {
2399  }
2400  else if (strcmp(optarg, "s") == 0 ||
2401  strcmp(optarg, "stream") == 0)
2402  {
2404  }
2405  else
2406  pg_fatal("invalid wal-method option \"%s\", must be \"fetch\", \"stream\", or \"none\"",
2407  optarg);
2408  break;
2409  case 'z':
2410  compression_algorithm = "gzip";
2411  compression_detail = NULL;
2412  compressloc = COMPRESS_LOCATION_UNSPECIFIED;
2413  break;
2414  case 'Z':
2416  &compression_detail, &compressloc);
2417  break;
2418  case 1:
2420  break;
2421  case 2:
2422  no_slot = true;
2423  break;
2424  case 3:
2425  verify_checksums = false;
2426  break;
2427  case 4:
2428  estimatesize = false;
2429  break;
2430  case 5:
2431  manifest = false;
2432  break;
2433  case 6:
2434  manifest_force_encode = true;
2435  break;
2436  case 7:
2438  break;
2439  default:
2440  /* getopt_long already emitted a complaint */
2441  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2442  exit(1);
2443  }
2444  }
2445 
2446  /*
2447  * Any non-option arguments?
2448  */
2449  if (optind < argc)
2450  {
2451  pg_log_error("too many command-line arguments (first is \"%s\")",
2452  argv[optind]);
2453  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2454  exit(1);
2455  }
2456 
2457  /*
2458  * Setting the backup target to 'client' is equivalent to leaving out the
2459  * option. This logic allows us to assume elsewhere that the backup is
2460  * being stored locally if and only if backup_target == NULL.
2461  */
2462  if (backup_target != NULL && strcmp(backup_target, "client") == 0)
2463  {
2465  backup_target = NULL;
2466  }
2467 
2468  /*
2469  * Can't use --format with --target. Without --target, default format is
2470  * tar.
2471  */
2472  if (backup_target != NULL && format != '\0')
2473  {
2474  pg_log_error("cannot specify both format and backup target");
2475  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2476  exit(1);
2477  }
2478  if (format == '\0')
2479  format = 'p';
2480 
2481  /*
2482  * Either directory or backup target should be specified, but not both
2483  */
2484  if (basedir == NULL && backup_target == NULL)
2485  {
2486  pg_log_error("must specify output directory or backup target");
2487  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2488  exit(1);
2489  }
2490  if (basedir != NULL && backup_target != NULL)
2491  {
2492  pg_log_error("cannot specify both output directory and backup target");
2493  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2494  exit(1);
2495  }
2496 
2497  /*
2498  * If the user has not specified where to perform backup compression,
2499  * default to the client, unless the user specified --target, in which
2500  * case the server is the only choice.
2501  */
2502  if (compressloc == COMPRESS_LOCATION_UNSPECIFIED)
2503  {
2504  if (backup_target == NULL)
2505  compressloc = COMPRESS_LOCATION_CLIENT;
2506  else
2507  compressloc = COMPRESS_LOCATION_SERVER;
2508  }
2509 
2510  /*
2511  * If any compression that we're doing is happening on the client side, we
2512  * must try to parse the compression algorithm and detail, but if it's all
2513  * on the server side, then we're just going to pass through whatever was
2514  * requested and let the server decide what to do.
2515  */
2516  if (compressloc == COMPRESS_LOCATION_CLIENT)
2517  {
2519  char *error_detail;
2520 
2522  pg_fatal("unrecognized compression algorithm: \"%s\"",
2524 
2525  parse_compress_specification(alg, compression_detail, &client_compress);
2526  error_detail = validate_compress_specification(&client_compress);
2527  if (error_detail != NULL)
2528  pg_fatal("invalid compression specification: %s",
2529  error_detail);
2530  }
2531  else
2532  {
2533  Assert(compressloc == COMPRESS_LOCATION_SERVER);
2534  client_compress.algorithm = PG_COMPRESSION_NONE;
2535  client_compress.options = 0;
2536  }
2537 
2538  /*
2539  * Can't perform client-side compression if the backup is not being sent
2540  * to the client.
2541  */
2542  if (backup_target != NULL && compressloc == COMPRESS_LOCATION_CLIENT)
2543  {
2544  pg_log_error("client-side compression is not possible when a backup target is specified");
2545  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2546  exit(1);
2547  }
2548 
2549  /*
2550  * Client-side compression doesn't make sense unless tar format is in use.
2551  */
2552  if (format == 'p' && compressloc == COMPRESS_LOCATION_CLIENT &&
2553  client_compress.algorithm != PG_COMPRESSION_NONE)
2554  {
2555  pg_log_error("only tar mode backups can be compressed");
2556  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2557  exit(1);
2558  }
2559 
2560  /*
2561  * Sanity checks for WAL method.
2562  */
2563  if (backup_target != NULL && includewal == STREAM_WAL)
2564  {
2565  pg_log_error("WAL cannot be streamed when a backup target is specified");
2566  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2567  exit(1);
2568  }
2569  if (format == 't' && includewal == STREAM_WAL && strcmp(basedir, "-") == 0)
2570  {
2571  pg_log_error("cannot stream write-ahead logs in tar mode to stdout");
2572  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2573  exit(1);
2574  }
2575 
2577  {
2578  pg_log_error("replication slots can only be used with WAL streaming");
2579  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2580  exit(1);
2581  }
2582 
2583  /*
2584  * Sanity checks for replication slot options.
2585  */
2586  if (no_slot)
2587  {
2588  if (replication_slot)
2589  {
2590  pg_log_error("--no-slot cannot be used with slot name");
2591  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2592  exit(1);
2593  }
2594  temp_replication_slot = false;
2595  }
2596 
2597  if (create_slot)
2598  {
2599  if (!replication_slot)
2600  {
2601  pg_log_error("%s needs a slot to be specified using --slot",
2602  "--create-slot");
2603  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2604  exit(1);
2605  }
2606 
2607  if (no_slot)
2608  {
2609  pg_log_error("%s and %s are incompatible options",
2610  "--create-slot", "--no-slot");
2611  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2612  exit(1);
2613  }
2614  }
2615 
2616  /*
2617  * Sanity checks on WAL directory.
2618  */
2619  if (xlog_dir)
2620  {
2621  if (backup_target != NULL)
2622  {
2623  pg_log_error("WAL directory location cannot be specified along with a backup target");
2624  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2625  exit(1);
2626  }
2627  if (format != 'p')
2628  {
2629  pg_log_error("WAL directory location can only be specified in plain mode");
2630  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2631  exit(1);
2632  }
2633 
2634  /* clean up xlog directory name, check it's absolute */
2636  if (!is_absolute_path(xlog_dir))
2637  {
2638  pg_log_error("WAL directory location must be an absolute path");
2639  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2640  exit(1);
2641  }
2642  }
2643 
2644  /*
2645  * Sanity checks for progress reporting options.
2646  */
2647  if (showprogress && !estimatesize)
2648  {
2649  pg_log_error("%s and %s are incompatible options",
2650  "--progress", "--no-estimate-size");
2651  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2652  exit(1);
2653  }
2654 
2655  /*
2656  * Sanity checks for backup manifest options.
2657  */
2658  if (!manifest && manifest_checksums != NULL)
2659  {
2660  pg_log_error("%s and %s are incompatible options",
2661  "--no-manifest", "--manifest-checksums");
2662  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2663  exit(1);
2664  }
2665 
2667  {
2668  pg_log_error("%s and %s are incompatible options",
2669  "--no-manifest", "--manifest-force-encode");
2670  pg_log_error_hint("Try \"%s --help\" for more information.", progname);
2671  exit(1);
2672  }
2673 
2674  /* connection in replication mode to server */
2675  conn = GetConnection();
2676  if (!conn)
2677  {
2678  /* Error message already written in GetConnection() */
2679  exit(1);
2680  }
2681  atexit(disconnect_atexit);
2682 
2683 #ifndef WIN32
2684 
2685  /*
2686  * Trap SIGCHLD to be able to handle the WAL stream process exiting. There
2687  * is no SIGCHLD on Windows, there we rely on the background thread
2688  * setting the signal variable on unexpected but graceful exit. If the WAL
2689  * stream thread crashes on Windows it will bring down the entire process
2690  * as it's a thread, so there is nothing to catch should that happen. A
2691  * crash on UNIX will be caught by the signal handler.
2692  */
2694 #endif
2695 
2696  /*
2697  * Set umask so that directories/files are created with the same
2698  * permissions as directories/files in the source data directory.
2699  *
2700  * pg_mode_mask is set to owner-only by default and then updated in
2701  * GetConnection() where we get the mode from the server-side with
2702  * RetrieveDataDirCreatePerm() and then call SetDataDirectoryCreatePerm().
2703  */
2704  umask(pg_mode_mask);
2705 
2706  /* Backup manifests are supported in 13 and newer versions */
2708  manifest = false;
2709 
2710  /*
2711  * If an output directory was specified, verify that it exists, or create
2712  * it. Note that for a tar backup, an output directory of "-" means we are
2713  * writing to stdout, so do nothing in that case.
2714  */
2715  if (basedir != NULL && (format == 'p' || strcmp(basedir, "-") != 0))
2717 
2718  /* determine remote server's xlog segment size */
2719  if (!RetrieveWalSegSize(conn))
2720  exit(1);
2721 
2722  /* Create pg_wal symlink, if required */
2723  if (xlog_dir)
2724  {
2725  char *linkloc;
2726 
2728 
2729  /*
2730  * Form name of the place where the symlink must go. pg_xlog has been
2731  * renamed to pg_wal in post-10 clusters.
2732  */
2733  linkloc = psprintf("%s/%s", basedir,
2735  "pg_xlog" : "pg_wal");
2736 
2737  if (symlink(xlog_dir, linkloc) != 0)
2738  pg_fatal("could not create symbolic link \"%s\": %m", linkloc);
2739  free(linkloc);
2740  }
2741 
2742  BaseBackup(compression_algorithm, compression_detail, compressloc,
2743  &client_compress);
2744 
2745  success = true;
2746  return 0;
2747 }
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1204
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:436
bool parse_compress_algorithm(char *name, pg_compress_algorithm *algorithm)
Definition: compression.c:47
void parse_compress_specification(pg_compress_algorithm algorithm, char *specification, pg_compress_specification *result)
Definition: compression.c:105
char * validate_compress_specification(pg_compress_specification *spec)
Definition: compression.c:300
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
Definition: connection.c:135
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void pg_free(void *ptr)
Definition: fe_memutils.c:105
int pg_mode_mask
Definition: file_perm.c:25
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
#define no_argument
Definition: getopt_long.h:24
#define required_argument
Definition: getopt_long.h:25
#define free(a)
Definition: header.h:65
void pg_logging_init(const char *argv0)
Definition: logging.c:83
const char * progname
Definition: main.c:45
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
Definition: option_utils.c:50
static int32 parse_max_rate(char *src)
static bool create_slot
static void backup_parse_compress_options(char *option, char **algorithm, char **detail, CompressionLocation *locationres)
static void BaseBackup(char *compression_algorithm, char *compression_detail, CompressionLocation compressloc, pg_compress_specification *client_compress)
static void cleanup_directories_atexit(void)
static bool temp_replication_slot
#define MINIMUM_VERSION_FOR_MANIFESTS
Definition: pg_basebackup.c:96
static bool no_slot
static void usage(void)
static void tablespace_list_append(const char *arg)
static void disconnect_atexit(void)
#define MINIMUM_VERSION_FOR_PG_WAL
Definition: pg_basebackup.c:86
static void sigchld_handler(SIGNAL_ARGS)
PGDLLIMPORT int optind
Definition: getopt.c:50
PGDLLIMPORT char * optarg
Definition: getopt.c:52
#define is_absolute_path(filename)
Definition: port.h:103
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * get_progname(const char *argv0)
Definition: path.c:574
pqsigfunc pqsignal(int signo, pqsigfunc func)
char * c
int dbgetpassword
Definition: streamutil.c:52
bool RetrieveWalSegSize(PGconn *conn)
Definition: streamutil.c:268
char * dbhost
Definition: streamutil.c:48
char * dbport
Definition: streamutil.c:50
char * connection_string
Definition: streamutil.c:47
char * dbuser
Definition: streamutil.c:49
#define SIGCHLD
Definition: win32_port.h:186
#define symlink(oldpath, newpath)
Definition: win32_port.h:237

References pg_compress_specification::algorithm, Assert(), backup_parse_compress_options(), backup_target, BaseBackup(), basedir, canonicalize_path(), cleanup_directories_atexit(), COMPRESS_LOCATION_CLIENT, COMPRESS_LOCATION_SERVER, COMPRESS_LOCATION_UNSPECIFIED, compression_algorithm, conn, connection_string, create_slot, dbgetpassword, dbhost, dbport, dbuser, disconnect_atexit(), do_sync, estimatesize, exit(), fastcheckpoint, FETCH_WAL, format, found_existing_pgdata, found_existing_xlogdir, free, get_progname(), GetConnection(), getopt_long(), includewal, is_absolute_path, label, made_new_pgdata, made_new_xlogdir, manifest, manifest_checksums, manifest_force_encode, maxrate, MINIMUM_VERSION_FOR_MANIFESTS, MINIMUM_VERSION_FOR_PG_WAL, no_argument, no_slot, NO_WAL, noclean, optarg, optind, option_parse_int(), pg_compress_specification::options, parse_compress_algorithm(), parse_compress_specification(), parse_max_rate(), PG_COMPRESSION_NONE, pg_fatal, pg_free(), pg_log_error, pg_log_error_hint, pg_logging_init(), pg_mode_mask, pg_strcasecmp(), pg_strdup(), PG_TEXTDOMAIN, PQserverVersion(), pqsignal(), progname, psprintf(), replication_slot, required_argument, RetrieveWalSegSize(), set_pglocale_pgservice(), showprogress, SIGCHLD, sigchld_handler(), standby_message_timeout, STREAM_WAL, success, symlink, tablespace_list_append(), temp_replication_slot, usage(), validate_compress_specification(), verbose, verify_checksums, verify_dir_is_empty_or_create(), writerecoveryconf, and xlog_dir.

◆ parse_max_rate()

static int32 parse_max_rate ( char *  src)
static

Definition at line 874 of file pg_basebackup.c.

875 {
876  double result;
877  char *after_num;
878  char *suffix = NULL;
879 
880  errno = 0;
881  result = strtod(src, &after_num);
882  if (src == after_num)
883  pg_fatal("transfer rate \"%s\" is not a valid value", src);
884  if (errno != 0)
885  pg_fatal("invalid transfer rate \"%s\": %m", src);
886 
887  if (result <= 0)
888  {
889  /*
890  * Reject obviously wrong values here.
891  */
892  pg_fatal("transfer rate must be greater than zero");
893  }
894 
895  /*
896  * Evaluate suffix, after skipping over possible whitespace. Lack of
897  * suffix means kilobytes.
898  */
899  while (*after_num != '\0' && isspace((unsigned char) *after_num))
900  after_num++;
901 
902  if (*after_num != '\0')
903  {
904  suffix = after_num;
905  if (*after_num == 'k')
906  {
907  /* kilobyte is the expected unit. */
908  after_num++;
909  }
910  else if (*after_num == 'M')
911  {
912  after_num++;
913  result *= 1024.0;
914  }
915  }
916 
917  /* The rest can only consist of white space. */
918  while (*after_num != '\0' && isspace((unsigned char) *after_num))
919  after_num++;
920 
921  if (*after_num != '\0')
922  pg_fatal("invalid --max-rate unit: \"%s\"", suffix);
923 
924  /* Valid integer? */
925  if ((uint64) result != (uint64) ((uint32) result))
926  pg_fatal("transfer rate \"%s\" exceeds integer range", src);
927 
928  /*
929  * The range is checked on the server side too, but avoid the server
930  * connection if a nonsensical value was passed.
931  */
932  if (result < MAX_RATE_LOWER || result > MAX_RATE_UPPER)
933  pg_fatal("transfer rate \"%s\" is out of range", src);
934 
935  return (int32) result;
936 }
#define MAX_RATE_UPPER
Definition: basebackup.h:21
signed int int32
Definition: c.h:478

References MAX_RATE_UPPER, and pg_fatal.

Referenced by main().

◆ progress_report()

static void progress_report ( int  tablespacenum,
bool  force,
bool  finished 
)
static

Definition at line 789 of file pg_basebackup.c.

790 {
791  int percent;
792  char totaldone_str[32];
793  char totalsize_str[32];
794  pg_time_t now;
795 
796  if (!showprogress)
797  return;
798 
799  now = time(NULL);
800  if (now == last_progress_report && !force && !finished)
801  return; /* Max once per second */
802 
804  percent = totalsize_kb ? (int) ((totaldone / 1024) * 100 / totalsize_kb) : 0;
805 
806  /*
807  * Avoid overflowing past 100% or the full size. This may make the total
808  * size number change as we approach the end of the backup (the estimate
809  * will always be wrong if WAL is included), but that's better than having
810  * the done column be bigger than the total.
811  */
812  if (percent > 100)
813  percent = 100;
814  if (totaldone / 1024 > totalsize_kb)
815  totalsize_kb = totaldone / 1024;
816 
817  snprintf(totaldone_str, sizeof(totaldone_str), UINT64_FORMAT,
818  totaldone / 1024);
819  snprintf(totalsize_str, sizeof(totalsize_str), UINT64_FORMAT, totalsize_kb);
820 
821 #define VERBOSE_FILENAME_LENGTH 35
822  if (verbose)
823  {
824  if (!progress_filename)
825 
826  /*
827  * No filename given, so clear the status line (used for last
828  * call)
829  */
830  fprintf(stderr,
831  ngettext("%*s/%s kB (100%%), %d/%d tablespace %*s",
832  "%*s/%s kB (100%%), %d/%d tablespaces %*s",
834  (int) strlen(totalsize_str),
835  totaldone_str, totalsize_str,
836  tablespacenum, tablespacecount,
837  VERBOSE_FILENAME_LENGTH + 5, "");
838  else
839  {
840  bool truncate = (strlen(progress_filename) > VERBOSE_FILENAME_LENGTH);
841 
842  fprintf(stderr,
843  ngettext("%*s/%s kB (%d%%), %d/%d tablespace (%s%-*.*s)",
844  "%*s/%s kB (%d%%), %d/%d tablespaces (%s%-*.*s)",
846  (int) strlen(totalsize_str),
847  totaldone_str, totalsize_str, percent,
848  tablespacenum, tablespacecount,
849  /* Prefix with "..." if we do leading truncation */
850  truncate ? "..." : "",
853  /* Truncate filename at beginning if it's too long */
855  }
856  }
857  else
858  fprintf(stderr,
859  ngettext("%*s/%s kB (%d%%), %d/%d tablespace",
860  "%*s/%s kB (%d%%), %d/%d tablespaces",
862  (int) strlen(totalsize_str),
863  totaldone_str, totalsize_str, percent,
864  tablespacenum, tablespacecount);
865 
866  /*
867  * Stay on the same line if reporting to a terminal and we're not done
868  * yet.
869  */
870  fputc((!finished && isatty(fileno(stderr))) ? '\r' : '\n', stderr);
871 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1546
#define ngettext(s, p, n)
Definition: c.h:1171
#define UINT64_FORMAT
Definition: c.h:533
static char * progress_filename
static pg_time_t last_progress_report
#define VERBOSE_FILENAME_LENGTH
int64 pg_time_t
Definition: pgtime.h:23

References fprintf, last_progress_report, ngettext, now(), progress_filename, showprogress, snprintf, tablespacecount, totaldone, totalsize_kb, UINT64_FORMAT, verbose, and VERBOSE_FILENAME_LENGTH.

Referenced by BaseBackup(), ReceiveArchiveStreamChunk(), ReceiveTarCopyChunk(), and ReceiveTarFile().

◆ progress_update_filename()

static void progress_update_filename ( const char *  filename)
static

Definition at line 765 of file pg_basebackup.c.

766 {
767  /* We needn't maintain this variable if not doing verbose reports. */
768  if (showprogress && verbose)
769  {
771  if (filename)
773  else
774  progress_filename = NULL;
775  }
776 }

References filename, free, pg_strdup(), progress_filename, showprogress, and verbose.

Referenced by BaseBackup(), CreateBackupStreamer(), and ReceiveTarFile().

◆ reached_end_position()

static bool reached_end_position ( XLogRecPtr  segendpos,
uint32  timeline,
bool  segment_finished 
)
static

Definition at line 451 of file pg_basebackup.c.

453 {
454  if (!has_xlogendptr)
455  {
456 #ifndef WIN32
457  fd_set fds;
458  struct timeval tv = {0};
459  int r;
460 
461  /*
462  * Don't have the end pointer yet - check our pipe to see if it has
463  * been sent yet.
464  */
465  FD_ZERO(&fds);
466  FD_SET(bgpipe[0], &fds);
467 
468  r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
469  if (r == 1)
470  {
471  char xlogend[64] = {0};
472  uint32 hi,
473  lo;
474 
475  r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
476  if (r < 0)
477  pg_fatal("could not read from ready pipe: %m");
478 
479  if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
480  pg_fatal("could not parse write-ahead log location \"%s\"",
481  xlogend);
482  xlogendptr = ((uint64) hi) << 32 | lo;
483  has_xlogendptr = 1;
484 
485  /*
486  * Fall through to check if we've reached the point further
487  * already.
488  */
489  }
490  else
491  {
492  /*
493  * No data received on the pipe means we don't know the end
494  * position yet - so just say it's not time to stop yet.
495  */
496  return false;
497  }
498 #else
499 
500  /*
501  * On win32, has_xlogendptr is set by the main thread, so if it's not
502  * set here, we just go back and wait until it shows up.
503  */
504  return false;
505 #endif
506  }
507 
508  /*
509  * At this point we have an end pointer, so compare it to the current
510  * position to figure out if it's time to stop.
511  */
512  if (segendpos >= xlogendptr)
513  return true;
514 
515  /*
516  * Have end pointer, but haven't reached it yet - so tell the caller to
517  * keep streaming.
518  */
519  return false;
520 }
#define read(a, b, c)
Definition: win32.h:13
#define select(n, r, w, e, timeout)
Definition: win32_port.h:499

References bgpipe, has_xlogendptr, pg_fatal, read, select, and xlogendptr.

Referenced by LogStreamerMain().

◆ ReceiveArchiveStream()

static void ReceiveArchiveStream ( PGconn conn,
pg_compress_specification compress 
)
static

Definition at line 1249 of file pg_basebackup.c.

1250 {
1252 
1253  /* Set up initial state. */
1254  memset(&state, 0, sizeof(state));
1255  state.tablespacenum = -1;
1256  state.compress = compress;
1257 
1258  /* All the real work happens in ReceiveArchiveStreamChunk. */
1260 
1261  /* If we wrote the backup manifest to a file, close the file. */
1262  if (state.manifest_file !=NULL)
1263  {
1264  fclose(state.manifest_file);
1265  state.manifest_file = NULL;
1266  }
1267 
1268  /*
1269  * If we buffered the backup manifest in order to inject it into the
1270  * output tarfile, do that now.
1271  */
1272  if (state.manifest_inject_streamer != NULL &&
1273  state.manifest_buffer != NULL)
1274  {
1275  bbstreamer_inject_file(state.manifest_inject_streamer,
1276  "backup_manifest",
1277  state.manifest_buffer->data,
1278  state.manifest_buffer->len);
1279  destroyPQExpBuffer(state.manifest_buffer);
1280  state.manifest_buffer = NULL;
1281  }
1282 
1283  /* If there's still an archive in progress, end processing. */
1284  if (state.streamer != NULL)
1285  {
1286  bbstreamer_finalize(state.streamer);
1287  bbstreamer_free(state.streamer);
1288  state.streamer = NULL;
1289  }
1290 }
static void bbstreamer_finalize(bbstreamer *streamer)
Definition: bbstreamer.h:136
static void bbstreamer_free(bbstreamer *streamer)
Definition: bbstreamer.h:144
void bbstreamer_inject_file(bbstreamer *streamer, char *pathname, char *data, int len)
static void ReceiveArchiveStreamChunk(size_t r, char *copybuf, void *callback_data)
static void ReceiveCopyData(PGconn *conn, WriteDataCallback callback, void *callback_data)
Definition: regguts.h:318

References bbstreamer_finalize(), bbstreamer_free(), bbstreamer_inject_file(), conn, destroyPQExpBuffer(), ReceiveArchiveStreamChunk(), and ReceiveCopyData().

Referenced by BaseBackup().

◆ ReceiveArchiveStreamChunk()

static void ReceiveArchiveStreamChunk ( size_t  r,
char *  copybuf,
void *  callback_data 
)
static

Definition at line 1297 of file pg_basebackup.c.

1298 {
1299  ArchiveStreamState *state = callback_data;
1300  size_t cursor = 0;
1301 
1302  /* Each CopyData message begins with a type byte. */
1303  switch (GetCopyDataByte(r, copybuf, &cursor))
1304  {
1305  case 'n':
1306  {
1307  /* New archive. */
1308  char *archive_name;
1309  char *spclocation;
1310 
1311  /*
1312  * We force a progress report at the end of each tablespace. A
1313  * new tablespace starts when the previous one ends, except in
1314  * the case of the very first one.
1315  */
1316  if (++state->tablespacenum > 0)
1317  progress_report(state->tablespacenum, true, false);
1318 
1319  /* Sanity check. */
1320  if (state->manifest_buffer != NULL ||
1321  state->manifest_file !=NULL)
1322  pg_fatal("archives must precede manifest");
1323 
1324  /* Parse the rest of the CopyData message. */
1325  archive_name = GetCopyDataString(r, copybuf, &cursor);
1326  spclocation = GetCopyDataString(r, copybuf, &cursor);
1328 
1329  /*
1330  * Basic sanity checks on the archive name: it shouldn't be
1331  * empty, it shouldn't start with a dot, and it shouldn't
1332  * contain a path separator.
1333  */
1334  if (archive_name[0] == '\0' || archive_name[0] == '.' ||
1335  strchr(archive_name, '/') != NULL ||
1336  strchr(archive_name, '\\') != NULL)
1337  pg_fatal("invalid archive name: \"%s\"",
1338  archive_name);
1339 
1340  /*
1341  * An empty spclocation is treated as NULL. We expect this
1342  * case to occur for the data directory itself, but not for
1343  * any archives that correspond to tablespaces.
1344  */
1345  if (spclocation[0] == '\0')
1346  spclocation = NULL;
1347 
1348  /* End processing of any prior archive. */
1349  if (state->streamer != NULL)
1350  {
1351  bbstreamer_finalize(state->streamer);
1352  bbstreamer_free(state->streamer);
1353  state->streamer = NULL;
1354  }
1355 
1356  /*
1357  * Create an appropriate backup streamer, unless a backup
1358  * target was specified. In that case, it's up to the server
1359  * to put the backup wherever it needs to go.
1360  */
1361  if (backup_target == NULL)
1362  {
1363  /*
1364  * We know that recovery GUCs are supported, because this
1365  * protocol can only be used on v15+.
1366  */
1367  state->streamer =
1368  CreateBackupStreamer(archive_name,
1369  spclocation,
1370  &state->manifest_inject_streamer,
1371  true, false,
1372  state->compress);
1373  }
1374  break;
1375  }
1376 
1377  case 'd':
1378  {
1379  /* Archive or manifest data. */
1380  if (state->manifest_buffer != NULL)
1381  {
1382  /* Manifest data, buffer in memory. */
1383  appendPQExpBuffer(state->manifest_buffer, copybuf + 1,
1384  r - 1);
1385  }
1386  else if (state->manifest_file !=NULL)
1387  {
1388  /* Manifest data, write to disk. */
1389  if (fwrite(copybuf + 1, r - 1, 1,
1390  state->manifest_file) != 1)
1391  {
1392  /*
1393  * If fwrite() didn't set errno, assume that the
1394  * problem is that we're out of disk space.
1395  */
1396  if (errno == 0)
1397  errno = ENOSPC;
1398  pg_fatal("could not write to file \"%s\": %m",
1399  state->manifest_filename);
1400  }
1401  }
1402  else if (state->streamer != NULL)
1403  {
1404  /* Archive data. */
1405  bbstreamer_content(state->streamer, NULL, copybuf + 1,
1406  r - 1, BBSTREAMER_UNKNOWN);
1407  }
1408  else
1409  pg_fatal("unexpected payload data");
1410  break;
1411  }
1412 
1413  case 'p':
1414  {
1415  /*
1416  * Progress report.
1417  *
1418  * The remainder of the message is expected to be an 8-byte
1419  * count of bytes completed.
1420  */
1423 
1424  /*
1425  * The server shouldn't send progress report messages too
1426  * often, so we force an update each time we receive one.
1427  */
1428  progress_report(state->tablespacenum, true, false);
1429  break;
1430  }
1431 
1432  case 'm':
1433  {
1434  /*
1435  * Manifest data will be sent next. This message is not
1436  * expected to have any further payload data.
1437  */
1439 
1440  /*
1441  * If a backup target was specified, figuring out where to put
1442  * the manifest is the server's problem. Otherwise, we need to
1443  * deal with it.
1444  */
1445  if (backup_target == NULL)
1446  {
1447  /*
1448  * If we're supposed inject the manifest into the archive,
1449  * we prepare to buffer it in memory; otherwise, we
1450  * prepare to write it to a temporary file.
1451  */
1452  if (state->manifest_inject_streamer != NULL)
1453  state->manifest_buffer = createPQExpBuffer();
1454  else
1455  {
1456  snprintf(state->manifest_filename,
1457  sizeof(state->manifest_filename),
1458  "%s/backup_manifest.tmp", basedir);
1459  state->manifest_file =
1460  fopen(state->manifest_filename, "wb");
1461  if (state->manifest_file == NULL)
1462  pg_fatal("could not create file \"%s\": %m",
1463  state->manifest_filename);
1464  }
1465  }
1466  break;
1467  }
1468 
1469  default:
1471  break;
1472  }
1473 }
static void bbstreamer_content(bbstreamer *streamer, bbstreamer_member *member, const char *data, int len, bbstreamer_archive_context context)
Definition: bbstreamer.h:126
@ BBSTREAMER_UNKNOWN
Definition: bbstreamer.h:55
static char * GetCopyDataString(size_t r, char *copybuf, size_t *cursor)
static void GetCopyDataEnd(size_t r, char *copybuf, size_t cursor)
static bbstreamer * CreateBackupStreamer(char *archive_name, char *spclocation, bbstreamer **manifest_inject_streamer_p, bool is_recovery_guc_supported, bool expect_unterminated_tarfile, pg_compress_specification *compress)
static char GetCopyDataByte(size_t r, char *copybuf, size_t *cursor)
static uint64 GetCopyDataUInt64(size_t r, char *copybuf, size_t *cursor)
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265

References appendPQExpBuffer(), backup_target, basedir, bbstreamer_content(), bbstreamer_finalize(), bbstreamer_free(), BBSTREAMER_UNKNOWN, copybuf, CreateBackupStreamer(), createPQExpBuffer(), GetCopyDataByte(), GetCopyDataEnd(), GetCopyDataString(), GetCopyDataUInt64(), pg_fatal, progress_report(), ReportCopyDataParseError(), snprintf, and totaldone.

Referenced by ReceiveArchiveStream().

◆ ReceiveBackupManifest()

static void ReceiveBackupManifest ( PGconn conn)
static

Definition at line 1663 of file pg_basebackup.c.

1664 {
1666 
1667  snprintf(state.filename, sizeof(state.filename),
1668  "%s/backup_manifest.tmp", basedir);
1669  state.file = fopen(state.filename, "wb");
1670  if (state.file == NULL)
1671  pg_fatal("could not create file \"%s\": %m", state.filename);
1672 
1674 
1675  fclose(state.file);
1676 }
static void ReceiveBackupManifestChunk(size_t r, char *copybuf, void *callback_data)

References basedir, conn, pg_fatal, ReceiveBackupManifestChunk(), ReceiveCopyData(), and snprintf.

Referenced by BaseBackup().

◆ ReceiveBackupManifestChunk()

static void ReceiveBackupManifestChunk ( size_t  r,
char *  copybuf,
void *  callback_data 
)
static

Definition at line 1682 of file pg_basebackup.c.

1683 {
1684  WriteManifestState *state = callback_data;
1685 
1686  errno = 0;
1687  if (fwrite(copybuf, r, 1, state->file) != 1)
1688  {
1689  /* if write didn't set errno, assume problem is no disk space */
1690  if (errno == 0)
1691  errno = ENOSPC;
1692  pg_fatal("could not write to file \"%s\": %m", state->filename);
1693  }
1694 }

References copybuf, and pg_fatal.

Referenced by ReceiveBackupManifest().

◆ ReceiveBackupManifestInMemory()

static void ReceiveBackupManifestInMemory ( PGconn conn,
PQExpBuffer  buf 
)
static

Definition at line 1700 of file pg_basebackup.c.

1701 {
1703 }
static void ReceiveBackupManifestInMemoryChunk(size_t r, char *copybuf, void *callback_data)

References buf, conn, ReceiveBackupManifestInMemoryChunk(), and ReceiveCopyData().

Referenced by ReceiveTarFile().

◆ ReceiveBackupManifestInMemoryChunk()

static void ReceiveBackupManifestInMemoryChunk ( size_t  r,
char *  copybuf,
void *  callback_data 
)
static

Definition at line 1709 of file pg_basebackup.c.

1711 {
1712  PQExpBuffer buf = callback_data;
1713 
1715 }

References appendPQExpBuffer(), buf, and copybuf.

Referenced by ReceiveBackupManifestInMemory().

◆ ReceiveCopyData()

static void ReceiveCopyData ( PGconn conn,
WriteDataCallback  callback,
void *  callback_data 
)
static

Definition at line 987 of file pg_basebackup.c.

989 {
990  PGresult *res;
991 
992  /* Get the COPY data stream. */
993  res = PQgetResult(conn);
995  pg_fatal("could not get COPY data stream: %s",
997  PQclear(res);
998 
999  /* Loop over chunks until done. */
1000  while (1)
1001  {
1002  int r;
1003  char *copybuf;
1004 
1005  r = PQgetCopyData(conn, &copybuf, 0);
1006  if (r == -1)
1007  {
1008  /* End of chunk. */
1009  break;
1010  }
1011  else if (r == -2)
1012  pg_fatal("could not read COPY data: %s",
1013  PQerrorMessage(conn));
1014 
1015  if (bgchild_exited)
1016  pg_fatal("background process terminated unexpectedly");
1017 
1018  (*callback) (r, copybuf, callback_data);
1019 
1020  PQfreemem(copybuf);
1021  }
1022 }
void PQfreemem(void *ptr)
Definition: fe-exec.c:3869
int PQgetCopyData(PGconn *conn, char **buffer, int async)
Definition: fe-exec.c:2702
@ PGRES_COPY_OUT
Definition: libpq-fe.h:103

References bgchild_exited, conn, copybuf, pg_fatal, PGRES_COPY_OUT, PQclear(), PQerrorMessage(), PQfreemem(), PQgetCopyData(), PQgetResult(), PQresultStatus(), and res.

Referenced by ReceiveArchiveStream(), ReceiveBackupManifest(), ReceiveBackupManifestInMemory(), and ReceiveTarFile().

◆ ReceiveTarCopyChunk()

static void ReceiveTarCopyChunk ( size_t  r,
char *  copybuf,
void *  callback_data 
)
static

Definition at line 1627 of file pg_basebackup.c.

1628 {
1629  WriteTarState *state = callback_data;
1630 
1631  bbstreamer_content(state->streamer, NULL, copybuf, r, BBSTREAMER_UNKNOWN);
1632 
1633  totaldone += r;
1634  progress_report(state->tablespacenum, false, false);
1635 }

References bbstreamer_content(), BBSTREAMER_UNKNOWN, copybuf, progress_report(), and totaldone.

Referenced by ReceiveTarFile().

◆ ReceiveTarFile()

static void ReceiveTarFile ( PGconn conn,
char *  archive_name,
char *  spclocation,
bool  tablespacenum,
pg_compress_specification compress 
)
static

Definition at line 1564 of file pg_basebackup.c.

1566 {
1568  bbstreamer *manifest_inject_streamer;
1569  bool is_recovery_guc_supported;
1570  bool expect_unterminated_tarfile;
1571 
1572  /* Pass all COPY data through to the backup streamer. */
1573  memset(&state, 0, sizeof(state));
1574  is_recovery_guc_supported =
1576  expect_unterminated_tarfile =
1578  state.streamer = CreateBackupStreamer(archive_name, spclocation,
1579  &manifest_inject_streamer,
1580  is_recovery_guc_supported,
1581  expect_unterminated_tarfile,
1582  compress);
1583  state.tablespacenum = tablespacenum;
1586 
1587  /*
1588  * The decision as to whether we need to inject the backup manifest into
1589  * the output at this stage is made by CreateBackupStreamer; if that is
1590  * needed, manifest_inject_streamer will be non-NULL; otherwise, it will
1591  * be NULL.
1592  */
1593  if (manifest_inject_streamer != NULL)
1594  {
1596 
1597  /* Slurp the entire backup manifest into a buffer. */
1598  initPQExpBuffer(&buf);
1601  pg_fatal("out of memory");
1602 
1603  /* Inject it into the output tarfile. */
1604  bbstreamer_inject_file(manifest_inject_streamer, "backup_manifest",
1605  buf.data, buf.len);
1606 
1607  /* Free memory. */
1608  termPQExpBuffer(&buf);
1609  }
1610 
1611  /* Cleanup. */
1612  bbstreamer_finalize(state.streamer);
1613  bbstreamer_free(state.streamer);
1614 
1615  progress_report(tablespacenum, true, false);
1616 
1617  /*
1618  * Do not sync the resulting tar file yet, all files are synced once at
1619  * the end.
1620  */
1621 }
static void ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data)
#define MINIMUM_VERSION_FOR_TERMINATED_TARFILE
static void ReceiveBackupManifestInMemory(PGconn *conn, PQExpBuffer buf)
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
#define PQExpBufferDataBroken(buf)
Definition: pqexpbuffer.h:67
#define MINIMUM_VERSION_FOR_RECOVERY_GUC
Definition: recovery_gen.h:21

References bbstreamer_finalize(), bbstreamer_free(), bbstreamer_inject_file(), buf, conn, CreateBackupStreamer(), initPQExpBuffer(), MINIMUM_VERSION_FOR_RECOVERY_GUC, MINIMUM_VERSION_FOR_TERMINATED_TARFILE, pg_fatal, PQExpBufferDataBroken, PQserverVersion(), progress_report(), progress_update_filename(), ReceiveBackupManifestInMemory(), ReceiveCopyData(), ReceiveTarCopyChunk(), and termPQExpBuffer().

Referenced by BaseBackup().

◆ ReportCopyDataParseError()

static void ReportCopyDataParseError ( size_t  r,
char *  copybuf 
)
static

Definition at line 1549 of file pg_basebackup.c.

1550 {
1551  if (r == 0)
1552  pg_fatal("empty COPY message");
1553  else
1554  pg_fatal("malformed COPY message of type %d, length %zu",
1555  copybuf[0], r);
1556 }

References copybuf, and pg_fatal.

Referenced by GetCopyDataByte(), GetCopyDataEnd(), GetCopyDataString(), GetCopyDataUInt64(), and ReceiveArchiveStreamChunk().

◆ sigchld_handler()

static void sigchld_handler ( SIGNAL_ARGS  )
static

Definition at line 290 of file pg_basebackup.c.

291 {
292  bgchild_exited = true;
293 }

References bgchild_exited.

Referenced by main().

◆ StartLogStreamer()

static void StartLogStreamer ( char *  startpos,
uint32  timeline,
char *  sysidentifier,
pg_compress_algorithm  wal_compress_algorithm,
int  wal_compress_level 
)
static

Definition at line 605 of file pg_basebackup.c.

608 {
609  logstreamer_param *param;
610  uint32 hi,
611  lo;
612  char statusdir[MAXPGPATH];
613 
614  param = pg_malloc0(sizeof(logstreamer_param));
615  param->timeline = timeline;
616  param->sysidentifier = sysidentifier;
617  param->wal_compress_algorithm = wal_compress_algorithm;
618  param->wal_compress_level = wal_compress_level;
619 
620  /* Convert the starting position */
621  if (sscanf(startpos, "%X/%X", &hi, &lo) != 2)
622  pg_fatal("could not parse write-ahead log location \"%s\"",
623  startpos);
624  param->startptr = ((uint64) hi) << 32 | lo;
625  /* Round off to even segment position */
626  param->startptr -= XLogSegmentOffset(param->startptr, WalSegSz);
627 
628 #ifndef WIN32
629  /* Create our background pipe */
630  if (pipe(bgpipe) < 0)
631  pg_fatal("could not create pipe for background process: %m");
632 #endif
633 
634  /* Get a second connection */
635  param->bgconn = GetConnection();
636  if (!param->bgconn)
637  /* Error message already written in GetConnection() */
638  exit(1);
639 
640  /* In post-10 cluster, pg_xlog has been renamed to pg_wal */
641  snprintf(param->xlog, sizeof(param->xlog), "%s/%s",
642  basedir,
644  "pg_xlog" : "pg_wal");
645 
646  /* Temporary replication slots are only supported in 10 and newer */
648  temp_replication_slot = false;
649 
650  /*
651  * Create replication slot if requested
652  */
654  replication_slot = psprintf("pg_basebackup_%d", (int) PQbackendPID(param->bgconn));
656  {
657  if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,
658  temp_replication_slot, true, true, false, false))
659  exit(1);
660 
661  if (verbose)
662  {
664  pg_log_info("created temporary replication slot \"%s\"",
666  else
667  pg_log_info("created replication slot \"%s\"",
669  }
670  }
671 
672  if (format == 'p')
673  {
674  /*
675  * Create pg_wal/archive_status or pg_xlog/archive_status (and thus
676  * pg_wal or pg_xlog) depending on the target server so we can write
677  * to basedir/pg_wal or basedir/pg_xlog as the directory entry in the
678  * tar file may arrive later.
679  */
680  snprintf(statusdir, sizeof(statusdir), "%s/%s/archive_status",
681  basedir,
683  "pg_xlog" : "pg_wal");
684 
685  if (pg_mkdir_p(statusdir, pg_dir_create_mode) != 0 && errno != EEXIST)
686  pg_fatal("could not create directory \"%s\": %m", statusdir);
687  }
688 
689  /*
690  * Start a child process and tell it to start streaming. On Unix, this is
691  * a fork(). On Windows, we create a thread.
692  */
693 #ifndef WIN32
694  bgchild = fork();
695  if (bgchild == 0)
696  {
697  /* in child process */
698  exit(LogStreamerMain(param));
699  }
700  else if (bgchild < 0)
701  pg_fatal("could not create background process: %m");
702 
703  /*
704  * Else we are in the parent process and all is well.
705  */
706  atexit(kill_bgchild_atexit);
707 #else /* WIN32 */
708  bgchild = _beginthreadex(NULL, 0, (void *) LogStreamerMain, param, 0, NULL);
709  if (bgchild == 0)
710  pg_fatal("could not create background thread: %m");
711 #endif
712 }
int PQbackendPID(const PGconn *conn)
Definition: fe-connect.c:7207
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
int pg_dir_create_mode
Definition: file_perm.c:18
#define MINIMUM_VERSION_FOR_TEMP_SLOTS
Definition: pg_basebackup.c:91
static int LogStreamerMain(logstreamer_param *param)
static void kill_bgchild_atexit(void)
int pg_mkdir_p(char *path, int omode)
Definition: pgmkdirp.c:57
uint32 WalSegSz
Definition: streamutil.c:34
static void CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
Definition: walsender.c:1030
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)

References basedir, bgchild, logstreamer_param::bgconn, bgpipe, conn, create_slot, CreateReplicationSlot(), exit(), format, GetConnection(), kill_bgchild_atexit(), LogStreamerMain(), MAXPGPATH, MINIMUM_VERSION_FOR_PG_WAL, MINIMUM_VERSION_FOR_TEMP_SLOTS, pg_dir_create_mode, pg_fatal, pg_log_info, pg_malloc0(), pg_mkdir_p(), PQbackendPID(), PQserverVersion(), psprintf(), replication_slot, snprintf, startpos, logstreamer_param::startptr, logstreamer_param::sysidentifier, temp_replication_slot, logstreamer_param::timeline, verbose, logstreamer_param::wal_compress_algorithm, logstreamer_param::wal_compress_level, WalSegSz, logstreamer_param::xlog, and XLogSegmentOffset.

Referenced by BaseBackup().

◆ tablespace_list_append()

static void tablespace_list_append ( const char *  arg)
static

Definition at line 313 of file pg_basebackup.c.

314 {
316  char *dst;
317  char *dst_ptr;
318  const char *arg_ptr;
319 
320  dst_ptr = dst = cell->old_dir;
321  for (arg_ptr = arg; *arg_ptr; arg_ptr++)
322  {
323  if (dst_ptr - dst >= MAXPGPATH)
324  pg_fatal("directory name too long");
325 
326  if (*arg_ptr == '\\' && *(arg_ptr + 1) == '=')
327  ; /* skip backslash escaping = */
328  else if (*arg_ptr == '=' && (arg_ptr == arg || *(arg_ptr - 1) != '\\'))
329  {
330  if (*cell->new_dir)
331  pg_fatal("multiple \"=\" signs in tablespace mapping");
332  else
333  dst = dst_ptr = cell->new_dir;
334  }
335  else
336  *dst_ptr++ = *arg_ptr;
337  }
338 
339  if (!*cell->old_dir || !*cell->new_dir)
340  pg_fatal("invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"", arg);
341 
342  /*
343  * All tablespaces are created with absolute directories, so specifying a
344  * non-absolute path here would just never match, possibly confusing users.
345  * Since we don't know whether the remote side is Windows or not, and it
346  * might be different than the local side, permit any path that could be
347  * absolute under either set of rules.
348  *
349  * (There is little practical risk of confusion here, because someone
350  * running entirely on Linux isn't likely to have a relative path that
351  * begins with a backslash or something that looks like a drive
352  * specification. If they do, and they also incorrectly believe that
353  * a relative path is acceptable here, we'll silently fail to warn them
354  * of their mistake, and the -T option will just not get applied, same
355  * as if they'd specified -T for a nonexistent tablespace.)
356  */
357  if (!is_nonwindows_absolute_path(cell->old_dir) &&
359  pg_fatal("old directory is not an absolute path in tablespace mapping: %s",
360  cell->old_dir);
361 
362  if (!is_absolute_path(cell->new_dir))
363  pg_fatal("new directory is not an absolute path in tablespace mapping: %s",
364  cell->new_dir);
365 
366  /*
367  * Comparisons done with these values should involve similarly
368  * canonicalized path values. This is particularly sensitive on Windows
369  * where path values may not necessarily use Unix slashes.
370  */
371  canonicalize_path(cell->old_dir);
372  canonicalize_path(cell->new_dir);
373 
374  if (tablespace_dirs.tail)
375  tablespace_dirs.tail->next = cell;
376  else
377  tablespace_dirs.head = cell;
378  tablespace_dirs.tail = cell;
379 }
void * arg
#define is_windows_absolute_path(filename)
Definition: port.h:89
#define is_nonwindows_absolute_path(filename)
Definition: port.h:82
TablespaceListCell * tail
Definition: pg_basebackup.c:53

References arg, canonicalize_path(), TablespaceList::head, is_absolute_path, is_nonwindows_absolute_path, is_windows_absolute_path, MAXPGPATH, TablespaceListCell::new_dir, TablespaceListCell::next, TablespaceListCell::old_dir, pg_fatal, pg_malloc0(), tablespace_dirs, and TablespaceList::tail.

Referenced by main().

◆ usage()

static void usage ( void  )
static

Definition at line 383 of file pg_basebackup.c.

384 {
385  printf(_("%s takes a base backup of a running PostgreSQL server.\n\n"),
386  progname);
387  printf(_("Usage:\n"));
388  printf(_(" %s [OPTION]...\n"), progname);
389  printf(_("\nOptions controlling the output:\n"));
390  printf(_(" -D, --pgdata=DIRECTORY receive base backup into directory\n"));
391  printf(_(" -F, --format=p|t output format (plain (default), tar)\n"));
392  printf(_(" -r, --max-rate=RATE maximum transfer rate to transfer data directory\n"
393  " (in kB/s, or use suffix \"k\" or \"M\")\n"));
394  printf(_(" -R, --write-recovery-conf\n"
395  " write configuration for replication\n"));
396  printf(_(" -t, --target=TARGET[:DETAIL]\n"
397  " backup target (if other than client)\n"));
398  printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
399  " relocate tablespace in OLDDIR to NEWDIR\n"));
400  printf(_(" --waldir=WALDIR location for the write-ahead log directory\n"));
401  printf(_(" -X, --wal-method=none|fetch|stream\n"
402  " include required WAL files with specified method\n"));
403  printf(_(" -z, --gzip compress tar output\n"));
404  printf(_(" -Z, --compress=[{client|server}-]METHOD[:DETAIL]\n"
405  " compress on client or server as specified\n"));
406  printf(_(" -Z, --compress=none do not compress tar output\n"));
407  printf(_("\nGeneral options:\n"));
408  printf(_(" -c, --checkpoint=fast|spread\n"
409  " set fast or spread checkpointing\n"));
410  printf(_(" -C, --create-slot create replication slot\n"));
411  printf(_(" -l, --label=LABEL set backup label\n"));
412  printf(_(" -n, --no-clean do not clean up after errors\n"));
413  printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
414  printf(_(" -P, --progress show progress information\n"));
415  printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
416  printf(_(" -v, --verbose output verbose messages\n"));
417  printf(_(" -V, --version output version information, then exit\n"));
418  printf(_(" --manifest-checksums=SHA{224,256,384,512}|CRC32C|NONE\n"
419  " use algorithm for manifest checksums\n"));
420  printf(_(" --manifest-force-encode\n"
421  " hex encode all file names in manifest\n"));
422  printf(_(" --no-estimate-size do not estimate backup size in server side\n"));
423  printf(_(" --no-manifest suppress generation of backup manifest\n"));
424  printf(_(" --no-slot prevent creation of temporary replication slot\n"));
425  printf(_(" --no-verify-checksums\n"
426  " do not verify checksums\n"));
427  printf(_(" -?, --help show this help, then exit\n"));
428  printf(_("\nConnection options:\n"));
429  printf(_(" -d, --dbname=CONNSTR connection string\n"));
430  printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
431  printf(_(" -p, --port=PORT database server port number\n"));
432  printf(_(" -s, --status-interval=INTERVAL\n"
433  " time between status packets sent to server (in seconds)\n"));
434  printf(_(" -U, --username=NAME connect as specified database user\n"));
435  printf(_(" -w, --no-password never prompt for password\n"));
436  printf(_(" -W, --password force password prompt (should happen automatically)\n"));
437  printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
438  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
439 }
#define printf(...)
Definition: port.h:244

References _, printf, and progname.

Referenced by main().

◆ verify_dir_is_empty_or_create()

static void verify_dir_is_empty_or_create ( char *  dirname,
bool created,
bool found 
)
static

Definition at line 720 of file pg_basebackup.c.

721 {
722  switch (pg_check_dir(dirname))
723  {
724  case 0:
725 
726  /*
727  * Does not exist, so create
728  */
729  if (pg_mkdir_p(dirname, pg_dir_create_mode) == -1)
730  pg_fatal("could not create directory \"%s\": %m", dirname);
731  if (created)
732  *created = true;
733  return;
734  case 1:
735 
736  /*
737  * Exists, empty
738  */
739  if (found)
740  *found = true;
741  return;
742  case 2:
743  case 3:
744  case 4:
745 
746  /*
747  * Exists, not empty
748  */
749  pg_fatal("directory \"%s\" exists but is not empty", dirname);
750  case -1:
751 
752  /*
753  * Access problem
754  */
755  pg_fatal("could not access directory \"%s\": %m", dirname);
756  }
757 }
int pg_check_dir(const char *dir)
Definition: pgcheckdir.c:33

References pg_check_dir(), pg_dir_create_mode, pg_fatal, and pg_mkdir_p().

Referenced by BaseBackup(), and main().

Variable Documentation

◆ backup_target

char* backup_target = NULL
static

Definition at line 144 of file pg_basebackup.c.

Referenced by BaseBackup(), main(), and ReceiveArchiveStreamChunk().

◆ basedir

◆ bgchild

pid_t bgchild = -1
static

Definition at line 172 of file pg_basebackup.c.

Referenced by BaseBackup(), kill_bgchild_atexit(), and StartLogStreamer().

◆ bgchild_exited

volatile sig_atomic_t bgchild_exited = false
static

◆ bgpipe

int bgpipe[2] = {-1, -1}
static

◆ checksum_failure

bool checksum_failure = false
static

Definition at line 131 of file pg_basebackup.c.

Referenced by BaseBackup(), cleanup_directories_atexit(), and PageIsVerifiedExtended().

◆ create_slot

bool create_slot = false
static

Definition at line 145 of file pg_basebackup.c.

Referenced by main(), and StartLogStreamer().

◆ do_sync

bool do_sync = true
static

Definition at line 138 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ estimatesize

bool estimatesize = true
static

Definition at line 133 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ fastcheckpoint

bool fastcheckpoint = false
static

Definition at line 136 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ format

◆ found_existing_pgdata

bool found_existing_pgdata = false
static

Definition at line 154 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ found_existing_xlogdir

bool found_existing_xlogdir = false
static

Definition at line 156 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ found_tablespace_dirs

bool found_tablespace_dirs = false
static

Definition at line 158 of file pg_basebackup.c.

Referenced by BaseBackup(), and cleanup_directories_atexit().

◆ has_xlogendptr

int has_xlogendptr = 0
static

Definition at line 182 of file pg_basebackup.c.

Referenced by BaseBackup(), and reached_end_position().

◆ in_log_streamer

bool in_log_streamer = false
static

Definition at line 173 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and LogStreamerMain().

◆ includewal

IncludeWal includewal = STREAM_WAL
static

Definition at line 135 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ label

◆ last_progress_report

pg_time_t last_progress_report = 0
static

Definition at line 140 of file pg_basebackup.c.

Referenced by progress_report().

◆ made_new_pgdata

bool made_new_pgdata = false
static

Definition at line 153 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ made_new_xlogdir

bool made_new_xlogdir = false
static

Definition at line 155 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ made_tablespace_dirs

bool made_tablespace_dirs = false
static

Definition at line 157 of file pg_basebackup.c.

Referenced by BaseBackup(), and cleanup_directories_atexit().

◆ manifest

◆ manifest_checksums

char* manifest_checksums = NULL
static

Definition at line 150 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ manifest_force_encode

bool manifest_force_encode = false
static

Definition at line 149 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ maxrate

int32 maxrate = 0
static

Definition at line 141 of file pg_basebackup.c.

Referenced by BaseBackup(), bbsink_throttle_new(), main(), and parse_basebackup_options().

◆ no_slot

bool no_slot = false
static

Definition at line 146 of file pg_basebackup.c.

Referenced by main().

◆ noclean

bool noclean = false
static

Definition at line 130 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ progress_filename

char* progress_filename = NULL
static

Definition at line 164 of file pg_basebackup.c.

Referenced by progress_report(), and progress_update_filename().

◆ recoveryconfcontents

PQExpBuffer recoveryconfcontents = NULL
static

◆ replication_slot

char* replication_slot = NULL
static

◆ showprogress

bool showprogress = false
static

Definition at line 132 of file pg_basebackup.c.

Referenced by BaseBackup(), main(), progress_report(), and progress_update_filename().

◆ standby_message_timeout

int standby_message_timeout = 10 * 1000
static

Definition at line 139 of file pg_basebackup.c.

Referenced by CalculateCopyStreamSleeptime(), LogStreamerMain(), and main().

◆ success

bool success = false
static

Definition at line 152 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ tablespace_dirs

TablespaceList tablespace_dirs = {NULL, NULL}
static

Definition at line 126 of file pg_basebackup.c.

Referenced by get_tablespace_mapping(), and tablespace_list_append().

◆ tablespacecount

int tablespacecount
static

Definition at line 163 of file pg_basebackup.c.

Referenced by BaseBackup(), and progress_report().

◆ temp_replication_slot

bool temp_replication_slot = true
static

Definition at line 143 of file pg_basebackup.c.

Referenced by main(), and StartLogStreamer().

◆ totaldone

uint64 totaldone
static

◆ totalsize_kb

uint64 totalsize_kb
static

Definition at line 161 of file pg_basebackup.c.

Referenced by BaseBackup(), and progress_report().

◆ verbose

int verbose = 0
static

◆ verify_checksums

bool verify_checksums = true
static

Definition at line 147 of file pg_basebackup.c.

Referenced by BaseBackup(), and main().

◆ writerecoveryconf

bool writerecoveryconf = false
static

Definition at line 137 of file pg_basebackup.c.

Referenced by BaseBackup(), CreateBackupStreamer(), and main().

◆ xlog_dir

char* xlog_dir = NULL
static

Definition at line 127 of file pg_basebackup.c.

Referenced by cleanup_directories_atexit(), and main().

◆ xlogendptr

XLogRecPtr xlogendptr
static

Definition at line 179 of file pg_basebackup.c.

Referenced by BaseBackup(), and reached_end_position().