迁移Blog数据到本地

Posted by wxianfeng Thu, 02 Sep 2010 18:20:00 GMT

为了更好的调试,今天把我远程服务器上的blog数据同步到本地了,一切都是手动做的,要能够有自动化工具就好了,就像 capistrano 部署一样,通过ssh隧道实现远程操作,暂且这样,以后再想想办法。。。

1,备份远程数据库的数据,注意只是数据,没有表结构

>mysqldump -t -uroot -proot wxianfeng_com > db.txt

2,清空本地数据库中所有表的数据 (ruby脚本)

require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
  :adapter => "mysql",
  :host => "localhost",
  :database => "wxianfeng_com",
  :encoding => "utf8",
  :username => "root",
  :password => "root"
)

begin
  ActiveRecord::Base.connection.tables.each do |table|
    p "TRUNCATEing #{table}"
    ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
  end
rescue
  $stderr.puts "Ooops Error"
end

3,导入 数据

>mysql -uroot -proot wxianfeng_com < db.txt

4,备份远程服务器上的资源文件 (图片,文件等)

>tar -zcvf directory.tar.gz directory 

5,用 windows 下ssh客户端,例如 ssh secure shell client ,把远程文件down到本地

6,ok。。。搞定~!

最近写的比较多 哈, 权当笔记了,同时加大google收录数,提升流量,为下一步 计划 打好准备…………………………………..

This entry was posted on Thu, 02 Sep 2010 18:20:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags ,


Trackbacks

Use the following link to trackback from your own site:
http://wxianfeng.com/trackbacks?article_id=72

Comments

  1. Avatar
    Willie 10 months ago:

    Life is short, and this aticrle saved valuable time on this Earth.

Leave a comment