When large backup directories on a Hetzner StorageBox refuse to delete and keep throwing
cannot remove directory
or No such file or directory
errors —
even after rm -rf
— the cause is often CIFS caching and shortname conflicts.
Below is the full story, the failed attempts, and the final working solution.
💥 The Problem
While cleaning up a daily backup folder on a Hetzner StorageBox mounted via CIFS:
rm -r daily/
rm: cannot remove 'daily/www/_de/media/files/2021/2/10/ISYVFV~E': No such file or directory
rm: cannot remove 'daily/www/_de/templates/sitemap/keywords': Directory not empty
Files appeared in ls -la
but could not be deleted, read, or found by find
.
These were ghost entries created by CIFS caching and 8.3-style shortnames (IDGBQ9~O
etc.).
Even rm -rf
, find -delete
, and rsync --delete
failed.
🔍 Failed Attempts
- rm -rf daily/ — produced endless
No such file or directory
errors. - find ... -delete — failed with the same error; CIFS cache still held stale entries.
- rsync --delete — could not remove non-empty directories.
- Unmount + remount with cache=none — improved reliability but ghost entries remained.
- SFTP (ssh uXXXX@...) — login succeeded but no shell available (PTY allocation failed).
- sftp> rm -r — invalid flag; OpenSSH SFTP does not support recursive delete.
🧠 Root Cause
The Hetzner StorageBox CIFS mount layer sometimes holds directory entries in memory that no longer
exist on the server. These “ghost files” appear in directory listings but cannot be accessed or removed locally.
CIFS also translates some filenames into DOS 8.3 shortnames (e.g. ABCD12~X
),
which Linux cannot properly resolve.
✅ The Working Solution
The only reliable fix was to delete the directory directly on the server side using
lftp
over SFTP — bypassing CIFS entirely.
1. Install lftp
sudo apt update
sudo apt install lftp -y
2. Run a recursive delete command
lftp -u u2,YourPassword sftp://u2.your-storagebox.de -e "
set sftp:auto-confirm yes;
rm -r backup/daily;
quit"
This command connects directly to the StorageBox SFTP service and performs a server-side
recursive delete.
Unlike sftp
, lftp
supports rm -r
natively.
In this case it removed 1,172 files in one go:
rm ok, 1172 files removed
3. (Optional) Remount CIFS properly
To avoid stale cache issues in the future, add this to /etc/fstab
:
//u2.your-storagebox.de/backup /mnt/backupbox cifs \
credentials=/root/.smbcredentials-u2,iocharset=utf8,uid=root,gid=root,\
file_mode=0664,dir_mode=0775,noperm,vers=3.0,cache=none,actimeo=1,noserverino,\
_netdev,x-systemd.automount,nofail 0 0
📘 Lessons Learned
rm -rf
andfind -delete
may not work on CIFS-mounted paths due to stale cache.rsync --delete
is safe but fails if directories are “ghosted” in the mount table.lftp
is the most reliable tool for deep cleanup on Hetzner StorageBox via SFTP.- Always mount with
cache=none, actimeo=1, noserverino
to reduce inode and directory caching issues.
Comments
Post a Comment