Skip to content

Commit d5d58f5

Browse files
committed
Merge branch 'master' into issue_120
2 parents 98c22ca + 943548c commit d5d58f5

27 files changed

+1836
-982
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The utility is compatible with:
77

88
As compared to other backup solutions, `pg_probackup` offers the following benefits that can help you implement different backup strategies and deal with large amounts of data:
99
* Incremental backup: page-level incremental backup allows you to save disk space, speed up backup and restore. With three different incremental modes, you can plan the backup strategy in accordance with your data flow.
10+
* Merge: using this feature allows you to implement "incrementally updated backups" strategy, eliminating the need to to do periodical full backups.
1011
* Validation: automatic data consistency checks and on-demand backup validation without actual data recovery
1112
* Verification: on-demand verification of PostgreSQL instance with the `checkdb` command.
1213
* Retention: managing WAL archive and backups in accordance with retention policy. You can configure retention policy based on recovery time or the number of backups to keep, as well as specify `time to live` (TTL) for a particular backup. Expired backups can be merged or deleted.

doc/pgprobackup.xml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,13 @@ BACKUP INSTANCE 'node'
22432243
<literal>MERGING</literal> — the backup is being merged.
22442244
</para>
22452245
</listitem>
2246+
<listitem>
2247+
<para>
2248+
<literal>MERGED</literal> — the backup data files were
2249+
successfully merged, but its metadata is in the process
2250+
of been updated. Only full backup can have this status.
2251+
</para>
2252+
</listitem>
22462253
<listitem>
22472254
<para>
22482255
<literal>DELETING</literal> — the backup files are being deleted.
@@ -3147,7 +3154,9 @@ pg_probackup merge -B <replaceable>backup_dir</replaceable> --instance <replacea
31473154
<para>
31483155
This command merges the specified incremental backup to its
31493156
parent full backup, together with all incremental backups
3150-
between them. Once the merge is complete, the incremental
3157+
between them. If the specified backup ID belong to the full backup,
3158+
then it will be merged with the closest incremental backup.
3159+
Once the merge is complete, the incremental
31513160
backups are removed as redundant. Thus, the merge operation is
31523161
virtually equivalent to retaking a full backup and removing all
31533162
the outdated backups, but it allows to save much time,
@@ -3166,7 +3175,8 @@ pg_probackup show -B <replaceable>backup_dir</replaceable> --instance <replaceab
31663175
</programlisting>
31673176
<para>
31683177
If the merge is still in progress, the backup status is
3169-
displayed as <literal>MERGING</literal>. The merge is idempotent, so you can
3178+
displayed as <literal>MERGING</literal> or, at the final stage,
3179+
<literal>MERGED</literal>. The merge is idempotent, so you can
31703180
restart the merge if it was interrupted.
31713181
</para>
31723182
</refsect2>
@@ -3412,6 +3422,7 @@ pg_probackup backup -B <replaceable>backup_dir</replaceable> -b <replaceable>bac
34123422
[--no-validate] [--skip-block-validation]
34133423
[-w --no-password] [-W --password]
34143424
[--archive-timeout=<replaceable>timeout</replaceable>] [--external-dirs=<replaceable>external_directory_path</replaceable>]
3425+
[--no-sync]
34153426
[<replaceable>connection_options</replaceable>] [<replaceable>compression_options</replaceable>] [<replaceable>remote_options</replaceable>]
34163427
[<replaceable>retention_options</replaceable>] [<replaceable>pinning_options</replaceable>] [<replaceable>logging_options</replaceable>]
34173428
</programlisting>
@@ -3564,6 +3575,18 @@ pg_probackup backup -B <replaceable>backup_dir</replaceable> -b <replaceable>bac
35643575
</para>
35653576
</listitem>
35663577
</varlistentry>
3578+
3579+
<varlistentry>
3580+
<term><option>--no-sync</option></term>
3581+
<listitem>
3582+
<para>
3583+
Do not sync backed up files to disk. You can use this flag to speed
3584+
up backup process. Using this flag can result in data
3585+
corruption in case of operating system or hardware crash.
3586+
Corruption can be detected by backup validation.
3587+
</para>
3588+
</listitem>
3589+
</varlistentry>
35673590
</variablelist>
35683591
</para>
35693592

