You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-09-16 09:26:30 +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:
26
backup.c
26
backup.c
@@ -856,8 +856,10 @@ backup_files(const char *from_root,
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
/* record as skipped file in file_xxx.txt */
|
||||
file->write_size = BYTES_INVALID;
|
||||
if (verbose)
|
||||
printf(_("deleted\n"));
|
||||
printf(_("skip\n"));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@@ -921,21 +923,17 @@ backup_files(const char *from_root,
|
||||
}
|
||||
|
||||
/* copy the file into backup */
|
||||
if (file->is_datafile)
|
||||
if (!(file->is_datafile
|
||||
? backup_data_file(from_root, to_root, file, lsn, compress)
|
||||
: copy_file(from_root, to_root, file,
|
||||
compress ? COMPRESSION : NO_COMPRESSION)))
|
||||
{
|
||||
backup_data_file(from_root, to_root, file, lsn, compress);
|
||||
if (file->write_size == 0 && file->read_size > 0)
|
||||
{
|
||||
/* record as skipped file in file_xxx.txt */
|
||||
file->write_size = BYTES_INVALID;
|
||||
if (verbose)
|
||||
printf(_("skip\n"));
|
||||
continue;
|
||||
}
|
||||
/* record as skipped file in file_xxx.txt */
|
||||
file->write_size = BYTES_INVALID;
|
||||
if (verbose)
|
||||
printf(_("skip\n"));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
copy_file(from_root, to_root, file,
|
||||
compress ? COMPRESSION : NO_COMPRESSION);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
|
54
data.c
54
data.c
@@ -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
|
||||
* copied.
|
||||
*/
|
||||
void
|
||||
bool
|
||||
backup_data_file(const char *from_root, const char *to_root,
|
||||
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];
|
||||
#endif
|
||||
|
||||
INIT_CRC32(crc);
|
||||
|
||||
/* reset size summary */
|
||||
file->read_size = 0;
|
||||
file->write_size = 0;
|
||||
|
||||
/* open backup mode file for read */
|
||||
in = fopen(file->path, "r");
|
||||
if (in == NULL)
|
||||
{
|
||||
/* meybe vanished, it's not error */
|
||||
FIN_CRC32(crc);
|
||||
file->crc = crc;
|
||||
|
||||
/* maybe vanished, it's not error */
|
||||
if (errno == ENOENT)
|
||||
return;
|
||||
return false;
|
||||
|
||||
elog(ERROR_SYSTEM, _("can't open backup mode file \"%s\": %s"),
|
||||
file->path, strerror(errno));
|
||||
@@ -317,12 +326,6 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
to_path, strerror(errno_tmp));
|
||||
}
|
||||
|
||||
INIT_CRC32(crc);
|
||||
|
||||
/* reset size summary */
|
||||
file->read_size = 0;
|
||||
file->write_size = 0;
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
if (compress)
|
||||
{
|
||||
@@ -365,9 +368,8 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
file->is_datafile = false;
|
||||
copy_file(from_root, to_root, file,
|
||||
compress ? COMPRESSION : NO_COMPRESSION);
|
||||
return;
|
||||
return copy_file(from_root, to_root, file,
|
||||
compress ? COMPRESSION : NO_COMPRESSION);
|
||||
}
|
||||
|
||||
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. */
|
||||
if (file->write_size == 0 && file->read_size > 0)
|
||||
{
|
||||
if (remove(to_path) == -1)
|
||||
elog(ERROR_SYSTEM, _("can't remove file \"%s\": %s"), to_path,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* remove $BACKUP_PATH/tmp created during check */
|
||||
if (check)
|
||||
remove(to_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -746,7 +753,7 @@ restore_data_file(const char *from_root,
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
CompressionMode mode)
|
||||
{
|
||||
@@ -765,13 +772,22 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
char inbuf[zlibInSize];
|
||||
#endif
|
||||
|
||||
INIT_CRC32(crc);
|
||||
|
||||
/* reset size summary */
|
||||
file->read_size = 0;
|
||||
file->write_size = 0;
|
||||
|
||||
/* open backup mode file for read */
|
||||
in = fopen(file->path, "r");
|
||||
if (in == NULL)
|
||||
{
|
||||
/* meybe deleted, it's not error */
|
||||
FIN_CRC32(crc);
|
||||
file->crc = crc;
|
||||
|
||||
/* maybe deleted, it's not error */
|
||||
if (errno == ENOENT)
|
||||
return;
|
||||
return false;
|
||||
|
||||
elog(ERROR_SYSTEM, _("can't open source file \"%s\": %s"), file->path,
|
||||
strerror(errno));
|
||||
@@ -798,12 +814,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
INIT_CRC32(crc);
|
||||
|
||||
/* reset size summary */
|
||||
file->read_size = 0;
|
||||
file->write_size = 0;
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
z.zalloc = Z_NULL;
|
||||
z.zfree = Z_NULL;
|
||||
@@ -962,4 +972,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
|
||||
if (check)
|
||||
remove(to_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
/* 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);
|
||||
extern void restore_data_file(const char *from_root, const char *to_root,
|
||||
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);
|
||||
|
||||
/* in util.c */
|
||||
|
Reference in New Issue
Block a user