Skip to content

Commit

Permalink
[Core] Fix errors with [p]backup on MongoDB
Browse files Browse the repository at this point in the history
Resolves Cog-Creators#2094.

This command needs some more fixing and cleaning up than this, this is just a simple bugfix which gets it mostly working for now.

Signed-off-by: Toby Harradine <[email protected]>
  • Loading branch information
Tobotimus committed Oct 8, 2018
1 parent 9e13ca4 commit 468dbd2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down

0 comments on commit 468dbd2

Please sign in to comment.