From 53a1b91a62463b30384fae918d621a992e705ab0 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 3 Oct 2023 22:47:28 +0200 Subject: [PATCH] new: [mongo] add ``README.org`` with some help --- mongo/README.org | 120 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 mongo/README.org diff --git a/mongo/README.org b/mongo/README.org new file mode 100644 index 0000000..aaa38e7 --- /dev/null +++ b/mongo/README.org @@ -0,0 +1,120 @@ +#+TITLE: Mongo Charm + +* Quick information + +** Upgrade + + +Since 4.0.6 based on alpine 3.9, alpine is not packaging mongo +anymore. So we use the official version (that is huge). We still +must change entrypoint to enforce proper directory paths. + +A ``Dockerfile`` is provided for this mean. + +You can fetch latest official tags: +#+begin_quote +docker-tags-fetch mongo -l 10 -f '^[0-9]+\.[0-9]+\.[0-9]+$' +#+end_quote + +change it in docker file, then + +#+begin_quote +docker build . -t docker.0k.io/mongo:"$TAG"-myc +#+end_quote + + +** General Access + +You can access mondo db, if running, through + + +#+begin_src sh +SERVICENAME=mongo +compose exec "$SERVICENAME" /usr/bin/mongo --quiet --eval "some js code" +#+end_src + +if not running, you might want to run it. + + +The following could be added to actions + +*** list databases + + +#+begin_src sh +SERVICENAME=mongo +compose exec -T mongo /usr/bin/mongo --quiet \ + --eval "JSON.stringify(db.adminCommand({listDatabases: 1}))" | \ + jq -r '.databases[] | .name' +#+end_src + + +*** Dump database + +This one will use the probably already builded image from your project on your +host to run a competing mongo with a host directory to store the dump. + +#+begin_src sh +PROJECTNAME=myc +SERVICENAME=mongo +docker run --rm --name mongo_client -ti \ + -v /tmp/mongo:/tmp/mongo --network "${PROJECTNAME}_default" \ + -u root \ + --entrypoint /bin/sh "${PROJECTNAME}_$SERVICENAME" +#+end_src + +Then inside docker: + +#+begin_src sh +apk add mongodb-tools +#+end_src + +Then for each databases: + +#+begin_src sh +DBNAME="xxx" +cd /tmp/mongo +mongodump -h mongo -d "$DBNAME" -o mdump/ +#+end_src + + +*** Drop database + + +#+begin_src sh +DBNAME=xxx +PROJECTNAME=myc +SERVICENAME=mongo +docker exec -i "${PROJECTNAME}_${SERVICE}_1" /usr/bin/mongo --quiet < \ + <(echo " +use $DBNAME; +db.dropDatabase(); +") +#+end_src + +Note: if some connection are active to the database, it might not be +deleted, you should check by relisting the database. + + + +*** Restore database + + +#+begin_src sh +SOURCE_DIR=/tmp/gogocarto +docker run --rm -ti \ + -v "$SOURCE_DIR":/tmp/backups/gogocarto \ + -w /tmp/backups \ + --entrypoint mongorestore \ + --network myc_default \ + myc_mongo \ + --host rs01/mongo /tmp/backups/ +#+end_src + +There should not have any errors. + +Please note that '/tmp/backups' in the last example should contain +one directory per database. + +Note also that you should drop database (see previous section) prior +to restore them. \ No newline at end of file