Skip to content

Commit db249c8

Browse files
author
Michael Paquier
committed
Replace incremental backup by page-level differential backup
This will allow the introduction of file-level differential backup.
1 parent a1de8d6 commit db249c8

File tree

15 files changed

+53
-52
lines changed

15 files changed

+53
-52
lines changed

README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ pg_arman
22
========
33

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

backup.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
9393
current.tli = get_current_timeline();
9494

9595
/*
96-
* In incremental backup mode, check if there is an already-validated
96+
* In differential backup mode, check if there is an already-validated
9797
* full backup on current timeline.
9898
*/
99-
if (current.backup_mode == BACKUP_MODE_INCREMENTAL)
99+
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE)
100100
{
101101
pgBackup *prev_backup;
102102

103103
prev_backup = catalog_get_last_data_backup(backup_list, current.tli);
104104
if (prev_backup == NULL)
105105
elog(ERROR_SYSTEM, _("Valid full backup not found for "
106-
"incremental backup. Either create a full backup "
106+
"differential backup. Either create a full backup "
107107
"or validate existing one."));
108108
}
109109

@@ -154,10 +154,10 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
154154
files = NULL;
155155

156156
/*
157-
* To take incremental backup, the file list of the last completed database
157+
* To take differential backup, the file list of the last completed database
158158
* backup is needed.
159159
*/
160-
if (current.backup_mode == BACKUP_MODE_INCREMENTAL)
160+
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE)
161161
{
162162
pgBackup *prev_backup;
163163

@@ -287,7 +287,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
287287
elog(ERROR_SYSTEM, _("tablespace storage directory doesn't exist: %s"), mp);
288288

289289
/*
290-
* create the previous backup file list to take incremental backup
290+
* create the previous backup file list to take differential backup
291291
* from the snapshot volume.
292292
*/
293293
if (prev_files != NULL)
@@ -392,10 +392,10 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
392392
continue;
393393
/*
394394
* Count only the amount of data. For a full backup, the total
395-
* amount of data written counts while for an incremental
395+
* amount of data written counts while for an differential
396396
* backup only the data read counts.
397397
*/
398-
if (current.backup_mode == BACKUP_MODE_INCREMENTAL)
398+
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE)
399399
current.data_bytes += file->read_size;
400400
else if (current.backup_mode == BACKUP_MODE_FULL)
401401
current.data_bytes += file->size;
@@ -514,7 +514,7 @@ do_backup(pgBackupOption bkupopt)
514514

515515
/* Database data */
516516
if (current.backup_mode == BACKUP_MODE_FULL ||
517-
current.backup_mode == BACKUP_MODE_INCREMENTAL)
517+
current.backup_mode == BACKUP_MODE_DIFF_PAGE)
518518
total_read += current.data_bytes;
519519

520520
if (total_read == 0)
@@ -821,7 +821,9 @@ backup_cleanup(bool fatal, void *userdata)
821821
}
822822
}
823823

