PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include "access/xlog_internal.h"
#include "access/xlogbackup.h"
#include "backup/backup_manifest.h"
#include "backup/basebackup.h"
#include "backup/basebackup_incremental.h"
#include "backup/basebackup_sink.h"
#include "backup/basebackup_target.h"
#include "catalog/pg_tablespace_d.h"
#include "commands/defrem.h"
#include "common/compression.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/pg_list.h"
#include "pgstat.h"
#include "pgtar.h"
#include "postmaster/syslogger.h"
#include "postmaster/walsummarizer.h"
#include "replication/slot.h"
#include "replication/walsender.h"
#include "replication/walsender_private.h"
#include "storage/bufpage.h"
#include "storage/checksum.h"
#include "storage/dsm_impl.h"
#include "storage/ipc.h"
#include "storage/reinit.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/ps_status.h"
#include "utils/relcache.h"
#include "utils/resowner.h"
Go to the source code of this file.
Data Structures | |
struct | basebackup_options |
struct | exclude_list_item |
Macros | |
#define | SINK_BUFFER_LENGTH Max(32768, BLCKSZ) |
Functions | |
static int64 | sendTablespace (bbsink *sink, char *path, Oid spcoid, bool sizeonly, struct backup_manifest_info *manifest, IncrementalBackupInfo *ib) |
static int64 | sendDir (bbsink *sink, const char *path, int basepathlen, bool sizeonly, List *tablespaces, bool sendtblspclinks, backup_manifest_info *manifest, Oid spcoid, IncrementalBackupInfo *ib) |
static bool | sendFile (bbsink *sink, const char *readfilename, const char *tarfilename, struct stat *statbuf, bool missing_ok, Oid dboid, Oid spcoid, RelFileNumber relfilenumber, unsigned segno, backup_manifest_info *manifest, unsigned num_incremental_blocks, BlockNumber *incremental_blocks, unsigned truncation_block_length) |
static off_t | read_file_data_into_buffer (bbsink *sink, const char *readfilename, int fd, off_t offset, size_t length, BlockNumber blkno, bool verify_checksum, int *checksum_failures) |
static void | push_to_sink (bbsink *sink, pg_checksum_context *checksum_ctx, size_t *bytes_done, void *data, size_t length) |
static bool | verify_page_checksum (Page page, XLogRecPtr start_lsn, BlockNumber blkno, uint16 *expected_checksum) |
static void | sendFileWithContent (bbsink *sink, const char *filename, const char *content, int len, backup_manifest_info *manifest) |
static int64 | _tarWriteHeader (bbsink *sink, const char *filename, const char *linktarget, struct stat *statbuf, bool sizeonly) |
static void | _tarWritePadding (bbsink *sink, int len) |
static void | convert_link_to_directory (const char *pathbuf, struct stat *statbuf) |
static void | perform_base_backup (basebackup_options *opt, bbsink *sink, IncrementalBackupInfo *ib) |
static void | parse_basebackup_options (List *options, basebackup_options *opt) |
static int | compareWalFileNames (const ListCell *a, const ListCell *b) |
static ssize_t | basebackup_read_file (int fd, char *buf, size_t nbytes, off_t offset, const char *filename, bool partial_read_ok) |
void | SendBaseBackup (BaseBackupCmd *cmd, IncrementalBackupInfo *ib) |
Variables | |
static bool | backup_started_in_recovery = false |
static long long int | total_checksum_failures |
static bool | noverify_checksums = false |
static const char *const | excludeDirContents [] |
static const struct exclude_list_item | excludeFiles [] |
#define SINK_BUFFER_LENGTH Max(32768, BLCKSZ) |
Definition at line 60 of file basebackup.c.
|
static |
Definition at line 2021 of file basebackup.c.
References Assert, bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink_archive_contents(), elog, ereport, errcode(), errmsg(), ERROR, filename, stat::st_gid, stat::st_mode, stat::st_mtime, stat::st_size, stat::st_uid, StaticAssertDecl, TAR_BLOCK_SIZE, TAR_NAME_TOO_LONG, TAR_OK, TAR_SYMLINK_TOO_LONG, and tarCreateHeader().
Referenced by perform_base_backup(), sendDir(), sendFile(), sendFileWithContent(), and sendTablespace().
|
static |
Definition at line 2075 of file basebackup.c.
References Assert, bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink_archive_contents(), len, MemSet, TAR_BLOCK_SIZE, and tarPaddingBytesRequired().
Referenced by sendFile(), and sendFileWithContent().
|
static |
Definition at line 2115 of file basebackup.c.
References buf, ereport, errcode_for_file_access(), errmsg(), ERROR, fd(), filename, pg_pread, pgstat_report_wait_end(), and pgstat_report_wait_start().
Referenced by perform_base_backup(), and read_file_data_into_buffer().
|
static |
Definition at line 2098 of file basebackup.c.
References pg_dir_create_mode, S_ISLNK, and stat::st_mode.
Referenced by sendDir().
|
static |
Definition at line 698 of file basebackup.c.
References pg_compress_specification::algorithm, BaseBackupGetTargetHandle(), CHECKSUM_TYPE_CRC32C, CHECKSUM_TYPE_NONE, basebackup_options::compression, basebackup_options::compression_specification, defGetBoolean(), defGetInt64(), defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, basebackup_options::fastcheckpoint, basebackup_options::includewal, basebackup_options::incremental, basebackup_options::label, lfirst, basebackup_options::manifest, basebackup_options::manifest_checksum_type, MANIFEST_OPTION_FORCE_ENCODE, MANIFEST_OPTION_NO, MANIFEST_OPTION_YES, MAX_RATE_LOWER, MAX_RATE_UPPER, basebackup_options::maxrate, maxrate, MemSet, noverify_checksums, basebackup_options::nowait, parse_bool(), parse_compress_algorithm(), parse_compress_specification(), pg_checksum_parse_type(), PG_COMPRESSION_NONE, pg_strcasecmp(), basebackup_options::progress, basebackup_options::send_to_client, basebackup_options::sendtblspcmapfile, summarize_wal, basebackup_options::target_handle, basebackup_options::use_copytblspc, and validate_compress_specification().
Referenced by SendBaseBackup().
|
static |
Definition at line 234 of file basebackup.c.
References _tarWriteHeader(), AddWALInfoToBackupManifest(), AllocateDir(), Assert, AuxProcessResourceOwner, BACKUP_LABEL_FILE, backup_started_in_recovery, backup_state, basebackup_progress_done(), basebackup_progress_estimate_backup_size(), basebackup_progress_transfer_wal(), basebackup_progress_wait_checkpoint(), basebackup_progress_wait_wal_archive(), basebackup_read_file(), bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink_archive_contents(), bbsink_begin_archive(), bbsink_begin_backup(), bbsink_end_archive(), bbsink_end_backup(), BoolGetDatum(), build_backup_content(), CheckXLogRemoved(), CloseTransientFile(), compareWalFileNames(), CurrentResourceOwner, dirent::d_name, StringInfoData::data, destroyStringInfo(), do_pg_abort_backup(), do_pg_backup_start(), do_pg_backup_stop(), ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), errmsg_plural(), ERROR, basebackup_options::fastcheckpoint, fd(), FreeBackupManifest(), FreeDir(), fstat, basebackup_options::includewal, InitializeBackupManifest(), InvalidOid, InvalidRelFileNumber, IsTLHistoryFileName(), IsXLogFileName(), basebackup_options::label, lappend(), len, lfirst, linitial, list_sort(), lnext(), lstat, makeStringInfo(), basebackup_options::manifest, manifest, basebackup_options::manifest_checksum_type, MAXFNAMELEN, MAXPGPATH, Min, NIL, basebackup_options::nowait, tablespaceinfo::oid, OpenTransientFile(), palloc0(), tablespaceinfo::path, pfree(), PG_BINARY, PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, pgoff_t, PrepareForIncrementalBackup(), basebackup_options::progress, psprintf(), pstrdup(), ReadDir(), RecoveryInProgress(), ReleaseAuxProcessResources(), SendBackupManifest(), sendDir(), sendFile(), sendFileWithContent(), sendTablespace(), basebackup_options::sendtblspcmapfile, SINK_BUFFER_LENGTH, tablespaceinfo::size, snprintf, stat::st_size, BackupState::startpoint, BackupState::starttli, StaticAssertDecl, StaticAssertStmt, StatusFilePath(), BackupState::stoppoint, BackupState::stoptli, tablespace_map, TABLESPACE_MAP, TAR_BLOCK_SIZE, total_checksum_failures, wal_segment_size, WARNING, XLByteToPrevSeg, XLByteToSeg, XLOG_CONTROL_FILE, XLOGDIR, XLogFileName(), and XLogFromFileName().
Referenced by SendBaseBackup().
|
static |
Definition at line 1952 of file basebackup.c.
References bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink_archive_contents(), data, elog, ERROR, and pg_checksum_update().
Referenced by sendFile().
|
static |
Definition at line 1849 of file basebackup.c.
References basebackup_read_file(), bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink::bbs_state, ereport, errmsg(), fd(), i, Min, bbsink_state::startptr, verify_page_checksum(), and WARNING.
Referenced by sendFile().
void SendBaseBackup | ( | BaseBackupCmd * | cmd, |
IncrementalBackupInfo * | ib | ||
) |
Definition at line 990 of file basebackup.c.
References BaseBackupGetSink(), bbsink_cleanup(), bbsink_copystream_new(), bbsink_gzip_new(), bbsink_lz4_new(), bbsink_progress_new(), bbsink_throttle_new(), bbsink_zstd_new(), basebackup_options::compression, basebackup_options::compression_specification, ereport, errcode(), errmsg(), ERROR, get_backup_status(), basebackup_options::incremental, basebackup_options::label, basebackup_options::maxrate, BaseBackupCmd::options, parse_basebackup_options(), perform_base_backup(), PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_ZSTD, PG_END_TRY, PG_FINALLY, PG_TRY, basebackup_options::progress, basebackup_options::send_to_client, SESSION_BACKUP_RUNNING, set_ps_display(), snprintf, basebackup_options::target_handle, update_process_title, WalSndSetState(), and WALSNDSTATE_BACKUP.
Referenced by exec_replication_command().
|
static |
Definition at line 1189 of file basebackup.c.
References _tarWriteHeader(), AllocateDir(), atooid, BACK_UP_FILE_FULLY, BACK_UP_FILE_INCREMENTALLY, backup_started_in_recovery, CHECK_FOR_INTERRUPTS, convert_link_to_directory(), dirent::d_name, DEBUG1, DEBUG2, elog, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, excludeDirContents, excludeFiles, FreeDir(), GetFileBackupMethod(), GetIncrementalFileSize(), INIT_FORKNUM, InvalidForkNumber, InvalidOid, InvalidRelFileNumber, last_dir_separator(), lfirst, looks_like_temp_rel_name(), lstat, manifest, MAXPGPATH, exclude_list_item::name, name, OidIsValid, palloc(), parse_filename_for_nontemp_relation(), pfree(), PG_TBLSPC_DIR, PG_TEMP_FILE_PREFIX, psprintf(), pstrdup(), ReadDir(), readlink, RecoveryInProgress(), tablespaceinfo::rpath, S_ISDIR, S_ISLNK, S_ISREG, sendFile(), size, snprintf, stat::st_mode, stat::st_size, TABLESPACE_VERSION_DIRECTORY, TAR_BLOCK_SIZE, tarPaddingBytesRequired(), and WARNING.
Referenced by perform_base_backup(), and sendTablespace().
|
static |
Definition at line 1574 of file basebackup.c.
References _tarWriteHeader(), _tarWritePadding(), AddFileToBackupManifest(), Assert, bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink_archive_contents(), CloseTransientFile(), DataChecksumsEnabled(), elog, ereport, errcode_for_file_access(), errmsg(), errmsg_plural(), ERROR, fd(), INCREMENTAL_MAGIC, manifest, MemSet, Min, noverify_checksums, OpenTransientFile(), PG_BINARY, pg_checksum_init(), pg_checksum_update(), pgoff_t, pgstat_report_checksum_failures_in_db(), push_to_sink(), read_file_data_into_buffer(), RelFileNumberIsValid, remaining, stat::st_mtime, stat::st_size, total_checksum_failures, and WARNING.
Referenced by perform_base_backup(), and sendDir().
|
static |
Definition at line 1075 of file basebackup.c.
References _tarWriteHeader(), _tarWritePadding(), AddFileToBackupManifest(), bbsink::bbs_buffer, bbsink::bbs_buffer_length, bbsink_archive_contents(), elog, ERROR, filename, InvalidOid, len, manifest, Min, pg_checksum_init(), pg_checksum_update(), pg_file_create_mode, remaining, stat::st_gid, stat::st_mode, stat::st_mtime, stat::st_size, and stat::st_uid.
Referenced by perform_base_backup().
|
static |
Definition at line 1136 of file basebackup.c.
References _tarWriteHeader(), ereport, errcode_for_file_access(), errmsg(), ERROR, lstat, manifest, MAXPGPATH, NIL, sendDir(), size, snprintf, and TABLESPACE_VERSION_DIRECTORY.
Referenced by perform_base_backup().
|
static |
Definition at line 1993 of file basebackup.c.
References PageGetLSN(), PageIsNew(), PageHeaderData::pd_checksum, and pg_checksum_page().
Referenced by read_file_data_into_buffer().
|
static |
Definition at line 123 of file basebackup.c.
Referenced by do_pg_backup_start(), perform_base_backup(), and sendDir().
|
static |
Definition at line 151 of file basebackup.c.
Referenced by sendDir().
|
static |
Definition at line 151 of file basebackup.c.
Referenced by sendDir().
|
static |
Definition at line 129 of file basebackup.c.
Referenced by parse_basebackup_options(), and sendFile().
|
static |
Definition at line 126 of file basebackup.c.
Referenced by perform_base_backup(), and sendFile().