Skip to main content

Python tool to backup unifi event clips in realtime.

Project description

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

Requirements

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

Installation

  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

Usage

Usage: unifi-protect-backup [OPTIONS]

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

Options:
  --address TEXT                  Address of Unifi Protect instance
                                  [required]
  --port INTEGER                  Port of Unifi Protect instance
  --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
  --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)
  -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]
  --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

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.

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/dir/containing/rclone.conf/on/host':'/root/.config/rclone/' \
  ghcr.io/ep1cman/unifi-protect-backup

To create a rclone config file you can do the following:

$ docker run -it --rm ghcr.io/ep1cman/unifi-protect-backup /bin/sh
/app # rclone config
(Setup your rclone remote, see here for documentation: https://rclone.org/docs/#configure)
/app # cat $(rclone config file | sed -n 2p)
/app # exit

This should print out the contents of the newly configured rclone.conf file which you can now copy & paste into a file on your host system

Credits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unifi-protect-backup-0.1.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unifi_protect_backup-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file unifi-protect-backup-0.1.1.tar.gz.

File metadata

  • Download URL: unifi-protect-backup-0.1.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for unifi-protect-backup-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4131c03e66d42124d10c97139fe714e996b946fe836dac3487d04644c0758c7
MD5 81db2cd91fffdf56fe87de5121d4c136
BLAKE2b-256 e2f4094f37dffc9ebafc3fd1992a542e6aef48efeea4182890afc20bf65db279

See more details on using hashes here.

File details

Details for the file unifi_protect_backup-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: unifi_protect_backup-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for unifi_protect_backup-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 84cb58c18655be6fcfbd84f5263925c70f3f8d480cec50b7a458cb26da23657e
MD5 4e8ea24978120a80e292e82a0c3ba828
BLAKE2b-256 ecd5564c828650767187ced14cff4f84e95083a4f3d1dfc4f8d6bde8442b39da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page