<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux etc. &#187; rsync</title>
	<atom:link href="http://promberger.info/linux/category/rsync/feed/" rel="self" type="application/rss+xml" />
	<link>http://promberger.info/linux</link>
	<description>my outsourced memory for your perusal</description>
	<lastBuildDate>Thu, 08 Sep 2011 11:06:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Rsync: syncing back and forth using only one single ssh connection</title>
		<link>http://promberger.info/linux/2009/02/20/rsync-syncing-back-and-forth-using-only-one-single-ssh-connection/</link>
		<comments>http://promberger.info/linux/2009/02/20/rsync-syncing-back-and-forth-using-only-one-single-ssh-connection/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 10:26:00 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/2009/02/20/rsync-syncing-back-and-forth-using-only-one-single-ssh-connection/</guid>
		<description><![CDATA[Rsync is really handy for transferring files and keeping directories in sync, and it&#8217;s damn fast. If you transfer only very little, what takes longest is actually establishing the SSH connection to the server. While this is usually negligible, it has still irked me. Some googling turned up this post. Nice. One SSH tunnel for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://samba.anu.edu.au/rsync/">Rsync</a> is really handy for transferring files and keeping directories in sync, and it&#8217;s damn fast. If you transfer only very little, what takes longest is actually establishing the SSH connection to the server. While this is usually negligible, it has still irked me. Some googling turned up <a href="http://dandavis.com/multiple-concurrent-rsyncs-over-a-single-ssh-tunnel/">this post</a>. Nice. One SSH tunnel for rsyncing back and forth.</p>
<p>Here&#8217;s a little example for a shell script I use to sync my mutt directory up and down:</p>
<pre>
if `ping -c1 $server > /dev/null 2>&#038;1` ; then
    ssh -S $HOME/.tunnel.socket -M -N -f $server  # create shared connection
    $HOME/bin/muttup &#038;&#038; $HOME/bin/muttdown          # sync up and down
    ssh -q -S $HOME/.tunnel.socket -O exit $server 2> /dev/null # close shared
                                                                  # connection
fi
</pre>
<p>I&#8217;ve set this to run whenever mutt starts, to keep my mutt stuff synced across different machines. (<code>muttup</code> and <code>muttdown</code> are obviously other tiny scripts. I keep them separately so I can run them individually)</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2009/02/20/rsync-syncing-back-and-forth-using-only-one-single-ssh-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote backups using ssh and rsync</title>
		<link>http://promberger.info/linux/2007/03/18/remote-backups-using-rsync-and-ssh/</link>
		<comments>http://promberger.info/linux/2007/03/18/remote-backups-using-rsync-and-ssh/#comments</comments>
		<pubDate>Sun, 18 Mar 2007 15:29:51 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Noobs]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://www.promberger.de/blog/?p=9</guid>
		<description><![CDATA[Here&#8217;s a mini tutorial on how to do fast backups of important files to a remote server. This involves three steps: Getting ssh access to a remote machine, setting up keypair authentication, backing up data with rsync. Requirements: rsync and ssh server on the remote machine, rsync and ssh client on the local machine. Step [...]]]></description>
			<content:encoded><![CDATA[<p> Here&#8217;s a mini tutorial on how to do fast backups of important files to a remote server.</p>
<p>This involves three steps:</p>
<ol>
<li>Getting ssh access to a remote machine,</li>
<li>setting up keypair authentication,</li>
<li>backing up data with rsync.</li>
</ol>
<p>Requirements:</p>
<ul>
<li>rsync and ssh server on the remote machine,</li>
<li>rsync and ssh client on the local machine.</li>
</ul>
<h3><span id="more-9"></span>Step one: ssh access</h3>
<p>First, check that you can get ssh access to the remote machine, using your login on the remote machine. If you use the same login on your local and remote machine, you can omit everything up to and including the @ sign:</p>
<pre>ssh login@remote.machine.domain</pre>
<p>If you get an error message like this:</p>
<pre>ssh: connect to host remote.machine.domain port 22: Connection refused</pre>
<p>it may mean the remote machine is listening for incoming ssh connections on a different port than the standard 22 port. In that case, find out which port to use (from an administrator of the remote machine), then specify that port using the -p switch, as in the example below, where we specify port 75:</p>
<pre>ssh -p 75 login@remote.machine.domain</pre>
<h3>Step two: keypair authentication</h3>
<p>You can optionally skip this step, if you&#8217;re willing to type the password to your remote machine every time you back up data. In that case, you also won&#8217;t be able to schedule backups using crontab (something I&#8217;ll hopefully post about later).</p>
<p>This is described very nicely by <a href="http://www-128.ibm.com/developerworks/library/l-keyc.html">Daniel Robbins</a>. For the impatient, in Daniel&#8217;s description, scroll down to &#8220;ssh-keygen up close.&#8221;</p>
<p>Daniel talks about the security implications of setting up the private key without a password, and gives instructions on a workaround using ssh-agent in <a href="http://www-128.ibm.com/developerworks/library/l-keyc2/">part 2</a>. It seems to me that for most users who are running Linux on a fairly well-protected (single user) private machine, it is okay and much less hassle to set up the private key without a password.</p>
<h3>Step three: rsync</h3>
<p>Rsync is a very handy tool because it can figure out which files have changed since the last backup, and then upload only the changes (yes, apparently, not just &#8220;only the files that have changed,&#8221; but also &#8220;only the changed parts of the file(s).&#8221; Nifty.</p>
<p>To use rsync correctly, you should first figure out what you want it to do. Here&#8217;s my situation: I have access to a computer at the university running Linux. I want to back up directories with important data to that computer from time to time. Currently, I do this manually whenever I&#8217;ve made significant changes. However, I also sometimes work on that university computer locally, so when I backup data from my laptop, I don&#8217;t want to overwrite a newer version of the file on the university machine.</p>
<p>I do all this using rsync wih the following options:</p>
<pre>rsync -auv</pre>
<p>The -a option stands for archive mode, which does the following:</p>
<ul>
<li>recurses into directories,</li>
<li>copies symlinks as symlinks,</li>
<li>preserves owner, groups, permissions, and time.</li>
</ul>
<p>The -u option skips files that are newer on the receiver, in my case, on the remote machine. Note that this does not protect from human error. If I make important changes to the file on the remote machine, then make different changes to an older version on the local machine, the file on the local machine is the newer version, and rsync -u will still overwrite the version on the remote machine.</p>
<p>The -v option stands for verbose and shows you what&#8217;s going on.</p>
<p><strong>While you&#8217;re experimenting with rsync, you should definitely first use it with the -n option </strong>as well, as this will do a &#8220;dry run&#8221; without changing anything. Say -v as well, and you&#8217;ll see what rsync would do without the -n option.</p>
<p>Now that we have the options we like, let&#8217;s say we want to backup a directory called &#8220;ex&#8221; in the home directory of the local machine to the home directory of the remote machine:</p>
<pre>rsync -auv /home/mpromber/ex remote.machine.com:</pre>
<p>Note that there is no trailing slash after &#8220;ex&#8221;. If you write &#8220;ex/&#8221;, this will copy over the <strong>contents</strong> of the directory, so all the files would be dumped directly into the home directory on the remote machine. You could explicitly state that you want the files to go into the folder &#8220;ex&#8221; on the remote machine, so it would be equivalent to the line above to write:</p>
<pre>rsync -auv /home/mpromber/ex/ remote.machine.com:ex</pre>
<p>As a last step, we have to tell rsync to use an ssh connection for the transfer:</p>
<pre>rsync -e "ssh" -auv /home/mpromber/ex remote.machine.com:</pre>
<p>You can pass options to ssh inside the quotation marks. So if you have a nonstandard port, e.g. 75:</p>
<pre>rsync -e "ssh -p 75" -auv /home/mpromber/ex remote.machine.com:</pre>
<h3>Optional: create a function in ~/.bashrc</h3>
<p>The following assumes you are using bash as a shell:</p>
<pre>echo $SHELL</pre>
<p>will tell you the shell you are using.<br />
Put the following lines in your ~/.bashrc, of course substituting your own username, remote host, and nostandard ssh port if needed:</p>
<pre>
mybackup () {
    rsync -e "ssh -p 75" -auv /home/username/$1 remote.machine.com:
}</pre>
<p>This is a so-called function. I think it has to be preceded and followed by a blank line in the .bashrc, and anyway, that probably doesn&#8217;t hurt.</p>
<p>Tell your terminal about the changes:</p>
<pre>source ~/.bashrc</pre>
<p>Now, you can just type:</p>
<pre>mybackup ex</pre>
<p>to back up the directory ex to the remote machine. Note that when you are in your home directory and you use tab completion to finish the directory name after &#8220;mybackup,&#8221; this will usually add a trailing slash. You&#8217;ll want to remove this if you alias is set up like mine, to move over the directory and not just its contents.</p>
<h3>Addendum</h3>
<p>Corrections applied, see comment #1.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2007/03/18/remote-backups-using-rsync-and-ssh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

