Commit 677d4bee authored by ajil.k's avatar ajil.k

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	translator.py
parents bc798330 0a0a2786
import pymongo
import pytz
""" mongo dumping"""
import os
import subprocess
import zipfile
......@@ -7,60 +9,57 @@ from datetime import datetime, timedelta
from schema import DeviceDetails, DeviceParameters
#
# """ mongo dumping"""
#
# # Set the MongoDB URL to connect to
# mongo_url = 'mongodb://ilens:ilens%401234@192.168.0.220:4720/?authSource=admin'
#
# # Set the path to the mongodump executable
# mongodump_path = 'C:/Program Files/MongoDB/Server/6.0/bin/mongodump.exe'
#
# # Set the name of the database to be dumped
# db_name = 'Iot_manager(Test)'
#
# # Set the path where the dump will be saved
# dump_path = 'E:/Iot_manager(Test)/dumped_data'
#
# # Build the command to be executed
# command = [mongodump_path, '--uri', mongo_url, '--db', db_name, '--out', dump_path]
#
# # Execute the command
# subprocess.call(command)
#
# # mongo restore
#
# mongorestore_path = 'C:/Program Files/MongoDB/Server/6.0/bin/mongorestore.exe'
# now = datetime.now()
#
# date_str = now.strftime("%Y-%m-%d")
#
# new_db_name = f"Iot_manager(Test)_copy_{date_str}"
#
# restore_command = [mongorestore_path, '--uri', mongo_url, '--db', new_db_name, dump_path + "/" + db_name]
# subprocess.call(restore_command)
#
#
# def zip_folder(folder_path, zip_path):
# with zipfile.ZipFile(zip_path, 'w', compression=zipfile.ZIP_DEFLATED) as zip:
# for root, dirs, files in os.walk(folder_path):
# for file in files:
# file_path = os.path.join(root, file)
# zip.write(file_path, file_path[len(folder_path):])
#
#
# zip_folder(dump_path, 'E:/Iot_manager(Test)/dumped_data.zip')
#
# """ end of mongo dumping and backup"""
""" mongo migration"""
# set up the connection to MongoDB
client1 = pymongo.MongoClient("mongodb://192.168.3.145:2717")
client1 = pymongo.MongoClient("mongodb://ilens:ilens%401234@192.168.0.220:4720/")
col_list = ['mp201a', 'glens', 'ilens', 'ilens_ir4.0', 'dubai-munc', 'epda-rak', 'camw', 'ilens-avis', 'old_glens',
'old_calixto', "ilens-mc"]
db1 = client1["Assets_manager(old)"]
db1 = client1["Iot_manager(Test)"]
db2 = client1["Assets_manager"]
device_details = db2["Iot_devices_details"]
......@@ -290,19 +289,15 @@ for collection_name in col_list:
terminal=terminal
)
device_details_status = device_details.insert_one(device_data.dict())
if device_details_status.inserted_id:
device_details.create_index("software_name")
device_details.create_index("device_id")
device_details.create_index("mac_address")
parameters_details_status = parameters_details.insert_one(parameter_data.dict())
if parameters_details_status.inserted_id:
parameters_details.create_index("mac_address")
parameters_details.create_index("last_sync")
parameters_details.create_index("software_name")
else:
device_details.delete_one({"mac_address": mac_address})
device_details.insert_one(device_data.dict())
device_details.create_index("software_name")
device_details.create_index("device_id")
device_details.create_index("mac_address")
parameters_details.insert_one(parameter_data.dict())
parameters_details.create_index("mac_address")
parameters_details.create_index("last_sync")
parameters_details.create_index("software_name")
print(f"{collection_name} - {i}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment