This guide walks through taking a manual logical backup of Graylog's MongoDB
database with mongodump
and restoring it with mongorestore.
It applies to the MongoDB replica set deployed by this chart (the default
MongoDB Community resource).
Note: These commands assume a release named
graylogin thegraylognamespace. Adjust the release name, namespace, and secret name to match your deployment. The connection-string secret is named<release>-mongo-rs-admin-admin.
kubectlaccess to the cluster and namespace where Graylog is installed.jqinstalled locally (used to decode the connection secret).- Enough disk space for the dump, both inside the temporary pod and optionally on your local machine (only if you need to copy it out).
-
Build an admin connection URI from the secret the MongoDB operator generates. This decodes the standard connection string and rewrites it to authenticate against the
admindatabase while targeting thegraylogdatabase:MONGO_ADMIN_URI=$(kubectl get secret graylog-mongo-rs-admin-admin -n graylog -o jsonpath='{.data}' \ | jq -r '.["connectionString.standard"] | @base64d' \ | sed 's/admin\?/graylog\?authSource=admin\&/g')
-
Launch a throwaway pod with the MongoDB shell/tools image, passing the URI in as an environment variable, and drop into a shell:
kubectl run -i -t mongosh --image=alpine/mongosh -n graylog \ -e URI="$MONGO_ADMIN_URI" --restart=Never -- ash -
From inside the pod, dump the database to a local directory in the pod:
mongodump --uri "$URI" --out ./mongo-backup
Run this from your local machine while the mongosh pod is still running:
kubectl exec mongosh -n graylog -- tar cf - /mongo-backup | tar xf - -C .Restoring requires an admin connection URI for the target deployment
($NEW_MONGO_ADMIN_URI). Build it the same way as the backup URI in step 1,
using the target cluster's secret.
If the backup directory only exists on your local machine, copy it back into the pod first (the reverse of the copy-out step):
tar cf - ./mongo-backup | kubectl exec -i mongosh -n graylog -- tar xf - -C /mongo-backupThen, from inside the mongosh pod, restore the graylog database:
mongorestore --uri "$NEW_MONGO_ADMIN_URI" mongo-backup/graylogDelete the temporary pod when you are done:
kubectl delete pod mongosh -n graylog