Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dc21234

Browse files
committed
Add support for incremental backup.
To take an incremental backup, you use the new replication command UPLOAD_MANIFEST to upload the manifest for the prior backup. This prior backup could either be a full backup or another incremental backup. You then use BASE_BACKUP with the INCREMENTAL option to take the backup. pg_basebackup now has an --incremental=PATH_TO_MANIFEST option to trigger this behavior. An incremental backup is like a regular full backup except that some relation files are replaced with files with names like INCREMENTAL.${ORIGINAL_NAME}, and the backup_label file contains additional lines identifying it as an incremental backup. The new pg_combinebackup tool can be used to reconstruct a data directory from a full backup and a series of incremental backups. Patch by me. Reviewed by Matthias van de Meent, Dilip Kumar, Jakub Wartak, Peter Eisentraut, and Álvaro Herrera. Thanks especially to Jakub for incredibly helpful and extensive testing. Discussion: http://postgr.es/m/CA+TgmoYOYZfMCyOXFyC-P+-mdrZqm5pP2N7S-r0z3_402h9rsA@mail.gmail.com
1 parent 174c480 commit dc21234

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5834
-52
lines changed

doc/src/sgml/backup.sgml

+85-4
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,79 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
857857
</para>
858858
</sect2>
859859

860+
<sect2 id="backup-incremental-backup">
861+
<title>Making an Incremental Backup</title>
862+
863+
<para>
864+
You can use <xref linkend="app-pgbasebackup"/> to take an incremental
865+
backup by specifying the <literal>--incremental</literal> option. You must
866+
supply, as an argument to <literal>--incremental</literal>, the backup
867+
manifest to an earlier backup from the same server. In the resulting
868+
backup, non-relation files will be included in their entirety, but some
869+
relation files may be replaced by smaller incremental files which contain
870+
only the blocks which have been changed since the earlier backup and enough
871+
metadata to reconstruct the current version of the file.
872+
</para>
873+
874+
<para>
875+
To figure out which blocks need to be backed up, the server uses WAL
876+
summaries, which are stored in the data directory, inside the directory
877+
<literal>pg_wal/summaries</literal>. If the required summary files are not
878+
present, an attempt to take an incremental backup will fail. The summaries
879+
present in this directory must cover all LSNs from the start LSN of the
880+
prior backup to the start LSN of the current backup. Since the server looks
881+
for WAL summaries just after establishing the start LSN of the current
882+
backup, the necessary summary files probably won't be instantly present
883+
on disk, but the server will wait for any missing files to show up.
884+
This also helps if the WAL summarization process has fallen behind.
885+
However, if the necessary files have already been removed, or if the WAL
886+
summarizer doesn't catch up quickly enough, the incremental backup will
887+
fail.
888+
</para>
889+
890+
<para>
891+
When restoring an incremental backup, it will be necessary to have not
892+
only the incremental backup itself but also all earlier backups that
893+
are required to supply the blocks omitted from the incremental backup.
894+
See <xref linkend="app-pgcombinebackup"/> for further information about
895+
this requirement.
896+
</para>
897+
898+
<para>
899+
Note that all of the requirements for making use of a full backup also
900+
apply to an incremental backup. For instance, you still need all of the
901+
WAL segment files generated during and after the file system backup, and
902+
any relevant WAL history files. And you still need to create a
903+
<literal>recovery.signal</literal> (or <literal>standby.signal</literal>)
904+
and perform recovery, as described in
905+
<xref linkend="backup-pitr-recovery" />. The requirement to have earlier
906+
backups available at restore time and to use
907+
<literal>pg_combinebackup</literal> is an additional requirement on top of
908+
everything else. Keep in mind that <application>PostgreSQL</application>
909+
has no built-in mechanism to figure out which backups are still needed as
910+
a basis for restoring later incremental backups. You must keep track of
911+
the relationships between your full and incremental backups on your own,
912+
and be certain not to remove earlier backups if they might be needed when
913+
restoring later incremental backups.
914+
</para>
915+
916+
<para>
917+
Incremental backups typically only make sense for relatively large
918+
databases where a significant portion of the data does not change, or only
919+
changes slowly. For a small database, it's simpler to ignore the existence
920+
of incremental backups and simply take full backups, which are simpler
921+
to manage. For a large database all of which is heavily modified,
922+
incremental backups won't be much smaller than full backups.
923+
</para>
924+
</sect2>
925+
860926
<sect2 id="backup-lowlevel-base-backup">
861927
<title>Making a Base Backup Using the Low Level API</title>
862928
<para>
863-
The procedure for making a base backup using the low level
864-
APIs contains a few more steps than
865-
the <xref linkend="app-pgbasebackup"/> method, but is relatively
929+
Instead of taking a full or incremental base backup using
930+
<xref linkend="app-pgbasebackup"/>, you can take a base backup using the
931+
low-level API. This procedure contains a few more steps than
932+
the <application>pg_basebackup</application> method, but is relatively
866933
simple. It is very important that these steps are executed in
867934
sequence, and that the success of a step is verified before
868935
proceeding to the next step.
@@ -1118,14 +1185,28 @@ SELECT * FROM pg_backup_stop(wait_for_archive => true);
11181185
</listitem>
11191186
<listitem>
11201187
<para>
1121-
Restore the database files from your file system backup. Be sure that they
1188+
If you're restoring a full backup, you can restore the database files
1189+
directly into the target directories. Be sure that they
11221190
are restored with the right ownership (the database system user, not
11231191
<literal>root</literal>!) and with the right permissions. If you are using
11241192
tablespaces,
11251193
you should verify that the symbolic links in <filename>pg_tblspc/</filename>
11261194
were correctly restored.
11271195
</para>
11281196
</listitem>
1197+
<listitem>
1198+
<para>
1199+
If you're restoring an incremental backup, you'll need to restore the
1200+
incremental backup and all earlier backups upon which it directly or
1201+
indirectly depends to the machine where you are performing the restore.
1202+
These backups will need to be placed in separate directories, not the
1203+
target directories where you want the running server to end up.
1204+
Once this is done, use <xref linkend="app-pgcombinebackup"/> to pull
1205+
data from the full backup and all of the subsequent incremental backups
1206+
and write out a synthetic full backup to the target directories. As above,
1207+
verify that permissions and tablespace links are correct.
1208+
</para>
1209+
</listitem>
11291210
<listitem>
11301211
<para>
11311212
Remove any files present in <filename>pg_wal/</filename>; these came from the

