Skip to content

DB.Backup/Stream.Backup may duplicate entries in incremental backups if used naively #1351

@cannona

Description

@cannona

Looking at backup.go I see that both the wrapper function, Backup as well as Stream.Backup accept a since parameter for the purpose of taking an incremental backup. Their first return value is documented as follows:

It returns a timestamp indicating when the entries were dumped which can be passed into a later invocation to generate an incremental dump, of entries that have been added/modified since the last invocation of Stream.Backup().

First of all, this is technically incorrect, as the timestamp is of the last entry in the backup, not of the time the backup was taken. What's more, reading the code, only entries that are before the since parameter are omitted, but entries that match the since timestamp are not. This means, if I am understanding the code correctly, that simply passing the value returned by the previous call to Backup will duplicate the latest entry/entries in the new Backup.

I recommend either returning maxVersion + 1 from Stream.Backup, or changing line 55:

if item.Version() < since {

to:

if item.Version() <= since {

I would also recommend duplicating much of the documentation from Stream.Backup to DB.Backup, as it's not immediately obvious that this method returns the same thing that Stream.Backup does. I'm happy to submit a pull request, if that would help.

Metadata

Metadata

Assignees

Labels

kind/enhancementSomething could be better.status/acceptedWe accept to investigate or work on it.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions