Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 34 additions & 62 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PROGRAM = pg_probackup
WORKDIR ?= $(CURDIR)
BUILDDIR = $(WORKDIR)/build/
PBK_GIT_REPO = https://github.com/postgrespro/pg_probackup

subdir=src/bin/pg_probackup
top_builddir=../../..
include $(top_builddir)/src/Makefile.global

# utils
OBJS = src/utils/configuration.o src/utils/json.o src/utils/logger.o \
src/utils/parray.o src/utils/pgut.o src/utils/thread.o src/utils/remote.o src/utils/file.o
Expand All @@ -14,76 +15,47 @@ OBJS += src/archive.o src/backup.o src/catalog.o src/checkdb.o src/configure.o s

# borrowed files
OBJS += src/pg_crc.o src/receivelog.o src/streamutil.o \
src/xlogreader.o
src/xlogreader.o src/walmethods.o

EXTRA_CLEAN = src/pg_crc.c \
src/receivelog.c src/receivelog.h src/streamutil.c src/streamutil.h \
src/xlogreader.c src/instr_time.h
src/receivelog.c src/streamutil.c src/xlogreader.c src/walmethods.c

ifdef top_srcdir
srchome := $(abspath $(top_srcdir))
else
top_srcdir=../..
ifneq (,$(wildcard ../../../contrib/pg_probackup))
# separate build directory support
srchome := $(abspath $(top_srcdir)/..)
else
srchome := $(abspath $(top_srcdir))
endif
PG_CPPFLAGS = -I$(libpq_srcdir) -I$(top_srcdir)/src/port -I$(top_srcdir)/src/include/portability -I$(top_srcdir)/src/bin/pg_basebackup -Isrc -I$(srcdir)/src
ifneq ($(PORTNAME), win32)
PG_CPPFLAGS += $(PTHREAD_CFLAGS)
endif
override CPPFLAGS := -DFRONTEND $(CPPFLAGS) $(PG_CPPFLAGS)
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport)

# OBJS variable must be finally defined before invoking the include directive
ifneq (,$(wildcard $(srchome)/src/bin/pg_basebackup/walmethods.c))
OBJS += src/walmethods.o
EXTRA_CLEAN += src/walmethods.c src/walmethods.h
endif
src/pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
rm -f $@ && $(LN_S) $(top_srcdir)/src/backend/utils/hash/pg_crc.c $@
src/receivelog.c: $(top_srcdir)/src/bin/pg_basebackup/receivelog.c
rm -f $@ && $(LN_S) $(top_srcdir)/src/bin/pg_basebackup/receivelog.c $@
src/streamutil.c: $(top_srcdir)/src/bin/pg_basebackup/streamutil.c
rm -f $@ && $(LN_S) $(top_srcdir)/src/bin/pg_basebackup/streamutil.c $@
src/xlogreader.c: $(top_srcdir)/src/backend/access/transam/xlogreader.c
rm -f $@ && $(LN_S) $(top_srcdir)/src/backend/access/transam/xlogreader.c $@
src/walmethods.c: $(top_srcdir)/src/bin/pg_basebackup/walmethods.c
rm -f $@ && $(LN_S) $(top_srcdir)/src/bin/pg_basebackup/walmethods.c $@

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir=contrib/pg_probackup
top_builddir=../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
all: pg_probackup

PG_CPPFLAGS = -I$(libpq_srcdir) ${PTHREAD_CFLAGS} -Isrc -I$(srchome)/$(subdir)/src
override CPPFLAGS := -DFRONTEND $(CPPFLAGS) $(PG_CPPFLAGS)
PG_LIBS_INTERNAL = $(libpq_pgport) ${PTHREAD_CFLAGS}
pg_probackup: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)

src/utils/configuration.o: src/datapagemap.h
src/archive.o: src/instr_time.h
src/backup.o: src/receivelog.h src/streamutil.h
install: all installdirs
$(INSTALL_PROGRAM) pg_probackup$(X) '$(DESTDIR)$(bindir)/pg_probackup$(X)'

