Initial rsync support (untested)

Currently untested, but the main idea is there
Currently it's either the normal archive server or rsync; not both, which is something to consider when adding things like gdrive and s3 (make it more modular?)
This commit is contained in:
Gocnak
2018-10-20 03:26:08 -04:00
parent 29a79bf45e
commit 002d1e6f6c
5 changed files with 103 additions and 13 deletions

View File

@@ -55,7 +55,10 @@ Set up a share on a Windows (or macOS using Sharing, or Linux using Samba) machi
Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. You can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41. Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. You can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41.
### TODO Other hosting solutions ### Hosting via SFTP/rsync
Since sftp/rsync is accessing a computer through SSH, the only requirement for hosting an SFTP/rsync server is to have a box running Linux. An example can be another Raspberry Pi connected to your local network with a USB storage drive plugged in. The official Raspberry Pi site has a good example on [how to mount an external drive](https://www.raspberrypi.org/documentation/configuration/external-storage.md). You will need the username and host/IP of the storage server, as well as the path for the files to go in, and the storage server will need to allow SSH.
### ***TODO: Other hosting solutions***
## Set up the Raspberry Pi ## Set up the Raspberry Pi
There are four phases to setting up the Pi: There are four phases to setting up the Pi:
@@ -89,13 +92,18 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s
ping 192.168.0.41 ping 192.168.0.41
``` ```
1. If you can't ping the archive server by IP address from the Pi, you should go do whatever you need to on your network to fix that. If you can't reach the archive server by name, from the Pi but you can by IP address, then use its IP address, below, in place of its name. 1. If you can't ping the archive server by IP address from the Pi, you should go do whatever you need to on your network to fix that. If you can't reach the archive server by name, from the Pi but you can by IP address, then use its IP address, below, in place of its name.
1. Run these commands, subsituting your values. The last line is the percent of the drive you want to allocate for dashcam storage. The remaining percentage will be allocated for music. 1. Determine how much, as a percentage of the drive you want to allocate to recording dashcam footage by using:
```
export campercent=<number>
```
For example, using `export campercent=100` would allocate 100% of the space to recording footage from your car. `export campercent=50` would be only allocate half of the space for dashcam footage, and allow the other half to be used by music.
1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](SetupRSync.md), and skip the next step.
1. Run these commands, subsituting your values for your shared drive:
``` ```
export archiveserver=Nautilus export archiveserver=Nautilus
export sharename=SailfishCam export sharename=SailfishCam
export shareuser=sailfish export shareuser=sailfish
export sharepassword=pa$$w0rd export sharepassword=pa$$w0rd
export campercent=100
``` ```
1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md). 1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md).
1. Run these commands: 1. Run these commands:

36
SetupRSync.md Normal file
View File

