mirror of
https://github.com/ep1cman/unifi-protect-backup.git
synced 2025-12-10 05:13:28 +00:00
Add ability to INCLUDE specific cameras instead of EXCLUDE (#179)
Co-authored-by: Sebastian Goscik <sebastian.goscik@live.co.uk>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Console script for unifi_protect_backup."""
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
import click
|
||||
@@ -108,6 +109,16 @@ def parse_rclone_retention(ctx, param, retention) -> relativedelta:
|
||||
"Alternatively, use a Unifi user with a role which has access restricted to the subset of cameras "
|
||||
"that you wish to backup.",
|
||||
)
|
||||
@click.option(
|
||||
"--camera",
|
||||
"cameras",
|
||||
multiple=True,
|
||||
envvar="ONLY_CAMERAS",
|
||||
help="IDs of *ONLY* cameras for which events should be backed up. Use multiple times to include "
|
||||
"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.",
|
||||
)
|
||||
@click.option(
|
||||
"--file-structure-format",
|
||||
envvar="FILE_STRUCTURE_FORMAT",
|
||||
@@ -228,8 +239,25 @@ a lot of failed downloads with the default downloader.
|
||||
)
|
||||
def main(**kwargs):
|
||||
"""A Python based tool for backing up Unifi Protect event clips as they occur."""
|
||||
event_listener = UnifiProtectBackup(**kwargs)
|
||||
run(event_listener.start(), stop_on_unhandled_errors=True)
|
||||
|
||||
try:
|
||||
# Validate only one of the camera select arguments was given
|
||||
if kwargs.get("cameras") and kwargs.get("ignore_cameras"):
|
||||
click.echo(
|
||||
"Error: --camera and --ignore-camera options are mutually exclusive. "
|
||||
"Please use only one of these options.",
|
||||
err=True,
|
||||
)
|
||||
raise SystemExit(200) # throw 200 = arg error, service will not be restarted (docker)
|
||||
|
||||
# Only create the event listener and run if validation passes
|
||||
event_listener = UnifiProtectBackup(**kwargs)
|
||||
run(event_listener.start(), stop_on_unhandled_errors=True)
|
||||
except SystemExit as e:
|
||||
sys.exit(e.code)
|
||||
except Exception as e:
|
||||
click.echo(f"Error: {str(e)}", err=True)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user