src/instr_time.h: $(srchome)/src/include/portability/instr_time.h
rm -f $@ && $(LN_S) $(srchome)/src/include/portability/instr_time.h $@
src/pg_crc.c: $(srchome)/src/backend/utils/hash/pg_crc.c
rm -f $@ && $(LN_S) $(srchome)/src/backend/utils/hash/pg_crc.c $@
src/receivelog.c: $(srchome)/src/bin/pg_basebackup/receivelog.c
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/receivelog.c $@
ifneq (,$(wildcard $(srchome)/src/bin/pg_basebackup/walmethods.c))
src/receivelog.h: src/walmethods.h $(srchome)/src/bin/pg_basebackup/receivelog.h
else
src/receivelog.h: $(srchome)/src/bin/pg_basebackup/receivelog.h
endif
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/receivelog.h $@
src/streamutil.c: $(srchome)/src/bin/pg_basebackup/streamutil.c
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/streamutil.c $@
src/streamutil.h: $(srchome)/src/bin/pg_basebackup/streamutil.h
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/streamutil.h $@
src/xlogreader.c: $(srchome)/src/backend/access/transam/xlogreader.c
rm -f $@ && $(LN_S) $(srchome)/src/backend/access/transam/xlogreader.c $@
src/walmethods.c: $(srchome)/src/bin/pg_basebackup/walmethods.c
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/walmethods.c $@
src/walmethods.h: $(srchome)/src/bin/pg_basebackup/walmethods.h
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/walmethods.h $@
installdirs:
$(MKDIR_P) '$(DESTDIR)$(bindir)'

uninstall:
rm -f '$(DESTDIR)$(bindir)/pg_probackup$(X)'

ifeq ($(PORTNAME), aix)
CC=xlc_r
endif

