This article reviews the different options on how to backup the UniFi Video recordings, for both Windows and Linux (Hardware NVR).
Table of Contents
When planning on backing up recordings, there are a number of details that should be taken into account:
- Videos are large files. Off-site backups will likely be too cumbersome without a sufficient upload speed and may be subject to bandwidth caps on both sides, meaning the upload bandwidth of the NVR site and the download bandwidth of the off-site storage. A single UVC-G3 camera will need at least 6 Mbps of upload if it's recording full-time at maximum bitrate, to perform a constant backup.
- A 1:1 ratio of storage for backups is required. If expecting 1TB of recordings in the NVR device, 1TB of storage at the backup location will be needed as well.
- There may be situations where the cameras are recording faster than a backup can move data. Consider network speeds and transfer protocols prior to implementing the backup.
- A storage device can only read and write at a certain speed. Performing a backup will degrade the reading speed substantially. It is recommended to make use of bandwidth limiting utilities, keeping in mind the previous point: it will be a delicate balance.
Locating the Recordings
On any operating system, the storage location will be found by logging into UniFi Video and following these steps:
- Click Settings in the lower left-hand corner.
- Click NVR Settings in the upper left-hand corner.
- Click the Configure tab (selected by default).
- The Recording Path is the value for UniFi Video Recording Backup Options “Recording Path”.
The Default location of recordings are:
- Windows Default: C:\ProgramData\unifi-video\videos
- Linux Default: /var/lib/unifi-video/videos
- airVision-C/UVC-NVR Default: /srv/unifi-video/videos
Unless the Windows version used has the ability to install a native NFS client, a USB 3.0 drive is recommended. The NFS client is significantly faster when compared to Samba (Windows file sharing), but Microsoft has not adopted this protocol in recent Windows versions.
Method 1 (Recommended):
- Mount the backup device.
- Use a backup utility to copy the recordings to the backup device.
Method 2 (Alternate):
- Mount the backup device.
- Create a batch script that will copy the recording directory to the backup storage.
- Use Task Scheduler to run the script at your desired intervals .
A batch script would resemble something like:
xcopy /E C:\ProgramData\unifi-video\videos\* “D:\UFV Backup\”
Linux offers NFS and iSCSI out of the box. Here are a couple guides to get started:
- Adding iSCSI: UniFi Video - Adding a Network Volume to the NVR Appliance
- Adding USB: UniFi Video - Adding an External Hard Drive to the NVR Appliance
For any other Linux machines, make use of
/etc/fstab. A typical
fstab mount would look like this:
/path/to/your/partition /backup/mount/path auto defaults,nodiratime,noatime,errors=continue 0 2
Linux has a utility for copying files called rsync. This is what that would look like:
rsync -rltzhu --progress --delete /source/recording/path /destination/backup/path
For a reference of what these flags do, please see the rsync manual page. The keys here are the
-r tells rsync to copy recursively (sub directories) and
--delete tells rsync to delete files on the destination that do not exist on the source. Command
--delete is particularly important if you need to clear old data. Failing to use
--delete will inevitably fill up your backup location causing future syncs to fail.
It is recommended to run this command back-to-back until the transfer time is minimal. Then the sync to run on an interval can be scheduled. This is done via crontab in Linux. To edit the crontab, follow these steps:
2. Enter a line at the bottom of the crontab.
The following example will sync files every 5 minutes:
*\5 * * * * rsync -rltzhu --delete /source/recording/path /destination/backup/path
The following example will sync every night at 2AM:
0 2 * * * rsync -rltzhu --delete /source/recording/path /destination/backup/path
The frequency in which the command runs can be tweaked by editing the first 5 characters. The first character is minute, the second is hour, the third is day of month (i.e. the 15 would be the 15th day of the month), fourth is month (i.e. June is 6), and fifth is the day of the week (i.e. 0 is Sunday, 6 is Saturday). Wildcards (asterisks, *) should be used in most cases. In the second example, it says minute = 0, hour = 2 (or 2:00 am, to be specific), every day of the month, every month, and every day of the week.
Another example for wildcards is running intervals within those constraints. The first example has “*\5” for minutes, this means run every 5 minutes. A similar setup for hours would be “*” in the hour place to run every hour or “*\2” to run every two hours. There are also shortcuts such as “@daily” which is really an alias for “0 0 * * *” (this is Midnight every day). For a more thorough explanation of cron for your customization purposes, please see this guide.
Alternatives to rsync in Linux:
- DRBD (provides an exact replica of the entire partition as a live sync)
sudo apt-get update && sudo apt-get install rsync