Adds -persist option to check and restore commands to continue despite errors #595
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #157 and #205 and fixes #596
This PR adds a
-persist
option to thecheck
andrestore
modes of duplicacy. The function of this option is to allow these processes to continue despite encountering errors when downloading or decrypting file chunks. This allowscheck
orrestore
to continue until all chunks/files in the revision are processed. Incheck
, this means all chunks with errors (-chunks
mode) or all files with errors (-files
mode) are reported. Inrestore
, this means that duplicacy will attempt to restore all files rather than failing on first error. Only errors in file chunks can be recovered from; errors in metadata chunks will still cause fatal errors.In my view this PR increases the robustness of backups as they can be restored as far as possible despite corrupt/missing file chunks. Assuming only a small number of chunks are missing/corrupted, this reduces a potentially a critical failure (inability to restore entire backup) to a lesser failure (only several files corrupted). It is worth noting that this increased robustness only applies to loss of file chunks. Loss of a metadata chunk is likely to still lead to loss of an entire backup. Therefore, this PR can be considered to mostly fix #157 and #205.
Duplicacy function without the
-persist
option is largely the same as the current version (the difference is for behaviour withrestore -hash
without-overwrite
to fix #596, and additional statistics withrestore -stats
).Internal working:
The
-persist
option is propagated to theRestore()
andCheckSnapshops()
through the use of a new parameterallowFailures
(defaultallowFailures=false
;allowFailures=true
if-persist
enabled).Effect on chunk downloader
The
allowFailures
parameter is propagated toCreateChunkDownloader()
byRestore()
andCheckSnapshops()
. WithallowFailures==true
, the chunk downloader will produce warnings on chunk download/decrypt failures rather than fatal errors (following the standard number of retries), with chunks marked withisBroken=true
. Therefore, with-persist
, missing/corrupted file chunks will only affect the files encoded by these chunks.Effect on
CheckSnapshots()
The
allowFailures
parameter is propagated toCreateChunkDownloader()
. InCheckSnapshots()
and in-chunks
mode, file chunk failures will be output as warnings; verification will continue until all chunks processed (so warnings will be produced for all affected chunks). In-files
mode, corrupted files will be reported as well as total number of files affected.Effect on
Restore()
The
allowFailures
parameter is propagated toCreateChunkDownloader()
andRestoreFile()
. InRestoreFile()
,allowFailures=true
will cause failures to reduce to warnings rather than errors, including existing file overwrite withoverwrite==false
and restored file hash failures. Chunks withisBroken==true
are not used for reassembling the file and the resulting file will be corrupt and result in file hash errors.RestoreFile()
is altered to returnbool, Error
(rather than justbool
). Thebool
option indicates if the file was restored or not; theerror
option indicates if an error was encountered. The three return possibilities aretrue, nil
: file restored;false, nil
: file skipped (already present with correct hash); andfalse, error
: file could not be restored. With this change,Restore()
will track thedownloadedFiles
,skippedFiles
andfailedFiles
, reporting totals for all if-stats
requested.Restore differences without
-persist
Without
-overwrite
and with-hash
, duplicacy would previously fail if file is present even if file has same hash (see #596). This behaviour has been changed by shifting the exiting file hash check further up inRestoreFile()
and havingRestoreFile()
to signal a skipped file if an identical existing file is present (fixing #596); now-overwrite
off will only cause failures if the file exists but has a different hash.[This changes also works well with
restore -hash -persist
(overwrite=false
) as it allows a user to restore all missing files without any overwrites; any files with different hashes that could not be restored due to existing files are reported.]In addition, restore will report more statistics (
skippedFiles
andfailedFiles
) regardless of-persist
.Additional unit tests
Additional unit tests for
allowFailures=true
have been added toduplicacy_backupmanager_test.go
:TestBackupManagerPersist