|
1)从mysql导出数据位csv文件,如:
Java代码
SELECT * FROM APP_CALL_LOG_1362959187037 WHERE CREATE_TIME < '2013-03-07 14:45:04' into outfile '/tmp/all_call_log_012.csv' fields terminated by ',' lines terminated by '\n';
(2)导入csv文件到mongodb,如:
Java代码
bin/mongoimport --host 114.112.94.104 --port 27017 -d lb_v1_log -c APP_CALL_LOG --type csv --ignoreBlanks -f ID,IP,URI,URL,D_CODE,D_TYPE,UID,APP_FROM,CREATE
_TIME,USER_AGENT,REMARK -file /usr/local/all_call_log_012.csv
(3)对导入数据矫正处理,如:
Java代码
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({UID:"\\N"}, { $set: { 'UID': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({IP:"\\N"}, { $set: { 'IP': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({D_TYPE:"\\N"}, { $set: { 'D_TYPE': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({D_CODE:"\\N"}, { $set: { 'D_CODE': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({CREATE_TIME:"\\N"}, { $set: { 'CREATE_TIME': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({APP_FROM:"\\N"}, { $set: { 'APP_FROM': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({URI:"\\N"}, { $set: { 'URI': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({URL:"\\N"}, { $set: { 'URL': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({USER_AGENT:"\\N"}, { $set: { 'USER_AGENT': null} },false,true);
pmy_log_rs:PRIMARY> db.APP_CALL_LOG.update({REMARK:"\\N"}, { $set: { 'REMARK': null} },false,true);
(4)字段类型矫正,如:
Java代码
db.APP_CALL_LOG.find({}).forEach( function (x) {x.D_CODE = ""+x.D_CODE;db.APP_CALL_LOG.save(x);}); |
|