Home Assistant backups failing

Hi All,
I’m hoping you can help because I have no idea what’s going on.

I am trying to backup home assistant, but when I to start a backup, it looks like it’s loading for a bit and then comes up with this error

Logger: homeassistant.components.hassio
Source: components/hassio/websocket_api.py:124
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: 8:17:52 PM (1 occurrences)
Last logged: 8:17:52 PM

Failed to to call /backups/new/full - Unknown error, see supervisor

When I check the supervisor logs I see this…

23-02-19 20:17:52 ERROR (MainThread) [supervisor.homeassistant.module] Can't backup Home Assistant Core config folder: [Errno 5] I/O error
23-02-19 20:17:52 ERROR (MainThread) [supervisor.backups.manager] Backup 6e4a12bd error
Traceback (most recent call last):
  File "/usr/src/supervisor/supervisor/homeassistant/module.py", line 341, in backup
    await self.sys_run_in_executor(_write_tarfile)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/supervisor/supervisor/homeassistant/module.py", line 332, in _write_tarfile
    atomic_contents_add(
  File "/usr/local/lib/python3.10/site-packages/securetar/__init__.py", line 176, in atomic_contents_add
    atomic_contents_add(tar_file, directory_item, excludes, arcpath)
  File "/usr/local/lib/python3.10/site-packages/securetar/__init__.py", line 176, in atomic_contents_add
    atomic_contents_add(tar_file, directory_item, excludes, arcpath)
  File "/usr/local/lib/python3.10/site-packages/securetar/__init__.py", line 179, in atomic_contents_add
    tar_file.add(directory_item.as_posix(), arcname=arcpath, recursive=False)
  File "/usr/local/lib/python3.10/tarfile.py", line 2002, in add
    self.addfile(tarinfo, f)
  File "/usr/local/lib/python3.10/tarfile.py", line 2030, in addfile
    copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
  File "/usr/local/lib/python3.10/tarfile.py", line 248, in copyfileobj
    buf = src.read(bufsize)
OSError: [Errno 5] I/O error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/supervisor/supervisor/backups/manager.py", line 167, in _do_backup
    await backup.store_homeassistant()
  File "/usr/src/supervisor/supervisor/backups/backup.py", line 485, in store_homeassistant
    await self.sys_homeassistant.backup(homeassistant_file)
  File "/usr/src/supervisor/supervisor/jobs/decorator.py", line 156, in wrapper
    raise err
  File "/usr/src/supervisor/supervisor/jobs/decorator.py", line 154, in wrapper
    return await self._method(*args, **kwargs)
  File "/usr/src/supervisor/supervisor/homeassistant/module.py", line 344, in backup
    raise HomeAssistantBackupError(
supervisor.exceptions.HomeAssistantBackupError: Can't backup Home Assistant Core config folder: [Errno 5] I/O error

Please ask if you need anymore info, Thanks!

I have the same problem, did you resolve this issue?

1 Like

I have the same problem… did you resolve it?

Ran into the same issue.
The problem seems to be that there is “a” file in the /config directory that is corrupt and cannot be read. If you open an SSH session to your Home assistant system you can find the corrupt file (and hopefully delete it if it is not a critical file).
I am not saying that the following is the best or the quickest method but it worked for me :slight_smile:
A backup was more important than optimizing the way to find the corrupt file :).

In the SSH terminal try to manually tar the different directories/files by using “tar c -f - /config/replace this part by file or dir to check”.
This command wil start tar in a similar way as during the backup, but it will send output to the console only - so nothing is written on the file system (If you want to be 200% sure you may of course create a “test dir” and run the command from there anyway) .
On the corrupt file or directory you will receive the same read error.

Once you have identified the file and it is not critical - hopefully - it can be removed by a simple rm.
In my case it was a zigbee2mqtt log file that was corrupted… Good luck !

(edit) NOTE : as indicated below, it might be better to filter the output using a “random” grep in order to minimize console output. This would make a command look like this (example to scan zigbee2mqtt dir) : “tar c -f - /config/zigbee2mqtt | grep XXXXXXX”. Any other command that would actually read the contents of all the files recursively would actually be an option to use.

You don’t really want to be sending random characters to your terminal (stdout). A better approach would be ‘grep -r XXX .’. That will recursively read every file and would generate minimal output. I doubt this would help much as the file is probably just fine, it just does not contain the data that HA is expecting.

I agree with the approach to filter the output using grep.

Not sure however what you mean exactly with “I doubt this would help much …”.
The problem faced here is only indirectly related to Home Assistant; as an external tar command is started by Home Assistant through a script.

This tar command fails due to a read error on filesystem level - so the file is corrupted and cannot be read in full. The contents are of no interest to the tar command, it is more than happy to compress almost any file as long as there is no corruption on filesystem level.
After removing the corrupted file a successful backup is made.

Nerdy Linux details (and a little off topic)
You should not run tar on directory when there are active processes writing to files in the directory. Linux is a asynchronous buffered file system and typically a process does not know (or care) when the data is actually written to the disk. When HA does a backup it knows which processes are writing to which files and takes appropriate action to assure that when the tar runs all the files are in a ‘good’ state.

You can run tar on an active directory but if a file changes size while the tar is reading it, the tar will fail. It may also quietly archive a incomplete version of a file. As far as Linux is concerned, you got just what you asked for.

To find corrupted file you can connect via ssh. then :slight_smile:
tar -cvzf fooo.tar.gz .

tar will stop on corrupted file so the last file displayed is the corrupted.