Bug 14918 - backup command raises FileNotFoundError
Summary: backup command raises FileNotFoundError
Status: RESOLVED FIXED
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: 4.16
Assignee: Douglas Bagnall
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-24 18:07 UTC by James Dingwall
Modified: 2022-01-07 16:03 UTC (History)
3 users (show)

See Also:


Attachments
possible fix (2.07 KB, patch)
2021-11-24 20:28 UTC, Douglas Bagnall
no flags Details
fix v2, with non-symlink-following variation (3.64 KB, patch)
2021-11-30 21:28 UTC, Douglas Bagnall
abartlet: review+
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
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.
Comment 4 Douglas Bagnall 2021-11-30 21:28:38 UTC
Created attachment 17033 [details]
fix v2, with non-symlink-following variation

thanks for that.

I am wondering if we actually want to follow symlinks at all, or just back them up as is (as per the second patch in this series). We already won't follow directory symlinks. Joseph? Andrew?
Comment 5 Andrew Bartlett 2021-11-30 23:07:02 UTC
Comment on attachment 17033 [details]
fix v2, with non-symlink-following variation

Yes, I think this is the right approach.  Please push up a MR.
Comment 6 Douglas Bagnall 2021-12-01 01:33:14 UTC
(In reply to Andrew Bartlett from comment #5)
https://gitlab.com/samba-team/samba/-/merge_requests/2275
Comment 7 Samba QA Contact 2021-12-03 18:54:03 UTC
This bug was referenced in samba master:

697abc15ea50e9069eb483fdd734588281bae123
0f7e58b0e29778711d3385adbba957c175c3bdef