824-
/* take incremental backup. */
824+
/*
825+
* Take differential backup at page level.
826+
*/
825827
static void
826828
backup_files(const char *from_root,
827829
const char *to_root,

catalog.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ catalog_get_last_data_backup(parray *backup_list, TimeLineID tli)
256256

257257
/*
258258
* We need completed database backup in the case of a full or
259-
* incremental backup on current timeline.
259+
* differential backup on current timeline.
260260
*/
261261
if (backup->status == BACKUP_STATUS_OK &&
262262
backup->tli == tli &&
263-
(backup->backup_mode == BACKUP_MODE_INCREMENTAL ||
263+
(backup->backup_mode == BACKUP_MODE_DIFF_PAGE ||
264264
backup->backup_mode == BACKUP_MODE_FULL))
265265
return backup;
266266
}
@@ -295,7 +295,7 @@ pgBackupCreateDir(pgBackup *backup)
295295
void
296296
pgBackupWriteConfigSection(FILE *out, pgBackup *backup)
297297
{
298-
static const char *modes[] = { "", "INCREMENTAL", "FULL"};
298+
static const char *modes[] = { "", "PAGE", "FULL"};
299299

300300
fprintf(out, "# configuration\n");
301301

@@ -488,10 +488,10 @@ parse_backup_mode(const char *value)
488488
v++;
489489
len = strlen(v);
490490

491-
if (len > 0 && pg_strncasecmp("full", v, len) == 0)
491+
if (len > 0 && pg_strncasecmp("full", v, strlen("full")) == 0)
492492
return BACKUP_MODE_FULL;
493-
else if (len > 0 && pg_strncasecmp("incremental", v, len) == 0)
494-
return BACKUP_MODE_INCREMENTAL;
493+
else if (len > 0 && pg_strncasecmp("page", v, strlen("page")) == 0)
494+
return BACKUP_MODE_DIFF_PAGE;
495495

496496
/* Backup mode is invalid, so leave with an error */
497497
elog(ERROR_ARGS, _("invalid backup-mode \"%s\""), value);

data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ restore_data_file(const char *from_root,
526526

527527
/*
528528
* Open backup file for write. We use "r+" at first to overwrite only
529-
* modified pages for incremental restore. If the file is not exists,
529+
* modified pages for differential restore. If the file is not exists,
530530
* re-open it with "w" to create an empty file.
531531
*/
532532
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
@@ -652,7 +652,7 @@ restore_data_file(const char *from_root,
652652

653653
/*
654654
* Seek and write the restored page. Backup might have holes in
655-
* incremental backups.
655+
* differential backups.
656656
*/
657657
blknum = header.block;
658658
if (fseek(out, blknum * BLCKSZ, SEEK_SET) < 0)

data/sample_backup/20090601/170553/backup.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# configuration
2-
BACKUP_MODE=INCREMENTAL
2+
BACKUP_MODE=PAGE
33
COMPRESS_DATA=NO
44
# result
55
TIMELINEID=1

doc/pg_arman.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It proposes the following features:
2828
command
2929
- Recovery from backup with just one command, with customized targets
3030
to facilitate the use of PITR.
31-
- Support for full and incremental
31+
- Support for full and differential backup
3232
- Compression of backup files
3333
- Management of backups with integrated catalog
3434

@@ -72,11 +72,11 @@ specify it in PGDATA environmental variable or -D/--pgdata option.
7272
Backup target can be one of the following types:
7373

7474
- Full backup, backup a whole database cluster.
75-
- Incremental backup, backup only files or pages modified after the last
75+
- Differential backup, backup only files or pages modified after the last
7676
verified backup.
7777

7878
It is recommended to verify backup files as soon as possible after backup.
79-
Unverified backup cannot be used in restore and in incremental backup.
79+
Unverified backup cannot be used in restore and in differential backup.
8080

8181
=== RESTORE ===
8282

@@ -140,7 +140,7 @@ Here are some commands to restore from a backup:
140140
The fields are:
141141

142142
* Start: start time of backup
143-
* Mode: Mode of backup: FULL (full) or INCR (incremental)
143+
* Mode: Mode of backup: FULL (full) or PAGE (page differential)
144144
* Current TLI: current timeline of backup
145145
* Parent TLI: parent timeline of backup
146146
* Time: total time necessary to take this backup
@@ -214,8 +214,7 @@ absolute paths; relative paths are not allowed.
214214

215215
*-b* _BACKUPMODE_ / *--backup-mode*=_BACKUPMODE_::
216216
Specify backup target files. Available options are: "full",
217-
"incremental". Abbreviated forms (prefix match) are also available.
218-
For example, -b f means "full" backup.
217+
"page".
219218

220219
*-Z* / *--compress-data*::
221220
Compress backup files with zlib if specified.
@@ -350,7 +349,7 @@ pg_arman has the following restrictions.
350349
- If there are some unreadable files/directories in data folder of server
351350
WAL directory or archived WAL directory, the backup or restore will fail
352351
depending on the backup mode selected.
353-
- Incremental backup is not able to take necessary files after a database
352+
- Differential backup is not able to take necessary files after a database
354353
creation, so take a full backup once a new database is created.
355354

356355
== DETAILS ==

expected/backup_restore.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE DATABASE
55
0
66
full database backup
77
CHECKPOINT
8-
incremental database backup
8+
differential database backup
99
CHECKPOINT
1010
CHECKPOINT
1111
stop DB during running pgbench

expected/option.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Common Options:
1717
-v, --verbose output process information
1818

1919
Backup options:
20-
-b, --backup-mode=MODE full or incremental
20+
-b, --backup-mode=MODE full or page
2121
-Z, --compress-data compress data backup with zlib
2222
-C, --smooth-checkpoint do smooth checkpoint before backup
2323
--validate validate backup after taking it

expected/show_validate.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Start Mode Current TLI Parent TLI Time Data Status
77
==========================================================================
88
2009-06-03 17:05:53 FULL 1 0 0m ---- RUNNING
9-
2009-06-01 17:05:53 INCR 1 0 3m 9223PB DONE
9+
2009-06-01 17:05:53 PAGE 1 0 3m 9223PB DONE
1010
2009-05-31 17:05:53 FULL 1 0 3m 1242MB DONE
1111
\! pg_arman validate -B ${PWD}/results/sample_backup 2009-05-31 17:05:53 --debug
1212
INFO: validate: 2009-05-31 17:05:53 backup and archive log files by CRC
@@ -25,11 +25,11 @@ Start Mode Current TLI Parent TLI Time Data Status
2525
==========================================================================
2626
2009-06-03 17:05:53 FULL 1 0 0m ---- RUNNING
2727
2009-06-02 17:05:03 FULL 1 0 0m ---- DELETED
28-
2009-06-01 17:05:53 INCR 1 0 3m 9223PB CORRUPT
28+
2009-06-01 17:05:53 PAGE 1 0 3m 9223PB CORRUPT
2929
2009-05-31 17:05:53 FULL 1 0 3m 1242MB OK
3030
\! pg_arman show 2009-06-01 17:05:53 -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup
3131
# configuration
32-
BACKUP_MODE=INCREMENTAL
32+
BACKUP_MODE=PAGE
3333
COMPRESS_DATA=false
3434
# result
3535
TIMELINEID=1

pg_arman.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pgut_help(bool details)
217217
printf(_(" -c, --check show what would have been done\n"));
218218
printf(_(" -v, --verbose output process information\n"));
219219
printf(_("\nBackup options:\n"));
220-
printf(_(" -b, --backup-mode=MODE full or incremental\n"));
220+
printf(_(" -b, --backup-mode=MODE full or page\n"));
221221
printf(_(" -Z, --compress-data compress data backup with zlib\n"));
222222
printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));
223223
printf(_(" --validate validate backup after taking it\n"));

pg_arman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef enum BackupStatus
110110
typedef enum BackupMode
111111
{
112112
BACKUP_MODE_INVALID,
113-
BACKUP_MODE_INCREMENTAL, /* incremental backup */
113+
BACKUP_MODE_DIFF_PAGE, /* differential page backup */
114114
BACKUP_MODE_FULL /* full backup */
115115
} BackupMode;
116116

@@ -140,7 +140,7 @@ typedef struct pgBackup
140140
/* Different sizes (-1 means nothing was backed up) */
141141
/*
142142
* Amount of raw data. For a full backup, this is the total amount of
143-
* data while for an incremental backup this is just the differential
143+
* data while for a differential backup this is just the difference
144144
* of data taken.
145145
*/
146146
int64 data_bytes;

restore.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ do_restore(const char *target_time,
174174

175175
last_restored_index = base_index;
176176

177-
/* restore following incremental backup */
177+
/* restore following differential backup */
178178
if (verbose)
179-
printf(_("searching incremental backup...\n"));
179+
printf(_("searching differential backup...\n"));
180180
for (i = base_index - 1; i >= 0; i--)
181181
{
182182
pgBackup *backup = (pgBackup *) parray_get(backups, i);
@@ -187,7 +187,7 @@ do_restore(const char *target_time,
187187
continue;
188188

189189
/* use database backup only */
190-
if (backup->backup_mode != BACKUP_MODE_INCREMENTAL)
190+
if (backup->backup_mode != BACKUP_MODE_DIFF_PAGE)
191191
continue;
192192

193193
/* is the backup is necessary for restore to target timeline ? */

show.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
177177
for (i = 0; i < parray_num(backup_list); i++)
178178
{
179179
pgBackup *backup;
180-
const char *modes[] = { "", "INCR", "FULL"};
180+
const char *modes[] = { "", "PAGE", "FULL"};
181181
TimeLineID parent_tli;
182182
char timestamp[20];
183183
char duration[20] = "----";
@@ -196,8 +196,8 @@ show_backup_list(FILE *out, parray *backup_list, bool show_all)
196196

197197
/*
198198
* Calculate Data field, in the case of full backup this shows the
199-
* total amount of data. For an incremental backup, this size is only
200-
* the differential of data accumulated.
199+
* total amount of data. For an differential backup, this size is only
200+
* the difference of data accumulated.
201201
*/
202202
pretty_size(backup->data_bytes, data_bytes_str,
203203
lengthof(data_bytes_str));

sql/backup_restore.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,19 @@ psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
112112
pg_arman -w -p $TEST_PGPORT backup --verbose -d postgres > $BASE_PATH/results/log_full_1 2>&1
113113

114114
pgbench -p $TEST_PGPORT -T $DURATION -c 10 pgbench >> $BASE_PATH/results/pgbench.log 2>&1
115-
echo "incremental database backup"
115+
echo "differential database backup"
116116
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
117-
#pg_arman -p $TEST_PGPORT backup -b i --verbose -d postgres > $BASE_PATH/results/log_incr1 2>&1
118-
pg_arman -w -p $TEST_PGPORT backup -b i --verbose -d postgres > $BASE_PATH/results/log_incr1 2>&1
117+
#pg_arman -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr1 2>&1
118+
pg_arman -w -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr1 2>&1
119119

120120
# validate all backup
121121
pg_arman validate `date +%Y` --verbose > $BASE_PATH/results/log_validate1 2>&1
122122
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show0 2>&1
123123
pg_dumpall > $BASE_PATH/results/dump_before_rtx.sql
124124
target_xid=`psql --no-psqlrc -p $TEST_PGPORT pgbench -tAq -c "INSERT INTO pgbench_history VALUES (1) RETURNING(xmin);"`
125125
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
126-
#pg_arman -p $TEST_PGPORT backup -b i --verbose -d postgres > $BASE_PATH/results/log_incr2 2>&1
127-
pg_arman -w -p $TEST_PGPORT backup -b i --verbose -d postgres > $BASE_PATH/results/log_incr2 2>&1
126+
#pg_arman -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr2 2>&1
127+
pg_arman -w -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr2 2>&1
128128

129129
pgbench -p $TEST_PGPORT -T $DURATION -c 10 pgbench >> $BASE_PATH/results/pgbench.log 2>&1
130130

@@ -185,8 +185,8 @@ diff $BASE_PATH/results/dump_before.sql $BASE_PATH/results/dump_after.sql
185185
# incrementa backup can't find last full backup because new timeline started.
186186
echo "full database backup after recovery"
187187
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
188-
#pg_arman -p $TEST_PGPORT backup -b f --verbose -d postgres > $BASE_PATH/results/log_full2 2>&1
189-
pg_arman -w -p $TEST_PGPORT backup -b f --verbose -d postgres > $BASE_PATH/results/log_full2 2>&1
188+
#pg_arman -p $TEST_PGPORT backup -b full --verbose -d postgres > $BASE_PATH/results/log_full2 2>&1
189+
pg_arman -w -p $TEST_PGPORT backup -b full --verbose -d postgres > $BASE_PATH/results/log_full2 2>&1
190190

191191
# Symbolic links in $ARCLOG_PATH should be deleted.
192192
echo "# of symbolic links in ARCLOG_PATH"

validate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ pgBackupValidate(pgBackup *backup,
8181
if (!for_get_timeline)
8282
{
8383
if (backup->backup_mode == BACKUP_MODE_FULL ||
84-
backup->backup_mode == BACKUP_MODE_INCREMENTAL)
84+
backup->backup_mode == BACKUP_MODE_DIFF_PAGE)
8585
elog(INFO, "validate: %s backup and archive log files by %s",
8686
timestamp, (size_only ? "SIZE" : "CRC"));
8787
}
8888

8989
if (!check)
9090
{
9191
if (backup->backup_mode == BACKUP_MODE_FULL ||
92-
backup->backup_mode == BACKUP_MODE_INCREMENTAL)
92+
backup->backup_mode == BACKUP_MODE_DIFF_PAGE)
9393
{
9494
elog(LOG, "database files...");
9595
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
@@ -143,7 +143,7 @@ pgBackupValidateFiles(parray *files, const char *root, bool size_only)
143143
if (interrupted)
144144
elog(ERROR_INTERRUPTED, _("interrupted during validate"));
145145

146-
/* skipped backup while incremental backup */
146+
/* skipped backup while differential backup */
147147
if (file->write_size == BYTES_INVALID || !S_ISREG(file->mode))
148148
continue;
149149

0 commit comments

Comments
 (0)