<?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>#raynix# &#187; cron</title>
	<atom:link href="http://raynix.info/archives/tag/cron/feed" rel="self" type="application/rss+xml" />
	<link>http://raynix.info</link>
	<description>When others see chance, I see cause.</description>
	<lastBuildDate>Thu, 09 Sep 2010 04:40:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>LAMP服务器的简单备份方法</title>
		<link>http://raynix.info/archives/561</link>
		<comments>http://raynix.info/archives/561#comments</comments>
		<pubDate>Thu, 11 Jun 2009 06:49:19 +0000</pubDate>
		<dc:creator>raynix</dc:creator>
				<category><![CDATA[Free software]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Opensource]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[备份]]></category>
		<category><![CDATA[开源]]></category>

		<guid isPermaLink="false">http://raynix.cn/?p=561</guid>
		<description><![CDATA[我用CentOS作为网站服务器的OS，我是这样备份我的网站的。 以下简称网站服务器为C，我的电脑是A。首先，在C上用一段shell script备份网站： backup.sh #! /bin/bash # This script is to backup the website files and db mysqldump mydb -pmypass &#62;/var/www/mysite/mydump.sql datestamp=`date +%Y%m%d` filewww="/home/myuser/backup/mysite_""$datestamp"".zip" zip -r $filewww /var/www/mysite 然后可以先运行一下这个script，看看结果是否符合预期。如果没问题，就可以将其加入到crontab了，每天自动运行。 59 3 * * * /bin/bash /home/myuser/backup.sh 这样C这边每天凌晨会备份一次并生成一个zip压缩包。但是把C的备份留在C就没意义了，我还要定期的把zip从C传到A。由于A不像C那样不间断运行的，所以如果从C向A传输就需要测试A是否在线，麻烦。不如让A取C上的zip。这就涉及到另一个问题，身份验证。 为一段自动运行的script提供password，我觉得不如使用public key验证来得专业，而且简单，两步就搞定： ssh-keygen -t rsa ssh-copy-id -i .ssh/id_rsa.pub myuser@C 这期间问到private key password时直接回车就行了；myuser@C的password还是需要输入的（否则……）。 下一步就是在A上写script，获取C上的备份，成功获取后删除C上的备份，并将A本机上超过一个月的备份删除。 backup-mysite.sh #!/bin/bash #by Raymond, Jun, [...]]]></description>
			<content:encoded><![CDATA[<p>我用CentOS作为网站服务器的OS，我是这样备份我的网站的。</p>
<p>以下简称网站服务器为C，我的电脑是A。首先，在C上用一段shell script备份网站：</p>
<p>backup.sh</p>
<blockquote><p>#! /bin/bash<br />
# This script is to backup the website files and db</p>
<p>mysqldump mydb -pmypass &gt;/var/www/mysite/mydump.sql</p>
<p>datestamp=`date +%Y%m%d`<br />
filewww="/home/myuser/backup/mysite_""$datestamp"".zip"</p>
<p>zip -r $filewww /var/www/mysite</p></blockquote>
<p>然后可以先运行一下这个script，看看结果是否符合预期。如果没问题，就可以将其加入到crontab了，每天自动运行。</p>
<blockquote><p>59 3 * * * /bin/bash /home/myuser/backup.sh</p></blockquote>
<p>这样C这边每天凌晨会备份一次并生成一个zip压缩包。但是把C的备份留在C就没意义了，我还要定期的把zip从C传到A。由于A不像C那样不间断运行的，所以如果从C向A传输就需要测试A是否在线，麻烦。不如让A取C上的zip。这就涉及到另一个问题，身份验证。</p>
<p>为一段自动运行的script提供password，我觉得不如使用public key验证来得专业，而且简单，两步就搞定：</p>
<blockquote><p>ssh-keygen -t rsa</p>
<p>ssh-copy-id -i .ssh/id_rsa.pub myuser@C</p></blockquote>
<p>这期间问到private key password时直接回车就行了；myuser@C的password还是需要输入的（否则……）。</p>
<p>下一步就是在A上写script，获取C上的备份，成功获取后删除C上的备份，并将A本机上超过一个月的备份删除。</p>
<p>backup-mysite.sh</p>
<blockquote><p>#!/bin/bash<br />
#by Raymond, Jun, 2009<br />
#1, get backup files from ...<br />
#2, delete after a successful copy<br />
scp myuser@C:/home/myuser/backup/*.zip /home/myuser/backup<br />
if [ $? -eq 0 ]<br />
then<br />
ssh myuser@C rm /home/myuser/backup/*.zip<br />
fi</p>
<p>#3, delete old backup files here<br />
find /home/myuser/backup/*.zip -mtime +30 -exec rm {} \;</p></blockquote>
<p>最后在把此script添加到A的crontab基本就没事了。过程类似上面的crontab，就偷懒不写了。注：懒是SA的美德。</p>
<p>Update: mysqldump --opt 对于恢复数据是个很好的开关.</p>
<hr />
<p><small>© raynix for <a href="http://raynix.info">#raynix#</a>, 2009. |
<a href="http://raynix.info/archives/561">Permalink</a> |
<a href="http://raynix.info/archives/561#comments">3 条评论</a> |
Add to
<a href="http://del.icio.us/post?url=http://raynix.info/archives/561&title=LAMP服务器的简单备份方法">del.icio.us</a>
<br/>
Post tags: <a href="http://raynix.info/archives/tag/cron" rel="tag">cron</a>, <a href="http://raynix.info/archives/tag/linux" rel="tag">linux</a>, <a href="http://raynix.info/archives/tag/mysql" rel="tag">mysql</a>, <a href="http://raynix.info/archives/tag/ssh" rel="tag">ssh</a>, <a href="http://raynix.info/archives/tag/%e5%a4%87%e4%bb%bd" rel="tag">备份</a>, <a href="http://raynix.info/archives/tag/%e5%bc%80%e6%ba%90" rel="tag">开源</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://raynix.info/archives/561/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>笔记：cron和crontab</title>
		<link>http://raynix.info/archives/409</link>
		<comments>http://raynix.info/archives/409#comments</comments>
		<pubDate>Sat, 03 Jan 2009 03:51:46 +0000</pubDate>
		<dc:creator>raynix</dc:creator>
				<category><![CDATA[Free software]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://raynix.cn/?p=409</guid>
		<description><![CDATA[参考文章： Using cron by DJG（这文章的配图很有趣~） Matrix中的一段台词：“Never send a human to do machines' job.” 所以我们要好好的利用cron做好机器自己的工作。输入“crontab -e”命令后，你就会见到一个文本编辑界面，在此输入需要定期运行的任务就可以了，例如： #分钟  小时  日期  月份  星期   运行命令 #需要半夜备份我的blog，该如何写？ 0  3  *  *  *  /home/raynix/backup.sh #在周末每2小时备份一次我的blog 0  */2  *  *  6  /home/raynix/backup.sh  基本用法就是这样了，发挥一下想象力，也许以后就用运行crond的早饭机器了:) © raynix for #raynix#, 2009. &#124; Permalink &#124; 唉, 一个评论都没 &#124; Add to del.icio.us Post tags: cron, linux [...]]]></description>
			<content:encoded><![CDATA[<p>参考文章： <a href="http://www.d9x.net/linux/guides/crons.php" target="_blank">Using cron by DJG</a>（这文章的配图很有趣~）</p>
<p><img class="size-medium wp-image-411 alignleft" title="agent-smith" src="http://raynix.info/wp-content/uploads/2009/01/agent-smith-232x300.jpg" alt="agent-smith" width="232" height="300" />Matrix中的一段台词：“Never send a human to do machines' job.” 所以我们要好好的利用cron做好机器自己的工作。输入“crontab -e”命令后，你就会见到一个文本编辑界面，在此输入需要定期运行的任务就可以了，例如：</p>
<blockquote><p>#分钟  小时  日期  月份  星期   运行命令<br />
#需要半夜备份我的blog，该如何写？</p>
<p>0  3  *  *  *  /home/raynix/backup.sh</p>
<p>#在周末每2小时备份一次我的blog</p>
<p>0  */2  *  *  6  /home/raynix/backup.sh</p></blockquote>
<p> 基本用法就是这样了，发挥一下想象力，也许以后就用运行crond的早饭机器了:)</p>
<hr />
<p><small>© raynix for <a href="http://raynix.info">#raynix#</a>, 2009. |
<a href="http://raynix.info/archives/409">Permalink</a> |
<a href="http://raynix.info/archives/409#comments">唉, 一个评论都没</a> |
Add to
<a href="http://del.icio.us/post?url=http://raynix.info/archives/409&title=笔记：cron和crontab">del.icio.us</a>
<br/>
Post tags: <a href="http://raynix.info/archives/tag/cron" rel="tag">cron</a>, <a href="http://raynix.info/archives/tag/linux" rel="tag">linux</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://raynix.info/archives/409/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
