Skip to content

Commit 2b4c33e

Browse files
author
itagaki.takahiro
committed
Fix a bug to handle deleted files during backup. We should skipp those missing files during validation and restore.
git-svn-id: http://pg-rman.googlecode.com/svn/trunk@30 182aca00-e38e-11de-a668-6fd11605f5ce
1 parent 18b133c commit 2b4c33e

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

backup.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,10 @@ backup_files(const char *from_root,
856856
{
857857
if (errno == ENOENT)
858858
{
859+
/* record as skipped file in file_xxx.txt */
860+
file->write_size = BYTES_INVALID;
859861
if (verbose)
860-
printf(_("deleted\n"));
862+
printf(_("skip\n"));
861863
continue;
862864
}
863865
else
@@ -921,21 +923,17 @@ backup_files(const char *from_root,
921923
}
922924

923925
/* copy the file into backup */
924-
if (file->is_datafile)
926+
if (!(file->is_datafile
927+
? backup_data_file(from_root, to_root, file, lsn, compress)
928+
: copy_file(from_root, to_root, file,
929+
compress ? COMPRESSION : NO_COMPRESSION)))
925930
{
926-
backup_data_file(from_root, to_root, file, lsn, compress);
927-
if (file->write_size == 0 && file->read_size > 0)
928-
{
929-
/* record as skipped file in file_xxx.txt */
930-
file->write_size = BYTES_INVALID;
931-
if (verbose)
932-
printf(_("skip\n"));
933-
continue;
934-
}
931+
/* record as skipped file in file_xxx.txt */
932+
file->write_size = BYTES_INVALID;
933+
if (verbose)
934+
printf(_("skip\n"));
935+
continue;
935936
}
936-
else
937-
copy_file(from_root, to_root, file,
938-
compress ? COMPRESSION : NO_COMPRESSION);
939937

940938
if (verbose)
941939
{

data.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ parse_page(const DataPage *page, int server_version,
272272
* If lsn is not NULL, pages only which are modified after the lsn will be
273273
* copied.
274274
*/
275-
void
275+
bool
276276
backup_data_file(const char *from_root, const char *to_root,
277277
pgFile *file, const XLogRecPtr *lsn, bool compress)
278278
{
@@ -291,13 +291,22 @@ backup_data_file(const char *from_root, const char *to_root,
291291
char outbuf[zlibOutSize];
292292
#endif
293293

294+
INIT_CRC32(crc);
295+
296+
/* reset size summary */
297+
file->read_size = 0;
298+
file->write_size = 0;
299+
294300
/* open backup mode file for read */
295301
in = fopen(file->path, "r");
296302
if (in == NULL)
297303
{
298-
/* meybe vanished, it's not error */
304+
FIN_CRC32(crc);
305+
file->crc = crc;
306+
307+
/* maybe vanished, it's not error */
299308
if (errno == ENOENT)
300-
return;
309+
return false;
301310

302311
elog(ERROR_SYSTEM, _("can't open backup mode file \"%s\": %s"),
303312
file->path, strerror(errno));
@@ -317,12 +326,6 @@ backup_data_file(const char *from_root, const char *to_root,
317326
to_path, strerror(errno_tmp));
318327
}
319328

320-
INIT_CRC32(crc);
321-
322-
/* reset size summary */
323-
file->read_size = 0;
324-
file->write_size = 0;
325-
326329
#ifdef HAVE_LIBZ
327330
if (compress)
328331
{
@@ -365,9 +368,8 @@ backup_data_file(const char *from_root, const char *to_root,
365368
fclose(in);
366369
fclose(out);
367370
file->is_datafile = false;
368-
copy_file(from_root, to_root, file,
369-
compress ? COMPRESSION : NO_COMPRESSION);
370-
return;
371+
return copy_file(from_root, to_root, file,
372+
compress ? COMPRESSION : NO_COMPRESSION);
371373
}
372374

373375
file->read_size += read_len;
@@ -540,13 +542,18 @@ backup_data_file(const char *from_root, const char *to_root,
540542

541543
/* We do not backup if all pages skipped. */
542544
if (file->write_size == 0 && file->read_size > 0)
545+
{
543546
if (remove(to_path) == -1)
544547
elog(ERROR_SYSTEM, _("can't remove file \"%s\": %s"), to_path,
545548
strerror(errno));
549+
return false;
550+
}
546551

547552
/* remove $BACKUP_PATH/tmp created during check */
548553
if (check)
549554
remove(to_path);
555+
556+
return true;
550557
}
551558

552559
/*
@@ -746,7 +753,7 @@ restore_data_file(const char *from_root,
746753
fclose(out);
747754
}
748755

749-
void
756+
bool
750757
copy_file(const char *from_root, const char *to_root, pgFile *file,
751758
CompressionMode mode)
752759
{
@@ -765,13 +772,22 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
765772
char inbuf[zlibInSize];
766773
#endif
767774

775+
INIT_CRC32(crc);
776+
777+
/* reset size summary */
778+
file->read_size = 0;
779+
file->write_size = 0;
780+
768781
/* open backup mode file for read */
769782
in = fopen(file->path, "r");
770783
if (in == NULL)
771784
{
772-
/* meybe deleted, it's not error */
785+
FIN_CRC32(crc);
786+
file->crc = crc;
787+
788+
/* maybe deleted, it's not error */
773789
if (errno == ENOENT)
774-
return;
790+
return false;
775791

776792
elog(ERROR_SYSTEM, _("can't open source file \"%s\": %s"), file->path,
777793
strerror(errno));
@@ -798,12 +814,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
798814
strerror(errno));
799815
}
800816

801-
INIT_CRC32(crc);
802-
803-
/* reset size summary */
804-
file->read_size = 0;
805-
file->write_size = 0;
806-
807817
#ifdef HAVE_LIBZ
808818
z.zalloc = Z_NULL;
809819
z.zfree = Z_NULL;
@@ -962,4 +972,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
962972

963973
if (check)
964974
remove(to_path);
975+
976+
return true;
965977
}

pg_rman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ extern bool xlog_logfname2lsn(const char *logfname, XLogRecPtr *lsn);
249249
extern void xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn);
250250

251251
/* in data.c */
252-
extern void backup_data_file(const char *from_root, const char *to_root,
252+
extern bool backup_data_file(const char *from_root, const char *to_root,
253253
pgFile *file, const XLogRecPtr *lsn, bool compress);
254254
extern void restore_data_file(const char *from_root, const char *to_root,
255255
pgFile *file, bool compress);
256-
extern void copy_file(const char *from_root, const char *to_root,
256+
extern bool copy_file(const char *from_root, const char *to_root,
257257
pgFile *file, CompressionMode compress);
258258

259259
/* in util.c */

0 commit comments

Comments
 (0)