Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Core] Backup TypeError
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

backup

#### What cog is this command from?

Core

#### What were you expecting to happen?

Dunno, I was testing to see what backup does, but an error is likely not expected behavior.

#### What actually happened?

For whatever reason I get two of the same error for every run of `[p]backup`. Only one bot is running.
```py
[03/09/2018 20:59] ERROR events on_command_error 205: Exception in command 'backup'
Traceback (most recent call last):
  File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/discord/ext/commands/core.py", line 61, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/redbot/core/core_commands.py", line 1087, in backup
    m = Mongo("Core", **basic_config["STORAGE_DETAILS"])
TypeError: __init__() missing 1 required positional argument: 'identifier'
[03/09/2018 20:59] ERROR events on_command_error 210: Exception in command 'backup'
Traceback (most recent call last):
  File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/discord/ext/commands/core.py", line 61, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/redbot/core/core_commands.py", line 1087, in backup
    m = Mongo("Core", **basic_config["STORAGE_DETAILS"])
TypeError: __init__() missing 1 required positional argument: 'identifier'
```

#### How can we reproduce this issue?

Run `[p]backup` on a mongodb backend.



Discussion:

Resolving patch:
diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py
--- a/redbot/core/core_commands.py
+++ b/redbot/core/core_commands.py
@@ -1087,21 +1087,20 @@ async def backup(self, ctx: commands.Context, backup_path: str = None):
         if basic_config["STORAGE_TYPE"] == "MongoDB":
             from redbot.core.drivers.red_mongo import Mongo
 
-            m = Mongo("Core", **basic_config["STORAGE_DETAILS"])
+            m = Mongo("Core", "0", **basic_config["STORAGE_DETAILS"])
             db = m.db
-            collection_names = await db.collection_names(include_system_collections=False)
+            collection_names = await db.list_collection_names()
             for c_name in collection_names:
                 if c_name == "Core":
                     c_data_path = data_dir / basic_config["CORE_PATH_APPEND"]
                 else:
-                    c_data_path = data_dir / basic_config["COG_PATH_APPEND"]
-                output = {}
+                    c_data_path = data_dir / basic_config["COG_PATH_APPEND"] / c_name
                 docs = await db[c_name].find().to_list(None)
                 for item in docs:
                     item_id = str(item.pop("_id"))
-                    output[item_id] = item
-                target = JSON(c_name, data_path_override=c_data_path)
-                await target.jsonIO._threadsafe_save_json(output)
+                    output = item
+                    target = JSON(c_name, item_id, data_path_override=c_data_path)
+                    await target.jsonIO._threadsafe_save_json(output)
         backup_filename = "redv3-{}-{}.tar.gz".format(
             instance_name, ctx.message.created_at.strftime("%Y-%m-%d %H-%M-%S")
         )


Test patch: