<?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>后院&#124;kevin’s backyard &#187; scp</title>
	<atom:link href="http://kevin.9511.net/archives/tag/scp/feed" rel="self" type="application/rss+xml" />
	<link>http://kevin.9511.net</link>
	<description>立志做一个混事业型男人</description>
	<lastBuildDate>Fri, 30 Apr 2010 16:55:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用SCP和Cron进行数据备份</title>
		<link>http://kevin.9511.net/archives/406.html</link>
		<comments>http://kevin.9511.net/archives/406.html#comments</comments>
		<pubDate>Thu, 10 Dec 2009 11:15:36 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[七零八碎]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scp]]></category>

		<guid isPermaLink="false">http://kevin.9511.net/?p=406</guid>
		<description><![CDATA[服务器间的数据同步，rsync的确是个好方式，不过它只能被动同步而不能主动分发。
本想使用SVN+rsync的方案进行代码的管理，可是因为上面说到的原因，无法达到代码的即时分发。
遂想起SCP这个东西，但SCP每次执行必须要在控制台输入手动输入密码，于是就Google到了下面这个文章。
人家说的是用SCP进行数据备份，我是用来跟SVN的hook功能一起达到即时分发代码的目的，原理是一样的。
实在懒的翻译了，文章来自：http://www.spaceprogram.com/knowledge/cron_scp.html
Introduction
This document will explain the steps required to use scp in cron. This is generally useful to do automated backups on Linux and other nix variations.
Instructions
These instructions will walk you through what it takes.
1. Generate a private/public key pair 
Simple command to do this:
ssh-keygen -t rsa
Leave the passphrase empty so that cron can use it [...]]]></description>
			<content:encoded><![CDATA[<p>服务器间的数据同步，rsync的确是个好方式，不过它只能被动同步而不能主动分发。</p>
<p>本想使用SVN+rsync的方案进行代码的管理，可是因为上面说到的原因，无法达到代码的即时分发。</p>
<p>遂想起SCP这个东西，但SCP每次执行必须要在控制台输入手动输入密码，于是就Google到了下面这个文章。</p>
<p>人家说的是用SCP进行数据备份，我是用来跟SVN的hook功能一起达到即时分发代码的目的，原理是一样的。<span id="more-406"></span></p>
<p>实在懒的翻译了，文章来自：<a href="http://www.spaceprogram.com/knowledge/cron_scp.html" target="_blank">http://www.spaceprogram.com/knowledge/cron_scp.html</a></p>
<h5>Introduction</h5>
<p>This document will explain the steps required to use scp in cron. This is generally useful to do automated backups on Linux and other nix variations.</p>
<h5>Instructions</h5>
<p>These instructions will walk you through what it takes.</p>
<p><strong>1. Generate a private/public key pair </strong></p>
<p>Simple command to do this:</p>
<div>ssh-keygen -t rsa</div>
<p>Leave the passphrase empty so that cron can use it passwordless. Just         be sure nobody gets your private key.</p>
<p><strong>2. Copy the public key to the remote server </strong></p>
<div>scp ~/.ssh/id_rsa.pub remote_host:</div>
<p><strong>3. Add local key to remote servers trusted key </strong></p>
<p>Log on to the remote server and if there has never been a key created         for this user on the remote machine, run the <span>ssh-keygen         -t rsa</span> just to get the key directory and stuff set up.</p>
<p>Then concatenate the new key to your authorized_keys file:</p>
<p>cat ~/id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys</p>
<p>Now for some reason, you may have to do this to the keys file:</p>
<p>chmod 644 ~/.ssh/authorized_keys</p>
<p><strong>4. Now try logging into the remote machine again from local </strong></p>
<p>ssh REMOTE_USERNAME@remote_host</p>
<p>This <em>should</em> log you in without asking for a password. If it doesn&#8217;t, then something must be wrong at this point and you should go through the steps above again.</p>
<p>This should also mean that scp will work the same way and you might want to test that scp works by copying a file from local to remote using scp. If no password, then we&#8217;re all good.</p>
<p><strong>5. Now lets test out cron script</strong></p>
<p>My cron script for this example is simply going to copy a directory         of files using scp to the remote server.</p>
<p>scp -r /PATH_TO_FILES/ REMOTE_USER@remote_host:BACKUPS/</p>
<p>And that&#8217;s about all she wrote. Save that in a file called backup.sh (or whatever you want to call it), chmod 755 i it and then try running it. ./backup.sh to run it. If it works, then next stop is to cron it.</p>
<p><strong>6. Add script to cron jobs</strong></p>
<p>Easiest way is to simply copy the backup.sh file into /etc/cron.daily/ . This will make it run every day. Choose another cron.SOMETIME to make it run more or less often. If you want more control on when it&#8217;s run, read up on adding it to the crontab.</p>
]]></content:encoded>
			<wfw:commentRss>http://kevin.9511.net/archives/406.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