doc/src/sgml/config.sgml

-2
Original file line numberDiff line numberDiff line change
@@ -4153,13 +4153,11 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
41534153
<sect2 id="runtime-config-wal-summarization">
41544154
<title>WAL Summarization</title>
41554155

4156-
<!--
41574156
<para>
41584157
These settings control WAL summarization, a feature which must be
41594158
enabled in order to perform an
41604159
<link linkend="backup-incremental-backup">incremental backup</link>.
41614160
</para>
4162-
-->
41634161

41644162
<variablelist>
41654163
<varlistentry id="guc-summarize-wal" xreflabel="summarize_wal">

doc/src/sgml/protocol.sgml

+24
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,19 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
25992599
</listitem>
26002600
</varlistentry>
26012601

2602+
<varlistentry id="protocol-replication-upload-manifest">
2603+
<term>
2604+
<literal>UPLOAD_MANIFEST</literal>
2605+
<indexterm><primary>UPLOAD_MANIFEST</primary></indexterm>
2606+
</term>
2607+
<listitem>
2608+
<para>
2609+
Uploads a backup manifest in preparation for taking an incremental
2610+
backup.
2611+
</para>
2612+
</listitem>
2613+
</varlistentry>
2614+
26022615
<varlistentry id="protocol-replication-base-backup" xreflabel="BASE_BACKUP">
26032616
<term><literal>BASE_BACKUP</literal> [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
26042617
<indexterm><primary>BASE_BACKUP</primary></indexterm>
@@ -2838,6 +2851,17 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
28382851
</para>
28392852
</listitem>
28402853
</varlistentry>
2854+
2855+
<varlistentry>
2856+
<term><literal>INCREMENTAL</literal></term>
2857+
<listitem>
2858+
<para>
2859+
Requests an incremental backup. The
2860+
<literal>UPLOAD_MANIFEST</literal> command must be executed
2861+
before running a base backup with this option.
2862+
</para>
2863+
</listitem>
2864+
</varlistentry>
28412865
</variablelist>
28422866
</para>
28432867

doc/src/sgml/ref/allfiles.sgml

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Complete list of usable sgml source files in this directory.
202202
<!ENTITY pgBasebackup SYSTEM "pg_basebackup.sgml">
203203
<!ENTITY pgbench SYSTEM "pgbench.sgml">
204204
<!ENTITY pgChecksums SYSTEM "pg_checksums.sgml">
205+
<!ENTITY pgCombinebackup SYSTEM "pg_combinebackup.sgml">
205206
<!ENTITY pgConfig SYSTEM "pg_config-ref.sgml">
206207
<!ENTITY pgControldata SYSTEM "pg_controldata.sgml">
207208
<!ENTITY pgCtl SYSTEM "pg_ctl-ref.sgml">

doc/src/sgml/ref/pg_basebackup.sgml

+32-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,25 @@ PostgreSQL documentation
3838
</para>
3939

4040
<para>
41-
<application>pg_basebackup</application> makes an exact copy of the database
42-
cluster's files, while making sure the server is put into and
43-
out of backup mode automatically. Backups are always taken of the entire
44-
database cluster; it is not possible to back up individual databases or
45-
database objects. For selective backups, another tool such as
41+
<application>pg_basebackup</application> can take a full or incremental
42+
base backup of the database. When used to take a full backup, it makes an
43+
exact copy of the database cluster's files. When used to take an incremental
44+
backup, some files that would have been part of a full backup may be
45+
replaced with incremental versions of the same files, containing only those
46+
blocks that have been modified since the reference backup. An incremental
47+
backup cannot be used directly; instead,
48+
<xref linkend="app-pgcombinebackup"/> must first
49+
be used to combine it with the previous backups upon which it depends.
50+
See <xref linkend="backup-incremental-backup" /> for more information
51+
about incremental backups, and <xref linkend="backup-pitr-recovery" />
52+
for steps to recover from a backup.
53+
</para>
54+
55+
<para>
56+
In any mode, <application>pg_basebackup</application> makes sure the server
57+
is put into and out of backup mode automatically. Backups are always taken of
58+
the entire database cluster; it is not possible to back up individual
59+
databases or database objects. For selective backups, another tool such as
4660
<xref linkend="app-pgdump"/> must be used.
4761
</para>
4862

@@ -197,6 +211,19 @@ PostgreSQL documentation
197211
</listitem>
198212
</varlistentry>
199213

214+
<varlistentry>
215+
<term><option>-i <replaceable class="parameter">old_manifest_file</replaceable></option></term>
216+
<term><option>--incremental=<replaceable class="parameter">old_meanifest_file</replaceable></option></term>
217+
<listitem>
218+
<para>
219+
Performs an <link linkend="backup-incremental-backup">incremental
220+
backup</link>. The backup manifest for the reference
221+
backup must be provided, and will be uploaded to the server, which will
222+
respond by sending the requested incremental backup.
223+
</para>
224+
</listitem>
225+
</varlistentry>
226+
200227
<varlistentry>
201228
<term><option>-R</option></term>
202229
<term><option>--write-recovery-conf</option></term>

0 commit comments

Comments
 (0)