@@ -3590,9 +3613,11 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
35903613
[--help] [-D <replaceable>data_dir</replaceable>] [-i <replaceable>backup_id</replaceable>]
35913614
[-j <replaceable>num_threads</replaceable>] [--progress]
35923615
[-T <replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable>] [--external-mapping=<replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable>] [--skip-external-dirs]
3593-
[-R | --restore-as-replica] [--no-validate] [--skip-block-validation] [--force]
3616+
[-R | --restore-as-replica] [--no-validate] [--skip-block-validation]
3617+
[--force] [--no-sync]
35943618
[--restore-command=<replaceable>cmdline</replaceable>]
35953619
[--primary-conninfo=<replaceable>primary_conninfo</replaceable>]
3620+
[-S | --primary-slot-name=<replaceable>slotname</replaceable>]
35963621
[<replaceable>recovery_target_options</replaceable>] [<replaceable>logging_options</replaceable>] [<replaceable>remote_options</replaceable>]
35973622
[<replaceable>partial_restore_options</replaceable>] [<replaceable>remote_wal_archive_options</replaceable>]
35983623
</programlisting>
@@ -3637,14 +3662,27 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
36373662
Sets the
36383663
<ulink url="https://postgrespro.com/docs/postgresql/current/runtime-config-replication.html#GUC-PRIMARY-CONNINFO">primary_conninfo</ulink>
36393664
parameter to the specified value.
3640-
This option will be ignored if used without the <option>-R</option> flag.
3665+
This option will be ignored unless the <option>-R</option> flag if specified.
36413666
</para>
36423667
<para>
36433668
Example: <literal>--primary-conninfo='host=192.168.1.50 port=5432 user=foo password=foopass'</literal>
36443669
</para>
36453670
</listitem>
36463671
</varlistentry>
36473672

3673+
<varlistentry>
3674+
<term><option>-S</option></term>
3675+
<term><option>--primary-slot-name=<replaceable>slot_name</replaceable></option></term>
3676+
<listitem>
3677+
<para>
3678+
Sets the
3679+
<ulink url="https://postgrespro.com/docs/postgresql/current/runtime-config-replication#GUC-PRIMARY-SLOT-NAME">primary_slot_name</ulink>
3680+
parameter to the specified value.
3681+
This option will be ignored unless the <option>-R</option> flag if specified.
3682+
</para>
3683+
</listitem>
3684+
</varlistentry>
3685+
36483686
<varlistentry>
36493687
<term><option>-T <replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable></option></term>
36503688
<term><option>--tablespace-mapping=<replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable></option></term>
@@ -3729,6 +3767,17 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
37293767
</para>
37303768
</listitem>
37313769
</varlistentry>
3770+
3771+
<varlistentry>
3772+
<term><option>--no-sync</option></term>
3773+
<listitem>
3774+
<para>
3775+
Do not sync restored files to disk. You can use this flag to speed
3776+
up restore process. Using this flag can result in data
3777+
corruption in case of operating system or hardware crash.
3778+
</para>
3779+
</listitem>
3780+
</varlistentry>
37323781
</variablelist>
37333782
</para>
37343783
<para>
@@ -3855,7 +3904,9 @@ pg_probackup merge -B <replaceable>backup_dir</replaceable> --instance <replacea
38553904
<para>
38563905
Merges the specified incremental backup to its parent full
38573906
backup, together with all incremental backups between them, if
3858-
any. As a result, the full backup takes in all the merged
3907+
any. If the specified backup ID belong to the full backup,
3908+
then it will be merged with the closest incremental backup.
3909+
As a result, the full backup takes in all the merged
38593910
data, and the incremental backups are removed as redundant.
38603911
</para>
38613912
<para>

src/archive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ get_wal_file(const char *from_path, const char *to_path)
479479
}
480480
}
481481

