# motion_sync ...is a little bash script for rpi + a USB webcam that I wrote to upload motioneye vids and pics to you box account every minute for security reasons. The idea behind it is that a thief / malicious person might be knowledgeable of the pi / motioneye setup and either cut the power to the premise before breaking in or go to the setup pi / webcam and disconnect it from power / disconnect the USB webcam or the LAN cable... With my script even if a break-in happens, the thief / malicious person will be captured and if properly "UPS-ed" (pi+router) have no chance in "not" getting captures uploaded to cloud storage. I use motioneye because is open source and free, and lightweight, so can run on a pi. I use Box because the free account gives us 10GB I use a Pi because it is cheap and has WiFi and LAN and USB, so a cheap WebCam will do. It works in conjuction with motioneye and with an rclone box service I also created in /etc/systemd/user/rclone-box.service ## Getting started Install motioneye, create a box account and do not use it for anything else. Install rclone on the pi and connect it to Box (google it) Once Motioneye is working and saving to /var/lib/motioneye create a systemd service that keeps Box rclone alive: mkdir -p ~/.config/systemd/user nano ~/.config/systemd/user/rclone-box.service [Unit] Description=Rclone Box Mount Documentation=man:rclone(1) After=network-online.target Wants=network-online.target [Service] Type=notify ExecStart=/usr/bin/rclone mount box: %h/box \ --config %h/.config/rclone/rclone.conf \ --vfs-cache-mode full \ --vfs-cache-max-size 10G \ --vfs-cache-max-age 24h \ --dir-cache-time 72h \ --allow-other \ --umask 022 ExecStop=/bin/fuermount -u %h/box Restart=on-failure RestartSec=10s [Install] WantedBy=default.target Finally, create 2 crontab entries, one to keep the Box OAuth token alive and one to run my script every minute: sudo crontab -e # Keep Box OAuth token alive (runs weekly, e.g., every Sunday at 3 AM) 0 3 * * 0 rclone lsd box: >/dev/null 2>&1 # Sync motion recordings and cleanup (runs every minute) * * * * * /home/$USER/sync_motion.sh >/dev/null 2>&1 My script does the following for you: # 1. Ensures log directory exists # 2. Keeps log file under ~5 MB by trimming it when it gets too large # 3. Remuxes MKV to MP4 (so the videos work on the pi motioneye webserver) # 4. Local cleanup (Batch Trim down to 9GB) # 5. Syncs to BOX with rclone (Reflects local 9GB state & deletes missing remote files)