<?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>Feng Jun &#187; 备份</title>
	<atom:link href="http://www.feng-jun.com/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.feng-jun.com</link>
	<description></description>
	<lastBuildDate>Mon, 16 May 2011 17:12:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>使用Amazon S3云存储自动备份服务器文件</title>
		<link>http://www.feng-jun.com/backup-server-with-amazon-s3/</link>
		<comments>http://www.feng-jun.com/backup-server-with-amazon-s3/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 05:08:29 +0000</pubDate>
		<dc:creator>Feng Jun</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[备份]]></category>

		<guid isPermaLink="false">http://www.feng-jun.com/backup-server-with-amazon-s3/</guid>
		<description><![CDATA[Amazon S3是Amazon的付费云存储服务，提供高可靠性与高吞吐率的数据存储与外链，只需要根据使用量来付费，没有最低消费要求,具体价格可见此链接。

Amazon S3的客户端种类很多，我比较常用的是web端管理s3fm.com以及开源命令行工具s3cmd，后者功能较全，而且更适合服务器上的自动化管理。

服务器上选择备份的有网站文件、数据库、服务器配置文件以及各种维护脚本。每星期备份一次，并根据容量的使用情况选择合适的备份数目，自动删除早期备份文件。备份后进行日志输出，可通过浏览器查看日志。

<span class="readmore"><a href="http://www.feng-jun.com/backup-server-with-amazon-s3/" title="使用Amazon S3云存储自动备份服务器文件">阅读全文——共2285字</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://aws.amazon.com/s3/" target="_blank">Amazon S3</a>是Amazon的付费云存储服务，提供高可靠性与高吞吐率的数据存储与外链，只需要根据使用量来付费，没有最低消费要求,具体价格可见<a href="http://aws.amazon.com/s3/pricing/" target="_blank">此链接</a>。</p>
<p>Amazon S3的客户端种类很多，我比较常用的是web端管理<a href="http://www.s3fm.com/" target="_blank">s3fm.com</a>以及开源命令行工具<a href="http://s3tools.org/s3cmd" target="_blank">s3cmd</a>，后者功能较全，而且更适合服务器上的自动化管理。</p>
<p>服务器上选择备份的有网站文件、数据库、服务器配置文件以及各种维护脚本。每星期备份一次，并根据容量的使用情况选择合适的备份数目，自动删除早期备份文件。备份后进行日志输出，可通过浏览器查看日志。</p>
<h4></h4>
<h4>设置备份步骤：</h4>
<ol>
<li>申请Amazon.com帐号，并开通S3服务，需要输入信用卡信息并扣费1美元用于验证。</li>
<li>在Account页面的Access Credentials中，可查看Access Key ID以及Secret Access Key，前者可公开，后者要严格保密。</li>
<li>进入<a href="https://console.aws.amazon.com/s3/home" target="_blank">AWS Management Console</a>，创建Bucket， Bucket名称需要在S3服务所有Buckets中唯一，因此不能起简单或者通用的名字。创建Bucket时需选择数据中心所在区域，亚太有一个在新加坡，但没看出有速度优势。当不同的Bucket在不同的区域时，是分别计费的。创建后即可对Buckets中的文件及目录进行操作。</li>
<li>在服务器中下载S3cmd并进行安装，值得注意的是最新的release版本尚不支持<a href="http://aws.amazon.com/s3/faqs/#What_is_RRS" target="_blank">Reduced Redundancy Storage</a>,SVN版本支持。</li>
<li>安装完成后运行<code>s3cmd --configure进行配置。</code></li>
<li><code>创建相应的文件目录及脚本文件，脚本附在后面。</code></li>
<li><code>在crontab中设置脚本自动运行的时间，设置参数见脚本后面。</code></li>
</ol>
<h4></h4>
<h4>脚本文件process.sh：</h4>
<blockquote><p>#!/bin/sh</p>
<p>date &gt;&gt; /srv/http/nginx/mysite/log1.txt<br />
echo &#8220;===========================&#8221;&gt;&gt;/srv/http/nginx/mysite/log1.txt<br />
date &gt;&gt; /srv/http/nginx/mysite/error.txt<br />
echo &#8220;===========================&#8221;&gt;&gt;/srv/http/nginx/mysite/error.txt<br />
#在日志文件中做标识</p>
<p>tar czf /backup/content/$(date +%Y%m%d).tar.gz  /srv/http/nginx/<br />
#压缩网站文件，以日期作为文件名</p>
<p>mysqldump -h 127.0.0.1 -u root -ppassword &#8211;all-databases| gzip &gt; /backup/content/$(date +%Y%m%d).sql.gz<br />
#导出所有数据库，并进行压缩，以日期作为文件名</p>
<p>tar czf /backup/content/$(date +%Y%m%d)_set.tar.gz /etc /root /backup/script<br />
#压缩脚本及配置文件，以“日期_set”为文件名</p>
<p>rm -f /backup/content/$(date +%Y%m%d &#8211;date=&#8217;-350 day&#8217;).sql.gz<br />
rm -f /backup/content/$(date +%Y%m%d &#8211;date=&#8217;-70 day&#8217;).tar.gz<br />
rm -f /backup/content/$(date +%Y%m%d &#8211;date=&#8217;-350 day&#8217;)_set.tar.gz<br />
#删除服务器上的过期备份文件，可根据需要及备份文件大小选择合适的备份数目，因为这里每周备份一次，因些过期天数为7的倍数</p>
<p>s3cmd &#8211;rr put /backup/content/$(date +%Y%m%d).sql.gz s3://buckets/folder/<br />
s3cmd &#8211;rr put /backup/content/$(date +%Y%m%d).tar.gz s3://buckets/folder/<br />
s3cmd &#8211;rr put /backup/content/$(date +%Y%m%d)_set.tar.gz s3://buckets/folder/<br />
#上传备份文件至服务器，其中&#8211;rr参数指定上传后采用<a href="http://aws.amazon.com/s3/faqs/#What_is_RRS" target="_blank">Reduced Redundancy Storage</a>方式存储，注意S3服务器目录后的<strong>/</strong>是一定要的。</p>
<p>s3cmd del S3://buckets/folder/$(date +%Y%m%d &#8211;date=&#8217;-28 day&#8217;).tar.gz<br />
s3cmd del S3://buckets/folder/$(date +%Y%m%d &#8211;date=&#8217;-140 day&#8217;).sql.gz<br />
s3cmd del S3://buckets/folder/$(date +%Y%m%d &#8211;date=&#8217;-140 day&#8217;)_set.tar.gz<br />
#删除S3服务器上的过期备份。</p></blockquote>
<h4></h4>
<h4>设置备份计划</h4>
<p>在shell下输入</p>
<blockquote><p>crontab -e</p></blockquote>
<p>会打开一个文本文件，默认使用vi编辑器，如果很不习惯的话在以上命令之前运行</p>
<blockquote><p>export EDITOR=vim</p></blockquote>
<p>这样就可以使用vim来进行编辑。</p>
<p>然后在打开的文本文件中加入以下一行。</p>
<blockquote><p>30 01 * * 4 /backup/script/process.sh&gt;&gt;/srv/http/nginx/mysite/log.txt 2&gt;&gt;/srv/http/nginx/mysite/error.txt</p></blockquote>
<p>在本例中，设置每周四的1点30分（服务器上的时间）来运行备份脚本，并将运行输出及错误提示输出到日志，方便查阅。</p>
<h4>小结</h4>
<p>这样设置并实施备份计划以后，在服务器及S3服务器上都有了重要文件的备份，还可选择将备份文件下载到本地做一备份，可靠性有了更好的保障。</p>
<h4  class="related_post_title">你可能还喜欢如下文章</h4><ul class="related_post"><li>2010/07/30 -- <a href="http://www.feng-jun.com/speed-up-wtih-cdn/" title="使用Amazon CloudFront为网站提供CDN加速">使用Amazon CloudFront为网站提供CDN加速</a> (4)</li><li>2010/01/21 -- <a href="http://www.feng-jun.com/prevent-ssh-with-denyhosts/" title="用denyhosts防止暴力破解ssh">用denyhosts防止暴力破解ssh</a> (2)</li><li>2009/12/31 -- <a href="http://www.feng-jun.com/happy-new-year/" title="Happy new year!">Happy new year!</a> (6)</li><li>2009/06/17 -- <a href="http://www.feng-jun.com/wordpress-backup/" title="wordpress的备份方法小结">wordpress的备份方法小结</a> (3)</li></ul><h3>Recent Comments</h3><ul><li><a class="commentor" href="" >卢达</a> : <a class="comment_content" href="http://www.feng-jun.com/backup-server-with-amazon-s3/#comment-4377" title="View the entire comment by 卢达" >文中使用命令：
mysqldump -h 127.0.0.1 -u root -ppassword ...</a></li>
<li><a class="commentor" href="http://www.feng-jun.com" >Feng Jun</a> : <a class="comment_content" href="http://www.feng-jun.com/backup-server-with-amazon-s3/#comment-4376" title="View the entire comment by Feng Jun" >先用gzip解压
然后运行命令
mysql -h localhost -u root -p test...</a></li>
<li><a class="commentor" href="" >卢达</a> : <a class="comment_content" href="http://www.feng-jun.com/backup-server-with-amazon-s3/#comment-4363" title="View the entire comment by 卢达" >请问 .sql.gz 文件怎么导入比较方便呢？</a></li>
<li><a class="commentor" href="http://dallaslu.com" >LuDa</a> : <a class="comment_content" href="http://www.feng-jun.com/backup-server-with-amazon-s3/#comment-2594" title="View the entire comment by LuDa" >嗯。在用了。</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.feng-jun.com/backup-server-with-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>wordpress的备份方法小结</title>
		<link>http://www.feng-jun.com/wordpress-backup/</link>
		<comments>http://www.feng-jun.com/wordpress-backup/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 11:42:00 +0000</pubDate>
		<dc:creator>Feng Jun</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[备份]]></category>

		<guid isPermaLink="false">http://www.feng-jun.com/wordpress-backup/</guid>
		<description><![CDATA[<a href="http://www.feng-jun.com/wordpress-backup/"><img align="right" hspace="5" width="120" src="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-3.jpg" class="alignright wp-post-image tfe" alt="" title="" /></a>不管是电脑的原因还是操作的原因，或者其他种种人为的原因，都有可能使得辛苦积攒的博客数据毁于一旦，这方面已经有不少的教训。所以备份博客很重要，但备份一般的博客，是不应该需要花费很多人力物力的。下面介绍的三种备份方法，不需要很多的技术，也不需要很多的时间，其中的两种在设置好后，甚至不需要人工干预的。如果觉得不踏实的话，可以把这三种方法结合起来用，应该可以备份的比较全面了。

使用wordpress插件备份

这方面的插件用的比较多的应该是WordPress Databse Backup以及BackUpWordPress，我用的是前者，因为前者有个相当实用的功能，可以定时自动地把备份的数据库打包后发到指定的邮箱地址。插件的设置选项如图所示在wordpress边栏的工具框里，在插件的设置界面中，wordpress的核心数据表是默认备份的，其他的数据表可以选择性的备份，当然，还有如下图所示的定时备份选项，如果备份的文件发到gmail这样容量较大的邮箱而且博客不是很大的话，每天备份是完全可以的，而且备份的数据也相当的安全。

<span class="readmore"><a href="http://www.feng-jun.com/wordpress-backup/" title="wordpress的备份方法小结">阅读全文——共1365字</a></span>]]></description>
			<content:encoded><![CDATA[<p>不管是电脑的原因还是操作的原因，或者其他种种人为的原因，都有可能使得辛苦积攒的博客数据毁于一旦，这方面已经有不少的教训。所以备份博客很重要，但备份一般的博客，是不应该需要花费很多人力物力的。下面介绍的三种备份方法，不需要很多的技术，也不需要很多的时间，其中的两种在设置好后，甚至不需要人工干预的。如果觉得不踏实的话，可以把这三种方法结合起来用，应该可以备份的比较全面了。</p>
<h5>使用wordpress插件备份</h5>
<p>这方面的插件用的比较多的应该是<a href="http://www.ilfilosofo.com/blog/wp-db-backup">WordPress Databse Backup</a>以及<a href="http://wordpress.org/extend/plugins/backupwordpress/">BackUpWordPress</a>，我用的是前者，因为前者有个相当实用的功能，可以定时自动地把备份的数据库打包后发到指定的邮箱地址。插件的设置选项如图所示在wordpress边栏的工具框里，在插件的设置界面中，wordpress的核心数据表是默认备份的，其他的数据表可以选择性的备份，当然，还有如下图所示的定时备份选项，如果备份的文件发到gmail这样容量较大的邮箱而且博客不是很大的话，每天备份是完全可以的，而且备份的数据也相当的安全。</p>
<p align="center"><font color="#0080ff" size="2"><strong><a href="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-3.jpg"  rel="lightbox[roadtrip]"><img src="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-3.jpg" width="164" height="201" /></a> </strong></font></p>
<p align="center"><font color="#0080ff" size="2"><strong>点击图片看大图</strong></font></p>
<p align="center"><font color="#0080ff" size="2"><strong><a href="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-1.jpg"  rel="lightbox[roadtrip]"><img src="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-1.jpg" width="240" height="171" /></a> </strong></font></p>
<p align="center"><font color="#0080ff" size="2"><strong>点击图片看大图</strong></font></p>
<p><strong><font color="#0080ff" size="2"></font></strong></p>
<p align="left">&#160;</p>
<h6>使用备份软件进行备份</h6>
<p>有一些软件是运行在服务器上专门备份站点的，比如说我所用的<a href="http://www.phome.net/download/" target="_blank">帝国备份王2008开源版</a>。这款软件针对大站点进行了优化，比如可以实现mySQL数据库的分卷备份等。用它来备份小博客有点杀鸡用牛刀的感觉，不过既然开源而且也不难用，不妨多个选择。用这个软件进行备份以后，备份的数据库可以放在主机上，也可以下载。利用这个软件也可以进行数据库的恢复，而且据称可以实现不同版本mySQL的平滑转换。对于一般的应用应该足够了。</p>
<p align="center"><font color="#0080ff" size="2"><strong><a href="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-4.jpg"  rel="lightbox[roadtrip]"><img src="http://www.feng-jun.com/wp-content/uploads/mypic/wordpress-backup-4.jpg" width="101" height="240" /></a> </strong></font></p>
<p align="center"><font color="#0080ff" size="2"><strong>点击图片看大图</strong></font></p>
<h6>使用FTP进行自动备份</h6>
<p>我的域名是在Godaddy上注册的，注册后每个域名会赠送10G大小300G流量限制的免费空间，但在空间内做站点的话会插入广告，虽然通过一定得方法可以把这些广告去掉，但谁都不希望因为这个原因而被Godaddy收回空间，况且因为这个广告的原因，wordpress脚本运行也会有这样那样的问题。</p>
<p>这样的空间要利用起来，有两个比较好的方法，一个是把这个空间当作外链图片站，详细介绍可以参看<a href="http://www.allengao.com" target="_blank">AG’s blog</a>的<a href="http://www.allengao.com/blog/godaddy-free-web-hosting-imagehosting-subdomain.html" target="_blank">《使用Godaddy带广告免费空间做图片外链服务器》</a>。这个方法有个缺陷是听说Godaddy的ip被封的可能性比较大，所以稳定性是个问题，好处是，绑定二级域名后，即使那里的空间不能用了，依然可以比较方便的进行迁移。</p>
<p>利用这个空间另一个较好的方法就是做ftp备份。因为空间足够大，流量也足够大，再结合使用Cpanel里的时钟守护作业（cron jobs），就可以完全自动的对站点进行整站备份。备份的频度可选择的余地很大，而且据我观察，备份产生的流量，并不算在博客主机的流量限制里，而只占用备份主机的流量配额。即使IP被封，通过博客主机的SSH连接，比较容易下载到备份包，恢复并不麻烦。</p>
<p>具体的方法子在<a href="http://www.ifred.cn" target="_blank">Fred的博客</a>的<a href="http://www.ifred.cn/cp-full-backup/" target="_blank">《cPanel自动备份教程之完全备份篇》</a>里讲的很清楚，需要注意的是在CPanel中文版里，Cron jobs被翻译成了时钟守护作业，而且在计划里设定的时间是服务器时间，而非我们的北京时间。备份后会向指定邮箱中发送邮件通知。</p>
<p>&#160;</p>
<p>这三种备份方法如果结合起来用的话，可以实现在不同主机上存放不同规模的备份，因此是比较实用而且简便的备份方案。</p>
<p align="left">&#160;</p>
<p align="center"><strong><font color="#0080ff" size="2"></font></strong></p>
<h4  class="related_post_title">你可能还喜欢如下文章</h4><ul class="related_post"><li>2010/07/30 -- <a href="http://www.feng-jun.com/speed-up-wtih-cdn/" title="使用Amazon CloudFront为网站提供CDN加速">使用Amazon CloudFront为网站提供CDN加速</a> (4)</li><li>2010/07/29 -- <a href="http://www.feng-jun.com/backup-server-with-amazon-s3/" title="使用Amazon S3云存储自动备份服务器文件">使用Amazon S3云存储自动备份服务器文件</a> (4)</li><li>2009/06/14 -- <a href="http://www.feng-jun.com/optimization-of-web-pages-2/" title="wordpress页面加载速度优化之二:四种方法">wordpress页面加载速度优化之二:四种方法</a> (8)</li><li>2009/06/14 -- <a href="http://www.feng-jun.com/optimization-of-web-pages-1/" title="wordpress页面加载速度优化之一:网页分析">wordpress页面加载速度优化之一:网页分析</a> (2)</li></ul><h3>Recent Comments</h3><ul><li><a class="commentor" href="http://www.feng-jun.com" >Feng Jun</a> : <a class="comment_content" href="http://www.feng-jun.com/wordpress-backup/#comment-229" title="View the entire comment by Feng Jun" >恩，linux主机应该都可以的。windows的，听说是不能发邮件。</a></li>
<li><a class="commentor" href="http://idea1983.com" >iDea1983</a> : <a class="comment_content" href="http://www.feng-jun.com/wordpress-backup/#comment-228" title="View the entire comment by iDea1983" >看了这篇文章之后我也安装了，挺好用，我的GMAIL也能收到备份内容了 :39</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://www.feng-jun.com/wordpress-backup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk
Database Caching using disk
Object Caching 814/870 objects using disk

Served from: www.feng-jun.com @ 2012-02-07 16:07:03 -->
