1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-28 09:33:54 +02:00
Backup and recovery manager for PostgreSQL https://postgrespro.github.io/pg_probackup/
Go to file
Arthur Zakirov 72c5d0d115 Add crazy function get_control_value().
It parses json-like lines of backup_content.control file.
2017-04-22 23:27:56 +03:00
doc Default --archive-timeout is 300 seconds 2017-03-24 14:24:29 +03:00
pgut Format change. pg_probackup.conf contains more info now. Options change: configure subcommand is implemented 2017-04-19 16:47:41 +03:00
tests Update version 2017-04-07 15:15:41 +03:00
travis Rename project to pg_probackup. 2016-11-16 20:34:21 +03:00
.gitignore Add retention show|purge commands. Add tests and documentation. 2017-02-12 23:42:10 +03:00
.travis.yml Travis tests 2016-09-16 00:26:18 +03:00
backup.c Improve comments. Add pgBackupGetBackupMode() 2017-04-21 14:54:33 +03:00
catalog.c Improve comments. Add pgBackupGetBackupMode() 2017-04-21 14:54:33 +03:00
configure.c fix a warning 2017-04-19 18:31:40 +03:00
COPYRIGHT Update some copyright lines to 2016 2016-01-16 00:02:09 +09:00
data.c Improve comments. Add pgBackupGetBackupMode() 2017-04-21 14:54:33 +03:00
delete.c Free base36enc's results 2017-04-21 12:06:07 +03:00
dir.c Add crazy function get_control_value(). 2017-04-22 23:27:56 +03:00
fetch.c Add retention show|purge commands. Add tests and documentation. 2017-02-12 23:42:10 +03:00
init.c Format change. pg_probackup.conf contains more info now. Options change: configure subcommand is implemented 2017-04-19 16:47:41 +03:00
Makefile Format change. pg_probackup.conf contains more info now. Options change: configure subcommand is implemented 2017-04-19 16:47:41 +03:00
parray.c Rename project to pg_probackup. 2016-11-16 20:34:21 +03:00
parray.h Convert newline characters from CRLF to LF. 2013-01-24 06:35:48 +00:00
parsexlog.c Check target LSN. Archived WAL segment should contain it. 2017-04-20 12:38:51 +03:00
pg_probackup.c Move state() under backup_path initialization 2017-04-20 16:46:51 +03:00
pg_probackup.h Improve comments. Add pgBackupGetBackupMode() 2017-04-21 14:54:33 +03:00
README.md update links to ptrack patches in README 2017-03-13 18:46:46 +03:00
restore.c Fix dir_read_file_list(). 2017-04-21 19:46:19 +03:00
show.c Improve comments. Add pgBackupGetBackupMode() 2017-04-21 14:54:33 +03:00
status.c Add retention show|purge commands. Add tests and documentation. 2017-02-12 23:42:10 +03:00
util.c Little fixes 2017-04-21 11:54:00 +03:00
validate.c Free base36enc's results 2017-04-21 12:06:07 +03:00

pg_probackup fork of pg_arman by Postgres Professional

pg_probackup is a backup and recovery manager for PostgreSQL servers able to do differential and full backup as well as restore a cluster to a state defined by a given recovery target. It is designed to perform periodic backups of an existing PostgreSQL server, combined with WAL archives to provide a way to recover a server in case of failure of server because of a reason or another. Its differential backup facility reduces the amount of data necessary to be taken between two consecutive backups.

Main features:

  • incremental backup from WAL and PTRACK
  • backup from replica
  • multithreaded backup and restore
  • autonomous backup without archive command (will need slot replication)

Requirements:

  • =PostgreSQL 9.5

  • =gcc 4.4 or >=clang 3.6 or >= XLC 12.1

  • pthread

Download

The latest version of this software can be found on the project website at https://github.com/postgrespro/pg_probackup. Original fork of pg_probackup can be found at https://github.com/michaelpq/pg_arman.

Installation

Compiling pg_probackup requires a PostgreSQL installation to be in place as well as a raw source tree. Pass the path to the PostgreSQL source tree to make, in the top_srcdir variable:

