File open (busy) during backup

Hello

I have a setup with Duplicati, things go well, but now users want to backup a NAS to the cloud.
I am not keen to try to setup Duplicati on the NAS itself, these systems being very specific, so I have setup Duplicati as a service on a rarely used workstation to backup the NAS.

This works, but there is a wrinckle; as the backup source is remote, snapshots can’t work, so if a file is locked on the NAS, it can’t be opened by Duplicati. This is not a big problem; file can be handled at next backup occurrence. What’s more annoying is that the backup status is reported as a warning.

Things are, the risk is that half the backups will be reported as warnings, leading to users not caring too much about it. This is bad in the long term, what if there is a more serious problem such as an erroneous permission configuration ?

I have tried to change Duplicati to fix this.
Patch follows based on this issue.

diff --git a/Duplicati/Library/Main/Operation/Backup/FileBlockProcessor.cs b/Duplicati/Library/Main/Operation/Backup/FileBlockProcessor.cs
index dcf1a4229..e21b95a63 100644
--- a/Duplicati/Library/Main/Operation/Backup/FileBlockProcessor.cs
+++ b/Duplicati/Library/Main/Operation/Backup/FileBlockProcessor.cs
@@ -20,6 +20,7 @@
 using System;
 using CoCoL;
 using Duplicati.Library.Main.Operation.Common;
+using System.IO;
 using System.Threading.Tasks;
 using System.Threading;
 
@@ -34,6 +35,8 @@ namespace Duplicati.Library.Main.Operation.Backup
         /// The tag to use for log messages
         /// </summary>
         private static readonly string FILELOGTAG = Logging.Log.LogTagFromType(typeof(FileBlockProcessor)) + ".FileEntry";
+       /// Windows error 0x80070020 file open by another process
+        public const int ERRORCODEFILEBUSY = -2147024864;
 
         public static Task Run(Snapshots.ISnapshotService snapshot, Options options, BackupDatabase database, BackupStatsCollector stats, ITaskReader taskreader, CancellationToken token)
         {
@@ -138,7 +141,16 @@ namespace Duplicati.Library.Main.Operation.Backup
                         if (ex.IsRetiredException())
                             return;
                         else
-                            Logging.Log.WriteWarningMessage(FILELOGTAG, "PathProcessingFailed", ex, "Failed to process path: {0}", e.Path);
+                       {
+                           if (ex is System.IO.IOException && ex.HResult == ERRORCODEFILEBUSY)^M
+                           {
+                                Logging.Log.WriteInformationMessage(FILELOGTAG, "File open", "File is busy (try to use VSS) {0}: {1} ({2})", e.Path, ex.HResult, ex.Message);^M
+                           }
+                           else
+                           {
+                                Logging.Log.WriteWarningMessage(FILELOGTAG, "PathProcessingFailed", ex, "Failed to process path: {0}", e.Path);^M
+                            }
+                       }
                     }
                 }
             });

This works, probably the style is not the best as this change is my first lines of code in C#,
my question: is there any chance that such a change could be added to Duplicati ? If answer is not a straight no, I am of course open to do something better in a future PR.

Against:

  • this is checking for a specific Windows error code.
  • backing up a networked source is not a core use case.

I’d say that first, I don’t see anything wrong with this use case, it’s marginal yes, but it could happen elsewhere and is not obviously a unique case. And if it’s justified, I don’t see a sane way other than to check the error code (I may be wrong, advice welcome)

Against: in the normal use cases, the snapshot capability could be disabled thanks to Windows being misconfigured or just having trouble (unfortunately there are many cases where snapshots are not working right), in this case, this feature could mask legitimate warnings, that is, the opened files would be ignored without warning while this would be a real problem.
This could be avoided by adding a specific configuration to disable snapshots maybe, false by default so people wanting to not set the jobs in warning because of opened file would have to set this option explicitly to true. Advice welcome too.

Thanks for reading and giving your ideas.

Hello and thanks for your contribution!

I am not a core developer, but I don’t think your idea would be implemented as-is. I believe the design was to intentionally warn about any condition that results in a less-than-100%-complete backup. Missed files due to being locked would mean you don’t have a complete backup, and suppressing any such warning in all cases is probably not the best idea.

It’s more likely to be accepted (but I’m not sure) if it were based on a configurable option. If the option is left at the default you’d get the warning like you do now, but if the option were set maybe the warnings could be suppressed.

What kind of NAS is this? I’m kind of surprised you are getting locked file issue if it’s a Linux-based NAS. But maybe it’s good at emulating SMB file lock mechanics.

Thanks for your advice @drwtsn32.

It’s a recent QNAP, TS-253A.
Yes the SMB emulation is good enough to lock the file, the NAS is replacing a Windows server. I have done the test by opening an Excel file and puting it in rw mode by editing a cell.

There I have created a PR for this change.