Bug 14918 - backup command raises FileNotFoundError
Summary: backup command raises FileNotFoundError
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Python (show other bugs)
Version: 4.13.14
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Douglas Bagnall
QA Contact: Samba QA Contact
Depends on:
Reported: 2021-11-24 18:07 UTC by James Dingwall
Modified: 2021-11-25 07:01 UTC (History)
2 users (show)

See Also:

possible fix (2.07 KB, patch)
2021-11-24 20:28 UTC, Douglas Bagnall
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Dingwall 2021-11-24 18:07:09 UTC
My environment (although probably not distribution specific) is Ubuntu Focal 20.04 using default packages.  After a recent upgrade from 4.11.x to 4.13.14 the domain backup command has started failing with this exception:

running backup on dirs: /var/lib/samba/private /var/lib/samba /etc/samba                                                                    
ERROR(<class 'FileNotFoundError'>): uncaught exception - [Errno 2] No such file or directory: '/var/lib/samba/dfs/netlogon'                 
  File "/usr/lib/python3/dist-packages/samba/netcmd/__init__.py", line 186, in _run                                                         
    return self.run(*args, **kwargs)                                                                                                        
  File "/usr/lib/python3/dist-packages/samba/netcmd/domain_backup.py", line 1105, in run                                                    
    if any(os.path.samefile(full_path, file) for file in all_files):                                                                        
  File "/usr/lib/python3/dist-packages/samba/netcmd/domain_backup.py", line 1105, in <genexpr>                                              
    if any(os.path.samefile(full_path, file) for file in all_files):                                                                        
  File "/usr/lib/python3.8/genericpath.py", line 100, in samefile                                                                           
    s1 = os.stat(f1)                                                                                                                        

$ apt-cache policy samba
  Installed: 2:4.13.14+dfsg-0ubuntu0.20.04.1
  Candidate: 2:4.13.14+dfsg-0ubuntu0.20.04.1
  Version table:
 *** 2:4.13.14+dfsg-0ubuntu0.20.04.1 500
        500 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
        100 /var/lib/dpkg/status
     2:4.11.6+dfsg-0ubuntu1 500
        500 http://gb.archive.ubuntu.com/ubuntu focal/main amd64 Packages

The backup is executed as:

/usr/bin/samba-tool domain backup offline --targetdir="${BACKDIR}"

I suspect that the cause of the issue is having a [dfs] share under /var/lib/samba which is included in the backup.  The directory contains dangling symbolic links of the form:

lrwxrwxrwx 1 root root 39 Mar 26  2021 sysvol -> msdfs:dc0\sysvol,dc1\sysvol
Comment 1 Douglas Bagnall 2021-11-24 20:28:08 UTC
Created attachment 17026 [details]
possible fix

Are you able to try this patch?
Comment 2 Douglas Bagnall 2021-11-24 20:31:50 UTC
This may have been caused by the fix for bug #14027.
Comment 3 James Dingwall 2021-11-25 07:01:28 UTC
There is an extra umatched '(' in the last '+' line but otherwise applying that patch allows the backup command to complete.  I see the new 'info' message printed for the dangling links.