@@ -0,0 +1,36 @@
# Introduction
This guide will show you how to utilize [rsync](https://rsync.samba.org/) to archive your saved TeslaCam footage on a remote storage server. In my case, I use this for a networked pi storage server.
This guide makes the following assumptions:
1. You are running your own ftp/rsync server that you have admin rights to, or can at least add a public key to its `~/.ssh/authorized_keys` file
2. You have **NOT** run the `setup-teslacam` script yet
# Step 1: Authentication
Similar to sftp, rsync by default utilizes ssh to connect to a remote server and transfer files. This guide will use a generated ssh keypair, hence the first assumption above.
On your teslausb pi, run `ssh-keygen` to generate an ssh key. Add the contents of the newly generated `~/.ssh/id_rsa.pub` file from your teslausb pi to the storage server's `~/.ssh/authorized_keys` file. This will allow a nice and easy connection through rsync, no passwords needed!
# Step 2: Exports
To be able to configure the teslausb pi use rsync, you'll need to export a few things. On your teslausb pi, run:
```
export RSYNC_ENABLE=true
export RSYNC_USER=<ftp username>
export RSYNC_SERVER=<ftp IP/host>
export RSYNC_PATH=<destination path to save in>
```
Explanations for each:
* `RSYNC_ENABLE`: `true` for enabling rsync
* `RSYNC_USER`: The user on the FTP server
* `RSYNC_SERVER`: The IP address/hostname of the destination machine
* `RSYNC_PATH`: The path on the destination machine where the files will be saved
An example (of my) config is listed below:
```
export RSYNC_ENABLE=true
export RSYNC_USER=pi
export RSYNC_SERVER=192.168.1.254
export RSYNC_PATH=/mnt/PIHDD/TeslaCam/
```
***Note: RSYNC_ENABLE=true is going to disable the default archive server. Perhaps future releases will allow both to be defined and function at the same time, for redundancy, but for now just pick one that you'll want the most.***

View File

@@ -0,0 +1,12 @@
#!/bin/bash -eu
function log () {
echo "$( date )" >> "$LOG_FILE"
echo "$1" >> "$LOG_FILE"
}
source /root/.teslaCamRsyncConfig
rsync -au /mnt/archive $user@$server:$path
log "Successfully synced files through rsync!"

View File

@@ -81,11 +81,22 @@ function move_clips_to_archive () {
done done
log "Moved $move_count file(s)." log "Moved $move_count file(s)."
if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0 ]
if [ $move_count > 0]
then then
log "Sending Pushover message for copied files." if [ -r "/root/.teslaCamRsyncConfig" ]
/root/bin/send-pushover $move_count then
log "Archiving through rsync..."
/root/bin/archive-rsync
fi
if [ -r "/root/.teslaCamPushoverCredentials" ]
then
log "Sending Pushover message for copied files."
/root/bin/send-pushover $move_count
fi
fi fi
log "Finished moving clips to archive." log "Finished moving clips to archive."
} }

View File

@@ -109,11 +109,20 @@ function create_usb_drive_backing_files () {
function configure_archive () { function configure_archive () {
echo "Configuring the archive..." echo "Configuring the archive..."
mkdir /mnt/archive mkdir /mnt/archive
local archive_server_ip_address="$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')" if [ $RSYNC_ENABLE = true ]
echo "//$archive_server_ip_address/$sharename /mnt/archive cifs vers=3,credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab then
echo "Configuring for Rsync..."
echo "user=$RSYNC_USER" > /root/.teslaCamRsyncConfig
echo "server=$RSYNC_SERVER" > /root/.teslaCamRsyncConfig
echo "path=$RSYNC_PATH" > /root/.teslaCamRsyncConfig
else
echo "Configuring for a shared drive..."
local archive_server_ip_address="$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')"
echo "//$archive_server_ip_address/$sharename /mnt/archive cifs vers=3,credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab
echo "username=$shareuser" > /root/.teslaCamArchiveCredentials echo "username=$shareuser" > /root/.teslaCamArchiveCredentials
echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials
fi
echo "Configured the archive." echo "Configured the archive."
} }
@@ -131,6 +140,12 @@ function configure_archive_scripts () {
pushd /root/bin pushd /root/bin
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-teslacam-clips
chmod +x archive-teslacam-clips chmod +x archive-teslacam-clips
if [ $RSYNC_ENABLE = true ]
then
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/archive-rsync
chmod +x archive-rsync
fi
popd popd
echo "Configured the archive scripts." echo "Configured the archive scripts."
@@ -193,10 +208,18 @@ function make_root_fs_readonly () {
echo "Verifying environment variables..." echo "Verifying environment variables..."
if [ $RSYNC_ENABLE = true ]
then
check_variable "RSYNC_USER"
check_variable "RSYNC_SERVER"
archiveserver = $RSYNC_SERVER
check_variable "RSYNC_PATH"
else # Else for now, TODO allow both for more redundancy?
check_variable "sharename"
check_variable "shareuser"
check_variable "sharepassword"
fi
check_variable "archiveserver" check_variable "archiveserver"
check_variable "sharename"
check_variable "shareuser"
check_variable "sharepassword"
check_variable "campercent" check_variable "campercent"
check_pushover_enabled check_pushover_enabled