Skip to content

Commit 8b45e97

Browse files
committed
Merge branch 'master' into stable
2 parents 1795815 + 4d478e3 commit 8b45e97

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

+1957
-826
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PROGRAM = pg_probackup
22
OBJS = src/backup.o src/catalog.o src/configure.o src/data.o \
33
src/delete.o src/dir.o src/fetch.o src/help.o src/init.o \
4-
src/pg_probackup.o src/restore.o src/show.o src/status.o \
4+
src/pg_probackup.o src/restore.o src/show.o \
55
src/util.o src/validate.o src/datapagemap.o src/parsexlog.o \
66
src/xlogreader.o src/streamutil.o src/receivelog.o \
77
src/archive.o src/utils/parray.o src/utils/pgut.o src/utils/logger.o \
@@ -38,7 +38,7 @@ EXTRA_CLEAN += src/walmethods.c src/walmethods.h
3838
INCLUDES += src/walmethods.h
3939
endif
4040

41-
PG_CPPFLAGS = -I$(libpq_srcdir) ${PTHREAD_CFLAGS} -Isrc
41+
PG_CPPFLAGS = -I$(libpq_srcdir) ${PTHREAD_CFLAGS} -Isrc -I$(top_srcdir)/$(subdir)/src
4242
override CPPFLAGS := -DFRONTEND $(CPPFLAGS) $(PG_CPPFLAGS)
4343
PG_LIBS = $(libpq_pgport) ${PTHREAD_CFLAGS}
4444

gen_probackup_project.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ sub build_pgprobackup
145145
'pg_probackup.c',
146146
'restore.c',
147147
'show.c',
148-
'status.c',
149148
'util.c',
150149
'validate.c'
151150
);

src/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*
88
*-------------------------------------------------------------------------
99
*/
10+
1011
#include "pg_probackup.h"
1112

1213
#include <unistd.h>
13-
#include <sys/stat.h>
1414

1515
/*
1616
* pg_probackup specific archive command for archive backups

src/backup.c

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@
1010

1111
#include "pg_probackup.h"
1212

13-
#include <stdio.h>
14-
#include <stdlib.h>
15-
#include <string.h>
16-
#include <sys/stat.h>
17-
#include <sys/time.h>
18-
#include <unistd.h>
19-
#include <dirent.h>
20-
#include <time.h>
21-
13+
#if PG_VERSION_NUM < 110000
2214
#include "catalog/catalog.h"
15+
#endif
2316
#include "catalog/pg_tablespace.h"
24-
#include "datapagemap.h"
25-
#include "libpq/pqsignal.h"
2617
#include "pgtar.h"
2718
#include "receivelog.h"
28-
#include "storage/bufpage.h"
2919
#include "streamutil.h"
20+
21+
#include <sys/stat.h>
22+
#include <unistd.h>
23+
3024
#include "utils/thread.h"
3125

26+
#define PG_STOP_BACKUP_TIMEOUT 300
27+
28+
/*
29+
* Macro needed to parse ptrack.
30+
* NOTE Keep those values syncronised with definitions in ptrack.h
31+
*/
32+
#define PTRACK_BITS_PER_HEAPBLOCK 1
33+
#define HEAPBLOCKS_PER_BYTE (BITS_PER_BYTE / PTRACK_BITS_PER_HEAPBLOCK)
34+
3235
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
3336
static XLogRecPtr stop_backup_lsn = InvalidXLogRecPtr;
3437
static XLogRecPtr stop_stream_lsn = InvalidXLogRecPtr;
@@ -531,7 +534,7 @@ do_backup_instance(void)
531534
prev_backup_start_lsn = prev_backup->start_lsn;
532535
current.parent_backup = prev_backup->start_time;
533536

534-
pgBackupWriteBackupControlFile(&current);
537+
write_backup(&current);
535538
}
536539

537540
/*
@@ -906,11 +909,13 @@ do_backup(time_t start_time)
906909
/* Start backup. Update backup status. */
907910
current.status = BACKUP_STATUS_RUNNING;
908911
current.start_time = start_time;
912+
StrNCpy(current.program_version, PROGRAM_VERSION,
913+
sizeof(current.program_version));
909914

910915
/* Create backup directory and BACKUP_CONTROL_FILE */
911916
if (pgBackupCreateDir(&current))
912917
elog(ERROR, "cannot create backup directory");
913-
pgBackupWriteBackupControlFile(&current);
918+
write_backup(&current);
914919

915920
elog(LOG, "Backup destination is initialized");
916921

@@ -932,7 +937,7 @@ do_backup(time_t start_time)
932937
/* Backup is done. Update backup status */
933938
current.end_time = time(NULL);
934939
current.status = BACKUP_STATUS_DONE;
935-
pgBackupWriteBackupControlFile(&current);
940+
write_backup(&current);
936941

937942
//elog(LOG, "Backup completed. Total bytes : " INT64_FORMAT "",
938943
// current.data_bytes);
@@ -2010,7 +2015,7 @@ backup_cleanup(bool fatal, void *userdata)
20102015
base36enc(current.start_time));
20112016
current.end_time = time(NULL);
20122017
current.status = BACKUP_STATUS_ERROR;
2013-
pgBackupWriteBackupControlFile(&current);
2018+
write_backup(&current);
20142019
}
20152020

