Off-site CCTV backup part 2

In part 1 of this series, I demonstrated how IP security cameras could be used to upload once-per-minute snapshots via FTP, over an IPsec tunnel to an Amazon EC2 instance. The EC2 takes care of compressing the generated series of images into daily time-lapse videos, which can be used as a second layer of security for monitoring premises.

In this post, a USB webcam will be used along with the linux software motion to detect motion, do client-side compression, and save these on the EC2 instance via. FTP.

The advantage over the previous method is that real-time video is saved to the cloud backup immediately, and the drawback is the limit imposed by available bandwidth, and reliance on a computer for video processing.

Equipment used: ELP-USB100W05MT-DL36 1MP USB dome camera; a MikroTik RB951GL for IPsec tunnel to AWS.

Setup on client: First, install motion, as well as curlftpfs – on ubuntu this is done by sudo apt-get install motion curlftpfs. Curlftpfs will allow us to mount an ftp server (specifically, the one used in part 1) to a directory.

Then, some changes will be made to /etc/motion/motion.conf to set the destination format and make the program runnable as non-root (these configuration variables are specific to the latest motion):

process_id_file /tmp/motion.pid
logfile /tmp/motion.log
width 1280
height 720
framerate 30
output_pictures off
ffmpeg_output_movies on
target_dir /tmp/cam/_home/
movie_filename "%Y-%m-%d_%H:%M:%S"

In addition, I turned off the live stream server and HTTP server.

Now, a script will create the temporary folder, mount the ftp server to it, and start motion:

#!/bin/bash
mkdir /tmp/cam
curlftpfs 172.31.1.1 /tmp/cam -o user=camera:password
motion

Now, any time motion is detected, a movie file is encoded and streamed to the cloud backup. Since these would normally accumulate indefinitely, it’s good to have a cron job run a daily cleanup on the EC2 instance. The following code in pseudo-lingo reads: While the folder has more than 100MB of files, remove the oldest 10 AVI files.

cd /home/camera/_home
while [ `du -b |awk 'NR==1{print $1}'` -gt 100000000 ]
do
    rm `ls -1 *.avi |head -10`
done

With all this running, I managed to figure out that my cat sulks quite a bit when I’m away!