Giter Club home page Giter Club logo

unifi-protect-backup's Introduction

Unifi Protect Backup

pypi python Build Status codecov

A Python based tool for backing up UniFi Protect event clips as they occur.

The idea for this project came after realising that if something were to happen, e.g. a fire, or a burglary that meant I could no longer access my UDM, all the footage recorded by all my nice expensive UniFi cameras would have been rather pointless. With this tool, all motion and smart detection clips are immediately backed up to off-site storage thanks to rclone, and kept for the configured retention period.

Buy me a coffee

Features

  • Listens to events in real-time via the Unifi Protect websocket API
  • Ensures any previous and/or missed events within the retention period are also backed up
  • Supports uploading to a wide range of storage systems using rclone
  • Automatic pruning of old clips

Requirements

  • Python 3.10+
  • Unifi Protect version 1.20 or higher (as per uiprotect)
  • rclone installed with at least one remote configured.

Setup

Unifi Protect Account Setup

In order to connect to your unifi protect instance, you will first need to setup a local admin account:

  • Login to your Local Portal on your UniFiOS device, and click on Users
  • Open the Roles tab and click Add Role in the top right.
  • Give the role a name like unifi protect backup and give it Full Management permissions for the unifi protect app.
  • Now switch to the User tab and click Add User in the top right, and fill out the form. Specific Fields to pay attention to:
    • Role: Must be the role created in the last step
    • Account Type: Local Access Only
  • Click Add in at the bottom Right.
  • Select the newly created user in the list, and navigate to the Assignments tab in the left-hand pane, and ensure all cameras are ticked.

Installation

The preferred way to run this tool is using a container

Docker Container

You can run this tool as a container if you prefer with the following command. Remember to change the variable to make your setup.

Note As of version 0.8.0, the event database needs to be persisted for the tool to function properly please see the updated commands below

Backing up locally:

By default, if no rclone config is provided clips will be backed up to /data.

docker run \
  -e UFP_USERNAME='USERNAME' \
  -e UFP_PASSWORD='PASSWORD' \
  -e UFP_ADDRESS='UNIFI_PROTECT_IP' \
  -e UFP_SSL_VERIFY='false' \
  -v '/path/to/save/clips':'/data' \
  -v '/path/to/save/database':/config/database/ \
  ghcr.io/ep1cman/unifi-protect-backup

Backing up to cloud storage:

In order to backup to cloud storage you need to provide a rclone.conf file.

If you do not already have a rclone.conf file you can create one as follows:

$ docker run -it --rm -v $PWD:/root/.config/rclone --entrypoint rclone ghcr.io/ep1cman/unifi-protect-backup config

Follow the interactive configuration process, this will create a rclone.conf file in your current directory.

Finally, start the container:

docker run \
  -e UFP_USERNAME='USERNAME' \
  -e UFP_PASSWORD='PASSWORD' \
  -e UFP_ADDRESS='UNIFI_PROTECT_IP' \
  -e UFP_SSL_VERIFY='false' \
  -e RCLONE_DESTINATION='my_remote:/unifi_protect_backup' \
  -v '/path/to/save/clips':'/data' \
  -v '/path/to/rclone.conf':'/config/rclone/rclone.conf' \
  -v '/path/to/save/database':/config/database/ \
  ghcr.io/ep1cman/unifi-protect-backup

Installing on host:

  1. Install rclone. Instructions for your platform can be found here: https://rclone.org/install/#quickstart
  2. Configure the rclone remote you want to backup to. Instructions can be found here: https://rclone.org/docs/#configure
  3. pip install unifi-protect-backup
  4. Optional: Install ffprobe so that unifi-protect-backup can check the length of the clips it downloads

Usage

Usage: unifi-protect-backup [OPTIONS]

  A Python based tool for backing up Unifi Protect event clips as they occur.

Options:
  --version                       Show the version and exit.
  --address TEXT                  Address of Unifi Protect instance  [required]
  --port INTEGER                  Port of Unifi Protect instance  [default: 443]
  --username TEXT                 Username to login to Unifi Protect instance  [required]
  --password TEXT                 Password for Unifi Protect user  [required]
  --verify-ssl / --no-verify-ssl  Set if you do not have a valid HTTPS Certificate for your
                                  instance  [default: verify-ssl]
  --rclone-destination TEXT       `rclone` destination path in the format {rclone remote}:{path on
                                  remote}. E.g. `gdrive:/backups/unifi_protect`  [required]
  --retention TEXT                How long should event clips be backed up for. Format as per the
                                  `--max-age` argument of `rclone`
                                  (https://rclone.org/filtering/#max-age-don-t-transfer-any-file-
                                  older-than-this)  [default: 7d]
  --rclone-args TEXT              Optional extra arguments to pass to `rclone rcat` directly.
                                  Common usage for this would be to set a bandwidth limit, for
                                  example.
  --rclone-purge-args TEXT        Optional extra arguments to pass to `rclone delete` directly.
                                  Common usage for this would be to execute a permanent delete
                                  instead of using the recycle bin on a destination. Google Drive
                                  example: `--drive-use-trash=false`
  --detection-types TEXT          A comma separated list of which types of detections to backup.
                                  Valid options are: `motion`, `person`, `vehicle`, `ring`
                                  [default: motion,person,vehicle,ring]
  --ignore-camera TEXT            IDs of cameras for which events should not be backed up. Use
                                  multiple times to ignore multiple IDs. If being set as an
                                  environment variable the IDs should be separated by whitespace.
                                  Alternatively, use a Unifi user with a role which has access
                                  restricted to the subset of cameras that you wish to backup.
  --file-structure-format TEXT    A Python format string used to generate the file structure/name
                                  on the rclone remote.For details of the fields available, see
                                  the projects `README.md` file.  [default: {camera_name}/{event.s
                                  tart:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S}
                                  {detection_type}.mp4]
  -v, --verbose                   How verbose the logging output should be.
                                  
                                      None: Only log info messages created by `unifi-protect-
                                      backup`, and all warnings
                                  
                                      -v: Only log info & debug messages created by `unifi-
                                      protect-backup`, and all warnings
                                  
                                      -vv: Log info & debug messages created by `unifi-protect-
                                      backup`, command output, and all warnings
                                  
                                      -vvv Log debug messages created by `unifi-protect-backup`,
                                      command output, all info messages, and all warnings
                                  
                                      -vvvv: Log debug messages created by `unifi-protect-backup`
                                      command output, all info messages, all warnings, and
                                      websocket data
                                  
                                      -vvvvv: Log websocket data, command output, all debug
                                      messages, all info messages and all warnings  [x>=0]
  --sqlite_path TEXT              Path to the SQLite database to use/create
  --color-logging / --plain-logging
                                  Set if you want to use color in logging output  [default: plain-
                                  logging]
  --download-buffer-size TEXT     How big the download buffer should be (you can use suffixes like
                                  "B", "KiB", "MiB", "GiB")  [default: 512MiB]
  --purge_interval TEXT           How frequently to check for file to purge.
                                  
                                  NOTE: Can create a lot of API calls, so be careful if your cloud
                                  provider charges you per api call  [default: 1d]
  --apprise-notifier TEXT         Apprise URL for sending notifications.
                                  E.g: ERROR,WARNING=tgram://[BOT KEY]/[CHAT ID]
                                  
                                  You can use this parameter multiple times to use more than one
                                  notification platform.
                                  
                                  The following notification tags are available (corresponding to
                                  the respective logging levels):
                                  
                                      ERROR, WARNING, INFO, DEBUG, EXTRA_DEBUG, WEBSOCKET_DATA
                                  
                                  If no tags are specified, it defaults to ERROR
                                  
                                  More details about supported platforms can be found here:
                                  https://github.com/caronc/apprise
  --skip-missing                  If set, events which are 'missing' at the start will be ignored.
                                  Subsequent missing events will be downloaded (e.g. a missed event)  [default: False]
  --download-rate-limit FLOAT     Limit how events can be downloaded in one minute. Disabled by
                                  default
  --max-event-length INTEGER      Only download events shorter than this maximum length, in
                                  seconds  [default: 7200]
  --experimental-downloader       If set, a new experimental download mechanism will be used to match
                                  what the web UI does. This might be more stable if you are experiencing
                                  a lot of failed downloads with the default downloader.  [default: False]
  --help                          Show this message and exit.

The following environment variables can also be used instead of command line arguments (note, CLI arguments always take priority over environment variables):

  • UFP_USERNAME
  • UFP_PASSWORD
  • UFP_ADDRESS
  • UFP_PORT
  • UFP_SSL_VERIFY
  • RCLONE_RETENTION
  • RCLONE_DESTINATION
  • RCLONE_ARGS
  • RCLONE_PURGE_ARGS
  • IGNORE_CAMERAS
  • DETECTION_TYPES
  • FILE_STRUCTURE_FORMAT
  • SQLITE_PATH
  • DOWNLOAD_BUFFER_SIZE
  • COLOR_LOGGING
  • PURGE_INTERVAL
  • APPRISE_NOTIFIERS
  • SKIP_MISSING
  • DOWNLOAD_RATELIMIT
  • MAX_EVENT_LENGTH
  • EXPERIMENTAL_DOWNLOADER

File path formatting

By default, the application will save clips in the following structure on the provided rclone remote:

