Skip to content

Instantly share code, notes, and snippets.

@TaylorBurnham
Last active January 15, 2023 16:20
Show Gist options
  • Save TaylorBurnham/72284e3d0b8c7abdf4f65b3703fd99eb to your computer and use it in GitHub Desktop.
Save TaylorBurnham/72284e3d0b8c7abdf4f65b3703fd99eb to your computer and use it in GitHub Desktop.
Unifi Video Rsync to NAS with remux

I've made some changes to this to improve performance. Running prepare.sh takes too long on my CloudKey Gen 2, so I installed the qemu libraries to run it on my desktop where I will be extracting videos. The author of the remux utility has instructions for how to do this on the README.

I'm running seven total cameras and will synchronize all of the data to my Synology NAS, and from there I'll run the remux utility to extract videos. This is still a work in progress but I will eventually have all of this documented under my Unifi Protect Extract repository.

Requirements:

  • A passwordless SSH key generated on the user running it.
  • sync.sh saved to the user's home.

Fill out the variables in the sync.sh script and run it. It will only pull the standard ubv files that are written by Protect and skip timelapse and others. I found it easier to just synchronize the whole hierarchy than have to deal with formatting dates and creating directories.

This can run as a scheduled task and if the ubv file that was previously synchronized is updated it will replaced.

#!/bin/bash
# Destination Paths
RSYNC_USER="user"
RSYNC_HOST="host.name.com"
RSYNC_PATH="/path/to/output/"
# Set our paths
SRC_PATH="/srv/unifi-protect/video/"
DST_PATH="${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}"
# Now rsync
echo "Synchronizing Files from ${SRC_PATH} to ${DST_PATH}"
rsync -avP --inplace \
-e "ssh -i /root/.ssh/id_rsa -p 22" \
--include="*_0_rotating_*.ubv" \
--exclude="*_2_*" \
--exclude="*_0_timelapse*" \
--exclude="pool" \
"${SRC_PATH}" "${DST_PATH}"
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment