Solve problems with the shell and Mongoshell!

Source: Internet
Author: User



Fix the problem: convert GMT to Beijing time via JS script and push it to the demand side.


# time converted to pure digital

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中导出 (be careful not to use--csv, otherwise you will get an error when importing)

Mongoexport--host=10.136.3.117--port=27017--authenticationdatabase=admin--username=root [email protected]--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 [email protected]--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 [email protected]--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 [Email protected]:/home/backup/

SCP signinlogs.csv [Email protected]:/home/backup/

SCP traderecords.csv [Email protected]:/home/backup/


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


#导入数据

/usr/local/mongodb_test/bin/mongoimport--host=10.136.54.121--port=27018--authenticationdatabase=admin-- username=root [email protected]--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 [email protected]--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 [email protected]--db=gowdb--collection=traderecords/home/backup/traderecords.csv--drop


# Data conversion (using the MONGO customer-side command to invoke JS files in the script, JS script in the last side)

/usr/local/mongodb_test/bin/mongo 10.136.54.121:27018/gowdb-uroot [email protected]--authenticationdatabase=admin /home/backup/datatransformation.js


# Export Data

/usr/local/mongodb_test/bin/mongoexport--host=10.136.54.121--port=27018--authenticationdatabase=admin-- username=root [email protected]--db=gowdb--collection=newplayerlogs-f userid,start--csv--out=/home/backup/newplay Erlogs.csv


/usr/local/mongodb_test/bin/mongoexport--host=10.136.54.121--port=27018--authenticationdatabase=admin-- username=root [email protected]--db=gowdb--collection=newsigninlogs-f userid,time--csv--out=/home/backup/newsign Inlogs.csv


/usr/local/mongodb_test/bin/mongoexport--host=10.136.54.121--port=27018--authenticationdatabase=admin-- username=root [email protected]--db=gowdb--collection=newtraderecords-f userid,amount,tradetime--csv--out=/home/b Ackup/newtraderecords.csv


# Push data (mutt send mail)

Mutt [email Protected],jiang[email protected],[email Protected],[email protected]-S "I am Warcraft-Operational Data"-a/home/backup/newpla Yerlogs.csv/home/backup/newsigninlogs.csv/home/backup/newtraderecords.csv

#. js Script

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 ()});


# The shell is digitizing time

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


# SSH Trust Login

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

SSH Trust Login

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


# How to install and use Mutt

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




This article is from the "SQL Server MySQL" blog, so be sure to keep this source http://dwchaoyue.blog.51cto.com/2826417/1618970

Solve problems with the shell and Mongoshell!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.