20162021
/*
@@ -2096,12 +2101,13 @@ backup_files(void *arg)
20962101

20972102
if (S_ISREG(buf.st_mode))
20982103
{
2104+
pgFile **prev_file;
2105+
20992106
/* Check that file exist in previous backup */
21002107
if (current.backup_mode != BACKUP_MODE_FULL)
21012108
{
21022109
char *relative;
21032110
pgFile key;
2104-
pgFile **prev_file;
21052111

21062112
relative = GetRelativePath(file->path, arguments->from_root);
21072113
key.path = relative;
@@ -2131,20 +2137,27 @@ backup_files(void *arg)
21312137
continue;
21322138
}
21332139
}
2134-
/* TODO:
2135-
* Check if file exists in previous backup
2136-
* If exists:
2137-
* if mtime > start_backup_time of parent backup,
2138-
* copy file to backup
2139-
* if mtime < start_backup_time
2140-
* calculate crc, compare crc to old file
2141-
* if crc is the same -> skip file
2142-
*/
2143-
else if (!copy_file(arguments->from_root, arguments->to_root, file))
2140+
else
21442141
{
2145-
file->write_size = BYTES_INVALID;
2146-
elog(VERBOSE, "File \"%s\" was not copied to backup", file->path);
2147-
continue;
2142+
bool skip = false;
2143+
2144+
/* If non-data file has not changed since last backup... */
2145+
if (file->exists_in_prev &&
2146+
buf.st_mtime < current.parent_backup)
2147+
{
2148+
calc_file_checksum(file);
2149+
/* ...and checksum is the same... */
2150+
if (EQ_CRC32C(file->crc, (*prev_file)->crc))
2151+
skip = true; /* ...skip copying file. */
2152+
}
2153+
if (skip ||
2154+
!copy_file(arguments->from_root, arguments->to_root, file))
2155+
{
2156+
file->write_size = BYTES_INVALID;
2157+
elog(VERBOSE, "File \"%s\" was not copied to backup",
2158+
file->path);
2159+
continue;
2160+
}
21482161
}
21492162

21502163
elog(VERBOSE, "File \"%s\". Copied "INT64_FORMAT " bytes",

src/catalog.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111
#include "pg_probackup.h"
1212

1313
#include <dirent.h>
14-
#include <fcntl.h>
1514
#include <signal.h>
16-
#include <sys/file.h>
1715
#include <sys/stat.h>
18-
#include <sys/types.h>
19-
#include <stdlib.h>
20-
#include <time.h>
2116
#include <unistd.h>
2217

2318
static const char *backupModes[] = {"", "PAGE", "PTRACK", "DELTA", "FULL"};
@@ -221,6 +216,25 @@ read_backup(time_t timestamp)
221216
return readBackupControlFile(conf_path);
222217
}
223218

219+
/*
220+
* Save the backup status into BACKUP_CONTROL_FILE.
221+
*
222+
* We need to reread the backup using its ID and save it changing only its
223+
* status.
224+
*/
225+
void
226+
write_backup_status(pgBackup *backup)
227+
{
228+
pgBackup *tmp;
229+
230+
tmp = read_backup(backup->start_time);
231+
232+
tmp->status = backup->status;
233+
write_backup(tmp);
234+
235+
pgBackupFree(tmp);
236+
}
237+
224238
/*
225239
* Get backup_mode in string representation.
226240
*/
@@ -431,7 +445,8 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
431445
fprintf(out, "block-size = %u\n", backup->block_size);
432446
fprintf(out, "xlog-block-size = %u\n", backup->wal_block_size);
433447
fprintf(out, "checksum-version = %u\n", backup->checksum_version);
434-
fprintf(out, "program-version = %s\n", PROGRAM_VERSION);
448+
if (backup->program_version[0] != '\0')
449+
fprintf(out, "program-version = %s\n", backup->program_version);
435450
if (backup->server_version[0] != '\0')
436451
fprintf(out, "server-version = %s\n", backup->server_version);
437452

@@ -481,17 +496,19 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
481496
fprintf(out, "primary_conninfo = '%s'\n", backup->primary_conninfo);
482497
}
483498

484-
/* create BACKUP_CONTROL_FILE */
499+
/*
500+
* Save the backup content into BACKUP_CONTROL_FILE.
501+
*/
485502
void
486-
pgBackupWriteBackupControlFile(pgBackup *backup)
503+
write_backup(pgBackup *backup)
487504
{
488505
FILE *fp = NULL;
489-
char ini_path[MAXPGPATH];
506+
char conf_path[MAXPGPATH];
490507

491-
pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_CONTROL_FILE);
492-
fp = fopen(ini_path, "wt");
508+
pgBackupGetPath(backup, conf_path, lengthof(conf_path), BACKUP_CONTROL_FILE);
509+
fp = fopen(conf_path, "wt");
493510
if (fp == NULL)
494-
elog(ERROR, "cannot open configuration file \"%s\": %s", ini_path,
511+
elog(ERROR, "Cannot open configuration file \"%s\": %s", conf_path,
495512
strerror(errno));
496513

497514
pgBackupWriteControl(fp, backup);

src/configure.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
*/
99

1010
#include "pg_probackup.h"
11-
#include "utils/logger.h"
12-
13-
#include "pqexpbuffer.h"
1411

1512
#include "utils/json.h"
1613

0 commit comments

Comments
 (0)