解决问题:通过js脚本将格林威治时间转换成北京时间,并且推送给需求方。


# 时间转换为纯数字

startTime=`date -d "-1  day" "+%Y-%m-%d 00:00:00"`

endTime=`date "+%Y-%m-%d 00:00:00"`

st=$((`date --date "$startTime" +"%s"` * 1000))

et=$((`date --date "$endTime" +"%s"` * 1000))


#将数据从primary中导出(注意不要使用--csv,否则到导入的时候会报错)

mongoexport --host=10.136.3.117 --port=27017 --authenticationDatabase=admin --username=root --password=anyu@2014 --db=gow --collection=playerlogs --query="{start:{\$gte:new Date($st),\$lt:new Date($et)}}"  -f userId,start  --out=/home/backup/playerlogs.csv 


mongoexport --host=10.136.3.117 --port=27017 --authenticationDatabase=admin --username=root --password=anyu@2014 --db=gow --collection=signinlogs --query="{time:{\$gte:new Date($st),\$lt:new Date($et)}}"  -f user,time   --out=/home/backup/signinlogs.csv 


mongoexport --host=10.136.3.117 --port=27017 --authenticationDatabase=admin --username=root --password=anyu@2014 --db=gow --collection=traderecords --query="{tradeTime:{\$gte:new Date($st),\$lt:new Date($et)}}"  -f userId,amount,tradeTime    --out=/home/backup/traderecords.csv 


cd  /home/backup  


#将文件传送到目标服务器

scp  playerlogs.csv  root@10.136.54.121:/home/backup/

scp  signinlogs.csv  root@10.136.54.121:/home/backup/

scp  traderecords.csv  root@10.136.54.121:/home/backup/


###############这个时候需要切换到另外一台机器上===========


#导入数据

/usr/local/mongodb_test/bin/mongoimport  --host=10.136.54.121 --port=27018 --authenticationDatabase=admin  --username=root --password=anyu@2015 --db=gowDB --collection=playerlogs /home/backup/playerlogs.csv --drop


/usr/local/mongodb_test/bin/mongoimport  --host=10.136.54.121 --port=27018 --authenticationDatabase=admin  --username=root --password=anyu@2015 --db=gowDB  --collection=signinlogs /home/backup/signinlogs.csv --drop


/usr/local/mongodb_test/bin/mongoimport  --host=10.136.54.121 --port=27018 --authenticationDatabase=admin  --username=root --password=anyu@2015 --db=gowDB  --collection=traderecords /home/backup/traderecords.csv --drop


# 数据转换(使用mongo客服端命令调用js文件中的脚本,js脚本在最后面)

/usr/local/mongodb_test/bin/mongo 10.136.54.121:27018/gowDB -uroot  -panyu@2015 --authenticationDatabase=admin  /home/backup/Datatransformation.js


# 导出数据

/usr/local/mongodb_test/bin/mongoexport --host=10.136.54.121 --port=27018 --authenticationDatabase=admin --username=root --password=anyu@2015 --db=gowDB --collection=NewPlayerlogs  -f userId,start   --csv  --out=/home/backup/NewPlayerlogs.csv 


/usr/local/mongodb_test/bin/mongoexport --host=10.136.54.121 --port=27018 --authenticationDatabase=admin --username=root --password=anyu@2015 --db=gowDB --collection=NewSigninLogs  -f userId,time   --csv   --out=/home/backup/NewSigninLogs.csv 


/usr/local/mongodb_test/bin/mongoexport --host=10.136.54.121 --port=27018 --authenticationDatabase=admin --username=root --password=anyu@2015 --db=gowDB --collection=newTradeRecords -f userId,amount,tradeTime  --csv   --out=/home/backup/newTradeRecords.csv 


# 推送数据(mutt发送邮件)

mutt guocm@anyumedia.com,jiangjc@anyumedia.com,weijie@anyumedia.com,dengwang@anyumedia.com   -s "我是魔兽-运营数据" -a /home/backup/NewPlayerlogs.csv /home/backup/NewSigninLogs.csv /home/backup/newTradeRecords.csv  </home/backup/Readme.txt 

 

# .js脚本

db.newTradeRecords.drop() ; 

db.NewPlayerlogs.drop();

db.NewSigninLogs.drop();


db.traderecords.find().forEach(function(x){ db.newTradeRecords.save({userId:x.userId,amount:x.amount,tradeTime:x.tradeTime.getFullYear().toString()+"-"+(x.tradeTime.getMonth()+1).toString()+"-"+x.tradeTime.getDate().toString()+" "+x.tradeTime.getHours().toString()+":"+x.tradeTime.getMinutes().toString()+":"+x.tradeTime.getSeconds().toString()})}) ;


db.playerlogs.find().forEach(function(x){ db.NewPlayerlogs.save({userId:x.userId,start:x.start.getFullYear().toString()+"-"+(x.start.getMonth()+1).toString()+"-"+x.start.getDate().toString()+" "+x.start.getHours().toString()+":"+x.start.getMinutes().toString()+":"+x.start.getSeconds().toString()})}) ;


db.signinlogs.find().forEach(function(x){ db.NewSigninLogs.save({userId:x.user,time:x.time.getFullYear().toString()+"-"+(x.time.getMonth()+1).toString()+"-"+x.time.getDate().toString()+" "+x.time.getHours().toString()+":"+x.time.getMinutes().toString()+":"+x.time.getSeconds().toString()})}) ;


# shell 将时间数字化

http://www.oschina.net/code/piece_full?code=6554&piece=10486#10486


# ssh信任登陆

http://www.lvtao.net/server/ssh-no-password.html

ssh信任登陆

ssh-keygen -t rsa

/root/.ssh/id_rsa

/root/.ssh/id_rsa.pub

scp -r id_rsa.pub 10.136.3.117:/root/.ssh/authorized_keys


# mutt的安装和使用方法

http://blog.sina.com.cn/s/blog_6cde2617010142kp.html