|
| 1 | +pg_arman fork from Postgres Professional |
| 2 | +======================================== |
| 3 | + |
| 4 | +This repository contains fork of pg_arman by Postgres Professional with |
| 5 | +block level incremental backup support. |
| 6 | + |
| 7 | +pg_arman is a backup and recovery manager for PostgreSQL servers able to do |
| 8 | +differential and full backup as well as restore a cluster to a |
| 9 | +state defined by a given recovery target. It is designed to perform |
| 10 | +periodic backups of an existing PostgreSQL server, combined with WAL |
| 11 | +archives to provide a way to recover a server in case of failure of |
| 12 | +server because of a reason or another. Its differential backup |
| 13 | +facility reduces the amount of data necessary to be taken between |
| 14 | +two consecutive backups. |
| 15 | + |
| 16 | +Download |
| 17 | +-------- |
| 18 | + |
| 19 | +The latest version of this software can be found on the project website at |
| 20 | +https://github.com/postgrespro/pg_arman. Original fork of pg_arman can be |
| 21 | +found athttps://github.com/michaelpq/pg_arman. |
| 22 | + |
| 23 | +Installation |
| 24 | +------------ |
| 25 | + |
| 26 | +Compiling pg_arman requires a PostgreSQL installation to be in place |
| 27 | +as well as a raw source tree. Pass the path to the PostgreSQL source tree |
| 28 | +to make, in the top_srcdir variable: |
| 29 | + |
| 30 | +make USE_PGXS=1 top_srcdir=<path to PostgreSQL source tree> |
| 31 | + |
| 32 | +In addition, you must have pg_config in $PATH. |
| 33 | + |
| 34 | +The current version of pg_arman is compatible with PostgreSQL 9.5 and |
| 35 | +upper versions. |
| 36 | + |
| 37 | +Platforms |
| 38 | +--------- |
| 39 | + |
| 40 | +pg_arman has been tested on Linux and Unix-based platforms. |
| 41 | + |
| 42 | +Documentation |
| 43 | +------------- |
| 44 | + |
| 45 | +All the documentation you can find[here](doc/pg_arman.md). |
| 46 | + |
| 47 | +Regression tests |
| 48 | +---------------- |
| 49 | + |
| 50 | +The test suite of pg_arman is available in the code tree and can be |
| 51 | +launched in a way similar to common PostgreSQL extensions and modules: |
| 52 | + |
| 53 | +make installcheck |
| 54 | + |
| 55 | +Block level incremental backup |
| 56 | +------------------------------ |
| 57 | + |
| 58 | +Idea of block level incremental backup is that you may backup only blocks |
| 59 | +changed since last full backup. It gives two major benefits: taking backups |
| 60 | +faster and making backups smaller. |
| 61 | + |
| 62 | +The major question here is how to get the list of changed blocks. Since |
| 63 | +each block contains LSN number, changed blocks could be retrieved by full scan |
| 64 | +of all the blocks. But this approach consumes as much server IO as full |
| 65 | +backup. |
| 66 | + |
| 67 | +This is why we implemented alternative approaches to retrieve |
| 68 | +list of changed blocks. |
| 69 | + |
| 70 | +1. Scan WAL archive and extract changed blocks from it. However, shortcoming |
| 71 | +of these approach is requirement to have WAL archive. |
| 72 | + |
| 73 | +2. Track bitmap of changes blocks inside PostgreSQL (ptrack). It introduces |
| 74 | +some overhead to PostgreSQL performance. On our experiments it appears to be |
| 75 | +less than 3%. |
| 76 | + |
| 77 | +These two approaches were implemented in this fork of pg_arman. The second |
| 78 | +approach requires[patch for PostgreSQL 9.5](https://gist.github.com/stalkerg/44703dbcbac1da08f448b7e6966646c0). |
| 79 | + |
| 80 | +Testing block level incremental backup |
| 81 | +-------------------------------------- |
| 82 | + |
| 83 | +You need build and install[PGPRO9_5 branch of PostgreSQL](https://github.com/postgrespro/postgrespro) or[apply this patch to PostgreSQL 9.5](https://gist.github.com/stalkerg/44703dbcbac1da08f448b7e6966646c0). |
| 84 | + |
| 85 | +###Retrieving changed blocks from WAL archive |
| 86 | + |
| 87 | +You need to enable WAL archive by adding following lines to postgresql.conf: |
| 88 | + |
| 89 | +``` |
| 90 | +wal_level = archive |
| 91 | +archive_command = 'test ! -f /home/postgres/backup/arman/wal/%f && cp %p /home/postgres/backup/arman/wal/%f' |
| 92 | +wal_log_hints = on |
| 93 | +``` |
| 94 | + |
| 95 | +Example backup (assuming PostgreSQL is running): |
| 96 | +```bash |
| 97 | +# Init pg_aramn backup folder |
| 98 | +pg_arman init -B /home/postgres/backup/pgarman |
| 99 | +cat<<__EOF__ >> /home/postgres/backup/pgarman/pg_arman.ini |
| 100 | +ARCLOG_PATH = '/home/postgres/backup/arman/wal' |
| 101 | +__EOF__ |
| 102 | +# Make full backup with 2 thread and verbose mode. |
| 103 | +pg_arman backup -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -b full -v -j 2 |
| 104 | +# Validate backup |
| 105 | +pg_arman validate -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman |
| 106 | +# Show backups information |
| 107 | +pg_arman show -B /home/postgres/backup/pgarman |
| 108 | + |
| 109 | +# Now you can insert or update some data in your database |
| 110 | + |
| 111 | +# Then start the incremental backup. |
| 112 | +pg_arman backup -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -b page -v -j 2 |
| 113 | +pg_arman validate -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman |
| 114 | +# You should see that increment is really small |
| 115 | +pg_arman show -B /home/postgres/backup/pgarman |
| 116 | +``` |
| 117 | + |
| 118 | +For restore after remove your pgdata you can use: |
| 119 | +``` |
| 120 | +pg_arman restore -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -j 4 --verbose |
| 121 | +``` |
| 122 | + |
| 123 | +###Retrieving changed blocks from ptrack |
| 124 | + |
| 125 | +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). |
| 126 | + |
| 127 | +``` |
| 128 | +ptrack_enable = on |
| 129 | +``` |
| 130 | + |
| 131 | +Also, some WALs still need to be fetched in order to get consistent backup. pg_arman can fetch them trough the streaming replication protocol. Thus, you also need to[enable streaming replication connection](https://wiki.postgresql.org/wiki/Streaming_Replication). |
| 132 | + |
| 133 | +Example backup (assuming PostgreSQL is running): |
| 134 | +```bash |
| 135 | +# Init pg_aramn backup folder |
| 136 | +pg_arman init -B /home/postgres/backup/pgarman |
| 137 | +cat<<__EOF__ >> /home/postgres/backup/pgarman/pg_arman.ini |
| 138 | +ARCLOG_PATH = '/home/postgres/backup/arman/wal' |
| 139 | +__EOF__ |
| 140 | +# Make full backup with 2 thread and verbose mode. |
| 141 | +pg_arman backup -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -b full -v -j 2 --stream |
| 142 | +# Validate backup |
| 143 | +pg_arman validate -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman |
| 144 | +# Show backups information |
| 145 | +pg_arman show -B /home/postgres/backup/pgarman |
| 146 | + |
| 147 | +# Now you can insert or update some data in your database |
| 148 | + |
| 149 | +# Then start the incremental backup. |
| 150 | +pg_arman backup -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -b ptrack -v -j 2 --stream |
| 151 | +pg_arman validate -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman |
| 152 | +# You should see that increment is really small |
| 153 | +pg_arman show -B /home/postgres/backup/pgarman |
| 154 | +``` |
| 155 | + |
| 156 | +For restore after remove your pgdata you can use: |
| 157 | +``` |
| 158 | +pg_arman restore -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -j 4 --verbose --stream |
| 159 | +``` |
| 160 | + |
| 161 | +License |
| 162 | +------- |
| 163 | + |
| 164 | +pg_arman can be distributed under the PostgreSQL license. See COPYRIGHT |
| 165 | +file for more information. pg_arman is a fork of the existing project |
| 166 | +pg_rman, initially created and maintained by NTT and Itagaki Takahiro. |