SSH -rsync
by kzo81 from LinuxQuestions.org on (#6KEYH)
Hi Folks,
I encountered a strange problem. There is a video encoder that constantly records files, and I created this syncroniser script.
If I --remove-source-files parameter to rsync it senses that a file is beeing written by another process, and skips that file. I tested it on my laptop and it really skips it, but not always. On the server side some files are truncated to 828 bytes. Now I user it without that option, but I would really like to remove the files after sync:
Code:#!/bin/sh
set -x
MAC=$(ip a | grep ether | head -1 | awk '{print $2}' | sed 's/:/-/g')
CONFIG="/usr/bin/syncroniser.cfg"
KEY="/usr/bin/dropbear_rsa_host_key"
SRC="/media/sdmmc/mmcblk0p1/RECORD/"
DST="$MAC"
FREQ=60
while true
do
if test -f "$CONFIG"; then
. "$CONFIG"
fi
rsync -avme "ssh -i $KEY -p $REMOTE_PORT" $SRC $REMOTE_USER@$REMOTE_IP:$DST
sleep $FREQ
doneI was trying to pipe to rsync with find and xargs, but it still did that file truncation on the file beeing written.
Code:find $SRC -type f -exec sh -c 'if ! lsof `readlink -f {}` > /dev/null; then echo `basename {}`; fi' \; | tr '\n' '\0' | rsync -avme "ssh -i $KEY -p $REMOTE_PORT" $SRC $REMOTE_USER@$REMOTE_IP:$DST
I encountered a strange problem. There is a video encoder that constantly records files, and I created this syncroniser script.
If I --remove-source-files parameter to rsync it senses that a file is beeing written by another process, and skips that file. I tested it on my laptop and it really skips it, but not always. On the server side some files are truncated to 828 bytes. Now I user it without that option, but I would really like to remove the files after sync:
Code:#!/bin/sh
set -x
MAC=$(ip a | grep ether | head -1 | awk '{print $2}' | sed 's/:/-/g')
CONFIG="/usr/bin/syncroniser.cfg"
KEY="/usr/bin/dropbear_rsa_host_key"
SRC="/media/sdmmc/mmcblk0p1/RECORD/"
DST="$MAC"
FREQ=60
while true
do
if test -f "$CONFIG"; then
. "$CONFIG"
fi
rsync -avme "ssh -i $KEY -p $REMOTE_PORT" $SRC $REMOTE_USER@$REMOTE_IP:$DST
sleep $FREQ
doneI was trying to pipe to rsync with find and xargs, but it still did that file truncation on the file beeing written.
Code:find $SRC -type f -exec sh -c 'if ! lsof `readlink -f {}` > /dev/null; then echo `basename {}`; fi' \; | tr '\n' '\0' | rsync -avme "ssh -i $KEY -p $REMOTE_PORT" $SRC $REMOTE_USER@$REMOTE_IP:$DST