<p>I have created a database and accompanying user for the database but It appears I cant do backups with that user and neither can I add the backup role to the user.
Having checked documentation I added a user but this time at the admin database level (<code>use admin</code>) and added backup role for the same.</p>
<p>However when I attempt to do a backup I am getting an error <em>Failed: error dumping metadata: error creating directory for metadata file /var/backups/...: mkdir /var/backups/...: permission denied</em></p>
<p>Steps
1.</p>
<pre><code> `kubectl -n &lt;namespace&gt; exec -it &lt;pod_name&gt; -- sh`
</code></pre>
<p>(mongo is running in kubernetes)</p>
<p>2.</p>
<pre><code>`use admin` 
</code></pre>
<p>(switch to admin user)</p>
<p>3.</p>
<pre><code>db.createUser( {user: &quot;backupuser&quot;, pwd: &quot;abc123&quot;, roles: [&quot;root&quot;, &quot;userAdminAnyDatabase&quot;, &quot;dbAdminAnyDatabase&quot;, &quot;readWriteAnyDatabase&quot;,&quot;backup&quot;], mechanisms:[&quot;SCRAM-SHA-256&quot;]})
</code></pre>
<ol start="4">
<li></li>
</ol>
<pre><code> `db.getUsers({ filter: { mechanisms: &quot;SCRAM-SHA-256&quot; } })`
</code></pre>
<p>(Verify if user exists)</p>
<p>5.</p>
<pre><code> mongodump -u backupuser -p abc123 --authenticationDatabase admin -d TESTDB --out /var/backups/dump-25-05-22 --gzip
</code></pre>
<p>Is it possible to even amend permissions for this user in such a case or I should be looking somewhere else.
In the container it seems I cant do any permission updates (for the group) but the user already has all permissions on /var/backups :</p>
<pre><code>ls -la
total 8
drwxr-xr-x 2 root root 4096 Feb 18  2021 .
drwxr-xr-x 1 root root 4096 Feb 18  2021 ..
</code></pre>
<p>I am not convinced either that I should be going even this far. The backup should execute out of the box as per the user I added.</p>
<p>What exactly am I missing ?</p>

<p>There is nothing to do from mongodb side. The user that is running <code>mongodump</code> command doesn't have the required permission.  To check if thats the case, you can try this out : <code>sudo chmod 777 -R /var/backups/</code> before running <code>mongodump</code>.</p>
