使用shell和mongoShell結合解決問題!

來源:互聯網
上載者:User

標籤:mongoshell     linux shell   



解決問題:通過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 [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


# 資料轉換(使用mongo客服端命令調用js檔案中的指令碼,js指令碼在最後面)

/usr/local/mongodb_test/bin/mongo 10.136.54.121:27018/gowDB -uroot  [email protected] --authenticationDatabase=admin  /home/backup/Datatransformation.js


# 匯出資料

/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/NewPlayerlogs.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/NewSigninLogs.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/backup/newTradeRecords.csv 


# 推送資料(mutt發送郵件)

mutt [email protected],jiang[email protected],[email protected],[email protected]   -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




本文出自 “SQLServer MySQL” 部落格,請務必保留此出處http://dwchaoyue.blog.51cto.com/2826417/1618970

使用shell和mongoShell結合解決問題!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.