include packaging/Makefile.pkg
include packaging/Makefile.repo
include packaging/Makefile.test
include $(top_srcdir)/src/bin/pg_probackup/packaging/Makefile.pkg
include $(top_srcdir)/src/bin/pg_probackup/packaging/Makefile.repo
include $(top_srcdir)/src/bin/pg_probackup/packaging/Makefile.test
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,44 @@ Once you have `pg_probackup` installed, complete [the setup](https://postgrespro
For users of Postgres Pro products, commercial editions of pg_probackup are available for installation from the corresponding Postgres Pro product repository.

## Building from source

### Linux

To compile `pg_probackup`, you must have a PostgreSQL installation and raw source tree. Execute this in the module's directory:
To compile `pg_probackup`, you must have a PostgreSQL source tree.
You need place `pg_probackup` source directory into `src/bin` directory, modify `src/bin/Makefile` to include 'pg_probackup` subdirectory and build PostgreSQL.

```shell
make USE_PGXS=1 PG_CONFIG=<path_to_pg_config> top_srcdir=<path_to_PostgreSQL_source_tree>
cd <path_to_PostgreSQL_source_tree>/src/bin && git clone https://github.com/postgrespro/pg_probackup
```

The alternative way, without using the PGXS infrastructure, is to place `pg_probackup` source directory into `contrib` directory and build it there. Example:

```shell
cd <path_to_PostgreSQL_source_tree> && git clone https://github.com/postgrespro/pg_probackup contrib/pg_probackup && cd contrib/pg_probackup && make
Patch for PostgreSQL make system:
```
--- postgresql-17.5/src/bin/Makefile.orig 2025-07-02 14:16:44.042224100 +0300
+++ postgresql-17.5/src/bin/Makefile 2025-07-02 14:16:58.992937600 +0300
@@ -18,6 +18,7 @@
pg_amcheck \
pg_archivecleanup \
pg_basebackup \
+ pg_probackup \
pg_checksums \
pg_config \
pg_controldata \
--- postgresql-17.5/src/bin/meson.build.orig 2025-07-02 17:54:48.124397100 +0300
+++ postgresql-17.5/src/bin/meson.build 2025-07-02 17:55:22.920720200 +0300
@@ -10,6 +10,7 @@
subdir('pg_controldata')
subdir('pg_ctl')
subdir('pg_dump')
+subdir('pg_probackup')
subdir('pg_resetwal')
subdir('pg_rewind')
subdir('pg_test_fsync')
```

### Windows

Currently pg_probackup can be build using only MSVC 2013.
#### MSVC 2013

Build PostgreSQL using [pgwininstall](https://github.com/postgrespro/pgwininstall) or [PostgreSQL instruction](https://www.postgresql.org/docs/current/install-windows-full.html) with MSVC 2013.
If zlib support is needed, src/tools/msvc/config.pl must contain path to directory with compiled zlib. [Example](https://gist.githubusercontent.com/gsmol/80989f976ce9584824ae3b1bfb00bd87/raw/240032950d4ac4801a79625dd00c8f5d4ed1180c/gistfile1.txt)

Expand All @@ -104,6 +125,10 @@ SET PATH=%PATH%;C:\msys64\usr\bin
gen_probackup_project.pl C:\path_to_postgresql_source_tree
```

#### Mingw-w64 && MSYS2

PostgreSQL can be build using MSYS2 platform with its [Mingw-packages] (https://github.com/msys2/MINGW-packages) repository.

## License

This module available under the [license](LICENSE) similar to [PostgreSQL](https://www.postgresql.org/about/license/).
Expand Down
57 changes: 57 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
pg_probackup_sources = files(
'src/utils/configuration.c',
'src/utils/json.c',
'src/utils/logger.c',
'src/utils/parray.c',
'src/utils/pgut.c',
'src/utils/thread.c',
'src/utils/remote.c',
'src/utils/file.c',
'src/archive.c',
'src/backup.c',
'src/catalog.c',
'src/checkdb.c',
'src/configure.c',
'src/data.c',
'src/delete.c',
'src/dir.c',
'src/fetch.c',
'src/help.c',
'src/init.c',
'src/merge.c',
'src/parsexlog.c',
'src/ptrack.c',
'src/pg_probackup.c',
'src/restore.c',
'src/show.c',
'src/stream.c',
'src/util.c',
'src/validate.c',
'src/datapagemap.c',
'src/catchup.c',
)

pg_probackup_sources += files('../../backend/access/transam/xlogreader.c')
pg_probackup_sources += files('../../backend/utils/hash/pg_crc.c')
pg_probackup_sources += files('../pg_basebackup/receivelog.c')
pg_probackup_sources += files('../pg_basebackup/streamutil.c')
pg_probackup_sources += files('../pg_basebackup/walmethods.c')

pg_probackup_deps = [frontend_code, backend_code, libpq, lz4, zlib, zstd]

if host_system == 'windows'
pg_probackup_sources += rc_bin_gen.process(win32ver_rc, extra_args: [
'--NAME', 'pg_probackup',
'--FILEDESC', 'pg_probackup - utility to manage backup and recovery of PostgreSQL database clusters',])
endif

pg_probackup = executable('pg_probackup',
pg_probackup_sources,
dependencies: pg_probackup_deps,
include_directories: include_directories('./src', '../../include/portability', '../../port', '../pg_basebackup'),
c_args: ['-DFRONTEND'], # needed for xlogreader et al
kwargs: default_bin_args,
)
bin_targets += pg_probackup

subdir('po', if_found: libintl)
14 changes: 7 additions & 7 deletions packaging/Makefile.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ define build_deb
--rm pgpro/$1:$2 /app/in/scripts/deb.sh
endef

include packaging/pkg/Makefile.debian
include packaging/pkg/Makefile.ubuntu
include $(srcdir)/packaging/pkg/Makefile.debian
include $(srcdir)/packaging/pkg/Makefile.ubuntu

# CENTOS
build/centos: build/centos_7 build/centos_8 #build/rpm_repo_package_centos
Expand Down Expand Up @@ -127,9 +127,9 @@ define build_rpm
--rm pgpro/$1:$2 /app/in/scripts/rpm.sh
endef

include packaging/pkg/Makefile.centos
include packaging/pkg/Makefile.rhel
include packaging/pkg/Makefile.oraclelinux
include $(srcdir)/packaging/pkg/Makefile.centos
include $(srcdir)/packaging/pkg/Makefile.rhel
include $(srcdir)/packaging/pkg/Makefile.oraclelinux


# Alt Linux
Expand Down Expand Up @@ -157,7 +157,7 @@ define build_alt
--rm pgpro/$1:$2 /app/in/scripts/alt.sh
endef

include packaging/pkg/Makefile.alt
include $(srcdir)/packaging/pkg/Makefile.alt

# SUSE Linux
build/suse: build/suse_15.1 build/suse_15.2
Expand All @@ -182,4 +182,4 @@ define build_suse
--rm pgpro/$1:$2 /app/in/scripts/suse.sh
endef

include packaging/pkg/Makefile.suse
include $(srcdir)/packaging/pkg/Makefile.suse
14 changes: 7 additions & 7 deletions packaging/Makefile.test
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ define test_deb
--rm pgpro/$1:$2 /app/in/scripts/deb$(SCRIPT_SUFFIX).sh
endef

include packaging/test/Makefile.debian
include packaging/test/Makefile.ubuntu
include $(srcdir)/packaging/test/Makefile.debian
include $(srcdir)/packaging/test/Makefile.ubuntu

# CENTOS
build/test_centos: build/test_centos_7 build/test_centos_8
Expand Down Expand Up @@ -94,9 +94,9 @@ define test_rpm
--rm pgpro/$1:$2 /app/in/scripts/rpm$(SCRIPT_SUFFIX).sh
endef

include packaging/test/Makefile.centos
include packaging/test/Makefile.rhel
include packaging/test/Makefile.oraclelinux
include $(srcdir)/packaging/test/Makefile.centos
include $(srcdir)/packaging/test/Makefile.rhel
include $(srcdir)/packaging/test/Makefile.oraclelinux

# Alt Linux
build/test_alt: build/test_alt_8 build/test_alt_9
Expand All @@ -123,7 +123,7 @@ define test_alt
--rm pgpro/$1:$2 /app/in/scripts/alt$(SCRIPT_SUFFIX).sh
endef

include packaging/test/Makefile.alt
include $(srcdir)/packaging/test/Makefile.alt

# SUSE Linux
build/test_suse: build/test_suse_15.1 build/test_suse_15.2
Expand All @@ -147,4 +147,4 @@ define test_suse
--rm pgpro/$1:$2 /app/in/scripts/suse$(SCRIPT_SUFFIX).sh
endef

include packaging/test/Makefile.suse
include $(srcdir)/packaging/test/Makefile.suse
3 changes: 3 additions & 0 deletions po/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2022-2024, PostgreSQL Global Development Group

nls_targets += [i18n.gettext('pg_probackup-' + pg_version_major.to_string())]
3 changes: 1 addition & 2 deletions src/utils/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ fio_is_remote_fd(int fd)

#ifdef WIN32

#undef stat

/*
* The stat() function in win32 is not guaranteed to update the st_size
* field when run. So we define our own version that uses the Win32 API
Expand Down Expand Up @@ -179,6 +177,7 @@ fio_safestat(const char *path, struct stat *buf)
return 0;
}

#undef stat
#define stat(x, y) fio_safestat(x, y)

/* TODO: use real pread on Linux */
Expand Down
2 changes: 1 addition & 1 deletion src/utils/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ logfile_getname(const char *format, time_t timestamp)
len = strlen(filename);

/* Treat log_filename as a strftime pattern */
#ifdef WIN32
#ifdef _MSC_VER
if (pg_strftime(filename + len, MAXPGPATH - len, format, tm) <= 0)
#else
if (strftime(filename + len, MAXPGPATH - len, format, tm) <= 0)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/pgut.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ init_cancel_handler(void)
SetConsoleCtrlHandler(consoleHandler, TRUE);
}

#ifdef _MSC_VER
int
sleep(unsigned int seconds)
{
Expand All @@ -1111,6 +1112,7 @@ usleep(unsigned int usec)
Sleep((usec + 999) / 1000); /* rounded up */
return 0;
}
#endif

#undef select
static int
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pgut.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extern FILE *pgut_fopen(const char *path, const char *mode, bool missing_ok);
extern int wait_for_socket(int sock, struct timeval *timeout);
extern int wait_for_sockets(int nfds, fd_set *fds, struct timeval *timeout);

#ifdef WIN32
#ifdef _MSC_VER
extern int sleep(unsigned int seconds);
extern int usleep(unsigned int usec);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/utils/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bool launch_agent(void)
ssh_argv[2] = psprintf("%d", outfd[0]);
ssh_argv[3] = psprintf("%d", infd[1]);
{
intptr_t pid = _spawnvp(_P_NOWAIT, ssh_argv[0], ssh_argv);
intptr_t pid = _spawnvp(_P_NOWAIT, ssh_argv[0], (const char *const *)ssh_argv);
if (pid < 0)
return false;
child_pid = GetProcessId((HANDLE)pid);
Expand Down
Loading