mongoDB 小指令碼總結
批次建下個月的表
#!/bin/bash
#!/bin/bash
source /root/.bash_profile
date_today=`date +%Y-%m-%d`
date_month=`date -d '1 month' +%Y%m`
create_tab_log="/opt/scripts/mongodb/create_tab/create_tab_month.log"
echo '----------------------------------------------------'>>$create_tab_log
echo 'delete day is: '$date_today >> $create_tab_log
echo '----------------------------------------------------'>>$create_tab_log
for i in {1..9}
do
/usr/local/mongodb/bin/mongo 127.0.0.1:27017<< EOF >> $create_tab_log
use pmsadapterlog-ly
db.createCollection('pms_log_${date_month}0${i}');
db.pms_log_${date_month}0${i}.ensureIndex({"createTime":1});
db.pms_log_${date_month}0${i}.ensureIndex({"updateTime":1});
db.pms_log_${date_month}0${i}.ensureIndex({"prop":1});
db.pms_log_${date_month}0${i}.ensureIndex({"propName":1});
db.pms_log_${date_month}0${i}.ensureIndex({"hostIp":1});
db.pms_log_${date_month}0${i}.ensureIndex({"msgType":1});
db.pms_log_${date_month}0${i}.ensureIndex({"hotelCode":1});
db.pms_log_${date_month}0${i}.ensureIndex({"adapterKey":1});
db.pms_log_${date_month}0${i}.ensureIndex({"isSuccess":1});
db.pms_log_${date_month}0${i}.ensureIndex({"asyncIsSuccess":1});
db.pms_log_${date_month}0${i}.ensureIndex({"operationUser":1});
db.pms_log_${date_month}0${i}.ensureIndex({"isSendFog":1});
use pmsadapterlog-dc
db.createCollection('pms_log_${date_month}0${i}');
db.pms_log_${date_month}0${i}.ensureIndex({"createTime":1});
db.pms_log_${date_month}0${i}.ensureIndex({"updateTime":1});
db.pms_log_${date_month}0${i}.ensureIndex({"prop":1});
db.pms_log_${date_month}0${i}.ensureIndex({"propName":1});
db.pms_log_${date_month}0${i}.ensureIndex({"hostIp":1});
db.pms_log_${date_month}0${i}.ensureIndex({"msgType":1});
db.pms_log_${date_month}0${i}.ensureIndex({"hotelCode":1});
db.pms_log_${date_month}0${i}.ensureIndex({"adapterKey":1});
db.pms_log_${date_month}0${i}.ensureIndex({"isSuccess":1});
db.pms_log_${date_month}0${i}.ensureIndex({"asyncIsSuccess":1});
db.pms_log_${date_month}0${i}.ensureIndex({"operationUser":1});
db.pms_log_${date_month}0${i}.ensureIndex({"isSendFog":1});
exit
EOF
done
for i in {10..31}
do
/usr/local/mongodb/bin/mongo 127.0.0.1:27017<< EOF >> $create_tab_log
use pmsadapterlog-ly
db.createCollection('pms_log_${date_month}${i}');
db.pms_log_${date_month}${i}.ensureIndex({"createTime":1});
db.pms_log_${date_month}${i}.ensureIndex({"updateTime":1});
db.pms_log_${date_month}${i}.ensureIndex({"prop":1});
db.pms_log_${date_month}${i}.ensureIndex({"propName":1});
db.pms_log_${date_month}${i}.ensureIndex({"hostIp":1});
db.pms_log_${date_month}${i}.ensureIndex({"msgType":1});
db.pms_log_${date_month}${i}.ensureIndex({"hotelCode":1});
db.pms_log_${date_month}${i}.ensureIndex({"adapterKey":1});
db.pms_log_${date_month}${i}.ensureIndex({"isSuccess":1});
db.pms_log_${date_month}${i}.ensureIndex({"asyncIsSuccess":1});
db.pms_log_${date_month}${i}.ensureIndex({"operationUser":1});
db.pms_log_${date_month}${i}.ensureIndex({"isSendFog":1});
use pmsadapterlog-dc
db.createCollection('pms_log_${date_month}${i}');
db.pms_log_${date_month}${i}.ensureIndex({"createTime":1});
db.pms_log_${date_month}${i}.ensureIndex({"updateTime":1});
db.pms_log_${date_month}${i}.ensureIndex({"prop":1});
db.pms_log_${date_month}${i}.ensureIndex({"propName":1});
db.pms_log_${date_month}${i}.ensureIndex({"hostIp":1});
db.pms_log_${date_month}${i}.ensureIndex({"msgType":1});
db.pms_log_${date_month}${i}.ensureIndex({"hotelCode":1});
db.pms_log_${date_month}${i}.ensureIndex({"adapterKey":1});
db.pms_log_${date_month}${i}.ensureIndex({"isSuccess":1});
db.pms_log_${date_month}${i}.ensureIndex({"asyncIsSuccess":1});
db.pms_log_${date_month}${i}.ensureIndex({"operationUser":1});
db.pms_log_${date_month}${i}.ensureIndex({"isSendFog":1});
exit
EOF
done
刪除一個月前的表
#!/bin/bash
source /root/.bash_profile
date_today=`date +%Y-%m-%d`
date_month_ago=`date -d '1 month ago' +%Y%m%d`
drop_log="/opt/scripts/mongodb/create_tab/drop_tab_month.log"
echo '----------------------------------------------------'>>$drop_log
echo 'delete day is: '$date_today >> $drop_log
echo '----------------------------------------------------'>>$drop_log
/usr/local/mongodb/bin/mongo 127.0.0.1:27017<< EOF >> $drop_log
use pmsadapterlog-ly
db.pms_log_$date_month_ago.drop();
use pmsadapterlog-dc
db.pms_log_$date_month_ago.drop();
exit
EOF
按某個欄位刪除表裡一個月前的資料
#!/bin/bash
source /root/.bash_profile
rm_date_today=`date +%Y-%m-%d`
rm_date_month=`date -d '1 month ago' +%Y,%m,%d`
delete_log="/opt/scripts/mongodb/mongo_delete.log"
echo '----------------------------------------------------'>>$delete_log
echo 'delete day is: '$rm_date_today >> $delete_log
echo '----------------------------------------------------'>>$delete_log
/usr/local/mongodb/bin/mongo 127.0.0.1:27017<< EOF >> $delete_log
use pmsadapterlog-ly
db.pms_log.remove({createTime: {\$lt: new Date("$rm_date_month")},msgType:'updateavail'})
use pmsadapterlog-dc
db.pms_log.remove({createTime: {\$lt: new Date("$rm_date_month")},msgType:'updateavail'})
exit
EOF
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29320885/viewspace-1974427/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mongodb總結1-啟動和Shell指令碼MongoDB指令碼
- bash 指令碼總結指令碼
- shell指令碼總結指令碼
- nmap指令碼使用總結指令碼
- awk指令碼學習小結指令碼
- Mongodb 備份指令碼MongoDB指令碼
- Perl指令碼執行方法小結指令碼
- stap監控cpu指令碼小結指令碼
- MongoDB查詢總結MongoDB
- MongoDB基礎總結MongoDB
- bash shell指令碼執行方法總結指令碼
- shell指令碼基本概念和命令小結指令碼
- Vue 指令總結Vue
- MongoDB知識點總結MongoDB
- MongoDB的學習總結MongoDB
- MongoDB監控方法總結MongoDB
- Android cmake命令總結以及指令碼模板Android指令碼
- Jenkins 指令碼命令列應用總結Jenkins指令碼命令列
- 《shell指令碼if..then..elif..then.if語句的總結》指令碼
- github常用指令總結Github
- Mongodb總結4-Spring環境使用MongodbMongoDBSpring
- shell指令碼之特殊符號總結性梳理指令碼符號
- 微信小程式小總結微信小程式
- MongoDB日常運維操作命令小結MongoDB運維
- 小總結吧
- SVN小總結
- 小總結(1)
- mongodb 常用指令MongoDB
- 微信小程式開發總結(附原始碼)微信小程式原始碼
- Android程式碼優化小技巧總結Android優化
- 044 內建指令總結
- shell指令碼呼叫java jar包 的問題總結指令碼JavaJAR
- 使用sqlplus批量執行指令碼的總結SQL指令碼
- Shell指令碼程式設計總結及速查手冊指令碼程式設計
- MongoDB shell常用命令總結MongoDB
- mongodb 階段性技術總結MongoDB
- 前端知識點小結--node、express、mongodb前端ExpressMongoDB
- MongoDB服務端JavaScript指令碼使用方法MongoDB服務端JavaScript指令碼