Skip to content

Commit 59d0911

Browse files
author
itagaki.takahiro
committed
Fix a critical bug that pg_rman cannot restore database from incremental backup. Backup itself worked correctly, but restore command broke database files.
git-svn-id: http://pg-rman.googlecode.com/svn/trunk@25 182aca00-e38e-11de-a668-6fd11605f5ce
1 parent bc5717b commit 59d0911

File tree

9 files changed

+194
-195
lines changed

9 files changed

+194
-195
lines changed

backup.c

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void backup_cleanup(bool fatal, void *userdata);
3030
static void delete_old_files(const char *root, parray *files, int keep_files,
3131
int keep_days, int server_version, bool is_arclog);
3232
static void backup_files(const char *from_root, const char *to_root,
33-
parray *files, parray *prev_files, XLogRecPtr *lsn, bool compress_data);
33+
parray *files, parray *prev_files, const XLogRecPtr *lsn, bool compress);
3434
static parray *do_backup_database(parray *backup_list, bool smooth_checkpoint);
3535
static parray *do_backup_arclog(parray *backup_list);
3636
static parray *do_backup_srvlog(parray *backup_list);
@@ -137,7 +137,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
137137
files = parray_new();
138138
dir_list_file(files, pgdata, pgdata_exclude, true, false);
139139

