Add extra param to purge (#86)

* Added optional argument string to pass directly to the `rclone delete` command used to purge video files. This will allow for immediate deletion of files on destinations where the file might otherwise go to a recycle bin by default.

---------

Co-authored-by: Igor Wolbers <igor@sparcobv.onmicrosoft.com>
Co-authored-by: Sebastian Goscik <sebastian.goscik@live.co.uk>
This commit is contained in:
Igor Wolbers
2023-04-29 04:19:41 -04:00
committed by GitHub
parent 1b38cb3db3
commit e5112de35c
5 changed files with 28 additions and 4 deletions

View File

@@ -12,9 +12,9 @@ from unifi_protect_backup.utils import run_command, wait_until
logger = logging.getLogger(__name__)
async def delete_file(file_path):
async def delete_file(file_path, rclone_purge_args):
"""Deletes `file_path` via rclone."""
returncode, stdout, stderr = await run_command(f'rclone delete -vv "{file_path}"')
returncode, stdout, stderr = await run_command(f'rclone delete -vv "{file_path}" {rclone_purge_args}')
if returncode != 0:
logger.error(f" Failed to delete file: '{file_path}'")
@@ -35,6 +35,7 @@ class Purge:
retention: relativedelta,
rclone_destination: str,
interval: relativedelta = relativedelta(days=1),
rclone_purge_args: str = "",
):
"""Init.
@@ -43,11 +44,13 @@ class Purge:
retention (relativedelta): How long clips should be kept
rclone_destination (str): What rclone destination the clips are stored in
interval (relativedelta): How often to purge old clips
rclone_purge_args (str): Optional extra arguments to pass to `rclone delete` directly.
"""
self._db: aiosqlite.Connection = db
self.retention: relativedelta = retention
self.rclone_destination: str = rclone_destination
self.interval: relativedelta = interval
self.rclone_purge_args: str = rclone_purge_args
async def start(self):
"""Main loop - runs forever."""
@@ -68,7 +71,7 @@ class Purge:
async with self._db.execute(f"SELECT * FROM backups WHERE id = '{event_id}'") as backup_cursor:
async for _, remote, file_path in backup_cursor:
logger.debug(f" Deleted: {remote}:{file_path}")
await delete_file(f"{remote}:{file_path}")
await delete_file(f"{remote}:{file_path}", self.rclone_purge_args)
deleted_a_file = True
# delete event from database