backup via ssh-tunneled connection

in one context i need to pull backup from server C to server A. normally i’d use rsync with direct ssh connection as a transport method. in this particular case C is not directly reachable from A, so i need to use ssh tunneling to connect from A to C via jump-host B:

public ssh keys have been exchanged so A can log in both to B and C. backup code, executed on server A periodically:

# establish persistent tunnel
ssh -M -S ctrl-socket-for-backup -fnNT -L 50000:adressOfServerC:22 jumpuser@adressOfServerB

# if above ended successfully A can reach SSH on C via localhost:50000

# run preparation command - it'll be executed on server C
ssh -p 50000 root@localhost "apt list --installed > /root/apt-list.txt "
# fetch data from server C
rsync --timeout=300  -Ravz --delete --progress  -e "ssh -p 50000 " root@localhost:/var/spool :/var/www :/etc/ :/usr/local :/root :/usr/local/ /mnt/backups/serverC/
# tear down the tunnel
ssh -S ctrl-socket-for-backup -O exit jumpuser@adressOfServerB

Leave a Reply

Your email address will not be published. Required fields are marked *

(Spamcheck Enabled)