-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andres Hermosilla
committed
Jul 18, 2017
1 parent
b5da25e
commit 6389f20
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Mongodb | ||
|
||
**Get stats** | ||
`mongo Health --eval "db.stats()" &>/dev/null` | ||
|
||
**Query inline** | ||
```shell | ||
second_ago=$(date --date="2 minutes ago" +%s) | ||
query="{class: 0, ts: {\$gt: ${second_ago} }}" | ||
mongo Health --eval "db.Stats.findOne($query).ts" &>/dev/null | ||
``` | ||
|
||
## Export | ||
**Snapshot** | ||
`mongodump --quiet -d User -o /data/snapshot/user-$(date +%Y%m%d)` | ||
|
||
**CSV** | ||
`mongoexport --db Health --collection Stats --csv -q '{class: 1, type:"Customer"}' --fields sn,model_full,domain,cluster_serials,ts --out /tmp/data.csv` | ||
|
||
## Restore | ||
**Import from json** | ||
`mongoimport -db HealthTS --collection CountTS --jsonArray --file count-ts.json` | ||
|
||
**Import from snapshots** | ||
```shell | ||
restore_data() | ||
{ | ||
local reindex='db.getCollectionNames().forEach(function(col){db[col].reIndex()});' | ||
mongorestore --db Health ./snapshot/Health/ | ||
mongorestore --db User ./snapshot/User/ | ||
mongo User --eval "$reindex" &>/dev/null | ||
mongo Health --eval "$reindex" &>/dev/null | ||
} | ||
``` |