UniFi Protect backup to Synology NAS
UniFi Protect Daten auf einem Synology NAS sichern
Leider bietet die UniFi Protect GUI nur minimale Möglichkeiten der Datensicherung.
Es ist zwar möglich Events und auch Bereiche der Videoaufzeichnung von Hand extern, über den Download-Button, zu sichern, damit hat es sich dann aber auch schon. Eine automatische Sicherung der aufgezeichneten Videos und Events sucht man derzeit allerdings vergebens. Leider ist das für ein, wie Ubiquiti es nennt, profesionelles Überwachungssystem absolut unzureichend.
Werbung
Bis eine entsprechende Funktionalität in die UniFi Protect Umgebung implementiert wird, müssen wir uns erst mal selbst helfen und die wertvollen Daten mit anderen Mitteln sichern.
In meinem Video zeige ich wie du die Videoaufzeichnung, die Events und sogar Momentaufnahmen deiner UniFi Protect Umgebung zusätzlich auf deinem Synology NAS speichern kannst.
Du kannst diese Vorgänge natürlich auch vollständig automatisieren, was ich ebenfalls in diesem Video zeige.
Grundsätzlich lässt sich aber das Ganze auch in komplett anderen Szenarien verwirklichen. du brauchst dafür einfach eine Umgebung in welcher du einen Docker Container ausführen kannst.
Auch das Ziel der Daten muss nicht zwingend das NAS selbst sein. Du musst einfach einen gültigen Zielpfad für die Sicherung angeben, was dann ja so ziemlich alles sein kann.
Du kannst dir die einzelnen Scripts einfach herauskopieren oder alle drei als Zip-Datei downloaden.
Und hier nun die im Video gezeigten Scrips im einzelnen.
Events Script
containername=unifi_cams_events #Name of the created docker container deviceIP="192.168.10.1" #Ip adress of your UniFi Device deviceUsername="username" #Username of LOCAL UniFi user devicePassword="password" #Password of LOCAL UniFi user saveTarget="/path/to/target" #Target file path where the images will be saved timeZone="Europe/Paris" #============== NO CHANGES BEOW THIS LINE ========================== startPoint=$(date --date "2 day ago" +%Y-%m-%d)T00:00:00 endPoint=$(date --date "1 day ago" +%Y-%m-%d)T00:00:00 allCams=true firstCam=true noSubFolders=true cams="" startSet=false endSet=false while [ $# -gt 0 ] #until parameter amount ($#) bigger then 0 do if [ $1 = "--subfolders" ]; then noSubFolders=false elif [ $1 = "--start" ]; then startSet=true shift #move parameters $2->$1, $3->$2, $4->$3,... startPoint=$1 elif [ $1 = "--end" ]; then endSet=true shift #move parameters $2->$1, $3->$2, $4->$3,... endPoint=$1 elif [ $1 = "--help" ]; then echo echo "Usage: events_unifi_events.sh [CAMS] [OPTIONS]... [default:]Backup events from previous day" echo echo "OPTIONS:" echo "--help Show this message and exit." echo "--subfolders Video(s) will be put in subfolder yerr/month/day/cam/" echo "--start YYYY-MM-DDTHH:MM:SS Period start" echo "--end YYYY-MM-DDTHH:MM:SS Period end" echo echo "CAMS: (if empty, events from all cams will be taken)" echo "Camera ID e.g. 62d2f99003a7b303e70003zr (multible \"Camera IDs\" as seperate parameter)" echo echo "============================" echo "= EXAMPELS =" echo "============================" echo " events_unifi_cams.sh 2d2f99003a7b303e70003zr 2d2f99003a7b303e78703zr --subfolders" echo "... will take events from both specifide cameras and puts the image files in subfolders" echo echo " events_unifi_cams.sh" echo "... will take all events footage from yesterday and from all available cameras and puts all the images into the same folder" echo exit 0 else allCams=false #minimum one parameter present if [ $firstCam = true ] then cams=$1 firstCam=false else cams+=,$1 fi fi shift #move parameters $2->$1, $3->$2, $4->$3,... done if [ "$startSet" = 'true' ] || [ "$endSet" = 'true' ]; then if [ "$startSet" = 'false' ] || [ "$endSet" = 'false' ]; then echo "only period \"START\" or \"END\" is defined!" echo "if you define period, \"start\" AND \"end\" need to be specified" exit 5 elif [ $(date --date="$startPoint" +%s) -gt $(date --date="$endPoint" +%s) ]; then echo "Period START is later than period END!" exit 5 fi fi echo =============================== echo Starting UniFi Protect Events echo =============================== date if [ $allCams = true ] then echo All cams cams=all else echo Specific cam\(s\)\ $cams fi if [ $noSubFolders = true ] then docker run -e TZ=$timeZone --name=$containername --volume $saveTarget:/downloads unifitoolbox/protect-archiver events --address=$deviceIP --username=$deviceUsername --password=$devicePassword --cameras=$cams --start=$startPoint --end=$endPoint --no-use-subfolders --touch-files /downloads else docker run -e TZ=$timeZone --name=$containername --volume $saveTarget:/downloads unifitoolbox/protect-archiver events --address=$deviceIP --username=$deviceUsername --password=$devicePassword --cameras=$cams --start=$startPoint --end=$endPoint --touch-files /downloads fi echo removing Docker container ... docker container rm $containername echo all done
Video Backup Script
containername=unifi_cams_backup #Name of the created docker container deviceIP="192.168.10.1" #Ip adress of your UniFi Device deviceUsername="username" #Username of LOCAL UniFi user devicePassword="passwort" #Password of LOCAL UniFi user saveTarget="/path/to/target" #Target file path where the images will be saved timeZone="Europe/Paris" #============== NO CHANGES BEOW THIS LINE ========================== startPoint=$(date --date "2 day ago" +%Y-%m-%d)T00:00:00 endPoint=$(date --date "1 day ago" +%Y-%m-%d)T00:00:00 allCams=true firstCam=true noSubFolders=true cams="" startSet=false endSet=false while [ $# -gt 0 ] #until parameter amount ($#) bigger then 0 do if [ $1 = "--subfolders" ]; then noSubFolders=false elif [ $1 = "--start" ]; then startSet=true shift #move parameters $2->$1, $3->$2, $4->$3,... startPoint=$1 elif [ $1 = "--end" ]; then endSet=true shift #move parameters $2->$1, $3->$2, $4->$3,... endPoint=$1 elif [ $1 = "--help" ]; then echo echo "Usage: backup_unifi_cams.sh [CAMS] [OPTIONS]... [default:] Backup footage from previous day" echo echo "OPTIONS:" echo "--help Show this message and exit." echo "--subfolders Video(s) will be put in subfolder yerr/month/day/cam/" echo "--start YYYY-MM-DDTHH:MM:SS Period start" echo "--end YYYY-MM-DDTHH:MM:SS Period end" echo echo "CAMS: (if empty, snapsots from all cams will be taken)" echo "Camera ID e.g. 62d2f99003a7b303e70003zr (multible \"Camera IDs\" as seperate parameter)" echo echo "============================" echo "= EXAMPELS =" echo "============================" echo " backup_unifi_cams.sh 2d2f99003a7b303e70003zr 2d2f99003a7b303e78703zr --subfolders" echo "... will take video footage from both specifide cameras and puts the image files in subfolders" echo echo " backup_unifi_cams.sh" echo "... will take video footage from yesterday and from all available cameras and puts all the images into the same folder" echo exit 0 else allCams=false #minimum one parameter present if [ $firstCam = true ] then cams=$1 firstCam=false else cams+=,$1 fi fi shift #move parameters $2->$1, $3->$2, $4->$3,... done if [ "$startSet" = 'true' ] || [ "$endSet" = 'true' ]; then if [ "$startSet" = 'false' ] || [ "$endSet" = 'false' ]; then echo "only period \"START\" or \"END\" is defined!" echo "if you define period, \"start\" AND \"end\" need to be specified" exit 5 elif [ $(date --date="$startPoint" +%s) -gt $(date --date="$endPoint" +%s) ]; then echo "Period START is later than period END!" exit 5 fi fi echo =============================== echo Starting UniFi Protect Snapshot echo =============================== date if [ $allCams = true ] then echo All cams cams=all else echo Specific cam\(s\)\ $cams fi if [ $noSubFolders = true ] then docker run -e TZ=$timeZone --name=$containername --volume $saveTarget:/downloads unifitoolbox/protect-archiver download --address=$deviceIP --username=$deviceUsername --password=$devicePassword --cameras=$cams --start=$startPoint --end=$endPoint --no-use-subfolders --touch-files /downloads else docker run -e TZ=$timeZone --name=$containername --volume $saveTarget:/downloads unifitoolbox/protect-archiver download --address=$deviceIP --username=$deviceUsername --password=$devicePassword --cameras=$cams --start=$startPoint --end=$endPoint --touch-files /downloads fi echo removing Docker container ... docker container rm $containername echo all done
Snapshots Script
containername=unifi_cams_snapshot #Name of the created docker container deviceIP="192.168.10.1" #Ip adress of your UniFi Device deviceUsername="username" #Username of LOCAL UniFi user devicePassword="passwort" #Password of LOCAL UniFi user saveTarget="/path/to/target" #Target file path where the images will be saved timeZone="Europe/Paris" #============== NO CHANGES BEOW THIS LINE ========================== allCams=true firstCam=true noSubFolders=true cams="" while [ $# -gt 0 ] #until parameter amount ($#) bigger then 0 do if [ $1 = "--subfolders" ] then noSubFolders=false elif [ $1 = "--help" ] then echo echo "Usage: snapshot_unifi_cams.sh [CAMS] [OPTIONS]..." echo echo "OPTIONS:" echo "--help Show this message and exit." echo "--subfolders Images will be put in subfolder yerr/month/day/cam/" echo echo "CAMS: (if empty, snapsots from all cams will be taken)" echo "Camera ID e.g. 62d2f99003a7b303e70003zr (multible \"Camera IDs\" as seperate parameter)" echo echo "============================" echo "= EXAMPELS =" echo "============================" echo " snapshot_unifi_cams.sh 2d2f99003a7b303e70003zr 2d2f99003a7b303e78703zr --subfolders" echo "... will take snapshots from both specifide cameras and puts the image files in subfolders" echo echo " snapshot_unifi_cams.sh" echo "... will take snapshots from all available cameras and puts all the images into the same folder" echo exit 0 else allCams=false #minimum one parameter present if [ $firstCam = true ] then cams=$1 firstCam=false else cams+=,$1 fi fi shift #move parameters $2->$1, $3->$2, $4->$3,... done echo =============================== echo Starting UniFi Protect Snapshot echo =============================== date if [ $allCams = true ] then echo All cams cams=all else echo Specific cam\(s\)\ $cams fi if [ $noSubFolders = true ] then docker run -e TZ=$timeZone --name=$containername --volume $saveTarget:/downloads unifitoolbox/protect-archiver download --address=$deviceIP --username=$deviceUsername --password=$devicePassword --cameras=$cams --snapshot --no-use-subfolders --touch-files /downloads else docker run -e TZ=$timeZone --name=$containername --volume $saveTarget:/downloads unifitoolbox/protect-archiver download --address=$deviceIP --username=$deviceUsername --password=$devicePassword --cameras=$cams --snapshot --touch-files /downloads fi echo removing Docker container ... docker container rm "$containername" echo all done
Werbung