{"id":3072,"date":"2020-05-02T09:46:12","date_gmt":"2020-05-02T08:46:12","guid":{"rendered":"https:\/\/kudzia.eu\/b\/?p=3072"},"modified":"2020-05-02T09:49:29","modified_gmt":"2020-05-02T08:49:29","slug":"backup-via-ssh-tunneled-connection","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2020\/05\/backup-via-ssh-tunneled-connection\/","title":{"rendered":"backup via ssh-tunneled connection"},"content":{"rendered":"<p>in one context i need to pull backup from server C to server A. normally i&#8217;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:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kudzia.eu\/b\/wp-content\/uploads\/2020\/05\/tunnel.png\" alt=\"\" width=\"477\" height=\"96\" class=\"alignnone size-full wp-image-3073\" srcset=\"https:\/\/kudzia.eu\/b\/wp-content\/uploads\/2020\/05\/tunnel.png 477w, https:\/\/kudzia.eu\/b\/wp-content\/uploads\/2020\/05\/tunnel-300x60.png 300w\" sizes=\"auto, (max-width: 477px) 100vw, 477px\" \/><\/p>\n<p>public ssh keys have been exchanged so A can log in both to B and C. backup code, executed on server A periodically:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# establish persistent tunnel\r\nssh -M -S ctrl-socket-for-backup -fnNT -L 50000:adressOfServerC:22 jumpuser@adressOfServerB\r\n\r\n# if above ended successfully A can reach SSH on C via localhost:50000\r\n\r\n# run preparation command - it'll be executed on server C\r\nssh -p 50000 root@localhost &quot;apt list --installed &gt; \/root\/apt-list.txt &quot;\r\n# fetch data from server C\r\nrsync --timeout=300  -Ravz --delete --progress  -e &quot;ssh -p 50000 &quot; root@localhost:\/var\/spool :\/var\/www :\/etc\/ :\/usr\/local :\/root :\/usr\/local\/ \/mnt\/backups\/serverC\/\r\n# tear down the tunnel\r\nssh -S ctrl-socket-for-backup -O exit jumpuser@adressOfServerB\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>in one context i need to pull backup from server C to server A. normally i&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,51],"tags":[],"class_list":["post-3072","post","type-post","status-publish","format-standard","hentry","category-tech","category-unimportant"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=3072"}],"version-history":[{"count":6,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3072\/revisions"}],"predecessor-version":[{"id":3079,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3072\/revisions\/3079"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=3072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=3072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=3072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}