make USE_PGXS=1 top_srcdir=<path to PostgreSQL source tree>

In addition, you must have pg_config in $PATH.

The current version of pg_probackup is compatible with PostgreSQL 9.5 and upper versions.

Platforms

pg_probackup has been tested on Linux and Unix-based platforms.

Documentation

All the documentation you can find here.

Regression tests

For tests you must have python 2.7 or python 3.3 and higher. Also good idea is make virtual enviroment by virtualenv.
First of all you need to install testgres python module which contains useful functions to start postgres clusters and make queries:

pip install testgres

To run tests execute:

python -m unittest tests

from current (root of project) directory. If you want to run a specific postgres build then you should specify the path to your pg_config executable by setting PG_CONFIG environment variable:

export PG_CONFIG=/path/to/pg_config

Block level incremental backup

Idea of block level incremental backup is that you may backup only blocks changed since last full backup. It gives two major benefits: taking backups faster and making backups smaller.

The major question here is how to get the list of changed blocks. Since each block contains LSN number, changed blocks could be retrieved by full scan of all the blocks. But this approach consumes as much server IO as full backup.

This is why we implemented alternative approaches to retrieve list of changed blocks.

  1. Scan WAL archive and extract changed blocks from it. However, shortcoming of these approach is requirement to have WAL archive.

  2. Track bitmap of changes blocks inside PostgreSQL (ptrack). It introduces some overhead to PostgreSQL performance. On our experiments it appears to be less than 3%.

These two approaches were implemented in this fork of pg_probackup. The second approach requires patch for PostgreSQL 9.6.2 or patch for PostgreSQL 10 (master).

Testing block level incremental backup

You need to apply ptrack patch to PostgreSQL 9.6.2 or PostgreSQL 10 (master). Or you can build and install PGPRO9_5 or PGPRO9_6 branch of PostgreSQL. Note that PGPRO branches currently contain old version of ptrack.

Retrieving changed blocks from WAL archive

You need to enable WAL archive by adding following lines to postgresql.conf:

wal_level = archive
archive_mode = on
archive_command = 'test ! -f /home/postgres/backup/wal/%f && cp %p /home/postgres/backup/wal/%f'

Example backup (assuming PostgreSQL is running):

# Init pg_aramn backup folder
pg_probackup init -B /home/postgres/backup
# Make full backup with 2 thread and verbose mode.
pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b full -v -j 2
# Show backups information
pg_probackup show -B /home/postgres/backup

# Now you can insert or update some data in your database

# Then start the incremental backup.
pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b page -v -j 2
# You should see that increment is really small
pg_probackup show -B /home/postgres/backup

For restore after remove your pgdata you can use:

pg_probackup restore -B /home/postgres/backup -D /home/postgres/pgdata -j 4 --verbose

Retrieving changed blocks from ptrack

The advantage of this approach is that you don't have to save WAL archive. You will need to enable ptrack in postgresql.conf (restart required).

ptrack_enable = on

Also, some WALs still need to be fetched in order to get consistent backup. pg_probackup can fetch them trough the streaming replication protocol. Thus, you also need to enable streaming replication connection.

Example backup (assuming PostgreSQL is running):

# Init pg_aramn backup folder
pg_probackup init -B /home/postgres/backup
# Make full backup with 2 thread and verbose mode.
pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b full -v -j 2 --stream
# Show backups information
pg_probackup show -B /home/postgres/backup

# Now you can insert or update some data in your database

# Then start the incremental backup.
pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b ptrack -v -j 2 --stream
# You should see that increment is really small
pg_probackup show -B /home/postgres/backup

For restore after remove your pgdata you can use:

pg_probackup restore -B /home/postgres/backup -D /home/postgres/pgdata -j 4 --verbose --stream

License

pg_probackup can be distributed under the PostgreSQL license. See COPYRIGHT file for more information. pg_arman is a fork of the existing project pg_rman, initially created and maintained by NTT and Itagaki Takahiro.