惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - kylindai

Spark installation for windows java cpu load - kylindai remove all .git files and directories use one command - kylindai Android adb not responsing putty ssh login linux nodejs 实现 http proxy 透明转发 mybatis 处理数组类型及使用Json格式保存数据 JsonTypeHandler and ArrayTypeHandler nodejs 安装 postgresql module mongodb 安装为windows服务 memcached linux / win32 1.4.13 learning nodejs 2 - connect middleware learning nodejs 1 - stream.pipe javascript的变量、作用域和内存问题 javascript编程的最佳实践推荐 android download host jetty-distribution-7.6.x 部署 Quartz Cron 表达式 ImageMagick 批量处理图片脚本 常用 LINUX 命令
一次PostgreSql数据迁移,使用nodejs来完成
kylindai · 2014-02-09 · via 博客园 - kylindai

2014-02-08

XX开放平台不允许使用站外的服务器了,可是我们的app都在站外,数据库也在站外,全都要求迁移到其云主机上(坑爹啊)。我们在其云主机上仅有有限的资源,而且也有在运行中的数据库,要做数据迁移,正好重新清理一下数据库吧,把过期的没用的数据都转入到历史库,将原系统的数据和云主机上的数据做一次合并,打算用nodejs从站外服务读取数据,然后发送到云主机上,云主机接受数据并合并到现有系统里。站外服务器和云主机上的数据迁移都用nodejs来实现,想法确立之后,开始做一个简单设计。

为什么要选用nodejs,因为可以快速开发,快速部署,js代码写起很轻快,顺便实践一个小小的nodejs项目。

要实现的功能:

sender.js

  职责:接收命令行参数,读取需要迁移的源数据,转换成message格式,发送到云主机的服务上,并在开始和结束处记录日志,程序重启可以按日志断点续传。

receiver.js (云主机只有80端口开放,用apache做一个proxy)

  职责:接受源数据,保存message到数据库,并返回结果给sender。

processer.js

  职责:定时轮询读取message数据,有未处理的数据,则处理数据整合逻辑(合并用户ID,合并用户数据等)

 

2014-02-09

由于我们的数据库都是Postgresql,服务器都是CentOS,开发环境在Win7,先安装开发环境和生产环境的nodejs环境

(1)在Linux下安装nodejs,以及node-postgresql,比较简单,参见我的另一篇博客。

(2)在Win7下安装nodejs,以及node-postgresql,稍微麻烦,需要安装Python 2.7,还需要安装node-gyp,为了能安装node-postgresql 还需要安装VC++,我安装的是VC++2010 Express,都安装好了之后,测试一下,node-postgresql能正常工作。

至此工作环境准备完毕,接下来开始进入模块的简单设计阶段。

传输过程中的数据结构Json格式:

 

message.type: 数据名

message.content: 数据内容

至此貌似云主机上接受数据使用mongodb比较合适,在接下来的设计和实践中再做比较和决策。

(待续)