Skip to content

Commit cf88637

Browse files
authored
Merge pull request #33 from CherkashinSergey/skip_unchanged_files
Skip unchanged files
2 parents 0669939 + b36a6c1 commit cf88637

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/backup.c

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

20972097
if (S_ISREG(buf.st_mode))
20982098
{
2099+
pgFile **prev_file;
2100+
20992101
/* Check that file exist in previous backup */
21002102
if (current.backup_mode != BACKUP_MODE_FULL)
21012103
{
21022104
char *relative;
21032105
pgFile key;
2104-
pgFile **prev_file;
21052106

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

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

src/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ BlackListCompare(const void *str1, const void *str2)
368368
* pgFile objects to "files". We add "root" to "files" if add_root is true.
369369
*
370370
* When omit_symlink is true, symbolic link is ignored and only file or
371-
* directory llnked to will be listed.
371+
* directory linked to will be listed.
372372
*/
373373
void
374374
dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,

0 commit comments

Comments
 (0)