Repository: borgbackup/borg

Issue:
attrs: [Errno 28] No space left on device: '<FD x>'
## Have you checked borgbackup docs, FAQ, and open Github issues?
Yes

## Is this a BUG / ISSUE report or a QUESTION?
Not sure. Probably just a question.

## System information. For client/server mode post info for both machines.
#### Your borg version (borg -V).
    borg 1.1.5

#### Operating system (distribution) and version.
    Linux 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u2 (2018-02-21) x86_64 GNU/Linux
    ntfs-3g 2016.2.22AR.1 integrated FUSE 28

#### Hardware / network configuration, and filesystems used.
ext4 / ntfs

#### How much data is handled by borg?
approx 500 GB

#### Full borg commandline that lead to the problem (leave away excludes and passwords)
    borg extract ::archivename

## Describe the problem you're observing.
I did a full backup of an NTFS drive (mounted on linux over ntfs-3g in read only mode).

When I try to restore the files to an ext4 filesystem I get the following errors for some files:

    attrs: [Errno 28] No space left on device: '<FD xx>'

Interestingly the files I get those errors for are always picture files (BMP, TIFF,  JPG etc).

So I guess this might be some (x)attr incompatibility / limitation between NTFS and ext4 and nothing to worry about right?


Discussion:
I remember we already had a similar issue before. In that old case the strange error msg was caused by trying to restore ntfs fs special files/directories (stuff that rather should have been excluded from the backup).

In your case, the "attrs" means it had problems to restore some attributes (uid, gid, mode, timestamps, acls, xattrs, bsdflags). For a lot of these, we catch all OSErrors, so what's left is mode, acls and xattrs.

For xattrs, we catch some OSError, but not "no space left" (because that should mean that the disk is full and we can not just ignore that).

The relevant code is there:
https://github.com/borgbackup/borg/blob/1.1.5/src/borg/archive.py#L659

It would be interesting to find more about this, what precisely is causing the issue.

So maybe do an extraction with `--list` and post the line with the error plus 2 lines before it and 2 lines after it. If there is any traceback, post the full traceback.

You could also `borg list` the troublesome filenames or try to extract them to ntfs.
I managed to capture this issue in a test archive:
[borg_issue_3808.tar.gz](https://github.com/borgbackup/borg/files/1983056/borg_issue_3808.tar.gz)

It produces (at least on my system) the mentioned error message when I try to extract it on an ext4 filesystem:
```
root@xxx# borg extract ../test::test
test: attrs: [Errno 28] No space left on device: '<FD 6>'
```

Also it is to note that if I extract on an ntfs-3g filesystem I do not get any error.
`getfattr -d` shows some strange xattrs hanging on that file. Maybe it's something ext4 can't cope with.

Since it happens always in conjunction with picture files (but not with all of them) I could image that some programs store thumbnails or such stuff there.
Thanks for providing the test repo, I can reproduce the issue with it.
With your test repo and slightly modified borg code:
```
$ borg extract --list ../test::test
test
/home/tw/Desktop/test2/test: No space left while setting extended attribute user.Q30lsldxJoudresxAaaqpcawXc
```

WTF?

Added length output:
```
$ borg extract --list ../test::test
test
/home/tw/Desktop/test2/test: No space left on device while setting extended attribute user.Q30lsldxJoudresxAaaqpcawXc (len = 6960)
```

I wrote the (binary) value of that attribute to a file and ran the `file` utility on it, trying to identify it, but it just said 'binary file'. Also had a manual look into it, but nothing recognizable.

Resolving patch:
diff --git a/src/borg/archive.py b/src/borg/archive.py
--- a/src/borg/archive.py
+++ b/src/borg/archive.py
@@ -730,6 +730,13 @@ def restore_attrs(self, path, item, symlink=False, fd=None):
                     # permission denied to set this specific xattr (this may happen related to security.* keys)
                     logger.warning('%s: Permission denied when setting extended attribute %s' % (path, k.decode()))
                     set_ec(EXIT_WARNING)
+                elif e.errno == errno.ENOSPC:
+                    # no space left on device while setting this specific xattr
+                    # ext4 reports ENOSPC when trying to set an xattr with >4kiB while ext4 can only support 4kiB xattrs
+                    # (in this case, this is NOT a "disk full" error, just a ext4 limitation).
+                    logger.warning('%s: No space left on device while setting extended attribute %s (len = %d)' % (
+                        path, k.decode(), len(v)))
+                    set_ec(EXIT_WARNING)
                 else:
                     raise
         # bsdflags include the immutable flag and need to be set last:


Test patch: