mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
OP-2042 - updates to db dumps and loads
This commit is contained in:
parent
fab3b02b3e
commit
5795636af5
1 changed files with 10 additions and 7 deletions
|
|
@ -136,7 +136,8 @@ class DBHandler:
|
|||
print("Dropping {} database".format(db_name))
|
||||
self.client.drop_database(db_name)
|
||||
|
||||
def backup_to_dump(self, db_name, dump_dir, overwrite=False):
|
||||
def backup_to_dump(self, db_name, dump_dir, overwrite=False,
|
||||
collection=None):
|
||||
"""
|
||||
Helper method for running mongodump for specific 'db_name'
|
||||
"""
|
||||
|
|
@ -148,7 +149,8 @@ class DBHandler:
|
|||
raise RuntimeError("Backup already exists, "
|
||||
"run with overwrite=True")
|
||||
|
||||
query = self._dump_query(self.uri, dump_dir, db_name=db_name)
|
||||
query = self._dump_query(self.uri, dump_dir,
|
||||
db_name=db_name, collection=collection)
|
||||
print("Mongodump query:: {}".format(query))
|
||||
subprocess.run(query)
|
||||
|
||||
|
|
@ -187,7 +189,8 @@ class DBHandler:
|
|||
drop_part = "--drop"
|
||||
|
||||
if db_name_out:
|
||||
db_part += " --nsTo={}.*".format(db_name_out)
|
||||
collection_str = collection or '*'
|
||||
db_part += " --nsTo={}.{}".format(db_name_out, collection_str)
|
||||
|
||||
query = "\"{}\" --uri=\"{}\" --dir=\"{}\" {} {} {}".format(
|
||||
"mongorestore", uri, dump_dir, db_part, coll_part, drop_part
|
||||
|
|
@ -217,12 +220,12 @@ class DBHandler:
|
|||
|
||||
return query
|
||||
|
||||
# handler = DBHandler(uri="mongodb://localhost:27017")
|
||||
#handler = DBHandler(uri="mongodb://localhost:27017")
|
||||
#
|
||||
# backup_dir = "c:\\projects\\dumps"
|
||||
#backup_dir = "c:\\projects\\test_nuke_publish\\input\\dumps"
|
||||
# #
|
||||
# handler.backup_to_dump("openpype", backup_dir, True)
|
||||
# # handler.setup_from_dump("test_db", backup_dir, True)
|
||||
#handler.backup_to_dump("avalon", backup_dir, True, collection="test_project")
|
||||
#handler.setup_from_dump("test_db", backup_dir, True, db_name_out="avalon", collection="test_project")
|
||||
# # handler.setup_from_sql_file("test_db", "c:\\projects\\sql\\item.sql",
|
||||
# # collection="test_project",
|
||||
# # drop=False, mode="upsert")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue