How to Generate a MongoDB dump of a Juju Controller

See details from [Canonical](https://canonical.force.com/s/article/ka0D0000000CqlsIAC/How-to-generate-a-mongodump-for-a-Juju-Environment).

In summary:

  1. log in to the controller (replace CONTROLLER with the name of your model):

    $ juju ssh ubuntu@$(juju status -m CONTROLLER | grep 'started'| awk '{print $3}')
    
  2. become root and set the password in the enironment:

    $ sudo -s
    $ export dbpass=$(grep oldpassword /var/lib/juju/agents/machine-0/agent.conf | cut -d' ' -f2)
    
  3. run the mongodb dump utility:

    $ /usr/lib/juju/mongo3.2/bin/mongodump -h 127.0.0.1 --port 37017 --ssl -u admin -p $dbpass --authenticationDatabase admin --db juju
    

This will create a dump in [BSON format](https://docs.mongodb.com/manual/reference/glossary/#term-bson) in the folder dump. You can view the dump files wity the command bisondump.