{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4

If you wish for the clips to be structured differently you can do this using the --file-structure-format option. It uses standard python format string syntax.

The following fields are provided to the format string:

You can optionally format the event.start/event.end timestamps as per the strftime format by appending it after a : e.g to get just the date without the time: {event.start:%Y-%m-%d}

Skipping initially missing events

If you prefer to avoid backing up the entire backlog of events, and would instead prefer to back up events that occur from now on, you can use the --skip-missing flag. This does not enable the periodic check for missing event (e.g. one that was missed by a disconnection) but instead marks all missing events at start-up as backed up.

If you use this feature it is advised that your run the tool once with this flag, then stop it once the database has been created and the events are ignored. Keeping this flag set permanently could cause events to be missed if the tool crashes and is restarted etc.

Ignoring cameras

Cameras can be excluded from backups by either:

  • Using --ignore-camera, see usage
    • IDs can be obtained by scanning the logs, starting at Found cameras: up to the next log line (currently NVR TZ). You can find this section of the logs by piping the logs in to this sed command sed -n '/Found cameras:/,/NVR TZ/p'
  • Using a Unifi user with a role which has access restricted to the subset of cameras that you wish to backup.

A note about rclone backends and disk wear

This tool attempts to not write the downloaded files to disk to minimise disk wear, and instead streams them directly to rclone. Sadly, not all storage backends supported by rclone allow "Stream Uploads". Please refer to the StreamUpload column on this table to see which one do and don't: https://rclone.org/overview/#optional-features

If you are using a storage medium with poor write durability e.g. an SD card on a Raspberry Pi, it is advised to avoid such backends.

If you are running on a linux host you can setup rclone to use tmpfs (which is in RAM) to store its temp files, but this will significantly increase memory usage of the tool.

Running Docker Container (LINUX ONLY)

Add the following arguments to your docker run command:

-e RCLONE_ARGS='--temp-dir=/rclone_tmp'
--tmpfs /rclone_tmp

Running Directly (LINUX ONLY)

sudo mkdir /mnt/tmpfs
sudo mount -o size=1G -t tmpfs none /mnt/tmpfs
$ unifi-protect-backup --rclone-args "--temp-dir=/mnt/tmpfs"

To make this persist reboots add the following to /etc/fstab:

tmpfs /mnt/tmpfs tmpfs nosuid,nodev,noatime 0 0

Running Backup Tool as a Service (LINUX ONLY)

You can create a service that will run the docker or local version of this backup tool. The service can be configured to launch on boot. This is likely the preferred way you want to execute the tool once you have it completely configured and tested so it is continuously running.

First create a service configuration file. You can replace protectbackup in the filename below with the name you wish to use for your service, if you change it remember to change the other locations in the following scripts as well.

sudo nano /lib/systemd/system/protectbackup.service

Next edit the content and fill in the 4 placeholders indicated by {}, replace these placeholders (including the leading { and trailing } characters) with the values you are using.

[Unit]
Description=Unifi Protect Backup

[Service]
User={your machine username}
Group={your machine user group, could be the same as the username}
Restart=on-abort
WorkingDirectory=/home/{your machine username}
ExecStart={put your complete docker or local command here}

[Install]
WantedBy=multi-user.target

Now enable the service and then start the service.

sudo systemctl enable protectbackup.service
sudo systemctl start protectbackup.service

To check the status of the service use this command.

sudo systemctl status protectbackup.service --no-pager

Debugging

If you need to debug your rclone setup, you can invoke rclone directly like so:

docker run \
    --rm \
    -v /path/to/rclone.conf:/config/rclone/rclone.conf \
    -e RCLONE_CONFIG='/config/rclone/rclone.conf' \
    --entrypoint rclone \
    ghcr.io/ep1cman/unifi-protect-backup \
    {rclone subcommand as per: https://rclone.org/docs/#subcommands}

For example to check that your config file is being read properly and list the configured remotes:

docker run \
    --rm \
    -v /path/to/rclone.conf:/config/rclone/rclone.conf \
    -e RCLONE_CONFIG='/config/rclone/rclone.conf' \
    --entrypoint rclone \
    ghcr.io/ep1cman/unifi-protect-backup \
    listremotes

Credits

  • All the contributors who have helped make this project:

Star History

Star History Chart

unifi-protect-backup's People

Contributors

adriankeenan avatar cyberpower678 avatar darron avatar ep1cman avatar igorwolbers avatar ircmaxell avatar lloydpickering avatar mmolitor87 avatar roastlechon avatar sticklyman1936 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unifi-protect-backup's Issues

SSL Wrong Version

  • Unifi Protect Backup version: Protect 1.21.4
  • Python version: ?
  • Operating System: Unraid 6.9.2

Description

When py.unifi.protect attempts to connect to my UDM SE it throws an 'SSL: WRONG_VERSION_NUMBER'

What I Did

The docker must be set to the correct port given it is attempting to connect with the account I had made for it, however I am unsure if the SSL Version on my Unraid, Docker, or UDM SE is the culprit.

client_session: <aiohttp.client.ClientSession object at 0x149a27d2de80>
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Config:
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: address='192.168.1.1'
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: port=8080
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: username='Alexandria_Backup'
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: password=REDACTED
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: verify_ssl=False
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone_destination='local:/data'
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: retention='7d'
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone_args=''
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: ignore_cameras=()
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: verbose=1
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: detection_types=['motion', 'person', 'vehicle', 'ring']
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2022-04-15 02:56:30 [INFO]:unifi_protect_backup.unifi_protect_backup: Starting...
2022-04-15 02:56:30 [INFO]:unifi_protect_backup.unifi_protect_backup: Checking rclone configuration...
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone found: /usr/bin/rclone
2022-04-15 02:56:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup: ffprobe found: /usr/bin/ffprobe
2022-04-15 02:56:30 [INFO]:unifi_protect_backup.unifi_protect_backup: Connecting to Unifi Protect...
Traceback (most recent call last):
File "/usr/bin/unifi-protect-backup", line 8, in <module>
sys.exit(main())
File "/usr/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/unifi_protect_backup/cli.py", line 109, in main
loop.run_until_complete(event_listener.start())
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 288, in start
await self._protect.update()
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 507, in update
self._bootstrap = await self.get_bootstrap()
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 663, in get_bootstrap
data = await self.api_request_obj("bootstrap")
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 248, in api_request_obj
data = await self.api_request(
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 231, in api_request
data = await self.api_request_raw(
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 197, in api_request_raw
await self.ensure_authenticated()
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 277, in ensure_authenticated
await self.authenticate()
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 293, in authenticate
response = await self.request("post", url=url, json=auth)
File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 184, in request
raise NvrError(f"Error requesting data from {self._host}: {err}") from None
pyunifiprotect.exceptions.NvrError: Error requesting data from 192.168.1.1: Cannot connect to host 192.168.1.1:8080 ssl:False [[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)]
2022-04-15 02:56:30 [ERROR]:asyncio : Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x152b92ba59a0>
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

Interrupted event not being backed up

I did notice one peculiarity.

To upgrade I (accidentally) stopped the previous version in the middle of it backing up an event, and then upgraded and restarted (in debug to make sure the db was connecting OK). You can see the sequence here:

Dec  5 09:32:31 emp75 unifi_protect: 2022-12-05 09:32:31 [INFO]:unifi_protect_backup.unifi_protect_backup:#011Backing up event: 638d2dfc0139bf03e4034612
Dec  5 09:32:42 emp75 unifi_protect: 2022-12-05 09:32:42 [INFO]:unifi_protect_backup.unifi_protect_backup:#011Backed up successfully!
Dec  5 09:33:19 emp75 unifi_protect: 2022-12-05 09:33:19 [INFO]:unifi_protect_backup.unifi_protect_backup:#011Backing up event: 638d2e03031dbf03e403461b
Dec  5 09:35:00 emp75 unifi_protect: 2022-12-05 09:35:00 [#033[36;1m   DEBUG   #033[0m] unifi_protect_backup.unifi_protect_backup  :#011Config:
Dec  5 09:35:00 emp75 unifi_protect: 2022-12-05 09:35:00 [#033[36;1m   DEBUG   #033[0m] unifi_protect_backup.unifi_protect_backup  :#011  address='192.168.1.18'

The event that was backing up (638d2e03031dbf03e403461b) when the service was stopped has not been uploaded to OneDrive, and is not being picked up as 'missed'.

I've not tested to see if any subsequent restarts in the middle of an action result in the same miss.

Originally posted by @Swallowtail23 in #50 (comment)

ERROR: No matching distribution found for unifi-protect-backup

  • Unifi Protect Backup version: N/A
  • Unifi Protect version: 2.6.17
  • Python version: Python 3.8.10
  • Operating System: Ubuntu 20.04.5 LTS
  • Are you using a docker container or native?: Native

Description

Following the README, I cannot install unifi-protect-backup via pip.

What I Did

$ pip install unifi-protect-backup
ERROR: Could not find a version that satisfies the requirement unifi-protect-backup (from versions: none)
ERROR: No matching distribution found for unifi-protect-backup

Failed to run: 'rclone rcat - permission denied

  • Unifi Protect Backup version: 0.88
  • Unifi Protect version: 2.7.18
  • Python version: N/A
  • Operating System: Synology 920+ DSM 7.1.1-42962 Update 1
  • Are you using a docker container or native?: Docker

Description

Attempting to spin up unifi-protect-backup on my Synology NAS via portainer into docker. I am trying to read Protect recordings from my UDM SE, and store them locally on my NAS in its own Shared Folder.

What I Did

Attempted different iterations of a docker-compose stack deployment via portainer. The logs attached and docker-compose config shown is as close as I can get to working - but keep getting this permission denied error against what I think is activities looking for rclone. I installed rclone onto my NAS.. still getting the same errors. Looking for some advice/assistance with this one.

2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Camera: G4 Doorbell
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Type: smartDetectZone (vehicle)
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Start: 2023-02-24T13-48-15 (1677264495.373)
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] End: 2023-02-24T13-48-30 (1677264510.276)
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Duration: 14.903s
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Downloading video...
2023-03-05 01:35:07 [ WARNING ] unifi_protect_backup.utils : Failed to run: 'rclone rcat -vv "local:/data/G4 Doorbell/2023-02-23/2023-02-23T11-25-04 smartDetectZone (vehicle).mp4"
2023-03-05 01:35:07 [ WARNING ] unifi_protect_backup.utils : stdout:
2023-03-05 01:35:07 [ WARNING ] unifi_protect_backup.utils : stderr:
2023/03/05 01:35:07 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2023/03/05 01:35:07 DEBUG : rclone: Version "v1.58.1-DEV" starting with parameters ["rclone" "rcat" "-vv" "local:/data/G4 Doorbell/2023-02-23/2023-02-23T11-25-04 smartDetectZone (vehicle).mp4"]
2023/03/05 01:35:07 DEBUG : Creating backend with remote "local:/data/G4 Doorbell/2023-02-23/"
2023/03/05 01:35:07 DEBUG : Using config file from "/config/rclone/rclone.conf"
2023/03/05 01:35:07 DEBUG : fs cache: renaming cache item "local:/data/G4 Doorbell/2023-02-23/" to be canonical "/data/G4 Doorbell/2023-02-23/"
2023/03/05 01:35:07 ERROR : 2023-02-23T11-25-04 smartDetectZone (vehicle).mp4: Post request rcat error: mkdir /data/G4 Doorbell: permission denied
2023/03/05 01:35:07 DEBUG : 4 go routines active
2023/03/05 01:35:07 Failed to rcat with 2 errors: last error was: mkdir /data/G4 Doorbell: permission denied
2023-03-05 01:35:07 [ WARNING ] unifi_protect_backup.uploader : [63f7935602d1d603e40030be] Failed to upload file: 'local:/data/G4 Doorbell/2023-02-23/2023-02-23T11-25-04 smartDetectZone (vehicle).mp4'
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Downloaded video size: 2.7MiBs
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Downloaded video length: 16.000s(+1.097s)
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.uploader : [63f7935602d1d603e40030be] Uploaded
2023-03-05 01:35:07 [ INFO ] unifi_protect_backup.uploader : [63f7742b0274d603e4002fcf] Uploading event: 63f7742b0274d603e4002fcf
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.uploader : [63f7742b0274d603e4002fcf] Remaining Upload Queue: 124 (507.7MiB)
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.uploader : [63f7742b0274d603e4002fcf] Destination: local:/data/G4 Doorbell/2023-02-23/2023-02-23T09-12-02 smartDetectZone (vehicle).mp4
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f90675035cd603e4003bc4] Added to upload queue
2023-03-05 01:35:07 [ INFO ] unifi_protect_backup.downloader : [63f23bb70146d603e4000b77] Downloading event: 63f23bb70146d603e4000b77
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f23bb70146d603e4000b77] Remaining Download Queue: 170
2023-03-05 01:35:07 [ DEBUG ] unifi_protect_backup.downloader : [63f23bb70146d603e4000b77] Video Download Buffer: 510.4MiB/512.0MiB

version: '3.3'
services:
    unifi-protect-backup:
        container_name: unifi-protect-backup
        hostname: unifi-protect-backup
        image: ghcr.io/ep1cman/unifi-protect-backup
        restart: always
        user: root
        environment:
            - 'UFP_USERNAME=protect_backup'
            - 'UFP_PASSWORD=REDACTED'
            - 'UFP_ADDRESS=10.10.20.1'
            - UFP_SSL_VERIFY=false
            - 'TZ=America/New_York'
            - RCLONE_RETENTION=90d
            #- 'RCLONE_DESTINATION=local:/data'
        volumes:
            #- '/volume1/Protect Backups/clips:/data'
            #- '/volume1/Protect Backups/database:/config/database/'
            #- '/volume1/Protect Backups/rclone.conf:/config/rclone/rclone.conf'
            - '/volume1/Protect Backups:/data'

Stop retrying an event if it keeps failing

Sometimes unifi will have an event where the video data is missing and will fail all attempts to download it. This causes the tool to retry every 5 minutes till the event is removed.

This is especially bad with the new notification feature, where it caused me 800+ notifications in one week.

Not finding any cameras

  • Unifi Protect Backup version: 0.8.8
  • Unifi Protect version: 2.2.6
  • Python version: Docker
  • Operating System: Ubuntu 22.04.1 LTS
  • Are you using a docker container or native?: Docker

The tool runs without any errors in the log. It does, however, not find any cameras. I tried the Docker image as well as the Python script directly. No change. I can rule out network connectivity problems, an instance of Home Assistant on the same machine can connect to Protect without problem. To rule out any issues with two services connecting at the same time, I've stopped HA as well - no change.
I upgraded to a different release channel in Unifi a few weeks ago and I think it might have stopped working there, but I am not 100% sure regarding the dates.

This is the log output:

2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  Config:
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    address='192.168.1.1'
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    port=443
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    username='unifi-protect-backup'
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    password=REDACTED
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    verify_ssl=False
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    rclone_destination='unifi-protect-backup:/'
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    retention='180d'
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    rclone_args=''
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    ignore_cameras=()
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    verbose=1
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    detection_types=['motion', 'person', 'vehicle', 'ring']
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    sqlite_path='/config/database/events.sqlite'
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    download_buffer_size=512.0MiB
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :    purge_interval='1d'
2023-01-20 23:13:42 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Starting...
2023-01-20 23:13:42 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Checking rclone configuration...
2023-01-20 23:13:42 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  rclone found: /usr/bin/rclone

root@aumkse1p:/data-volume/unify-protect# 2023-01-20 23:13:42 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Connecting to Unifi Protect...
2023-01-20 23:13:43 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Found cameras:
2023-01-20 23:13:43 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  NVR TZ: Europe/Berlin
2023-01-20 23:13:43 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  Local TZ: UTC
2023-01-20 23:13:43 [   DEBUG   ] unifi_protect_backup.downloader            :  ffprobe found: /usr/bin/ffprobe
2023-01-20 23:13:43 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Starting...
2023-01-20 23:13:43 [   INFO    ] unifi_protect_backup.downloader            :  Starting Downloader
2023-01-20 23:13:43 [   INFO    ] unifi_protect_backup.uploader              :  Starting Uploader
2023-01-20 23:13:43 [   DEBUG   ] unifi_protect_backup.event_listener        :  Subscribed to websocket
2023-01-20 23:13:43 [   INFO    ] unifi_protect_backup.missing_event_checker :  Starting Missing Event Checker
2023-01-20 23:13:43 [   DEBUG   ] unifi_protect_backup.missing_event_checker :   Total undownloaded events: 0
2023-01-20 23:13:43 [   DEBUG   ] unifi_protect_backup.missing_event_checker :   Undownloaded events of wanted types: 0


Has anyone else tested the compatibility with Unifi Protect 2.2.6? Is it working for you?

rclone: too many non-flag arguments

Discussed in #21

Originally posted by Amphiboly March 7, 2022
It appears that poorly formatted file names are being passed to rclone. I get the message:
Command rcat needs 1 arguments maximum: you provided 2 non flag arguments: ["'remote:Unifi\Wanderer\2022-03-07\2022-03-07T03-20-06" "motion.mp4'"]
when my camera name has no spaces, and
Command rcat needs 1 arguments maximum: you provided 4 non flag arguments: ["'remote:Unifi\Mud" "Room" "Door\2022-03-07\2022-03-07T03-20-05" "motion.mp4'"]
when it has two spaces. So even if I were to rename the camera "Front Door" to "FrontDoor" it looks like there will still be a problem because of the "motion.mp4" addition.

This is on Windows 11 with the current versions of all involved packages (Python 3.10.2, unifi-protect-backup 0.5.0, pyunifiprotect 3.2.1, ffprobe 0.5, rclone 1.57.0).

unifi-protect generates test data per the readme, and rclone rcat can put files into the target directory.

What should I look at next?

--
rik

Ignore flag for cameras

Not all cameras are used for security, such as pet monitoring cameras, and don't need to be archived. Adding a flag to ignore certain cameras would alleviate this issue.

sometimes videos are too short

  • Unifi Protect Backup version: 0.3.1
  • Python version: 3.9.10
  • Operating System: Raspbian GNU/Linux 10 (buster)

Description

video clips are sometimes shorter than expected (eg, vehicles already in frame at start of clip or still in frame at end of clip)

What I Did

Ran software, captured clips to AWS, downloaded clips, and viewed them.

Suggestion

Two separate options to allow specifying a length of time in seconds before and after the "standard" clip value that the Protect device reports. That way a user can adjust those values to suit their set up.

Not following RCLONE_RETENTION

  • Unifi Protect Backup version: latest
  • Unifi Protect version: 2.1.2
  • Python version:
  • Operating System:
  • Are you using a docker container or native?: docker

Description

When I set retention via environment variable, it doesn't appear to follow that. In my docker compose file, I have the retention set to 5d. However, when the nightly delete happens, it follows the default 7d retention. Aka, folders and all the files that are up to 7 days old stay around. Folders and files older than 7 days are deleted nightly. It's just not following the overwritten value of 5d.

Docker compose file:

version: '3'
services:
  unifi-protect-backup-box:
    restart: always
    image: ghcr.io/ep1cman/unifi-protect-backup:latest
    environment:
      - UFP_USERNAME=removed
      - UFP_PASSWORD=removed
      - UFP_ADDRESS=removed
      - UFP_SSL_VERIFY=false
      - RCLONE_RETENTION=5d
    volumes:
      - /unifi-protect-backup/data:/data

What I Did

cont-init: info: /etc/cont-init.d/99-custom-files exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service init-mods: starting
s6-rc: info: service init-mods successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun unifi-protect-backup (no readiness notification)
s6-rc: info: service legacy-services successfully started
s6-rc: info: service 99-ci-service-check: starting
[ls.io-init] done.
s6-rc: info: service 99-ci-service-check successfully started
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Config:
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  address='removed'
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  port=443
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  username='removed'
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  password=REDACTED
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  verify_ssl=False
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  rclone_destination='local:/data'
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  retention='5d'
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  rclone_args=''
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  ignore_cameras=()
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  verbose=1
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  detection_types=['motion', 'person', 'vehicle', 'ring']
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2022-08-22 18:48:18 [INFO]:unifi_protect_backup.unifi_protect_backup:	Starting...
2022-08-22 18:48:18 [INFO]:unifi_protect_backup.unifi_protect_backup:	Checking rclone configuration...
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	rclone found: /usr/bin/rclone
2022-08-22 18:48:18 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	ffprobe found: /usr/bin/ffprobe
2022-08-22 18:48:18 [INFO]:unifi_protect_backup.unifi_protect_backup:	Connecting to Unifi Protect...
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	Found cameras:
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - removed camera name
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	Setting up purge task...
2022-08-22 18:48:19 [INFO]:unifi_protect_backup.unifi_protect_backup:	Listening for events...

image (7 days)

Container install not using container's TZ

  • Unifi Protect Backup version: 0.8.7
  • Are you using a docker container or native?: Container

Description

I have podman (docker) set to use my local timezone, and the logging shows that is working but UPB's logging uses only UTC - note container log entry on the following line with UPB then appending UTC:
2022-12-12T11:37:41.962213664+10:00 stderr F 2022-12-12 01:37:41 [ INFO ] unifi_protect_backup.unifi_protect_backup : Starting...
Can UPB use the container's TZ instead of UTC?

Ability to set custom conf directory and not run as root

Description

I have this running on k3s, but had to set some additional parameters to not run as root, set a specific user, etc.

Ideally would be nice to change which directory to mount the rclone.conf file from with appropriate permissions, and run unif-protect-backup and rclone as a specific user.

What I Did

Currently I am mounting volume at /.config since that was the first place it looks for configuration. I am also running the container as non-root as well.

Missed events not backed up

It is currently possible for events to exist within the retention period that are have not been backed up:

  • The most likely situation is that for some reason the tool is stopped without the user realising, maybe the docker container gets accidentally stopped etc.
  • while it hasn't been observed, it is theoretically possible for websocket messages to be dropped and thus events can be missed.

The current mode of operation of this tool is to subscribe to a websocket provided by Unifi Protect and monitor it for messages indication a clip has ended. This was done in order to not poll the device rapidly and generate excessive addition load, instead Unifi Protect notifies us.

This creates the unfortunate situation where while the this tool makes a best effort to backup all events, there is potential for missed events. This is especially true when the tool is first used/has been stopped for a period of time.

A proposed solution to this is to create a periodic task to check the list of clips on the device and compare them to what is backed up, back filling any missing events. This interval could be user configurable to cater for various users tolerance for possibly missed clips.

Handle new cameras being added

Since this is intended to be a long running service, itโ€™s not unlikely that a new camera might be added while it is running.

we should listen for events in the websocket and detect a new camera being added to backup its events. We should also periodically poll the system for new cameras in case we missed the message

Retention window is being ignored. No purging happening at all.

  • Unifi Protect Backup version: 0.8.8
  • Unifi Protect version: 2.2.7
  • Python version: Docker
  • Operating System: Docker (Debian)
  • Are you using a docker container or native?: Docker

Description

Retention period is not being followed. It's set to 2 months (2M), but it's got footage from 3 months ago and it's still accumulating. The log suggests its set to purge every day.

What I Did

Restart the container.

Running as a docker container not cleaning up old files

Discussed in #71

Originally posted by dkarzon January 11, 2023
I am running this as a docker container on an unraid instance syncing from a UDM Pro to OneDrive. The sync up to OneDrive works great. However, I have noticed it doesn't seem to clean up the old files (those that fall outside of the retention period) when the container is left constantly running.
As soon as I restart the container it then cleans up the old files as of the current time but continues to run only uploading.

Is this a known issue with the docker container method of running it or is there something I am missing to have the clean up functionality on an always on docker container?

Rclone: Failed to create file system for (remote) didn't find section in config file

  • Unifi Protect Backup version: 0.5.3
  • Python version: 3.9+
  • Operating System: Docker / Linux

Description

I am trying to get rclone to backup to Wasabi S3 compatible storage.
Whenever I make the rclone.conf file and setup with the Wasabi info it errors on me.

I'ved tested with another python script and using the cli for rclone that I am able to upload files and data to this bucket.

Super stumped on this on.

What I Did

here is my rclone.conf file

[wasabi]
env_auth = false
access_key_id = redacted
secret_access_key = redacted
region = us-west-1
endpoint = s3.us-west-1.wasabisys.com
location_constraint =
acl = public-read-write
server_side_encryption =
storage_class =
no_check_bucket = true

Here is the debug log from Docker

2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Config:
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  address='10.0.0.1'
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  port=443
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  username='unifiapi'
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  password=REDACTED
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  verify_ssl=False
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  rclone_destination='wasabi:asher-upb'
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  retention='7d'
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  rclone_args=''
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  ignore_cameras=()
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  verbose=1
2022-03-13 08:40:04 [INFO]:unifi_protect_backup.unifi_protect_backup:	Starting...
2022-03-13 08:40:04 [INFO]:unifi_protect_backup.unifi_protect_backup:	Checking rclone configuration...
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	rclone found: /usr/bin/rclone
2022-03-13 08:40:04 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	ffprobe found: /usr/bin/ffprobe
2022-03-13 08:40:04 [INFO]:unifi_protect_backup.unifi_protect_backup:	Connecting to Unifi Protect...
2022-03-13 08:40:05 [INFO]:unifi_protect_backup.unifi_protect_backup:	Found cameras:
2022-03-13 08:40:05 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - 608465ec02d04b0387004231: Front Door
2022-03-13 08:40:05 [INFO]:unifi_protect_backup.unifi_protect_backup:	 - 6227ff2001adcd0387001ab4: Side Patio
2022-03-13 08:40:05 [INFO]:unifi_protect_backup.unifi_protect_backup:	Setting up purge task...
2022-03-13 08:40:05 [INFO]:unifi_protect_backup.unifi_protect_backup:	Listening for events...
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Adding event 622dadf803b207038700144f to queue (Current queue=1)
2022-03-13 08:40:38 [INFO]:unifi_protect_backup.unifi_protect_backup:	Backing up event: 622dadf803b207038700144f
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Remaining Queue: 0
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Camera: Front Door
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Type: motion
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Start: 2022-03-13T08-40-21 (1647160821.808)
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  End: 2022-03-13T08-40-37 (1647160837.471)
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Duration: 15.663
2022-03-13 08:40:38 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Sleeping (6.052519s) to ensure clip is ready to download...
2022-03-13 08:40:44 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Downloading video...
2022-03-13 08:40:45 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Downloaded video length: 16.201s(+0.538s)
2022-03-13 08:40:45 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Uploading video via rclone...
2022-03-13 08:40:45 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	    To: wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4
2022-03-13 08:40:45 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	    Size: 3.7MiB
2022-03-13 08:40:45 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed upload attempt 1, retying in 1s
2022-03-13 08:40:45 [ERROR]:unifi_protect_backup.unifi_protect_backup:	Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:45 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:45 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:45 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:45 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:45 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 504, in _backup_events
    await self._upload_video(video, destination, self.rclone_args)
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 546, in _upload_video
    raise SubprocessException(stdout.decode(), stderr.decode(), proc.returncode)
unifi_protect_backup.unifi_protect_backup.SubprocessException: Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:45 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:45 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:45 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:45 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:45 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
2022-03-13 08:40:46 [ERROR]:asyncio             :	Future exception was never retrieved
future: <Future finished exception=BrokenPipeError()>
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/subprocess.py", line 153, in _feed_stdin
    await self.stdin.drain()
  File "/usr/lib/python3.9/asyncio/streams.py", line 387, in drain
    await self._protocol._drain_helper()
  File "/usr/lib/python3.9/asyncio/streams.py", line 197, in _drain_helper
    await waiter
BrokenPipeError
2022-03-13 08:40:46 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed upload attempt 2, retying in 1s
2022-03-13 08:40:46 [ERROR]:unifi_protect_backup.unifi_protect_backup:	Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:46 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:46 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:46 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:46 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:46 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 504, in _backup_events
    await self._upload_video(video, destination, self.rclone_args)
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 546, in _upload_video
    raise SubprocessException(stdout.decode(), stderr.decode(), proc.returncode)
unifi_protect_backup.unifi_protect_backup.SubprocessException: Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:46 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:46 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:46 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:46 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:46 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
2022-03-13 08:40:47 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed upload attempt 3, retying in 1s
2022-03-13 08:40:47 [ERROR]:unifi_protect_backup.unifi_protect_backup:	Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:47 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:47 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:47 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:47 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:47 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 504, in _backup_events
    await self._upload_video(video, destination, self.rclone_args)
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 546, in _upload_video
    raise SubprocessException(stdout.decode(), stderr.decode(), proc.returncode)
unifi_protect_backup.unifi_protect_backup.SubprocessException: Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:47 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:47 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:47 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:47 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:47 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
2022-03-13 08:40:48 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed upload attempt 4, retying in 1s
2022-03-13 08:40:48 [ERROR]:unifi_protect_backup.unifi_protect_backup:	Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:48 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:48 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:48 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:48 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:48 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 504, in _backup_events
    await self._upload_video(video, destination, self.rclone_args)
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 546, in _upload_video
    raise SubprocessException(stdout.decode(), stderr.decode(), proc.returncode)
unifi_protect_backup.unifi_protect_backup.SubprocessException: Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:48 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:48 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:48 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:48 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:48 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
2022-03-13 08:40:49 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed upload attempt 5, retying in 1s
2022-03-13 08:40:49 [ERROR]:unifi_protect_backup.unifi_protect_backup:	Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:49 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:49 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:49 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:49 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:49 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 504, in _backup_events
    await self._upload_video(video, destination, self.rclone_args)
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 546, in _upload_video
    raise SubprocessException(stdout.decode(), stderr.decode(), proc.returncode)
unifi_protect_backup.unifi_protect_backup.SubprocessException: Return Code: 1
Stdout:
Stderr:
2022/03/13 08:40:49 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"
2022/03/13 08:40:49 DEBUG : rclone: Version "v1.57.0-DEV" starting with parameters ["rclone" "rcat" "-vv" "wasabi:asher-upb/Front Door/2022-03-13/2022-03-13T08-40-21 motion.mp4"]
2022/03/13 08:40:49 DEBUG : Creating backend with remote "wasabi:asher-upb/Front Door/2022-03-13/"
2022/03/13 08:40:49 DEBUG : Using config file from "/config/rclone/rclone.conf"
2022/03/13 08:40:49 Failed to create file system for "wasabi:asher-upb/Front Door/2022-03-13/": didn't find section in config file
2022-03-13 08:40:50 [WARNING]:unifi_protect_backup.unifi_protect_backup:	Upload failed after 5 attempts, abandoning event 622dadf803b207038700144f:

'NoneType' object has no attribute 'id'

  • Unifi Protect Backup version: 0.8.5
  • Unifi Protect version:
  • Python version:
  • Operating System:
  • Are you using a docker container or native?: Container

Description

Error message per below

What I Did

Started the container...

2022-12-10 00:17:06 [   INFO    ] unifi_protect_backup.missing_event_checker :  Starting Missing Event Checker
2022-12-10 00:17:11 [  WARNING  ] unifi_protect_backup.missing_event_checker :  Unexpected exception occurred during missing event check:
2022-12-10 00:17:11 [   ERROR   ] unifi_protect_backup.missing_event_checker :  'NoneType' object has no attribute 'id'
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/missing_event_checker.py", line 65, in start
    downloading_event_ids.add(self._downloader.current_event.id)
AttributeError: 'NoneType' object has no attribute 'id'

Invalid characters passed to rclone delete

  • Unifi Protect Backup version: 0.5.1
  • Python version: 3.10.2
  • Operating System: Windows 11 Pro x64

Description

It looks like single quotes are being passed to rclone delete for purge.

What I Did

2022-03-10 00:00:00 [WARNING]:unifi_protect_backup.unifi_protect_backup:        stderr:
2022/03/10 00:00:00 DEBUG : --min-age 1M to 2022-02-08 00:00:00.0828157 -0500 EST m=-2591999.946268299
2022/03/10 00:00:00 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "delete" "-vv" "--min-age" "30d" "'remote:Unifi'"]
2022/03/10 00:00:00 Failed to create file system for "'remote:Unifi'": config name contains invalid characters - may only contain `0-9`, `A-Z`, `a-z`, `_`, `-` and space

Retry events until completed

Sometimes ISP connections are unstable. Such was the case for me on 2022-09-16. My connection was basically unusable for the whole day until I re-synchronized my "modem" with the ISP. During this time, at least one event was recorded and could not be uploaded to the remote store. The issue ends up looking like the attached screenshot.

I think this issue can be solved at the same time as #49. What I am thinking, is that a local sqlite or leveldb store can be used to keep track of the events received and successful uploads. When the script purges items from the remote storage, it can also remove records from this local tracking store (i.e. implement a sliding window of tracked events).

hp-elite-desk:0 0 0  tmux  docker logs -f protect-backup 2022-09-18 11-45-31

UNIQUE constraint failed: events.id

  • Unifi Protect Backup version: 0.8.3
  • Unifi Protect version: UNVR 3.0.13, Protect 2.6.17
  • Python version:
  • Operating System: RH8
  • Are you using a docker container or native?: Container

Description

Non unique violation errors

What I Did

Strange sequence... Why would it have downloaded/uploaded the same event twice? Presumably at some point something has failed and it is retrying, but the fail/catch/retry is ending up in a traceback, not an error routine.

2022-12-09T11:53:45.673871358+10:00 stderr F 2022-12-09 01:53:45 [   INFO    ] unifi_protect_backup.downloader            : [6392951b00dabf03e40b7a63]  Downloading event: 6392951b00dabf03e40b7a63
2022-12-09T11:53:55.340109434+10:00 stderr F 2022-12-09 01:53:55 [   INFO    ] unifi_protect_backup.uploader              : [6392950f029abf03e40b7a5a]  Uploading event: 6392950f029abf03e40b7a5a
2022-12-09T11:54:12.468989778+10:00 stderr F 2022-12-09 01:54:12 [  WARNING  ] unifi_protect_backup.missing_event_checker :   Adding missing event to backup queue: 6392950f029abf03e40b7a5a (person) (2022-12-09T01-53-16 - 2022-12-09T01-53-31)
2022-12-09T11:54:12.469073497+10:00 stderr F 2022-12-09 01:54:12 [  WARNING  ] unifi_protect_backup.missing_event_checker :   Adding missing event to backup queue: 6392951b00dabf03e40b7a63 (person) (2022-12-09T01-53-28 - 2022-12-09T01-53-39)
2022-12-09T11:54:12.469218014+10:00 stderr F 2022-12-09 01:54:12 [   INFO    ] unifi_protect_backup.downloader            : [6392950f029abf03e40b7a5a]  Downloading event: 6392950f029abf03e40b7a5a
2022-12-09T11:54:13.220555489+10:00 stderr F 2022-12-09 01:54:13 [   INFO    ] unifi_protect_backup.downloader            : [6392951b00dabf03e40b7a63]  Downloading event: 6392951b00dabf03e40b7a63
2022-12-09T11:54:17.424767356+10:00 stderr F 2022-12-09 01:54:17 [   INFO    ] unifi_protect_backup.uploader              : [6392951b00dabf03e40b7a63]  Uploading event: 6392951b00dabf03e40b7a63
2022-12-09T11:54:29.399325998+10:00 stderr F 2022-12-09 01:54:29 [   INFO    ] unifi_protect_backup.uploader              : [6392950f029abf03e40b7a5a]  Uploading event: 6392950f029abf03e40b7a5a
2022-12-09T11:54:52.296019582+10:00 stderr F 2022-12-09 01:54:52 [  WARNING  ] unifi_protect_backup.uploader              : [6392950f029abf03e40b7a5a]  Unexpected exception occurred, abandoning event 6392950f029abf03e40b7a5a:
2022-12-09T11:54:52.296395776+10:00 stderr F 2022-12-09 01:54:52 [   ERROR   ] unifi_protect_backup.uploader              : [6392950f029abf03e40b7a5a]  UNIQUE constraint failed: events.id
2022-12-09T11:54:52.296395776+10:00 stderr F Traceback (most recent call last):
2022-12-09T11:54:52.296395776+10:00 stderr F   File "/usr/lib/python3.10/site-packages/unifi_protect_backup/uploader.py", line 59, in start
2022-12-09T11:54:52.296395776+10:00 stderr F     await self._update_database(event, destination)
2022-12-09T11:54:52.296395776+10:00 stderr F   File "/usr/lib/python3.10/site-packages/unifi_protect_backup/uploader.py", line 89, in _update_database
2022-12-09T11:54:52.296395776+10:00 stderr F     await self._db.execute(
2022-12-09T11:54:52.296395776+10:00 stderr F   File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 184, in execute
2022-12-09T11:54:52.296395776+10:00 stderr F     cursor = await self._execute(self._conn.execute, sql, parameters)
2022-12-09T11:54:52.296395776+10:00 stderr F   File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 129, in _execute
2022-12-09T11:54:52.296395776+10:00 stderr F     return await future
2022-12-09T11:54:52.296395776+10:00 stderr F   File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 102, in run
2022-12-09T11:54:52.296395776+10:00 stderr F     result = function()
2022-12-09T11:54:52.296395776+10:00 stderr F sqlite3.IntegrityError: UNIQUE constraint failed: events.id
2022-12-09T11:54:52.297514968+10:00 stderr F 2022-12-09 01:54:52 [   INFO    ] unifi_protect_backup.uploader              : [6392951b00dabf03e40b7a63]  Uploading event: 6392951b00dabf03e40b7a63
2022-12-09T11:55:03.975104446+10:00 stderr F 2022-12-09 01:55:03 [  WARNING  ] unifi_protect_backup.uploader              : [6392951b00dabf03e40b7a63]  Unexpected exception occurred, abandoning event 6392951b00dabf03e40b7a63:
2022-12-09T11:55:03.975256744+10:00 stderr F 2022-12-09 01:55:03 [   ERROR   ] unifi_protect_backup.uploader              : [6392951b00dabf03e40b7a63]  UNIQUE constraint failed: events.id
2022-12-09T11:55:03.975256744+10:00 stderr F Traceback (most recent call last):
2022-12-09T11:55:03.975256744+10:00 stderr F   File "/usr/lib/python3.10/site-packages/unifi_protect_backup/uploader.py", line 59, in start
2022-12-09T11:55:03.975256744+10:00 stderr F     await self._update_database(event, destination)
2022-12-09T11:55:03.975256744+10:00 stderr F   File "/usr/lib/python3.10/site-packages/unifi_protect_backup/uploader.py", line 89, in _update_database
2022-12-09T11:55:03.975256744+10:00 stderr F     await self._db.execute(
2022-12-09T11:55:03.975256744+10:00 stderr F   File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 184, in execute
2022-12-09T11:55:03.975256744+10:00 stderr F     cursor = await self._execute(self._conn.execute, sql, parameters)
2022-12-09T11:55:03.975256744+10:00 stderr F   File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 129, in _execute
2022-12-09T11:55:03.975256744+10:00 stderr F     return await future
2022-12-09T11:55:03.975256744+10:00 stderr F   File "/usr/lib/python3.10/site-packages/aiosqlite/core.py", line 102, in run
2022-12-09T11:55:03.975256744+10:00 stderr F     result = function()
2022-12-09T11:55:03.975256744+10:00 stderr F sqlite3.IntegrityError: UNIQUE constraint failed: events.id
2022-12-09T11:58:23.248944369+10:00 stderr F 2022-12-09 01:58:23 [   INFO    ] unifi_protect_backup.downloader            : [6392963400bebf03e40b7bf6]  Downloading event: 6392963400bebf03e40b7bf6
2022-12-09T11:58:24.470889039+10:00 stderr F 2022-12-09 01:58:24 [   INFO    ] unifi_protect_backup.uploader              : [6392963400bebf03e40b7bf6]  Uploading event: 6392963400bebf03e40b7bf6
2022-12-09T13:25:26.660186610+10:00 stderr F 2022-12-09 03:25:26 [   INFO    ] unifi_protect_backup.downloader            : [6392aa83002dbf03e40b9890]  Downloading event: 6392aa83002dbf03e40b9890
2022-12-09T13:25:27.780016512+10:00 stderr F 2022-12-09 03:25:27 [   INFO    ] unifi_protect_backup.uploader              : [6392aa83002dbf03e40b9890]  Uploading event: 6392aa83002dbf03e40b9890

It would also be useful to tag an event like this with the filename that was to be written, so it can be checked for successful upload.

running out of memory

Hi, I've upgraded from 0.7.x to 0.8.8 and now unifi-protect-backup is eating all the memory of the NAS I'm running it.
It has around 450MB of reserverd and 1300MB of virtual memory. Also there is a constant large read load on the disk and the cpu load is also high at times.

Should I downgrade to eliminate the ram (and swap) filling problem?

free -h
total used free shared buff/cache available
Mem: 908M 697M 84M 2.6M 126M 39M
Swap: 2.5G 1.0G 1.5G

ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 20508 26.9 47.6 1428404 443192 ? Dl 16:59 5:43 /var/packages/python310/target/bin/python3.10 /var/packages/python310/target/bin/unifi-protect-backup --no-verify-ssl --address 192.168.2.1 --port 443 --username backup --password xxx --detection-types motion --retention 90d --download-buffer-size 64MiB --rclone-destination nas:/volume1/backup/protect/

Error starting container

  • Unifi Protect Backup version: Latest
  • Unifi Protect version: 2.7.34
  • Python version: 3.10.6
  • Operating System: Ubuntu
  • Are you using a docker container or native?: Docker

Description

Container will not start due to error

What I Did

Restart container and tried new host

docker run \
  -e UFP_USERNAME='MY_USERNAME' \
  -e UFP_PASSWORD='MY_PASSWORD' \
  -e UFP_ADDRESS='UNIFI_IP' \
  -e UFP_SSL_VERIFY='false' \
  -v '/media/sf_BigD/clips':'/data' \
  -v '/media/sf_BigD/database':/config/database/ \
  ghcr.io/ep1cman/unifi-protect-backup

OUTPUT:

2023-05-13 16:09:23 [   ERROR   ] unifi_protect_backup.unifi_protect_backup_core :  Unexpected exception occurred in main loop:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup_core.py", line 209, in start
    self._db = await create_database(self._sqlite_path)
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup_core.py", line 37, 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


Trying to backup to SMB Share

  • Unifi Protect Backup version: V0.1.1
  • Python version: (Docker)
  • Operating System: (Docker)

Description

I've tried to get SMB working but i just can't figure it out because it keeps asking for my Config file
Schermafbeelding 2022-02-21 om 11 50 25

Error:

2022-02-21 11:49:53 [INFO]:unifi_protect_backup.unifi_protect_backup: Starting...
2022-02-21 11:49:53 [INFO]:unifi_protect_backup.unifi_protect_backup: Checking rclone configuration...
2022-02-21 11:49:53 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone found: /usr/bin/rclone
Traceback (most recent call last):
File "/usr/local/bin/unifi-protect-backup", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1137, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/unifi_protect_backup/cli.py", line 60, in main
loop.run_until_complete(event_listener.start())
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/local/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 209, in start
await self._check_rclone()
File "/usr/local/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 282, in _check_rclone
raise ValueError(f"rclone does not have a remote called {remote}")
ValueError: rclone does not have a remote called remote

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

  • Unifi Protect Backup version: 0.8.1
  • Unifi Protect version: 2.2.6
  • Python version:
  • Operating System:
  • Are you using a docker container or native?: Docker

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?

Destination file and path names, timezone

Discussed in #26

Originally posted by Amphiboly March 9, 2022
All is working well, thank you. This is an enhancement request.

I see that the destination file and path names are based on the UTC date expansion of the event start time. The result for me (in EST5EDT) is that many events are placed in a directory with the next day's date (relative to the local time).

image

Is there a way to use the local time to fashion the file and directory names?

--
Rik

Events which are larger than the buffer size never get abandoned

  • Unifi Protect Backup version:
  • Unifi Protect version: 0.9.0
  • Python version: 3.10.10
  • Operating System: Unraid 6.11.5
  • Are you using a docker container or native?: Docker

Description

It appears that an event which is larger than the buffer size was generated. Every so often the tool is retrying the download and failing because the event is larger than the buffer. It seems that this event is not being abandoned after N attempts like the others, and instead keeps retrying. I don't know if it disappears at the end of the retention window or not as it has not been long enough to find out.

This event should either be abandoned after N attempts like some others are, or arguably immediately abandoned as it can never successfully download. (I presume the alternative would be to dynamically grow the buffer size with a default and a maximum, where maximum is only used if required. Abandon if larger than max. Just thinking out loud...).

What I Did

I am running with the latest docker image on github. The config is:

2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :  Config:
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    address='10.10.0.254'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    port=443
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    username='protectsync'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    password=REDACTED
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    verify_ssl=False
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    rclone_destination='Dropbox:/UnifiProtect'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    retention='7d'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    rclone_args='"--bwlimit=3000k"'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    ignore_cameras=()
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    verbose=1
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    detection_types=['motion', 'person', 'vehicle', 'ring']
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    sqlite_path='/config/database/events.sqlite'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    download_buffer_size=512.0MiB
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    purge_interval='1d'
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    apprise_notifiers=()
2023-04-27 19:04:57 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup_core :    skip_missing=False

The error I am seeing is:

ERROR
2023-04-27 19:07:20 [   ERROR   ] unifi_protect_backup.downloader            : [6449950c014ac403e40003f8]  Unexpected exception occurred, abandoning event 6449950c014ac403e40003f8:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/downloader.py", line 155, in start
    await self.upload_queue.put((event, video))
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/utils.py", line 413, in put
    raise ValueError(
ValueError: Item is larger (952.3MiB) than the size of the buffer (512.0MiB)
ERROR
2023-04-27 19:12:05 [   ERROR   ] unifi_protect_backup.downloader            : [6449950c014ac403e40003f8]  Unexpected exception occurred, abandoning event 6449950c014ac403e40003f8:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/downloader.py", line 155, in start
    await self.upload_queue.put((event, video))
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/utils.py", line 413, in put
    raise ValueError(
ValueError: Item is larger (952.3MiB) than the size of the buffer (512.0MiB)
ERROR
2023-04-27 19:17:24 [   ERROR   ] unifi_protect_backup.downloader            : [6449950c014ac403e40003f8]  Unexpected exception occurred, abandoning event 6449950c014ac403e40003f8:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/downloader.py", line 155, in start
    await self.upload_queue.put((event, video))
  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/utils.py", line 413, in put
    raise ValueError(
ValueError: Item is larger (952.3MiB) than the size of the buffer (512.0MiB)

Feature Request: Ability to execute current events and then quit

Description

Rather than the code running and re-polling every 5 mins, can we have an option for it to check the current queue, process all items and then quit?

This would allow me to vary the schedule of polling by using cron to manage my poll frequency rather than using the backed-in 5 min polling frequency.

I'd rather the code executed the entire queue and then terminated, rather than keep on polling.

Unable to connect to Unifi Protect 2.1.1

  • Unifi Protect Backup version:
    0.7.1
  • Unifi Protect version:
    2.1.1
  • Python version:
  • Operating System:
    Proxmox 7.2-7 (Debian)
  • Are you using a docker container or native?:
    Docker container at latest release 0.7.1

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

After updating from 1.x.x of Unifi Protect to 2.1.1. and a subsequent restart of my host that runs the Unifi Protect Backup container, I am no longer able to connect the two successfully. I created a new Protect role and user according to the updated readme, and when I then started the container I got a notification that the new user connected. However, it gets stuck in a loop, outputting the same error messages over and over, and uses lots of CPU.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Here are the container logs that repeat over and over.

2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Config:
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  address='192.168.1.1'
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  port=443
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  username='unifi_protect_backup'
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  password=REDACTED
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  verify_ssl=False
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  rclone_destination='local:/data'
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  retention='7d'
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  rclone_args=''
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  ignore_cameras=()
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  verbose=1
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  detection_types=['person']
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2022-07-16 21:23:17 [INFO]:unifi_protect_backup.unifi_protect_backup:	Starting...
2022-07-16 21:23:17 [INFO]:unifi_protect_backup.unifi_protect_backup:	Checking rclone configuration...
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	rclone found: /usr/bin/rclone
2022-07-16 21:23:17 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	ffprobe found: /usr/bin/ffprobe
2022-07-16 21:23:17 [INFO]:unifi_protect_backup.unifi_protect_backup:	Connecting to Unifi Protect...
Traceback (most recent call last):
  File "/usr/bin/unifi-protect-backup", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/cli.py", line 109, in main
    loop.run_until_complete(event_listener.start())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 288, in start
    await self._protect.update()
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 565, in update
    self._bootstrap = await self.get_bootstrap()
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/api.py", line 742, in get_bootstrap
    return Bootstrap.from_unifi_dict(**data, api=self)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 111, in from_unifi_dict
    data = cls.unifi_dict_to_dict(data)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 175, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 343, in unifi_dict_to_dict
    data[key] = cls._clean_protect_obj_dict(data[key], unifi_dicts[key], api)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 288, in _clean_protect_obj_dict
    items[key] = cls._clean_protect_obj(value, klass, api)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 272, in _clean_protect_obj
    return klass.unifi_dict_to_dict(data=data)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/devices.py", line 746, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 642, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 333, in unifi_dict_to_dict
    data[key] = cls._clean_protect_obj(data[key], unifi_objs[key], api)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 272, in _clean_protect_obj
    return klass.unifi_dict_to_dict(data=data)
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 326, in unifi_dict_to_dict
    data[key] = convert_unifi_data(data[key], cls.__fields__[key])
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/utils.py", line 169, in convert_unifi_data
    value = [convert_unifi_data(v, field) for v in value]
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/utils.py", line 169, in <listcomp>
    value = [convert_unifi_data(v, field) for v in value]
  File "/usr/lib/python3.9/site-packages/pyunifiprotect/utils.py", line 185, in convert_unifi_data
    value = field.type_(value)
  File "/usr/lib/python3.9/enum.py", line 384, in __call__
    return cls.__new__(cls, value)
  File "/usr/lib/python3.9/enum.py", line 702, in __new__
    raise ve_exc
ValueError: 'homekit' is not a valid VideoMode
2022-07-16 21:23:18 [ERROR]:asyncio             :	Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fdb27e315b0>
2022-07-16 21:23:18 [ERROR]:asyncio             :	Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7fdb27e308e0>, 3931.857471964)]']
connector: <aiohttp.connector.TCPConnector object at 0x7fdb27e31850>

Any suggestions?

Feature Request: Customizable Folder Layout

  • Unifi Protect Backup version: docker:latest
  • Python version: docker
  • Operating System: docker

Description

Presently, the backup script syncs with a folder structure of /{camera_name}/{date}/video_file. While this is great from an archival purpose, it's less ideal for other usages (correlating events, etc).

I'd love an option to flatten the structure by date and potentially time. So something like: /{date}/{hour}/{YYYY-MM-DDTHH:mm:ss}_{camera_name}_{event_type}.mp4 or potentially without the hour-resolution sub-folder.

One alternative to this would be to templatize the naming format with the appropriate variables to allow users to customize the filesystem layout.

[Bug] Attempting to download disconnect even types fails

  • Unifi Protect Backup version: 0.6-dev
  • Python version: docker
  • Operating System: docker

Description

When a disconnect event is received, the protect-backup attempts to download a video clip associated with the event. Such video clip doesn't exist and this causes it to try 5 times until hard-failing the sync.

While this doesn't cause any undesired behavior, it may be worth putting in handling for the event type to not try downloading the video which would never work (short of Unifi changing behavior).

Not a major issue, just something I noticed that I figured was worth pointing out.

2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Adding event 623f31d70...to queue (Current queue=1)
2022-03-26 15:32:16 [INFO]:unifi_protect_backup.unifi_protect_backup:	Backing up event: 623f31d70227f103e700daea
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	Remaining Queue: 0
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Camera: Front
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Type: disconnect
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Start: 2022-03-26T11-31-35 (1648308695.549)
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  End: 2022-03-26T11-32-16 (1648308736.596)
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Duration: 41.047
2022-03-26 15:32:16 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Sleeping (7.477881s) to ensure clip is ready to download...
2022-03-26 15:32:24 [DEBUG]:unifi_protect_backup.unifi_protect_backup:	  Downloading video...
2022-03-26 15:32:24 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed download attempt 1, retying in 1s
2022-03-26 15:32:24 [ERROR]:unifi_protect_backup.unifi_protect_backup:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 498, in _backup_events
    assert isinstance(video, bytes)
AssertionError
2022-03-26 15:32:25 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed download attempt 2, retying in 1s
2022-03-26 15:32:25 [ERROR]:unifi_protect_backup.unifi_protect_backup:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 498, in _backup_events
    assert isinstance(video, bytes)
AssertionError
2022-03-26 15:32:26 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed download attempt 3, retying in 1s
2022-03-26 15:32:26 [ERROR]:unifi_protect_backup.unifi_protect_backup:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 498, in _backup_events
    assert isinstance(video, bytes)
AssertionError
2022-03-26 15:32:27 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed download attempt 4, retying in 1s
2022-03-26 15:32:27 [ERROR]:unifi_protect_backup.unifi_protect_backup:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 498, in _backup_events
    assert isinstance(video, bytes)
AssertionError
2022-03-26 15:32:28 [WARNING]:unifi_protect_backup.unifi_protect_backup:	    Failed download attempt 5, retying in 1s
2022-03-26 15:32:28 [ERROR]:unifi_protect_backup.unifi_protect_backup:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 498, in _backup_events
    assert isinstance(video, bytes)
AssertionError
2022-03-26 15:32:29 [WARNING]:unifi_protect_backup.unifi_protect_backup:	Download failed after 5 attempts, abandoning event 623f31d70...:

new to python

  • Unifi Protect Backup version: CB UDM PRO
  • Unifi Protect version: CB UDM PRO
  • Python version: 3
  • Operating System: Ubuntu Server
  • Are you using a docker container or native?:

Description

issue with getting Python code to run.

What I Did

followed instructions for rclone with g drive. and installed python, pip and ffprobe. now need to run the code.

~/.local/lib/python3.10/site-packages/unifi_protect_backup$ python3 unifi_protect_backup.py

error:

Traceback (most recent call last):
  File "/home/username/.local/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 16, in <module>
    from unifi_protect_backup import EventListener, MissingEventChecker, Purge, VideoDownloader, VideoUploader
  File "/home/username/.local/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 16, in <module>
    from unifi_protect_backup import EventListener, MissingEventChecker, Purge, VideoDownloader, VideoUploader
ImportError: cannot import name 'EventListener' from partially initialized module 'unifi_protect_backup' (most likely due to a circular import) (/home/username/.local/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py)

New version not recognizing destination

Description

My configuration was running fine until the latest update.

The current setup is for a B2 remote with an encrypted overlay.

The config that unifi-protect-backup runs under points to the CRYPT_NAME destination (the encrypted overlay), with a trailing : since it doesn't need a path (being a overlay encryption to the other real remote destination, that is).

Somehow it seems the trailing colon gets removed at some point causing the script to crash?

This is the Rclone config:

[NAME]
type = b2
account = <REDACTED>
key = <REDACTED>
download_auth_duration = 1m0s

[CRYPT_NAME]
type = crypt
remote = NAME:/PATH
directory_name_encryption = <REDACTED>
password = <REDACTED>
filename_encryption = <REDACTED>

The Docker variables are thus set accordingly.

root@truecharts-unifi-protect-backup1:/app#ย echoย $RCLONE_DESTINATIONย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย 
CRYPT_NAME:ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย 
root@truecharts-unifi-protect-backup1:/app#ย rcloneย --configย /config/rclone/rclone.confย listremotesย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย 
NAME:ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย 
CRYPT_NAME:

What I Did

Confirmed that by simply rolling back to the previous Docker image (based on August's v 0.7.4 release) it works fine with the exact same setup.

Actual error message (names replaced accordingly):


-------------------------------------

[custom-init] No custom files found, skipping...

services-up: info: copying legacy longrun unifi-protect-backup (no readiness notification)

[ls.io-init] done.

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	Config:

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  address='<REDACTED>'

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  port=<REDACTED>

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  username='<REDACTED>'

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  password=REDACTED

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  verify_ssl=False

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  rclone_destination='CRYPT_NAME:'

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  retention='60d'

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  rclone_args=''

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  ignore_cameras=()

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  verbose=4

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  detection_types=['motion', 'person', 'vehicle', 'ring']

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	  sqlite_path='/config/database/events.sqlite'

2022-12-05 12:13:58 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :	Starting...

2022-12-05 12:13:58 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :	Checking rclone configuration...

2022-12-05 12:13:58 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :	rclone found: /usr/bin/rclone

2022-12-05 12:13:58 [EXTRA_DEBUG] unifi_protect_backup.utils                 :	stdout:

NAME:

	CRYPT_NAME:

2022-12-05 12:13:58 [EXTRA_DEBUG] unifi_protect_backup.utils                 :	stderr:

2022/12/05 12:13:58 DEBUG : Setting --config "/config/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/config/rclone/rclone.conf"

	2022/12/05 12:13:58 DEBUG : rclone: Version "v1.58.1-DEV" starting with parameters ["rclone" "listremotes" "-vv"]

	2022/12/05 12:13:58 DEBUG : Using config file from "/config/rclone/rclone.conf"

	2022/12/05 12:13:58 DEBUG : rclone: Version "v1.58.1-DEV" finishing with parameters ["rclone" "listremotes" "-vv"]

2022-12-05 12:13:58 [   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=ValueError('rclone does not have a remote called `CRYPT_NAME`')>

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 281, in start

    await self._check_rclone()

  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 373, in _check_rclone

    raise ValueError(f"rclone does not have a remote called `{remote}`")

ValueError: rclone does not have a remote called `CRYPT_NAME`

Docker in Mac - Cannot find rclone remote

  • Unifi Protect Backup version: 0.7.3
  • Unifi Protect version: 2.0.1
  • Python version: 3.9.12
  • Operating System: MacOS 12.4
  • Are you using a docker container or native?: Docker

Description

I am trying this out in Docker on a Mac but having trouble with the app finding the rclone remote. Error message:

raise ValueError(f"rclone does not have a remote called `{remote}`")

ValueError: rclone does not have a remote called `unifirclone`

What I Did

Docker script

docker run \
  -e UFP_USERNAME='unifibackup' \
  -e UFP_PASSWORD='REDACTED' \
  -e UFP_ADDRESS='192.168.1.1' \
  -e UFP_SSL_VERIFY='false' \
  -e RCLONE_DESTINATION='unifirclone:/12t-unifi-rclone' \
  -e RCLONE_RETENTION='180d' \
  -v /Users/porterranch/.config/rclone:/data \
  --mount type=bind,source="/Users/porterranch/.config/rclone/rclone.conf",target=/config/rclone.conf \
  -v /Users/porterranch/.config/rclone/:/config \
  ghcr.io/ep1cman/unifi-protect-backup

Rclone Config

[unifirclone]
type = dropbox
client_id = REDACTED
client_secret = REDACTED
token = {"access_token":"REDACTED","token_type":"bearer","refresh_token":"REDACTED","expiry":"2022-08-15T11:05:50.859498-07:00"}

Screenshot of docker inspect window
image

Traceback

Traceback (most recent call last):

  File "/usr/bin/unifi-protect-backup", line 8, in <module>

    sys.exit(main())

  File "/usr/lib/python3.10/site-packages/click/core.py", line 1137, in __call__

    return self.main(*args, **kwargs)

  File "/usr/lib/python3.10/site-packages/click/core.py", line 1062, in main

    rv = self.invoke(ctx)

  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke

    return ctx.invoke(self.callback, **ctx.params)

  File "/usr/lib/python3.10/site-packages/click/core.py", line 763, in invoke

    return __callback(*args, **kwargs)

  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/cli.py", line 109, in main

    loop.run_until_complete(event_listener.start())

  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete

    return future.result()

  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 278, in start

    await self._check_rclone()

  File "/usr/lib/python3.10/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 414, in _check_rclone

    raise ValueError(f"rclone does not have a remote called `{remote}`")

ValueError: rclone does not have a remote called `unifirclone`

no --version option

Unifi Protect Backup version: 0.3.1
Python version: 3.9.10
Operating System: Raspbian GNU/Linux 10 (buster)

Description

Tried to get version of the software, expected it to show a version. I had to use pip to figure out version

What I Did

(unifi-backup) thunt@raspberrypi:~ $ unifi-protect-backup --version
Usage: unifi-protect-backup [OPTIONS]
Try 'unifi-protect-backup --help' for help.

Error: No such option: --version (Possible options: --retention, --verbose)

Backup past and missed clips manually?

Is there a way to run the script manually to backup all past video clips that have not been backuped yet?

Use case:

  • Inital installation of this tool, and backing up everything that is already on protect
  • or, the docker/script failed for some reason over a time period, and now you have non-backuped footage that you would like to backup as well between the day when the script stopped and when you discovered it and restarted the task.

Thank you, that would be great! Otherwise, great work and tool! Thank you!

Add support for line crossing events

Unifi protect at some point added "Line crossing" events that are separate from motion or smart detect events. This tool should handle those too.

Notifications

Discussed in #62

Originally posted by Swallowtail23 December 8, 2022
The buffer size causing unifi-protect-backup to hang for me on the 342MB video got me thinking... No matter the limit, at some point someone is going to have a Unifi video that is too big...

Feature request:
As this is ideally run "headless", configure options for SMTP alert notification, or some other way for push notifications in event of a failed download/upload, or perhaps a "daily digest" style end of day container/app health update/stats summary to ensure ongoing successful function / recovery from failure.

https://github.com/caronc/apprise < Implement using this

Cameras no longer detected.

  • Unifi Protect Backup version: 0.7.3 and pyunifiprotect 4.1.1
  • Unifi Protect version: 2.1.2
  • Python version: 3.10.6
  • Operating System: W11x64
  • Are you using a docker container or native?: native

Description

Cameras are no longer detected since rolling update from Unifi to 2.5.11 (and through that, Protect 2.1.2). I have five cameras, one of which gets excluded.

What I Did

All was running fine until this morning. I have since uninstalled and (re)installed unifi-protect-backup and pyunifiprotect to ensure that the latest versions are in use. The problem persists.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Config:
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: address='192.168.1.102'
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: port=443
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: username='RikKabel'
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: password=REDACTED
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: verify_ssl=False
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone_destination='remote:Unifi'
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: retention='30D'
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone_args='--bwlimit=5M:20M'
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: ignore_cameras=('5ff74f4f0268be03e700045b',)
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: verbose=3
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: detection_types=['motion', 'person', 'vehicle', 'ring']
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2022-08-11 22:07:03 [INFO]:unifi_protect_backup.unifi_protect_backup: Starting...
2022-08-11 22:07:03 [INFO]:unifi_protect_backup.unifi_protect_backup: Checking rclone configuration...
2022-08-11 22:07:03 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone found: C:\Users\5CD\rclone\rclone.EXE
2022-08-11 22:07:03 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: stdout:
remote:

2022-08-11 22:07:03 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: stderr:
2022/08/11 22:07:03 DEBUG : rclone: Version "v1.59.1" starting with parameters ["rclone" "listremotes" "-vv"]
2022/08/11 22:07:03 DEBUG : Using config file from "C:\Users\5CD\AppData\Roaming\rclone\rclone.conf"
2022/08/11 22:07:03 DEBUG : rclone: Version "v1.59.1" finishing with parameters ["rclone" "listremotes" "-vv"]

2022-08-11 22:07:03 [INFO]:unifi_protect_backup.unifi_protect_backup: Connecting to Unifi Protect...
2022-08-11 22:07:03 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:07:03 [INFO]:unifi_protect_backup.unifi_protect_backup: Found cameras:
2022-08-11 22:07:03 [INFO]:unifi_protect_backup.unifi_protect_backup: Setting up purge task...
2022-08-11 22:07:03 [INFO]:unifi_protect_backup.unifi_protect_backup: Listening for events...
2022-08-11 22:08:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:08:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:08:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:08:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:08:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:08:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:09:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:09:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:09:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:09:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:09:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:09:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:10:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:10:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:10:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:10:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:10:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:10:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:11:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:11:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:11:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:11:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:11:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:11:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:11:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:11:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:11:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:11:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:12:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:12:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:12:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:12:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:12:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:12:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:13:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:13:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:14:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:14:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:14:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:14:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:14:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:14:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:14:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:14:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:14:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:14:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:15:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:15:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:16:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:16:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:16:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:16:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:16:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:16:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:17:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:17:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:17:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:17:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:17:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:17:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:18:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:18:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:18:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:18:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:18:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:18:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:18:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:18:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:18:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:18:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:19:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:19:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:19:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:19:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:19:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:19:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:20:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:20:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:21:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:21:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:21:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:21:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:21:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:21:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:22:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:22:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:22:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:22:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:22:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:22:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:23:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:23:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:23:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:23:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:23:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:23:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:23:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:23:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:23:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:23:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:24:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:24:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:25:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:25:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:25:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:25:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:25:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:25:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:25:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:25:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:25:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:25:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:26:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:26:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:27:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:27:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:27:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:27:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:27:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:27:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:28:00 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:28:00 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:28:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.
2022-08-11 22:28:00 [WARNING]:unifi_protect_backup.unifi_protect_backup: Attempting reconnect...
2022-08-11 22:28:00 [INFO]:pyunifiprotect.api : Websocket re-connected successfully
2022-08-11 22:28:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Re-established connection to Unifi Protect and to the websocket.
2022-08-11 22:28:59 [EXTRA_DEBUG]:unifi_protect_backup.unifi_protect_backup: Checking the status of the websocket...
2022-08-11 22:28:59 [WARNING]:pyunifiprotect.api : Websocket connection not active, failing back to polling
2022-08-11 22:28:59 [WARNING]:unifi_protect_backup.unifi_protect_backup: Lost connection to Unifi Protect.

--
Rik

Purging old files a week after creation?

  • Unifi Protect Backup version: 0.8.8
  • Unifi Protect version: 7.2.95
  • Python version: v3.9
  • Operating System: Debian 11
  • Are you using a docker container or native?: Native (well, LXC)

Description

Running unifi-protect-backup as a cron job, and noticed in the log the following:

2023-01-11 13:38:39 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Starting...
2023-01-11 13:38:39 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Checking rclone configuration...
2023-01-11 13:38:39 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  rclone found: /usr/bin/rclone
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Connecting to Unifi Protect...
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Found cameras:
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :   - 6113b4410315db0387000ed1: Driveway
2023-01-11 13:38:40 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  NVR TZ: Europe/London
2023-01-11 13:38:40 [   DEBUG   ] unifi_protect_backup.unifi_protect_backup  :  Local TZ: UTC
2023-01-11 13:38:40 [   DEBUG   ] unifi_protect_backup.downloader            :  ffprobe found: /usr/bin/ffprobe
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.unifi_protect_backup  :  Starting...
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.downloader            :  Starting Downloader
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.uploader              :  Starting Uploader
2023-01-11 13:38:40 [   DEBUG   ] unifi_protect_backup.event_listener        :  Subscribed to websocket
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.missing_event_checker :  Starting Missing Event Checker
2023-01-11 13:38:40 [   INFO    ] unifi_protect_backup.purge                 :  Purging event: 63b44924026a14038707c0e9.
2023-01-11 13:38:40 [   DEBUG   ] unifi_protect_backup.purge                 :   Deleted: OneDrive:/Backups/Unifi-Protect/Driveway/2023-01-03/2023-01-03T15-26-41 smartDetectZone (vehicle).mp4
2023-01-11 13:38:41 [   DEBUG   ] unifi_protect_backup.missing_event_checker :   Total undownloaded events: 0
2023-01-11 13:38:41 [   DEBUG   ] unifi_protect_backup.missing_event_checker :   Undownloaded events of wanted types: 0
2023-01-11 13:38:46 [   INFO    ] unifi_protect_backup.purge                 :  Purging event: 63b5352402b4140387084879.
2023-01-11 13:38:46 [   DEBUG   ] unifi_protect_backup.purge                 :   Deleted: OneDrive:/Backups/Unifi-Protect/Driveway/2023-01-04/2023-01-04T08-13-31 smartDetectZone (person).mp4
2023-01-11 13:38:51 [   INFO    ] unifi_protect_backup.purge                 :  Purging event: 63b55903013114038708634e.
2023-01-11 13:38:51 [   DEBUG   ] unifi_protect_backup.purge                 :   Deleted: OneDrive:/Backups/Unifi-Protect/Driveway/2023-01-04/2023-01-04T10-46-43 motion.mp4

I'm not sure why it's purging files that were uploaded less than a week ago? Is the default Cloud retention set to 7 days?

I assumed it would keep a copy of all motion events on the local server for as long as they were located on the local server, but appears wrong?

What I Did

Ran unifi-protect-backup -v (log as above).

Configure sleep time before download?

# Unifi protect does not return full video clips if the clip is requested too soon.
# There are two issues at play here:
# - Protect will only cut a clip on an keyframe which happen every 5s
# - Protect's pipeline needs a finite amount of time to make a clip available
# So we will wait 1.5x the keyframe interval to ensure that there is always ample video
# stored and Protect can return a full clip (which should be at least the length requested,
# but often longer)
time_since_event_ended = datetime.utcnow().replace(tzinfo=timezone.utc) - event.end
sleep_time = (timedelta(seconds=5 * 1.5) - time_since_event_ended).total_seconds()
if sleep_time > 0:
logger.debug(f" Sleeping ({sleep_time}s) to ensure clip is ready to download...")
await asyncio.sleep(sleep_time)

I like that we are waiting for the video to be ready, but in my initial setup and test I got:

2022-08-24 13:42:02 [INFO]:unifi_protect_backup.unifi_protect_backup:   Listening for events...
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:  Adding event 630663b402dc570387000b84-6304e6f900f75703870003ea to queue (Current queue=1)
2022-08-24 13:45:30 [INFO]:unifi_protect_backup.unifi_protect_backup:   Backing up event: 630663b402dc570387000b84-6304e6f900f75703870003ea
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:  Remaining Queue: 0
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:    Camera: Driveway
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:    Type: motion
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:    Start: 2022-08-24T13-45-18 (1661363118.658)
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:    End: 2022-08-24T13-45-42 (1661363142.653)
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:    Duration: 23.995
2022-08-24 13:45:30 [DEBUG]:unifi_protect_backup.unifi_protect_backup:    Sleeping (14420.020939s) to ensure clip is ready to download...
2022-08-24 13:45:36 [DEBUG]:unifi_protect_backup.unifi_protect_backup:  Adding event 630663b400fa570387000b83-6304e6f900f75703870003ea to queue (Current queue=1)
2022-08-24 13:48:46 [DEBUG]:unifi_protect_backup.unifi_protect_backup:  Adding event 6306647503ca570387000b94-6304e6f900f75703870003ea to queue (Current queue=2)
2022-08-24 13:48:46 [DEBUG]:unifi_protect_backup.unifi_protect_backup:  Adding event 6306646d00d4570387000b91-6304e6f900f75703870003ea to queue (Current queue=3)

Unless I'm mistaken, 14420.020939s is roughly 4 hours. That's a very long time to wait before uploading an event that could result in someone stealing the gear. I would think we want to upload the event to the offsite back up as soon as possible, i.e. before the gear is stolen.

ValueError for remote called '/data'

  • Unifi Protect Backup version: latest (4/13)
  • Python version: Unsure
  • Operating System: Unraid 6.9.2

Description

Filled out the template for the docker container in Unraid however on launch is failing to start with a manual /data path added. Note instructions in docker template read "By default it will backup clips locally to /data inside the container."

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.
Expecting UniFi-Protect-Backup to use local directories that are put into the Clip Directory parameter, however traceback reads as if it expects an additional path or variable.

What I Did

Created a new 'Data Path' path for the docker container to utilize for its rclone destination.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Config:
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: address='192.168.1.1'
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: port=8080
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: username='Alexandria_Backup'
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: password=REDACTED
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: verify_ssl=False
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone_destination='/data'
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: retention='7d'
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone_args=''
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: ignore_cameras=()
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: verbose=1
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: detection_types=['motion', 'person', 'vehicle', 'ring']
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: file_structure_format='{camera_name}/{event.start:%Y-%m-%d}/{event.end:%Y-%m-%dT%H-%M-%S} {detection_type}.mp4'
2022-04-14 02:13:09 [INFO]:unifi_protect_backup.unifi_protect_backup: Starting...
2022-04-14 02:13:09 [INFO]:unifi_protect_backup.unifi_protect_backup: Checking rclone configuration...
2022-04-14 02:13:09 [DEBUG]:unifi_protect_backup.unifi_protect_backup: rclone found: /usr/bin/rclone
Traceback (most recent call last):
File "/usr/bin/unifi-protect-backup", line 8, in <module>
sys.exit(main())
File "/usr/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/unifi_protect_backup/cli.py", line 109, in main
loop.run_until_complete(event_listener.start())
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 278, in start
await self._check_rclone()
File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 414, in _check_rclone
raise ValueError(f"rclone does not have a remote called `{remote}`")
ValueError: rclone does not have a remote called `/data`
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

Screenshot 2022-04-13 211919

New Unifi protect version appears to have broken backup

  • Unifi Protect Backup version: 0.7.0
  • Python version: 3.9.10
  • Operating System: Rasbian 10

Description

Had been running the backups fine. Updated Unifi protect to 2.0.1, backups started failing. Log from unifi protect showing successful downloads, then protect update, then no more successful downloads in attached screenshot
Screen Shot 2022-06-07 at 12 37 46 PM

What I Did

unifi-protect-backup --address 192.168.1.1 --no-verify-ssl --rclone-destination awsbackups:${BUCKTPREFIX}

2022-06-07 12:39:59 [INFO]:unifi_protect_backup.unifi_protect_backup:	Starting...
2022-06-07 12:39:59 [INFO]:unifi_protect_backup.unifi_protect_backup:	Checking rclone configuration...
2022-06-07 12:39:59 [INFO]:unifi_protect_backup.unifi_protect_backup:	Connecting to Unifi Protect...
Traceback (most recent call last):
  File "/home/thunt/unifi-backup/bin/unifi-protect-backup", line 8, in <module>
    sys.exit(main())
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/unifi_protect_backup/cli.py", line 109, in main
    loop.run_until_complete(event_listener.start())
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 288, in start
    await self._protect.update()
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/api.py", line 507, in update
    self._bootstrap = await self.get_bootstrap()
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/api.py", line 676, in get_bootstrap
    return Bootstrap.from_unifi_dict(**data, api=self)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 106, in from_unifi_dict
    data = cls.unifi_dict_to_dict(data)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/bootstrap.py", line 152, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 338, in unifi_dict_to_dict
    data[key] = cls._clean_protect_obj_dict(data[key], unifi_dicts[key], api)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 283, in _clean_protect_obj_dict
    items[key] = cls._clean_protect_obj(value, klass, api)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 267, in _clean_protect_obj
    return klass.unifi_dict_to_dict(data=data)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/devices.py", line 698, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 612, in unifi_dict_to_dict
    return super().unifi_dict_to_dict(data)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 328, in unifi_dict_to_dict
    data[key] = cls._clean_protect_obj(data[key], unifi_objs[key], api)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 267, in _clean_protect_obj
    return klass.unifi_dict_to_dict(data=data)
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/data/base.py", line 321, in unifi_dict_to_dict
    data[key] = convert_unifi_data(data[key], cls.__fields__[key])
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/utils.py", line 160, in convert_unifi_data
    value = [convert_unifi_data(v, field) for v in value]
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/utils.py", line 160, in <listcomp>
    value = [convert_unifi_data(v, field) for v in value]
  File "/home/thunt/unifi-backup/lib/python3.9/site-packages/pyunifiprotect/utils.py", line 176, in convert_unifi_data
    value = field.type_(value)
  File "/usr/local/lib/python3.9/enum.py", line 384, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.9/enum.py", line 702, in __new__
    raise ve_exc
ValueError: 'package' is not a valid SmartDetectObjectType
2022-06-07 12:40:01 [ERROR]:asyncio             :	Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0xb4ecebb0>
2022-06-07 12:40:01 [ERROR]:asyncio             :	Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0xb4ee9538>, 1580.794824017)]']
connector: <aiohttp.connector.TCPConnector object at 0xb4ecedf0>

Problems downloading video

  • Unifi Protect Backup version: 0.7
  • Python version: 3.9.7
  • Operating System: Arm64 Docker image, tested with pyunifiprotect v3.7 and 3.9

Description

Connects ok to UDM pro, but has issues downloading detections:
2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Adding event 629f0f8a03516603870019d9 to queue (Current queue=1) 2022-06-07 08:43:10 [INFO]:unifi_protect_backup.unifi_protect_backup: Backing up event: 629f0f8a03516603870019d9 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Remaining Queue: 0 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Camera: G3 Instant 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Type: motion 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Start: 2022-06-07T10-42-46 (1654591366.637) 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: End: 2022-06-07T10-43-02 (1654591382.822) 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Duration: 16.185 2022-06-07 08:43:10 [DEBUG]:unifi_protect_backup.unifi_protect_backup: Downloading video... 2022-06-07 08:43:10 [WARNING]:unifi_protect_backup.unifi_protect_backup: Failed download attempt 1, retying in 1s 2022-06-07 08:43:10 [ERROR]:unifi_protect_backup.unifi_protect_backup: Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 500, in _backup_events assert isinstance(video, bytes) AssertionError ... 2022-06-07 08:43:14 [WARNING]:unifi_protect_backup.unifi_protect_backup: Failed download attempt 5, retying in 1s 2022-06-07 08:43:14 [ERROR]:unifi_protect_backup.unifi_protect_backup: Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/unifi_protect_backup/unifi_protect_backup.py", line 500, in _backup_events assert isinstance(video, bytes) AssertionError 2022-06-07 08:43:15 [WARNING]:unifi_protect_backup.unifi_protect_backup: Download failed after 5 attempts, abandoning event 629f0f8a03516603870019d9:

What I Did

docker run -it \
  -e UFP_USERNAME='unifi-user \
  -e UFP_PASSWORD='password' \
  -e UFP_ADDRESS='10.0.10.1' \
  -e UFP_SSL_VERIFY='false' \
  -e RCLONE_DESTINATION='unifi-protect-backup:/mnt/unifi-protect-backup/' \
  -e VERBOSITY="vvvv" \
  -v /run \
  -v '/mnt/data/unifi-protect-backup/rclone.conf':'/root/.config/rclone/rclone.conf' \
  mydocker/unifi-protect-backup:latest $1

I rebuilt the docker image with arm64 support so I could run it on my UDM pro.

Feature Request: Option to skip previous recordings

Enhancement Request

It would be great to have an option to avoid re-uploading past videos, so that when working from a new setup and/or a DB refresh, users do not have to forcibly upload GBs of data (without knowing how much data the days of video represents) and can assume a future-recording only approach.

This could take the form of an environment variable like the others that would make the script only react to new recording events and not try to match previous missing ones.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.