Skip to content

Commit f3a6b4d

Browse files
committed
instruction for dump/restore method
1 parent 6338f15 commit f3a6b4d

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

docs/SELF_HOSTING.md

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
- [Upgrades](#upgrades)
1919
- [v.....](#v)
2020
- [Backup](#backup)
21-
- [Upgrade MongoDB](#upgrade-mongodb)
21+
- [Upgrade MongoDB with dump/restore](#upgrade-mongodb--with-dumprestore)
22+
- [Upgrade MongoDB incremental](#upgrade-mongodb-incremental)
2223
- [References](#references)
2324

2425
<!-- /TOC -->
@@ -206,14 +207,85 @@ Make sure the container is _STOPPED_ and run this command:
206207
docker run --rm -v monkeytype_mongo_data:/from -v $(pwd):/backup alpine tar czf /backup/monkeytype-mongodb.tar.gz -C /from .
207208
```
208209

209-
In case you need to restore the backup run this command:
210+
In case you need to restore the backup run this commands:
210211

211212
```
213+
docker volume rm monkeytype_mongo_data
214+
docker volume create monkeytype_mongo_data
212215
docker run --rm -v monkeytype_mongo_data:/to -v $(pwd):/backup alpine tar xzf /backup/monkeytype-mongodb.tar.gz -C /to
213216
214217
```
215218

216-
#### Upgrade MongoDB
219+
There are two ways to update your MongoDB instance to 8.2. You can use the dump/restore method if your database is not very huge and you have the storage for the full database dump. If not follow the guide for [Upgrade MongoDB incremental](#upgrade-mongodb-incremental)
220+
221+
#### Upgrade MongoDB with dump/restore
222+
223+
Make sure the container is _STOPPED_ and execute this command:
224+
225+
```
226+
docker run -d \
227+
--name mongodb-upgrade \
228+
-v monkeytype_mongo_data:/data/db \
229+
-v $(pwd):/backup \
230+
-p 27017:27017 \
231+
mongo:5.0.13
232+
```
233+
234+
Then dump the data using
235+
236+
```
237+
docker exec -it mongodb-upgrade \
238+
mongodump --db=monkeytype --out=/backup
239+
```
240+
241+
And stop the container again:
242+
243+
```
244+
docker stop mongodb-upgrade
245+
docker rm mongodb-upgrade
246+
```
247+
248+
Then replace the volume with an empty one:
249+
250+
```
251+
docker volume rm monkeytype_mongo_data
252+
docker volume create monkeytype_mongo_data
253+
```
254+
255+
Now start a new container with version 8.2
256+
257+
```
258+
docker run -d \
259+
--name mongodb-upgrade \
260+
-v monkeytype_mongo_data:/data/db \
261+
-v $(pwd):/backup \
262+
-p 27017:27017 \
263+
mongodb/mongodb-community-server:8.2.1-ubi8
264+
```
265+
266+
267+
Then restore the data using
268+
269+
```
270+
docker exec -it mongodb-upgrade \
271+
mongorestore --host=localhost --port=27017 \
272+
--db=monkeytype \
273+
--drop \
274+
/backup/monkeytype
275+
```
276+
277+
And stop the container again:
278+
279+
```
280+
docker stop mongodb-upgrade
281+
docker rm mongodb-upgrade
282+
```
283+
284+
At this point the MongoDB container is upgraded to version 8.2.
285+
286+
Now you can start your instance with `docker compose` as normal.
287+
288+
#### Upgrade MongoDB incremental
217289
218290
MongoDB needs to be upgraded for each major version. Don't skip any of theese steps:
219291
@@ -295,13 +367,13 @@ At this point the MongoDB container is upgraded to version 8.0.
295367
Make sure the container is _STOPPED_ and run this command:
296368
297369
```
298-
docker run --rm -v monkeytype_mongo-data:/data/db alpine chown -R 998:996 /data/db
370+
docker run --rm -v monkeytype_mongo_data:/data/db alpine chown -R 998:996 /data/db
299371
```
300372
301373
```
302374
docker run -d \
303375
--name mongodb-upgrade \
304-
-v monkeytype_mongo-data:/data/db \
376+
-v monkeytype_mongo_data:/data/db \
305377
-p 27017:27017 \
306378
mongodb/mongodb-community-server:8.2.1-ubi8
307379
```

0 commit comments

Comments
 (0)