<?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>Tim Bowler &#187; backup</title>
	<atom:link href="http://timothybowler.com/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://timothybowler.com</link>
	<description>Certified Scrum Master &#124; Certified Scrum Practitioner &#124; Agile Coach &#124; Agile Practitioner</description>
	<lastBuildDate>Sat, 19 Dec 2009 16:14:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SSH and automated backups</title>
		<link>http://timothybowler.com/2009/01/20/ssh-and-automated-backup/</link>
		<comments>http://timothybowler.com/2009/01/20/ssh-and-automated-backup/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 13:52:20 +0000</pubDate>
		<dc:creator>Tim Bowler</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://timothybowler.com/?p=91</guid>
		<description><![CDATA[One of the key tools for ssh automation is keychain, which is pretty much available in most flavors of linux. Its usually not installed by default, therefore using your package manager install &#8216;keychain&#8217;
Ubuntu users:
$sudo apt-get install keychain
After its install, you set it up by entering the keychain command followed by your private key (not the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the key tools for ssh automation is keychain, which is pretty much available in most flavors of linux. Its usually not installed by default, therefore using your package manager install &#8216;keychain&#8217;</p>
<p>Ubuntu users:</p>
<pre class="brush: bash; light: true; toolbar: true;">$sudo apt-get install keychain</pre>
<p>After its install, you set it up by entering the keychain command followed by your private key (not the public key).</p>
<pre class="brush: bash; light: true; toolbar: true;">$ keychain ~/.ssh/id_rsa
KeyChain 2.6.6; http://www.gentoo.org/proj/en/keychain/ Copyright 2002-2004
Gentoo Foundation; Distributed under the GPL&lt;/pre&gt;
* Initializing /home/timmy/.keychain/hostname-sh file...
* Initializing /home/timmy/.keychain/hostname-csh file...
* Initializing /home/timmy/.keychain/hostname-fish file...
* Starting ssh-agent
* Adding 1 ssh key(s)...
Enter passphrase for /home/timmy/.ssh/id_rsa:
Identity added: /home/timmy/.ssh/id_rsa (/home/timmy/.ssh/id_rsa)</pre>
<p>Keychain then creates three files which correspond to various shell environments. As I am using bash, the file I will be referencing will be  /home/timmy/.keychain/hostname-sh.</p>
<pre class="brush: bash; light: true; toolbar: true;">$ source ~/.keychain/hostname-sh</pre>
<p>To make sure everything is fine run the following to make sure the the environment is in fact set up:</p>
<pre class="brush: bash; light: true; toolbar: true;">$ env | grep SSH_A
SSH_AGENT_PID=9607
SSH_AUTH_SOCK=/tmp/ssh-bMoLeb9606/agent.9606</pre>
<p>Of course you will want this to happen automatically on login so add the following to your ~/.bashrc</p>
<pre class="brush: bash; light: true; toolbar: true;">keychain ~/.ssh/id_rsa
source ~/.keychain/hostname-sh</pre>
<p>The last step is to add the following line to your backup script (including the .)</p>
<pre class="brush: bash; light: true; toolbar: true;">. /home/timmy/.keychain/hostname-sh</pre>
<p>Backup Scripts<br />
Ill only mention the two methods that i use.<br />
1. scp: To copy files from one location to another<br />
2. rsync: To sync a remote location to local location</p>
<p><span id="more-91"></span></p>
<p><strong>SCP</strong></p>
<pre class="brush: bash; light: true; toolbar: true;">. /home/timmy/.keychain/hostname-sh
scp -r /home/timmy/Server_Backups/web/* root@192.168.0.1:/var/backup/web</pre>
<p><strong>Rsync</strong></p>
<pre class="brush: bash; light: true; toolbar: true;">. /home/timmy/.keychain/hostname-sh
rsync -rzvhlc --delete -e &quot;ssh -p 22 -i /home/timmy/.ssh/id_rsa -o 'BatchMode yes'&quot;
root@hostname:/var/www/vhosts/vhostname/httpd/ home/timmy/Server_Backups/web/</pre>
<p>After that you should not get the error:</p>
<pre class="brush: bash; light: true; toolbar: true;">Permission denied, please try again.
Received disconnect from 192.168.0.10: 2: Too many authentication failures for root
lost connection</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Ftimothybowler.com%2F2009%2F01%2F20%2Fssh-and-automated-backup%2F';
  addthis_title  = 'SSH+and+automated+backups';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://timothybowler.com/2009/01/20/ssh-and-automated-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
