1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2026-06-21 01:34:15 +02:00

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
This commit is contained in:
itagaki.takahiro
2010-01-21 08:40:29 +00:00
parent 18b133c544
commit 2b4c33e263
3 changed files with 47 additions and 37 deletions
+7 -9
View File
@@ -856,8 +856,10 @@ backup_files(const char *from_root,
{ {
if (errno == ENOENT) if (errno == ENOENT)
{ {
/* record as skipped file in file_xxx.txt */
file->write_size = BYTES_INVALID;
if (verbose) if (verbose)
printf(_("deleted\n")); printf(_("skip\n"));
continue; continue;
} }
else else
@@ -921,10 +923,10 @@ backup_files(const char *from_root,
} }
/* copy the file into backup */ /* copy the file into backup */
if (file->is_datafile) if (!(file->is_datafile
{ ? backup_data_file(from_root, to_root, file, lsn, compress)
backup_data_file(from_root, to_root, file, lsn, compress); : copy_file(from_root, to_root, file,
if (file->write_size == 0 && file->read_size > 0) compress ? COMPRESSION : NO_COMPRESSION)))
{ {
/* record as skipped file in file_xxx.txt */ /* record as skipped file in file_xxx.txt */
file->write_size = BYTES_INVALID; file->write_size = BYTES_INVALID;
@@ -932,10 +934,6 @@ backup_files(const char *from_root,
printf(_("skip\n")); printf(_("skip\n"));
continue; continue;
} }
}
else
copy_file(from_root, to_root, file,
compress ? COMPRESSION : NO_COMPRESSION);
if (verbose) if (verbose)
{ {
+32 -20
View File
@@ -272,7 +272,7 @@ parse_page(const DataPage *page, int server_version,
* If lsn is not NULL, pages only which are modified after the lsn will be * If lsn is not NULL, pages only which are modified after the lsn will be
* copied. * copied.
*/ */
void bool
backup_data_file(const char *from_root, const char *to_root, backup_data_file(const char *from_root, const char *to_root,
pgFile *file, const XLogRecPtr *lsn, bool compress) pgFile *file, const XLogRecPtr *lsn, bool compress)
{ {
@@ -291,13 +291,22 @@ backup_data_file(const char *from_root, const char *to_root,
char outbuf[zlibOutSize]; char outbuf[zlibOutSize];
#endif #endif
INIT_CRC32(crc);
/* reset size summary */
file->read_size = 0;
file->write_size = 0;
/* open backup mode file for read */ /* open backup mode file for read */
in = fopen(file->path, "r"); in = fopen(file->path, "r");
if (in == NULL) if (in == NULL)
{ {
/* meybe vanished, it's not error */ FIN_CRC32(crc);
file->crc = crc;
/* maybe vanished, it's not error */
if (errno == ENOENT) if (errno == ENOENT)
return; return false;
elog(ERROR_SYSTEM, _("can't open backup mode file \"%s\": %s"), elog(ERROR_SYSTEM, _("can't open backup mode file \"%s\": %s"),
file->path, strerror(errno)); file->path, strerror(errno));
@@ -317,12 +326,6 @@ backup_data_file(const char *from_root, const char *to_root,
to_path, strerror(errno_tmp)); to_path, strerror(errno_tmp));
} }
INIT_CRC32(crc);
/* reset size summary */
file->read_size = 0;
file->write_size = 0;
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
if (compress) if (compress)
{ {
@@ -365,9 +368,8 @@ backup_data_file(const char *from_root, const char *to_root,
fclose(in); fclose(in);
fclose(out); fclose(out);
file->is_datafile = false; file->is_datafile = false;
copy_file(from_root, to_root, file, return copy_file(from_root, to_root, file,
compress ? COMPRESSION : NO_COMPRESSION); compress ? COMPRESSION : NO_COMPRESSION);
return;
} }
file->read_size += read_len; file->read_size += read_len;
@@ -540,13 +542,18 @@ backup_data_file(const char *from_root, const char *to_root,
/* We do not backup if all pages skipped. */ /* We do not backup if all pages skipped. */
if (file->write_size == 0 && file->read_size > 0) if (file->write_size == 0 && file->read_size > 0)
{
if (remove(to_path) == -1) if (remove(to_path) == -1)
elog(ERROR_SYSTEM, _("can't remove file \"%s\": %s"), to_path, elog(ERROR_SYSTEM, _("can't remove file \"%s\": %s"), to_path,
strerror(errno)); strerror(errno));
return false;
}
/* remove $BACKUP_PATH/tmp created during check */ /* remove $BACKUP_PATH/tmp created during check */
if (check) if (check)
remove(to_path); remove(to_path);
return true;
} }
/* /*
@@ -746,7 +753,7 @@ restore_data_file(const char *from_root,
fclose(out); fclose(out);
} }
void bool
copy_file(const char *from_root, const char *to_root, pgFile *file, copy_file(const char *from_root, const char *to_root, pgFile *file,
CompressionMode mode) CompressionMode mode)
{ {
@@ -765,13 +772,22 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
char inbuf[zlibInSize]; char inbuf[zlibInSize];
#endif #endif
INIT_CRC32(crc);
/* reset size summary */
file->read_size = 0;
file->write_size = 0;
/* open backup mode file for read */ /* open backup mode file for read */
in = fopen(file->path, "r"); in = fopen(file->path, "r");
if (in == NULL) if (in == NULL)
{ {
/* meybe deleted, it's not error */ FIN_CRC32(crc);
file->crc = crc;
/* maybe deleted, it's not error */
if (errno == ENOENT) if (errno == ENOENT)
return; return false;
elog(ERROR_SYSTEM, _("can't open source file \"%s\": %s"), file->path, elog(ERROR_SYSTEM, _("can't open source file \"%s\": %s"), file->path,
strerror(errno)); strerror(errno));
@@ -798,12 +814,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
strerror(errno)); strerror(errno));
} }
INIT_CRC32(crc);
/* reset size summary */
file->read_size = 0;
file->write_size = 0;
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
z.zalloc = Z_NULL; z.zalloc = Z_NULL;
z.zfree = Z_NULL; z.zfree = Z_NULL;
@@ -962,4 +972,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
if (check) if (check)
remove(to_path); remove(to_path);
return true;
} }
+2 -2
View File
@@ -249,11 +249,11 @@ extern bool xlog_logfname2lsn(const char *logfname, XLogRecPtr *lsn);
extern void xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn); extern void xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn);
/* in data.c */ /* in data.c */
extern void backup_data_file(const char *from_root, const char *to_root, extern bool backup_data_file(const char *from_root, const char *to_root,
pgFile *file, const XLogRecPtr *lsn, bool compress); pgFile *file, const XLogRecPtr *lsn, bool compress);
extern void restore_data_file(const char *from_root, const char *to_root, extern void restore_data_file(const char *from_root, const char *to_root,
pgFile *file, bool compress); pgFile *file, bool compress);
extern void copy_file(const char *from_root, const char *to_root, extern bool copy_file(const char *from_root, const char *to_root,
pgFile *file, CompressionMode compress); pgFile *file, CompressionMode compress);
/* in util.c */ /* in util.c */