# Case sensitivity regarding filenames

**URL:** <https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259>\
**Category:** Uncategorized\
**Created:** [May 12, 2023, 8:24pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259 "2023-05-12T20:24:24Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 16, 2023, 2:45pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/21 "2023-05-16T14:45:15Z")

</div>

Another try, same result.  
Still Win11. New backup, only option set:USN  
One directory added to backup with one file: dAILY nEWS.txt. Backup. All right.  
rename to Daily News.txt. Backup. Nothing happens. Rename to dailynews.txt. Backup.  
Result: restore of version 0 shows both versions.  
Difference is that I rename to another name, not only differing in case, and I don’t turn off USN. In previous case I turned off USN only to verify the problem is fixed without USN.

---

<div class="post-metadata">

**Author:** ![ts678](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@ts678](https://forum.duplicati.com/u/ts678)\
**Post date:** [May 16, 2023, 5:36pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/22 "2023-05-16T17:36:33Z")

</div>

Thanks for the detail. That reproduces it.

```plaintext
select parent folder
USN on
database deleted
destination deleted
create dAILY nEWS.txt
backup (versions: 1)
rename Daily News.txt
backup (versions: 1)
rename dailynews.txt
backup (versions: 2)
restore version 0, see dAILY nEWS.txt dailynews.txt

```

Database views:

![image](https://forum.duplicati.com/uploads/default/original/2X/c/cf8ae5f19b721fd3989f0981e3ec88ca499f0092.png)

![image](https://forum.duplicati.com/uploads/default/original/2X/9/986d7ab078665e3a180e54f36e9aabad13c98bd5.png)

A fileset corresponds to a backup version (except for numbering). It’s a complete list, like dlist file has.  
Most of the previous list is copied forward for unchanged files, but USN may have missed the change:

 ![image](https://forum.duplicati.com/uploads/default/original/2X/d/d92c23e641eec3e6b7e3995a5baddcc25567a4bf.png)

> [@gpatel-fr](#):
>
> rename to another name, not only differing in case

probably should have seen the old name as Deleted, but the statistics show it didn’t. It did see Added.

> <https://github.com/duplicati/duplicati/blob/619e95d4a67265f8a1726d5359de615682901eef/Duplicati/Library/Main/Operation/BackupHandler.cs#L223-L226>

Underneath that is lots more code, but that’s one theory about how the now-gone file name got carried.

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 16, 2023, 5:50pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/23 "2023-05-16T17:50:47Z")

</div>

that’s an interesting problem, even if it’s not the original one in this thread.  
I know that I could browse the 1000 issues in the project, and I will but if by any chance your memory (longer than mine) has some trace of a similar problem already seen there, it would be nice 🙂

---

<div class="post-metadata">

**Author:** ![ts678](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@ts678](https://forum.duplicati.com/u/ts678)\
**Post date:** [May 16, 2023, 6:16pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/24 "2023-05-16T18:16:44Z")

</div>

From a short search, this sounds similar:

> <https://github.com/duplicati/duplicati/pull/4079>
>
> See issue https://github.com/duplicati/duplicati/issues/4071 for more detail.
> 
> …
> With USN enabled, Duplicati only looks at files that have changed according to USN journal. So it is desirable for Duplicati to bring forward unscanned (unchanged) files from the previous fileset to the new fileset so the user sees a full file listing.
> 
> A problem occurs when a folder is removed from the source selection list. Duplicati doesn't see or process those files any more during backup. It mistakenly interprets this as unscanned (unchanged) files and brings them forward in the fileset, per the previous paragraph.
> 
> Duplicati already has a mechanism in place to detect any change to source selection or filtering settings, and forces a Full Scan. This proposed change causes Duplicati to check that Full Scan flag, and if it's set, don't bring forward any files from the previous fileset (for that volume).

> A problem occurs when a folder is removed from the source selection list. Duplicati doesn’t see or process those files any more during backup. It mistakenly interprets this as unscanned (unchanged) files and brings them forward in the fileset, per the previous paragraph.

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 16, 2023, 6:35pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/25 "2023-05-16T18:35:18Z")

</div>

Unless I’m missing something, it does not look to be the same problem since no source has been removed in this case.

---

<div class="post-metadata">

**Author:** ![ts678](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@ts678](https://forum.duplicati.com/u/ts678)\
**Post date:** [May 16, 2023, 8:31pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/26 "2023-05-16T20:31:15Z")

</div>

> [@gpatel-fr](#):
>
> it does not look to be the same problem

Not claiming it is. It’s also fixed. You asked:

> [@gpatel-fr](#):
>
> has some trace of a similar problem

and if the cause here is similar, it might help.

Regardless, it probably merits a new issue…

It wasn’t clear to me if the USN journal gave enough information, especially on the case-only rename. Testing with `Everything` which [monitors the USN journal](https://www.voidtools.com/faq/), even those renames change result list fast, suggesting it’s possible but maybe not done in Duplicati yet. I don’t know USN, but did spot this code:

> <https://github.com/duplicati/duplicati/blob/619e95d4a67265f8a1726d5359de615682901eef/Duplicati/Library/Snapshots/USNJournal.cs#L544>

which looks like it’s trying to equate new name of a rename as a file add, and its old name as a delete.  
Searching for documentation on `USN_REASON_RENAME_OLD_NAME` found some Microsoft pages on that:

[READ\_USN\_JOURNAL\_DATA\_V1 structure](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh802706(v=vs.85))  
[USN\_RECORD\_V2 structure (winioctl.h)](https://learn.microsoft.com/en-us/windows/win32/api/winioctl/ns-winioctl-usn_record_v2)

and neither one appears to say if it’s case sensitive or case insensitive. Everything figures it out though.

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 16, 2023, 8:37pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/27 "2023-05-16T20:37:10Z")

</div>

Yes I have looked at the USN journal with fsutil and not found any obvious difference in the ‘rename with just case change’ and ‘rename with fully other name’ cases that could explain the bug. But it’s an interesting problem even if complicated. USN seems a very good feature to have when one wants to backup big setups very frequently (say, hourly)

---

<div class="post-metadata">

**Author:** ![runmode](https://forum.duplicati.com/user_avatar/forum.duplicati.com/runmode/32/8108_2.png) [@runmode](https://forum.duplicati.com/u/runmode)\
**Post date:** [May 17, 2023, 4:54pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/28 "2023-05-17T16:54:49Z")

</div>

Wow, a lot has happened since my last visit. Sorry for my late reply, I was on my bread job, and also I’ve been reading to get the basics about USN journal, but I am only scratching the surface by now.

> [@ts678](#):
>
> One suspect from advanced options that completely changes how changes in files are detected is:
> 
> [usn-policy](https://duplicati.readthedocs.io/en/latest/06-advanced-options/#usn-policy)

You pricisely hit the black: after removing usn-policy from the advanced options, renamings of just capital changes were recognized by Duplicati (no need to deliver more details, after your extensive tests) - I just confirm that it solved my problem. USN-policy was the difference in our settings I was looking for. I turn off the USN option until one day the code gets developed further:

> [@Real-time backup](https://forum.duplicati.com/t/real-time-backup/263/40):
>
> If you mean specifically this part, then it would be worth finding out what it means and if it still holds:
> 
> > [@Real-time backup](https://forum.duplicati.com/t/real-time-backup/263/40):
> >
> > (currently not case sensitive)

> [@ts678](#):
>
> Testing with `Everything` which [monitors the USN journal](https://www.voidtools.com/faq/), even those renames change result list fast, suggesting it’s possible but maybe not done in Duplicati yet.

> [@gpatel-fr](#):
>
> Well, I tried USN on a fresh Win11 VM and things are not pretty. Seems horribly bugged.

From reading throug articles and skimming the code (far from understanding), I spotted some hints, which I want to share (you decide if useful of not):

From the source code comments it looks as the code still relies on the USN\_RECORD\_V2 structure  
(Refer to code line # 242 //TODO: add support for V3 records),  
while Win 10 delivers USN\_RECORD\_V3 minimum and Win 11 USN\_RECORD\_V4 for sure. Microsoft points out to design principles to stay compatible with changing USN Journal versions:

[USN\_RECORD\_V3 structure (winioctl.h)](https://learn.microsoft.com/en-us/windows/win32/api/winioctl/ns-winioctl-usn_record_v3)  
[USN\_RECORD\_V4 structure (winioctl.h)](https://learn.microsoft.com/en-us/windows/win32/api/winioctl/ns-winioctl-usn_record_v4)

Although the USN\_REASON\_RENAME\_OLD\_NAME and  
USN\_REASON\_RENAME\_NEW\_NAME fields stayed unchanged, one difference is that USN\_RECORD\_V4 structure lacks of a filename member. But a USN\_RECORD\_V4 is followed by minimum one USN\_RECORD\_V3 where the file name can be retrieved from.

This could also be the reason for multiple file names appearing in a single version and USN Structure changes would explain why the situation is worse with Win11.

Without going into deep how the code currently retrieves the file names, USN version compatibility would be a good strategy to start with.

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 17, 2023, 5:56pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/29 "2023-05-17T17:56:14Z")

</div>

@runmode

thanks for taking the time to look up all this information, it may be useful. I’ll keep it in mind for sure.

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 30, 2023, 3:51pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/30 "2023-05-30T15:51:53Z")

</div>

USN is not the culprit, even if using USN\_RECORD\_V2 it provides all necessary information to handle the case change. In both cases (rename with only case change, complete rename), the USN journal puts the same info into the Duplicati pipeline (the previous name)

The different handling comes from here:

> <https://github.com/duplicati/duplicati/blob/8fad3ed5d01a56f11fe66769e365aea9489e86ee/Duplicati/Library/Main/Operation/Backup/MetadataPreProcess.cs#L139>

since Windows is not case sensitive, passing the previous name succeeds in finding the file with GetFileEntryAsync, and the entry gets an OldId defined. When the name has a complete name change, OldID = -1. In the succeeding stage of the Duplicati pipeline, in FilePreFilterProcess.cs, the file is transferred to the _next_ stage or not depending on that (if OldID != -1, the file is triaged as ‘not modified’).

Now my next step is finding a fix 🙂

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [May 30, 2023, 10:58pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/31 "2023-05-30T22:58:46Z")

</div>

After looking further into the case, that’s not exactly what is happening either.  
USN itself is indeed not problematic with the V2. However it’s what is happening afterwise but still in the USN handling that fails. First thing, when there is a file renaming, the code is supposed to store and handle the 2 versions. However, a hash table is used with case insensitivity:

> <https://github.com/duplicati/duplicati/blob/8fad3ed5d01a56f11fe66769e365aea9489e86ee/Duplicati/Library/Snapshots/UsnJournalService.cs#L141>

so only the _old_ version is kept. In normal handling, the old file name is removed from further handling here:

> <https://github.com/duplicati/duplicati/blob/8fad3ed5d01a56f11fe66769e365aea9489e86ee/Duplicati/Library/Snapshots/UsnJournalService.cs#L263>

in spite of the comment that says the opposite ☹

When there is a case change renaming, the condition where (m\_Snapshot.FileExists) does not remove the old file name, because it is found by Windows (not sensitive case search). So Duplicati basically sees nothing changed.

The other problem I found is only a follow-up of this first problem (because the database still holds the initial version of the file name).

Fixing the hash is easy, however fixing the file exists condition is a bit more involved.

---

<div class="post-metadata">

**Author:** ![runmode](https://forum.duplicati.com/user_avatar/forum.duplicati.com/runmode/32/8108_2.png) [@runmode](https://forum.duplicati.com/u/runmode)\
**Post date:** [June 1, 2023, 11:38pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/32 "2023-06-01T23:38:55Z")

</div>

Key findings, hep! 👍  
with cheers 🙌

---

<div class="post-metadata">

**Author:** ![gpatel-fr](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gpatel-fr](https://forum.duplicati.com/u/gpatel-fr)\
**Post date:** [June 2, 2023, 1:27pm UTC](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259/33 "2023-06-02T13:27:57Z")

</div>

Issue:

> <https://github.com/duplicati/duplicati/issues/4951>
>
> \- \[X \] I have searched open and closed issues for duplicates.
> \- \[X \] I have sea…rched the \[forum\](https://forum.duplicati.com) for related topics.
> 
> \----------------------------------------
> 
> \## Environment info
> \- \*\*Duplicati version\*\*: trunk
> \- \*\*Operating system\*\*: Windows server 2022
> \- \*\*Backend\*\*: Sftp
> 
> \## Description
> When a file has been renamed by only changing the case, a new backup does not record the change.
> \[See: \](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259)
> 
> \## Steps to reproduce
> Create a new USN enabled backup with one directory and one file in it, do an initial backup, change the case of one character in the file name, do a backup
> 
> \- \*\*Actual result\*\*:
> no new version is generated
> \- \*\*Expected result\*\*:
> A new version should be created

Preliminary pre-alpha tentative attempt at a fix:

> <https://github.com/duplicati/duplicati/pull/4952>

[Previous page](https://forum.duplicati.com/t/case-sensitivity-regarding-filenames/16259.md?page=1)