482-
if (fio_flush(out) != 0 || fio_close(out) != 0)
482+
if (fio_close(out) != 0)
483483
{
484484
errno_temp = errno;
485485
fio_unlink(to_path_temp, FIO_DB_HOST);
@@ -594,11 +594,11 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
594594
else
595595
#endif
596596
{
597-
crc2 = pgFileGetCRC(path2, true, true, NULL, FIO_BACKUP_HOST);
597+
crc2 = fio_get_crc32(path2, FIO_BACKUP_HOST);
598598
}
599599

600600
/* Get checksum of original file */
601-
crc1 = pgFileGetCRC(path1, true, true, NULL, FIO_DB_HOST);
601+
crc1 = fio_get_crc32(path1, FIO_DB_HOST);
602602

603603
return EQ_CRC32C(crc1, crc2);
604604
}

src/backup.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
575575
{
576576
parray *xlog_files_list;
577577
char pg_xlog_path[MAXPGPATH];
578+
char wal_full_path[MAXPGPATH];
578579

579580
/* Scan backup PG_XLOG_DIR */
580581
xlog_files_list = parray_new();
@@ -586,11 +587,13 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync)
586587
for (i = 0; i < parray_num(xlog_files_list); i++)
587588
{
588589
pgFile *file = (pgFile *) parray_get(xlog_files_list, i);
590+
591+
join_path_components(wal_full_path, pg_xlog_path, file->rel_path);
592+
589593
if (S_ISREG(file->mode))
590594
{
591-
file->crc = pgFileGetCRC(file->path, true, false,
592-
&file->read_size, FIO_BACKUP_HOST);
593-
file->write_size = file->read_size;
595+
file->crc = pgFileGetCRC(wal_full_path, true, false);
596+
file->write_size = file->size;
594597
}
595598
/* Remove file path root prefix*/
596599
if (strstr(file->path, database_path) == file->path)
@@ -1090,7 +1093,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
10901093

10911094
PQclear(res);
10921095

1093-
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE &&
1096+
if ((!stream_wal || current.backup_mode == BACKUP_MODE_DIFF_PAGE) &&
10941097
!backup->from_replica &&
10951098
!(nodeInfo->server_version < 90600 &&
10961099
!nodeInfo->is_superuser))
@@ -1102,17 +1105,14 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
11021105
*/
11031106
pg_switch_wal(conn);
11041107

1105-
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE)
1106-
/* In PAGE mode wait for current segment... */
1108+
/* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
1109+
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE ||!stream_wal)
1110+
/*
1111+
* Do not wait start_lsn for stream backup.
1112+
* Because WAL streaming will start after pg_start_backup() in stream
1113+
* mode.
1114+
*/
11071115
wait_wal_lsn(backup->start_lsn, true, backup->tli, false, true, ERROR, false);
1108-
/*
1109-
* Do not wait start_lsn for stream backup.
1110-
* Because WAL streaming will start after pg_start_backup() in stream
1111-
* mode.
1112-
*/
1113-
else if (!stream_wal)
1114-
/* ...for others wait for previous segment */
1115-
wait_wal_lsn(backup->start_lsn, true, backup->tli, true, true, ERROR, false);
11161116
}
11171117

11181118
/*
@@ -1805,10 +1805,11 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18051805
{
18061806
file = pgFileNew(backup_label, PG_BACKUP_LABEL_FILE, true, 0,
18071807
FIO_BACKUP_HOST);
1808-
file->crc = pgFileGetCRC(file->path, true, false,
1809-
&file->read_size, FIO_BACKUP_HOST);
1810-
file->write_size = file->read_size;
1811-
file->uncompressed_size = file->read_size;
1808+
1809+
file->crc = pgFileGetCRC(backup_label, true, false);
1810+
1811+
file->write_size = file->size;
1812+
file->uncompressed_size = file->size;
18121813
free(file->path);
18131814
file->path = strdup(PG_BACKUP_LABEL_FILE);
18141815
parray_append(backup_files_list, file);
@@ -1854,9 +1855,8 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18541855
FIO_BACKUP_HOST);
18551856
if (S_ISREG(file->mode))
18561857
{
1857-
file->crc = pgFileGetCRC(file->path, true, false,
1858-
&file->read_size, FIO_BACKUP_HOST);
1859-
file->write_size = file->read_size;
1858+
file->crc = pgFileGetCRC(tablespace_map, true, false);
1859+
file->write_size = file->size;
18601860
}
18611861
free(file->path);
18621862
file->path = strdup(PG_TABLESPACE_MAP_FILE);

0 commit comments

Comments
 (0)