public
Created

同步博文的Ruby脚本

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10
# -*- coding: utf-8 -*-
require 'digest/md5'
 
db = Mysql2::Client.new(:host => '127.0.0.1', :port => 3307, :username => 'blog', :password => '123456', :database => 'wpblog_global')
 
db.query('SELECT `blog_id` as blog FROM wpblog_global.wp_blogs').each do |row|
db.query("INSERT INTO `wpblog_global`.`all_posts`(`blog_id`, `user_id`, `post_id`, `status`, `title`, `excerpt`, `content`, `name`, `date`, `modified`, `comment_status`, `comment_count`, `post_type`)SELECT #{row['blog'].to_s}, `post_author`, `ID`,`post_status`, `post_title`, `post_excerpt`, `post_content`, `post_name`, `post_date`, `post_modified`, `comment_status`, `comment_count`, `post_type` FROM wpblog_#{Digest::MD5.hexdigest(row['blog'].to_s)[0, 3]}.wp_#{row['blog'].to_s}_posts;")
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.