docker-volume-backup: Error removing file over SFTP but SSH permissions are OK
Hi, thanks for this great software!
I’ve set 7 days of retention for my backups over SSH/SFTP and the backups are correctly and regularly created. However docker-volume-backup is unable to erase old backups: here’s a snippet of the log files (repeated many times):
time=2025-02-19T02:30:20.279Z level=ERROR msg="Unexpected error running schedule 30 2 * * *: sftp: \"Failure\" (SSH_FX_FAILURE)" error="main.runScript.func4: error running script: main.(*script).pruneBackups: error pruning backups: ssh.(*sshStorage).Prune.func1: error removing file: sftp: \"Failure\" (SSH_FX_FAILURE)"
time=2025-02-20T02:30:00.133Z level=INFO msg="Now running script on schedule 30 2 * * *"
time=2025-02-20T02:30:08.775Z level=INFO msg="Created backup of `/backup` at `/tmp/backup-2025-02-20T02-30-00.tar.gz`."
time=2025-02-20T02:30:15.762Z level=INFO msg="Uploaded a copy of backup `/tmp/backup-2025-02-20T02-30-00.tar.gz` to '192.168.1.5' at path '/mnt/mediadownloader-backup/'." storage=SSH
time=2025-02-20T02:30:16.610Z level=INFO msg="Removed tar file `/tmp/backup-2025-02-20T02-30-00.tar.gz`."
time=2025-02-20T02:30:16.620Z level=ERROR msg="Unexpected error running schedule 30 2 * * *: sftp: \"Failure\" (SSH_FX_FAILURE)" error="main.runScript.func4: error running script: main.(*script).pruneBackups: error pruning backups: ssh.(*sshStorage).Prune.func1: error removing file: sftp: \"Failure\" (SSH_FX_FAILURE)"
The thing is: if I log via SSH using exactly
- same RSA private key
- SSH host/user/pw provided to docker-volume-backup, I can remove old backups without any issue with “rm”…
Any hint/idea?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (12 by maintainers)
Commits related to this issue
- Paths are joined with client side separators when targeting remotes Currently, filepath.Join is used to join path fragments that are supposed to be created on remote storage backends. This could theo... — committed to offen/docker-volume-backup by m90 2 years ago
- Paths are joined with client side separators when targeting remotes (#547) Currently, filepath.Join is used to join path fragments that are supposed to be created on remote storage backends. This cou... — committed to offen/docker-volume-backup by m90 2 years ago
This is now fixed in v2.43.3
Thanks again @f18m and @puellanivis for your help in debugging this.
You should be able to add an
if candidate.IsDir() { continue }to the loop here: https://github.com/offen/docker-volume-backup/blob/failure-filename/internal/storage/ssh/ssh.go#L166-L173 That will skip any sub-directories in the directory.An empty directory shouldn’t stop the pruning, because
sftp.Client.Removewill remove an empty directory. (Same asos.Remove.)It would need to be either a protected directory, or a non-empty directory.
Interesting. I think I’d call the code trying to delete a directory a bug that needs to be fixed here. This behavior just wouldn’t make sense in any scenario.
In the meantime you should be able to work around this by setting a BACKUP_PRUNING_PREFIX in your configuration that matches your backups, e.g.
backup-.Thanks for your help in debugging this.
I’m not really sure that
fsyncis at all involved here.pkg/sftpdoes not issue anfsyncextended packet forsftp.Client.Remove()and the code in this repo isn’t callingsftp.File.Sync()either. 🤔One thing that could be happening is that
sftp.Removefirst tries to delete a file, and then unconditionally returns the error from asftp.Client.RemoveDirectory. So, the file remove could be returning a more informative error, which is being lost because thermdirobviously isn’t working.P.S.
openssh-sftp-server - 7.1p2-1this most certainly provides support forfsynchas been inopenssh-sftp-serversincev_6_5_P1.