From 62520bb7b420c760fed8d690bd667a12a1a4abed Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Wed, 7 Dec 2022 09:13:19 +0100 Subject: [PATCH 1/2] sftp: Fix ENOSPC check We now check for space that is not reserved for the root user on the remote, and the check is no longer in a defer block because it wouldn't fire. Some change in the surrounding code may have led the deferred function to capture the wrong err variable. Fixes #3336. --- internal/backend/sftp/sftp.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/backend/sftp/sftp.go b/internal/backend/sftp/sftp.go index 417b6681a..6ce07976f 100644 --- a/internal/backend/sftp/sftp.go +++ b/internal/backend/sftp/sftp.go @@ -354,14 +354,13 @@ func (r *SFTP) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader debug.Log("sftp: failed to remove broken file %v: %v", f.Name(), rmErr) } - - err = r.checkNoSpace(dirname, rd.Length(), err) }() // save data, make sure to use the optimized sftp upload method wbytes, err := f.ReadFrom(rd) if err != nil { _ = f.Close() + err = r.checkNoSpace(dirname, rd.Length(), err) return errors.Wrap(err, "Write") } @@ -403,7 +402,7 @@ func (r *SFTP) checkNoSpace(dir string, size int64, origErr error) error { debug.Log("sftp: StatVFS returned %v", err) return origErr } - if fsinfo.Favail == 0 || fsinfo.FreeSpace() < uint64(size) { + if fsinfo.Favail == 0 || fsinfo.Frsize*fsinfo.Bavail < uint64(size) { err := errors.New("sftp: no space left on device") return backoff.Permanent(err) } From 83d23b3ae816d1902a9066dcdccaf5274899bcda Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Wed, 7 Dec 2022 22:36:52 +0100 Subject: [PATCH 2/2] Changelog for ENOSPC handling bug --- changelog/unreleased/issue-3336 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 changelog/unreleased/issue-3336 diff --git a/changelog/unreleased/issue-3336 b/changelog/unreleased/issue-3336 new file mode 100644 index 000000000..b22ab244f --- /dev/null +++ b/changelog/unreleased/issue-3336 @@ -0,0 +1,12 @@ +Bugfix: SFTP backend now checks for disk space + +A backup to an SFTP backend would spew repeated SSH_FX_FAILURE messages when +the remote disk is full. Restic now reports "sftp: no space left on device" +and exits immediately when it detects this condition. + +A fix for this issue was promised in restic 0.12.1, but the fix itself +contained a bug that prevented it from triggering. + +https://github.com/restic/restic/issues/3336 +https://github.com/restic/restic/pull/3345 +https://github.com/restic/restic/pull/4075