rsync over active ssh connection
Trying to script as clean as possible, I wonder if there is some solution for the following situation:
One Linux server running sshd and one android device, with dropbear ssh client and rsync installed (no server).
I'm writing a script to be run remotely with a cron that backups the android memory to the linux server. The cron calls something like:
ssh remoteuser@linuxserver -i path_to_rsa_key runthisscript.sh
runthisscript.sh performs a few things with the existent data, and, what I want to do, in the middle of the script, is to rsync from the android device back to the server, taking advantage of the ssh connection that is already opened (as there is no sshd running on the android).
I've developed other solutions, like breaking my server script in several parts and calling them one after another, with the rsync (android to server direction) in the middle, but I was looking for a more elegantly implemented solution (single script, most of the work done in the server side).
Ideas?
Solution 1:
You may have a look at --rsh/-e argument of rsync.
You can replace the rsh with cat or something similar. But you have to add a script at android side which sends the output of your server script to a shell.
Android side:
socat 'EXEC:/bin/bash' 'TCP-LISTEN:20000' &
ssh remoteuser@linuxserver -i path_to_rsa_key -R 20000:127.0.0.1:20000 runthisscript.sh
helper.sh:
#!/bin/sh
host=$2
port=$1
shift 2
{
echo exec "$@"
socat 'STDIN' 'STDOUT'
} | socat '-' "TCP:$host:$port"
runthisscript.sh:
rsync -e './helper.sh 20000' --blocking-io <SRC> <DST>