ep1cman / unifi-protect-backup

Python tool to backup unifi event clips in realtime
MIT License
577 stars 25 forks source link

Docker: Database doesn't exist, creating a new one #58

Closed johnwarne closed 1 year ago

johnwarne commented 1 year ago

Description

When running version 0.8.0 or 0.8.1 in Docker, I get the following error when starting the container:

2022-12-04 22:44:24 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Database doesn't exist, creating a new one
2022-12-04 22:44:24 [   ERROR   ] asyncio                                    :  Task exception was never retrieved
future: <Task finished name='Task-1' coro=<run.<locals>.new_coro() done, defined at /usr/lib/python3.10/site-packages/aiorun.py:227> exception=OperationalError('unable to open database file')>
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/aiorun.py", line 237, in new_coro
    await coro
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 296, in start
    self._db = await create_database(self._sqlite_path)
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 168, in create_database
    db = await aiosqlite.connect(path)
  File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 137, in _connect
    self._connection = await future
  File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
  File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 397, in connector
    return sqlite3.connect(loc, **kwargs)
sqlite3.OperationalError: unable to open database file

Reverting back to image: ghcr.io/ep1cman/unifi-protect-backup:0.7.4 allows the container to run successfully again.

Anything I could try to get the database to be created within the container?

ep1cman commented 1 year ago

Could you post the part of the log where it shows all the config settings, specifically the SQLite path? (Redact anything you don't want to share)

Also, as of 0.8.0 you will need to add an addition volume mount for the database file (check the reader) to persist the database.

I suspect the issue here is that the directory /config/database doesn't exist unless said volume mount is added.

johnwarne commented 1 year ago

Yep, that was it. Once I specified a volume mount for the database the container started up as expected, and the database was created. The container had auto-updated from version 0.7.4, and this is what had made it fail when it was recreated at 0.8.0/0.8.1. Thanks for the heads up!

johnwarne commented 1 year ago

BTW the new functionality to back up the missed video files till the retention period allowed me to get the files that I missed while my Docker container was down. Really, really great addition here!