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"));

0 commit comments

Comments
 (0)