File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -103,3 +103,4 @@ bundle.js.map
103103tests /profiles
104104** /bundle /model.json
105105.wrangler
106+ dump
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ MONGO_URL=" mongodb://127.0.0.1:27017"
3+ DAYS=365
4+ dump=' dump'
5+
6+ mkdir -p ${dump}
7+ mkdir -p ${dump} /workspaces
8+
9+ get_dbs=" db.getSiblingDB('account').getCollection('workspace').find({lastVisit: {\$ gt: Date.now() - ($DAYS * 24 * 60 * 60 * 1000)}}).forEach(it=>console.log(it.workspace, it.lastVisit))"
10+
11+ mongosh --version
12+ mongosh ${MONGO_URL} --eval " $get_dbs " > ${dump} /databases.list
13+
14+ mongodump --uri=" ${MONGO_URL} " --gzip --db account --archive=" ${dump} /account.gz"
15+ mongodump --uri=" ${MONGO_URL} " --gzip --db ' %ai-bot' --archive=" ${dump} /ai-bot.gz"
16+ mongodump --uri=" ${MONGO_URL} " --gzip --db ' %github' --archive=" ${dump} /github.gz"
17+
18+ echo ' #restore script' > ${dump} /restore.sh
19+ echo " MONGO_URL=\" ${MONGO_URL} \" " >> ${dump} /restore.sh
20+ echo " do_drop=" >> ${dump} /restore.sh
21+ echo " #do_drop=--drop" >> ${dump} /restore.sh
22+
23+ echo ' mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "account" --nsTo "account" --archive=./account.gz ' >> ${dump} /restore.sh
24+ echo ' mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "%ai-bot" --nsTo "%ai-bot" --archive=./ai-bot.gz ' >> ${dump} /restore.sh
25+ echo ' mongorestore --uri="${MONGO_URL}" --gzip ${do_drop} --nsFrom "%github" --nsTo "%github" --archive=./github.gz ' >> ${dump} /restore.sh
26+
27+ while IFS= read -r line; do
28+ arr=($line )
29+ db=" ${arr[0]} "
30+ lastVisit=" ${arr[1]} "
31+ echo " DUMPING $db at lastModified $lastVisit "
32+ aName=" ${dump} /workspaces/$db -$lastVisit .gz"
33+ if [ -f $aName ]; then
34+ echo " DB already dumped $aName "
35+ else
36+ mongodump --uri=" $MONGO_URL " --gzip --db $db --archive=$aName
37+ fi
38+ echo " mongorestore --uri=\"\$ {MONGO_URL}\" --gzip \$ {do_drop} --nsFrom \" ${db} \" --nsTo \" ${db} \" --archive=\" ./workspaces/${db} -${lastVisit} .gz\" " >> ${dump} /restore.sh
39+ done < ${dump} /databases.list
40+
You can’t perform that action at this time.
0 commit comments