{"id":457,"date":"2011-09-12T16:37:34","date_gmt":"2011-09-12T21:37:34","guid":{"rendered":"http:\/\/blog.xfloyd.net\/?p=457"},"modified":"2012-06-04T20:17:51","modified_gmt":"2012-06-05T01:17:51","slug":"using-rsync-over-ssh","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=457","title":{"rendered":"Using rsync over ssh"},"content":{"rendered":"<p><strong>Keep large directory structures in sync quickly with rsync<\/strong><\/p>\n<p>While <em>tar<\/em> over <em>ssh<\/em> is ideal for making remote copies of parts of a filesystem, <em>rsync<\/em> is even better suited for keeping the filesystem in sync between two machines. Typically, <em>tar<\/em> is used for the initial copy, and <em>rsync<\/em> is used to pick up whatever has changed since the last copy. This is because <em>tar<\/em> tends to be faster than <em>rsync<\/em> when none of the destination files exist, but <em>rsync<\/em> is much faster than <em>tar<\/em> when there are only a few differences between the two filesystems.<\/p>\n<div>\n<!--more--><br \/>\nTo run an <em>rsync<\/em> over <em>ssh<\/em>, pass it the <em>-e<\/em> switch, like this:<\/p>\n<blockquote>\n<pre>root@rover:~# <strong>rsync -ave ssh greendome:\/home\/ftp\/pub\/ \/home\/ftp\/pub\/<\/strong><\/pre>\n<\/blockquote>\n<p>Notice the trailing <strong>\/<\/strong> on the file spec from the source side (on greendome.) On the source specification, a trailing <strong>\/<\/strong> tells <em>rsync<\/em> to copy the <em>contents<\/em> of the directory, but not the directory itself. To include the directory as the top level of whatever is being copied, leave off the <strong>\/<\/strong>:<\/p>\n<blockquote>\n<pre>root@village:~# <strong>rsync -ave ssh bcnu:\/home\/six .<\/strong><\/pre>\n<\/blockquote>\n<p>This will keep a copy of the <em>~root\/six\/<\/em> directory on village in sync with whatever is present on <em>bcnu:\/home\/six\/<\/em>.<\/p>\n<p>By default, <em>rsync<\/em> will only copy files and directories, but not remove them from the destination copy when they are removed from the source. To keep the copies exact, include the <em> &#8211;delete<\/em> flag:<\/p>\n<blockquote>\n<pre>six@jammer:~\/public_html# <strong>rsync -ave ssh --delete greendome:~one\/reports .<\/strong><\/pre>\n<\/blockquote>\n<p>Now when old reports are removed from <em>~one\/reports\/<\/em> on greendome, they&#8217;re also removed from <em>~six\/public_html\/reports\/ <\/em>on jammer, every time this command is run. If you run a command like this in <em>cron<\/em>, leave off the <em>v<\/em> switch. This will keep the output quiet (unless <em>rsync<\/em> has a problem running, in which case you&#8217;ll receive an email with the error output).<\/p>\n<p>Using <em>ssh<\/em> as your transport for <em>rsync<\/em> traffic has the advantage of encrypting the data over the network and also takes advantage of any trust relationships you already have established using <em>ssh<\/em> client keys. For keeping large, complex directory structures in sync between two machines (especially when there are only a few differences between them), <em>rsync<\/em> is a very handy (and fast) tool to have at your disposal.<\/p>\n<\/div>\n<p><a name=\"linuxsvrhack-CHP-3-SECT-2\"><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Keep large directory structures in sync quickly with rsync While tar over ssh is ideal for making remote copies of parts of a filesystem, rsync is even better suited for keeping the filesystem in sync between two machines. Typically, tar is used for the initial copy, and rsync is used to pick up whatever has [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/457"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=457"}],"version-history":[{"count":2,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":615,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions\/615"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}