mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
Merge pull request #42 from Gocnak/master
Archive to FTP server using rsync
This commit is contained in:
24
windows_archive/archive-rsync
Normal file
24
windows_archive/archive-rsync
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
LOG_FILE=/tmp/archive-rsync.log
|
||||
|
||||
function log () {
|
||||
echo "$( date )" >> "$LOG_FILE"
|
||||
echo "$1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
source /root/.teslaCamRsyncConfig
|
||||
|
||||
nfiles=$(rsync -auvh --stats --log-file=/tmp/archive-rsync-cmd.log /mnt/cam/TeslaCam/saved* $user@$server:$path | awk '/files transferred/{print $NF}')
|
||||
|
||||
if [ $nfiles > 0 ]
|
||||
then
|
||||
if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $nfiles > 0]
|
||||
then
|
||||
log "Sending Pushover message for copied files."
|
||||
/root/bin/send-pushover $nfiles
|
||||
fi
|
||||
log "Successfully synced files through rsync!"
|
||||
else
|
||||
log "No files to archive through rsync!"
|
||||
fi
|
||||
@@ -81,11 +81,13 @@ function move_clips_to_archive () {
|
||||
|
||||
done
|
||||
log "Moved $move_count file(s)."
|
||||
if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0 ]
|
||||
|
||||
if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0]
|
||||
then
|
||||
log "Sending Pushover message for copied files."
|
||||
/root/bin/send-pushover $move_count
|
||||
fi
|
||||
|
||||
log "Finished moving clips to archive."
|
||||
}
|
||||
|
||||
@@ -121,7 +123,10 @@ function unmount_cam_drive () {
|
||||
|
||||
log "Starting..."
|
||||
|
||||
ensure_archive_is_mounted
|
||||
if [ ! -r "/root/.teslaCamRsyncConfig" ]
|
||||
then
|
||||
ensure_archive_is_mounted
|
||||
fi
|
||||
|
||||
disconnect_usb_drives_from_host
|
||||
|
||||
@@ -129,7 +134,13 @@ fix_errors_on_cam_drive
|
||||
|
||||
ensure_cam_drive_is_mounted
|
||||
|
||||
move_clips_to_archive
|
||||
if [ -r "/root/.teslaCamRsyncConfig" ]
|
||||
then
|
||||
log "Archiving through rsync..."
|
||||
/root/bin/archive-rsync
|
||||
else
|
||||
move_clips_to_archive
|
||||
fi
|
||||
|
||||
unmount_cam_drive
|
||||
|
||||
|
||||
@@ -105,12 +105,21 @@ function create_usb_drive_backing_files () {
|
||||
|
||||
function configure_archive () {
|
||||
echo "Configuring the 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 '()')"
|
||||
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
|
||||
if [ $RSYNC_ENABLE = true ]
|
||||
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..."
|
||||
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 '()')"
|
||||
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 "password=$sharepassword" >> /root/.teslaCamArchiveCredentials
|
||||
echo "username=$shareuser" > /root/.teslaCamArchiveCredentials
|
||||
echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials
|
||||
fi
|
||||
echo "Configured the archive."
|
||||
}
|
||||
|
||||
@@ -128,6 +137,12 @@ function configure_archive_scripts () {
|
||||
pushd /root/bin
|
||||
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/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
|
||||
echo "Configured the archive scripts."
|
||||
|
||||
@@ -190,10 +205,18 @@ function make_root_fs_readonly () {
|
||||
|
||||
echo "Verifying environment variables..."
|
||||
|
||||
if [ $RSYNC_ENABLE = true ]
|
||||
then
|
||||
check_variable "RSYNC_USER"
|
||||
check_variable "RSYNC_SERVER"
|
||||
export 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 "sharename"
|
||||
check_variable "shareuser"
|
||||
check_variable "sharepassword"
|
||||
check_variable "campercent"
|
||||
|
||||
check_pushover_enabled
|
||||
|
||||
Reference in New Issue
Block a user