140-
/* mark files as 'datafile' which are under base/global/pg_tblspc */
140+
/* mark files that are possible datafile as 'datafile' */
141141
for (i = 0; i < parray_num(files); i++)
142142
{
143143
pgFile *file = (pgFile *) parray_get(files, i);
@@ -148,7 +148,7 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
148148
if (!S_ISREG(file->mode))
149149
continue;
150150

151-
/* data files are under base/global/pg_tblspc */
151+
/* data files are under "base", "global", or "pg_tblspc" */
152152
relative = file->path + strlen(pgdata) + 1;
153153
if (!path_is_prefix_of_path("base", relative) &&
154154
!path_is_prefix_of_path("global", relative) &&
@@ -214,16 +214,16 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
214214
static parray *
215215
do_backup_arclog(parray *backup_list)
216216
{
217-
int i;
218-
parray *files;
219-
parray *prev_files = NULL; /* file list of previous database backup */
220-
FILE *fp;
221-
char path[MAXPGPATH];
222-
char timeline_dir[MAXPGPATH];
223-
char prev_file_txt[MAXPGPATH];
224-
pgBackup *prev_backup;
225-
int64 arclog_write_bytes = 0;
226-
char last_wal[MAXPGPATH];
217+
int i;
218+
parray *files;
219+
parray *prev_files = NULL; /* file list of previous database backup */
220+
FILE *fp;
221+
char path[MAXPGPATH];
222+
char timeline_dir[MAXPGPATH];
223+
char prev_file_txt[MAXPGPATH];
224+
pgBackup *prev_backup;
225+
int64 arclog_write_bytes = 0;
226+
char last_wal[MAXPGPATH];
227227

228228
if (!HAVE_ARCLOG(&current))
229229
return NULL;
@@ -345,14 +345,14 @@ do_backup_arclog(parray *backup_list)
345345
static parray *
346346
do_backup_srvlog(parray *backup_list)
347347
{
348-
int i;
349-
parray *files;
350-
parray *prev_files = NULL; /* file list of previous database backup */
351-
FILE *fp;
352-
char path[MAXPGPATH];
353-
char prev_file_txt[MAXPGPATH];
354-
pgBackup *prev_backup;
355-
int64 srvlog_write_bytes = 0;
348+
int i;
349+
parray *files;
350+
parray *prev_files = NULL; /* file list of previous database backup */
351+
FILE *fp;
352+
char path[MAXPGPATH];
353+
char prev_file_txt[MAXPGPATH];
354+
pgBackup *prev_backup;
355+
int64 srvlog_write_bytes = 0;
356356

357357
if (!current.with_serverlog)
358358
return NULL;
@@ -818,10 +818,14 @@ backup_cleanup(bool fatal, void *userdata)
818818

819819
/* take incremental backup. */
820820
static void
821-
backup_files(const char *from_root, const char *to_root, parray *files,
822-
parray *prev_files, XLogRecPtr *lsn, bool compress_data)
821+
backup_files(const char *from_root,
822+
const char *to_root,
823+
parray *files,
824+
parray *prev_files,
825+
const XLogRecPtr *lsn,
826+
bool compress)
823827
{
824-
int i;
828+
int i;
825829
struct timeval tv;
826830

827831
/* sort pathname ascending */
@@ -832,8 +836,9 @@ backup_files(const char *from_root, const char *to_root, parray *files,
832836
/* backup a file or create a directory */
833837
for (i = 0; i < parray_num(files); i++)
834838
{
835-
int ret;
836-
struct stat buf;
839+
int ret;
840+
struct stat buf;
841+
837842
pgFile *file = (pgFile *) parray_get(files, i);
838843

839844
/* check for interrupt */
@@ -869,6 +874,7 @@ backup_files(const char *from_root, const char *to_root, parray *files,
869874
if (S_ISDIR(buf.st_mode))
870875
{
871876
char dirpath[MAXPGPATH];
877+
872878
snprintf(dirpath, lengthof(dirpath), "%s/%s", to_root,
873879
file->path + strlen(from_root) + 1);
874880
if (!check)
@@ -918,7 +924,7 @@ backup_files(const char *from_root, const char *to_root, parray *files,
918924
/* copy the file into backup */
919925
if (file->is_datafile)
920926
{
921-
backup_data_file(from_root, to_root, file, lsn, compress_data);
927+
backup_data_file(from_root, to_root, file, lsn, compress);
922928
if (file->write_size == 0 && file->read_size > 0)
923929
{
924930
/* record as skipped file in file_xxx.txt */
@@ -930,7 +936,7 @@ backup_files(const char *from_root, const char *to_root, parray *files,
930936
}
931937
else
932938
copy_file(from_root, to_root, file,
933-
compress_data ? COMPRESSION : NO_COMPRESSION);
939+
compress ? COMPRESSION : NO_COMPRESSION);
934940

935941
if (verbose)
936942
{
@@ -965,11 +971,10 @@ delete_old_files(const char *root,
965971
int server_version,
966972
bool is_arclog)
967973
{
968-
int i;
969-
int j;
970-
int file_num = 0;
971-
time_t days_threashold =
972-
current.start_time - (keep_days * 60 * 60 * 24);
974+
int i;
975+
int j;
976+
int file_num = 0;
977+
time_t days_threshold = current.start_time - (keep_days * 60 * 60 * 24);
973978

974979
if (verbose)
975980
{
@@ -990,7 +995,7 @@ delete_old_files(const char *root,
990995
root, files_str, days_str);
991996
}
992997

993-
/* delete files which satisfy both condition */
998+
/* delete files which satisfy both conditions */
994999
if (keep_files == KEEP_INFINITE || keep_days == KEEP_INFINITE)
9951000
{
9961001
elog(LOG, "%s() infinite", __FUNCTION__);
@@ -1003,7 +1008,7 @@ delete_old_files(const char *root,
10031008
pgFile *file = (pgFile *) parray_get(files, i);
10041009

10051010
elog(LOG, "%s() %s", __FUNCTION__, file->path);
1006-
/* Delete complete WAL only. */
1011+
/* Delete completed WALs only. */
10071012
if (is_arclog && !xlog_is_complete_wal(file, server_version))
10081013
{
10091014
elog(LOG, "%s() not complete WAL", __FUNCTION__);
@@ -1013,17 +1018,17 @@ delete_old_files(const char *root,
10131018
file_num++;
10141019

10151020
/*
1016-
* If the mtime of the file is older than the threashold and there are
1021+
* If the mtime of the file is older than the threshold and there are
10171022
* enough number of files newer than the files, delete the file.
10181023
*/
1019-
if (file->mtime >= days_threashold)
1024+
if (file->mtime >= days_threshold)
10201025
{
10211026
elog(LOG, "%s() %lu is not older than %lu", __FUNCTION__,
1022-
file->mtime, days_threashold);
1027+
file->mtime, days_threshold);
10231028
continue;
10241029
}
10251030
elog(LOG, "%s() %lu is older than %lu", __FUNCTION__,
1026-
file->mtime, days_threashold);
1031+
file->mtime, days_threshold);
10271032

10281033
if (file_num <= keep_files)
10291034
{
@@ -1035,7 +1040,7 @@ delete_old_files(const char *root,
10351040
if (verbose)
10361041
printf(_("delete \"%s\"\n"), file->path + strlen(root) + 1);
10371042

1038-
/* delete corresponding backup history file if any */
1043+
/* delete corresponding backup history file if exists */
10391044
file = (pgFile *) parray_remove(files, i);
10401045
for (j = parray_num(files) - 1; j >= 0; j--)
10411046
{

catalog.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ catalog_get_backup_list(const pgBackupRange *range)
247247
pgBackup *
248248
catalog_get_last_data_backup(parray *backup_list)
249249
{
250-
int i;
251-
pgBackup *backup = NULL;
250+
int i;
251+
pgBackup *backup = NULL;
252252

253253
/* backup_list is sorted in order of descending ID */
254254
for (i = 0; i < parray_num(backup_list); i++)
@@ -269,8 +269,8 @@ catalog_get_last_data_backup(parray *backup_list)
269269
pgBackup *
270270
catalog_get_last_arclog_backup(parray *backup_list)
271271
{
272-
int i;
273-
pgBackup *backup = NULL;
272+
int i;
273+
pgBackup *backup = NULL;
274274

275275
/* backup_list is sorted in order of descending ID */
276276
for (i = 0; i < parray_num(backup_list); i++)

0 commit comments

Comments
 (0)