[HOW TO] Docker backup mongo

Try manually setting COMPOSE_INTERACTIVE_NO_CLI to false and run the commands again. If call_docker() is not being used, stdout and stderr streams don’t get decoupled.

In dockerpty.pty.ExecOperation().start():

pumps.append(io.Pump(stream, io.Stream(self.stdout), propagate_close=False))
        # FIXME: since exec_start returns a single socket, how do we
        #        distinguish between stdout and stderr?
        # pumps.append(io.Pump(stream, io.Stream(self.stderr), propagate_close=False))

In my case this was the issue, didn’t get any output after the mongodump command and the log information corrupted the backup file.

Another option could be using mongodump --archive --quiet to remove the log altogether. Or forward stderr from inside the sh -c block.


E.g.-

COMPOSE_INTERACTIVE_NO_CLI=false docker-compose exec -T mongo mongodump --archive >db.dump

PS. sh -c isn’t necessary, I don’t know why the super author used that.


Ref: Compose CLI environment variables | Docker Documentation