Skip to content

Commit b36a6c1

Browse files
Skip backup of unchanged files
1 parent b0021bf commit b36a6c1

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/backup.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,12 +2091,13 @@ backup_files(void *arg)
20912091

20922092
if (S_ISREG(buf.st_mode))
20932093
{
2094+
pgFile **prev_file;
2095+
20942096
/* Check that file exist in previous backup */
20952097
if (current.backup_mode != BACKUP_MODE_FULL)
20962098
{
20972099
char *relative;
20982100
pgFile key;
2099-
pgFile **prev_file;
21002101

21012102
relative = GetRelativePath(file->path, arguments->from_root);
21022103
key.path = relative;
@@ -2126,20 +2127,27 @@ backup_files(void *arg)
21262127
continue;
21272128
}
21282129
}
2129-
/* TODO:
2130-
* Check if file exists in previous backup
2131-
* If exists:
2132-
* if mtime > start_backup_time of parent backup,
2133-
* copy file to backup
2134-
* if mtime < start_backup_time
2135-
* calculate crc, compare crc to old file
2136-
* if crc is the same -> skip file
2137-
*/
2138-
else if (!copy_file(arguments->from_root, arguments->to_root, file))
2130+
else
21392131
{
2140-
file->write_size = BYTES_INVALID;
2141-
elog(VERBOSE, "File \"%s\" was not copied to backup", file->path);
2142-
continue;
2132+
bool skip = false;
2133+
2134+
/* If non-data file has not changed since last backup... */
2135+
if (file->exists_in_prev &&
2136+
buf.st_mtime < current.parent_backup)
2137+
{
2138+
calc_file_checksum(file);
2139+
/* ...and checksum is the same... */
2140+
if (EQ_CRC32C(file->crc, (*prev_file)->crc))
2141+
skip = true; /* ...skip copying file. */
2142+
}
2143+
if (skip ||
2144+
!copy_file(arguments->from_root, arguments->to_root, file))
2145+
{
2146+
file->write_size = BYTES_INVALID;
2147+
elog(VERBOSE, "File \"%s\" was not copied to backup",
2148+
file->path);
2149+
continue;
2150+
}
21432151
}
21442152

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

0 commit comments

Comments
 (0)