<p>I am using <a href="https://github.com/bitnami/bitnami-docker-mongodb" rel="nofollow noreferrer">Bitnami MongoDB</a> together with <a href="https://github.com/bitnami/charts/tree/master/bitnami/mongodb" rel="nofollow noreferrer">MongoDB Helm Chart</a> (version 10.6.10, image tag being 3.6.17-ol-7-r26) to run a Mongo cluster in AWS under Kubernetes, which was initially created using the Helm chart. I am trying to get backups working using <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSSnapshots.html" rel="nofollow noreferrer">EBS Snapshots</a> so that periodically whole volume from the primary MongoDB member is copied, which in case something happens could be restored to a new MongoDB installation (using the same Helm chart).</p>
<p>Currently I'm trying to get a backup process so that the snapshot would be put into a new volume, and a new Mongo namespace could be created in the same Kubernetes cluster, where the existing volume would be mounted. This works so that I'm able to create the Kubernetes volumes manually from the snapshot (Kubernetes Persistent Volume and Persistent Volume Claim) and link them with the MongoDB Helm chart (as those PV + PVC contain proper names), and start the Mongo server.</p>
<p>However, once the pods are running (primary, secondary and arbiter), the previously existing replica set is in place (old local database I guess) and obviously not working, as it's from the snapshot state.</p>
<p>Now I would wish to, following <a href="https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup" rel="nofollow noreferrer">MongoDB documentation</a></p>
<ul>
<li>Destroy existing replica set</li>
<li>Reset default settings on arbiter+slave</li>
<li>Create replica set from primary/master (with data being in place for primary)</li>
<li>Attach arbiter and slave to replica set to sync the data similar to what's in the docs.</li>
</ul>
<p>Checking into the state from primary, I get</p>
<pre><code>{
    &quot;stateStr&quot; : &quot;REMOVED&quot;,
    &quot;errmsg&quot; : &quot;Our replica set config is invalid or we are not a member of it&quot;,
    &quot;codeName&quot; : &quot;InvalidReplicaSetConfig&quot;,
    .. other fields as well
}
</code></pre>
<p>So replica set is degraded. When I try to get local database deleted and move this to standalone, I'll get</p>
<pre><code>rs0:OTHER&gt; rs.slaveOk()
rs0:OTHER&gt; show dbs
admin       0.000GB
local       1.891GB
+ some actual databases for data, so I can see data is in place
rs0:OTHER&gt; use local
switched to db local
rs0:OTHER&gt; db.dropDatabase()
&quot;errmsg&quot; : &quot;not authorized on local to execute command { dropDatabase: 1.0, .. few other fields .., $readPreference: { mode: \&quot;secondaryPreferred\&quot; }, $db: \&quot;local\&quot; }&quot;
rs0:OTHER&gt; db.grantRolesToUser('root', [{ role: 'root', db: 'local' }])
2020-12-08T18:25:31.103+0000 E QUERY    [thread1] Error: Primary stepped down while waiting for replication :
</code></pre>
<p>As I'm using the Bitnami Helm chart, it's having some start parameters for the Kubernetes cluster which probably aren't in sync for getting this to run with the existing volume, which already has some configuration in place.</p>
<p>So I'm just wondering if I'm trying to do all the wrong things here, and the correct solution would be start a fresh MongoDB chart and then restore the database using Mongorestore (so basically not using EBS snapshots), or is there a way to launch this from an existing snapshot/volume, so that I would get use of the Helm Chart and EBS snapshots.</p>

mpartan
<p>When using existing data to restore Mongo cluster created with <code>bitnami/mongodb</code> helm chart you will need to set some values on the installation command that ensure all the configuration to be in sync between configmaps, secrets, etc and the data stored in this volume.</p>
<p>First, in addition to <code>--set architecture=replicaset</code> you must add an existing PVC to the chart:</p>
<pre><code>--set persistence.existingClaim=my-restored-pvc
</code></pre>
<p>If you did not set any other param such as <code>auth.username</code> or <code>auth.database</code> you will only need to add <code>--set auth.rootPassword=$MONGODB_ROOT_PASSWORD</code> and <code>--set auth.replicaSetKey=$MONGODB_REPLICA_SET_KEY</code> to your install command and the value must be the old instance value, you can get it by</p>
<pre><code>$ export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default mongo-mongodb -o jsonpath=&quot;{.data.mongodb-root-password}&quot; | base64 --decode)
$ export MONGODB_REPLICA_SET_KEY=$(kubectl get secret --namespace default mongo-mongodb -o jsonpath=&quot;{.data.mongodb-replica-set-key}&quot; | base64 --decode)
</code></pre>
<p>On the other hand, if you have set specific auth params, you will also need to add those values to the chart like: <code>--set auth.password=$MONGODB_PASSWORD,auth.username=myuser,auth.database=mydatabase</code>, you can get it by</p>
<pre><code>$ export MONGODB_PASSWORD=$(kubectl get secret --namespace default mongo-mongodb -o jsonpath=&quot;{.data.mongodb-password}&quot; | base64 --decode)
</code></pre>
<p>Thanks!</p>
