def main(): print("In main()...") """****************************************************************************************************************""" """ Collecting arguments into variables based on the format: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)] start """ #print("Collecting arguments into variables...") if length_of_args == 4: target_env = sys.argv[3] elif length_of_args==3: target_env = " " else: sys.exit("Arguments format mismatch. Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)].") #sys.exit("Arguments mismatch. Exiting!") #sys.exit(-1) print("Received target_env: %s"%target_env) #print "target_env: ", target_env db_operation = sys.argv[1] print("Received db_operation: %s"%db_operation) #print"db_operation: ", db_operation db_service = sys.argv[2] print("Received db_service: %s"%db_service) #print"db_service: ",db_service """Collecting arguments into variables...stop""" """****************************************************************************************************************""" """ Validate certificate location...start""" #print("Calling \"validate_cert_loc()\"...") #AWS_MYSQL_CERT = validate_cert_loc() """ Validate certificate location...start""" """****************************************************************************************************************""" """ calling validate_args()...start""" #print("Calling \"validate_args()\"...") validate_args(db_operation, db_service, target_env) print("Validate args successful. Back in main()...") """ calling validate_args()...stop""" """****************************************************************************************************************""" """ calling set_env()...start""" #print("Calling \"set_env()\"...") (source_env, target_env)=set_env(db_operation, target_env) print("set_env successful. Back in main()... Received:: source_env: %s, target_env: %s. "%(source_env, target_env)) """ calling set_env()...stop""" """****************************************************************************************************************""" """ calling validate_cert_loc()...start""" if ("aws.3top.com" in source_env) or ("aws.3top.com" in target_env): #print("Calling \"validate_cert_loc()\"...") AWS_MYSQL_CERT = validate_cert_loc() print("validate_cert_loc() successful. Back in main()... ") """ calling validate_cert_loc()...stop""" """****************************************************************************************************************""" """ calling set_host()...start""" #print("Calling \"set_host()\"...") if db_service == 'mysql': (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env) print("set_host successful. Back in main()... Received:: mysql_source_host: %s, mysql_target_host: %s."%(mysql_source_host, mysql_target_host)) elif db_service == 'mongodb': (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env) print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host)) elif db_service == 'all': (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env) (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env) print("set_host successful. Back in main()... Received:: mysql_source_host: %s, mysql_target_host: %s."%(mysql_source_host, mysql_target_host)) print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host)) """ calling set_host()...stop""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ Validate DB Accounts... start""" """ Validate Source Accounts... start""" #print("Validating source host..."), if db_service == 'mongodb': #print("Calling \"validate_mongodb_source_accounts\"...") validate_mongodb_source_accounts(mongodb_source_host) elif db_service == 'mysql': validate_mysql_source(AWS_MYSQL_CERT, mysql_source_host) elif db_service == 'all': validate_mongodb_source_accounts(mongodb_source_host) validate_mysql_source(AWS_MYSQL_CERT, mysql_source_host) """ Validate Source Accounts... stop""" """ Validate Target Accounts... start""" #print("Validating target host..."), if db_service == 'mongodb': #print("Calling \"validate_mongodb_target_accounts\"...") validate_mongodb_target_accounts(mongodb_target_host) elif db_service == 'mysql': if "nyc.3top.com" in mysql_target_host: validate_mysql_nyc_accounts(mysql_target_host) elif "aws.3top.com" in mysql_target_host: validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host) elif db_service == 'all': validate_mongodb_target_accounts(mongodb_target_host) if "nyc.3top.com" in mysql_target_host: validate_mysql_nyc_accounts(mysql_target_host) elif "aws.3top.com" in mysql_target_host: validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host) """ Validate Target Accounts... stop""" """ Validate DB Accounts... stop""" """****************************************************************************************************************""" """********************************************************************************************************************""" """ Find current working directory path: python_root...start""" global python_root #print "Finding real path (working directory)...", python_root = os.path.dirname(os.path.realpath(__file__)) + "/" #print"python_root:",python_root, #print "found." """ Find current working directory path: python_root...stop""" """********************************************************************************************************************""" """ Create a timestamp directory to store log files...start""" print "Creating timestamp directory...", from ttLib.ttSys import dirCreateTimestamp _aws_swap_dir = PATH_ROOT + dict_ttSettings["PATH_LOG"] + "/swap" #print"_aws_swap_dir:", _aws_swap_dir #print "Creating timestamp directory...", global swapTimeStampDirPath swapTimeStampDirPath = dirCreateTimestamp(_aws_swap_dir) #print "swapTimeStampDirPath: ",swapTimeStampDirPath """ Create a timestamp directory to store log files...stop""" """********************************************************************************************************************""" """ Implement Logging...start""" print "Setting up logging...", import logging from ttLib.logger import get_handlers log_handler_name='db_util' my_logger = logging.getLogger(log_handler_name) for h in my_logger.handlers: my_logger.removeHandler(h) log_file_name='db_util.log' log_file_abs_path = swapTimeStampDirPath + "/" + log_file_name #print"log_file_abs_path: ",log_file_abs_path for h in get_handlers(log_handler_name, log_file_abs_path): my_logger.addHandler(h) my_logger.setLevel(logging.DEBUG) #print "complete." #print "\nLog and backup location: %s"%swapTimeStampDirPath my_logger.info("Logging configured successfully!") """ Implement Logging...stop""" """********************************************************************************************************************""" """ Executing db_operation""" if db_service== "mongodb": print "Executing mongo_operations..." mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path) my_logger.info("MongoDB operations completed successfully") elif db_service == 'mysql': print "Executing mysql_operations..." mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path) my_logger.info("MySQL operations completed successfully") elif db_service == 'all': print "Executing mongo_operations..." mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path) my_logger.info("MongoDB operations completed successfully") print "Executing mysql_operations..." mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path) my_logger.info("MySQL operations completed successfully") """main() Module definition... start""" """main() Module definition... stop""" my_logger.info("Program execution complete. Exiting!") print "Program execution complete. Exiting!\nLogfile location: %s" %log_file_abs_path
print"complete." #print dict_ttSettings except: sys.exit("Download of ttSettings from S3 failed. Exiting! Error Encountered: %s." %str(sys.exc_info())) PATH_ROOT = dict_ttSettings["PATH_ROOT"] PATH_LOG = PATH_ROOT + dict_ttSettings["PATH_LOG"] import logging import logging.handlers import ttLib.logger as logger import ttLib.ttSys as ttSys #level1='logging.INFO' #print PATH_ROOT + PATH_LOG + "/dns" (dir_backup, timestamp) = ttSys.dirCreateTimestamp(PATH_LOG + "/dns") print"Backup and logging directory created successfully..." my_logger = logging.getLogger('dnsOps') for h in my_logger.handlers: my_logger.removeHandler(h) log_file = dir_backup + '/dnsOps.log' loglevel = dict_ttSettings["log_level"] try: confirm_loglevel = raw_input("\nCurrent loglevel is %s. Press [c/ C] to continue. To change the loglevel to 'DEBUG' enter [debug/ DEBUG]: "%loglevel) if confirm_loglevel.upper() == 'C': loglevel = "INFO" elif confirm_loglevel.upper() == "DEBUG": loglevel = "DEBUG" else: sys.exit("Incorrect entry received: %s. Exiting!"%confirm_loglevel) except:
""" Create a timestamp directory to store log files...start""" #print "Creating timestamp directory..." try: from ttLib.ttSys import dirCreateTimestamp except: sys.exit( "Error Encountered: %s. \"from ttLib.ttSys import dirCreateTimestamp\"...failed. Exiting!" % str(sys.exc_info())) _aws_swap_dir = PATH_ROOT + dict_ttSettings["PATH_LOG"] + "/swap" #print"_aws_swap_dir:", _aws_swap_dir #print "Creating timestamp directory...", global swapTimeStampDirPath print("Calling swapTimeStampDirPath = dirCreateTimestamp(%s)" % _aws_swap_dir) (swapTimeStampDirPath, timestamp) = dirCreateTimestamp(_aws_swap_dir) print "swapTimeStampDirPath: ", swapTimeStampDirPath """ Create a timestamp directory to store log files...stop""" """********************************************************************************************************************""" """ Implement Logging...start""" print "Setting up logging..." try: import logging except: sys.exit("Error Encountered: %s. \"import logging\"...failed. Exiting!" % str(sys.exc_info())) try: from ttLib.logger import get_handlers except: sys.exit(
def main(): print("In main()...") """****************************************************************************************************************""" length_of_args=len(sys.argv) if length_of_args==0: print "No arguments found. Use the format: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)]" sys.exit("Exiting!") """ Collecting arguments into variables based on the format: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)] start """ print("Collecting arguments into variables...") if length_of_args == 4: target_env = sys.argv[3] elif length_of_args==3: target_env = " " else: print("Arguments mismatch. Exiting!") sys.exit(-1) print("Received target_env: %s"%target_env) #print "target_env: ", target_env db_operation = sys.argv[1] print("Received db_operation: %s"%db_operation) #print"db_operation: ", db_operation db_service = sys.argv[2] print("Received db_service: %s"%db_service) #print"db_service: ",db_service """Collecting arguments into variables...stop""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ Validate certificate location...start""" #print("Calling \"validate_cert_loc()\"...") #AWS_MYSQL_CERT = validate_cert_loc() """ Validate certificate location...start""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ calling validate_args()...start""" print("Calling \"validate_args()\"...") validate_args(db_operation, db_service, target_env) print("Validate args successful. Back in main()...") """ calling validate_args()...stop""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ calling set_env()...start""" print("Calling \"set_env()\"...") (source_env, target_env)=set_env(db_operation, target_env) print("set_env successful. Back in main()... Received:: source_env: %s, target_env: %s. "%(source_env, target_env)) """ calling set_env()...stop""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ calling validate_cert_loc()...start""" if ("aws.3top.com" in source_env) or ("aws.3top.com" in target_env): print("Calling \"validate_cert_loc()\"...") AWS_MYSQL_CERT = validate_cert_loc() print("validate_cert_loc() successful. Back in main()... ") """ calling validate_cert_loc()...stop""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ calling set_host()...start""" print("Calling \"set_host()\"...") if db_service == 'mysql': (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env) elif db_service == 'mongodb': (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env) elif db_service == 'all': (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env) (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env) print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host)) """ calling set_host()...stop""" """****************************************************************************************************************""" """****************************************************************************************************************""" """ Validate DB Accounts... start""" """ Validate Source Accounts... start""" print("Validating source host..."), if db_service == 'mongodb': print("Calling \"validate_mongodb_source_accounts\"...") validate_mongodb_source_accounts(mongodb_source_host) elif db_service == 'mysql': validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_source_host) elif db_service == 'all': validate_mongodb_source_accounts(mongodb_source_host) validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_source_host) """ Validate Source Accounts... stop""" """ Validate Target Accounts... start""" print("Validating target host..."), if db_service == 'mongodb': print("Calling \"validate_mongodb_target_accounts\"...") validate_mongodb_target_accounts(mongodb_target_host) elif db_service == 'mysql': if "nyc.3top.com" in mysql_target_host: validate_mysql_nyc_accounts(mysql_target_host) elif "aws.3top.com" in mysql_target_host: validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host) elif db_service == 'all': validate_mongodb_target_accounts(mongodb_target_host) if "nyc.3top.com" in mysql_target_host: validate_mysql_nyc_accounts(mysql_target_host) elif "aws.3top.com" in mysql_target_host: validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host) """ Validate Target Accounts... stop""" """ Validate DB Accounts... stop""" """****************************************************************************************************************""" """********************************************************************************************************************""" """ Find current working directory path: python_root...start""" global python_root print "Finding real path (working directory)...", python_root = os.path.dirname(os.path.realpath(__file__)) + "/" #print"python_root:",python_root, print "found." """ Find current working directory path: python_root...stop""" """********************************************************************************************************************""" """ Create a timestamp directory to store log files...start""" print "Creating timestamp directory...", from ttLib.ttSys import dirCreateTimestamp _aws_swap_dir = PATH_ROOT + dict_ttSettings["PATH_LOG"] + "/swap" #print"_aws_swap_dir:", _aws_swap_dir print "Creating timestamp directory...", global swapTimeStampDirPath swapTimeStampDirPath = dirCreateTimestamp(_aws_swap_dir) #print "swapTimeStampDirPath: ",swapTimeStampDirPath """ Create a timestamp directory to store log files...stop""" """********************************************************************************************************************""" """ Implement Logging...start""" print "Setting up logging...", import logging from ttLib.logger import get_handlers log_handler_name='db_util' my_logger = logging.getLogger(log_handler_name) for h in my_logger.handlers: my_logger.removeHandler(h) log_file_name='db_util.log' log_file_abs_path = swapTimeStampDirPath + "/" + log_file_name #print"log_file_abs_path: ",log_file_abs_path for h in get_handlers(log_handler_name, log_file_abs_path): my_logger.addHandler(h) my_logger.setLevel(logging.DEBUG) print "complete." #print "\nLog and backup location: %s"%swapTimeStampDirPath my_logger.info("Logging configured successfully!") """ Implement Logging...stop""" """********************************************************************************************************************""" """ Executing db_operation""" if db_service== "mongodb": mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger) my_logger.info("MongoDB operations completed successfully") elif db_service == 'mysql': mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger) my_logger.info("MySQL operations completed successfully") elif db_service == 'all': mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger) my_logger.info("MongoDB operations completed successfully") mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger) my_logger.info("MySQL operations completed successfully") """main() Module definition... start""" """main() Module definition... stop""" my_logger.info("Program execution complete. Exiting!") print "Program execution complete. Exiting!\nLogfile location: %s" %swapTimeStampDirPath
print "Downloading ttSettings from S3 successful!" PATH_ROOT = dict_sys_ttSettings["PATH_ROOT"] """Download ttSettings.conf from S3...STOP""" """********************************************************************************************************************""" """ Create a timestamp directory to store log files...START""" try: from ttLib.ttSys import dirCreateTimestamp except: sys.exit("Error Encountered. \"from ttLib.ttSys import dirCreateTimestamp\"...failed. Exiting!") _aws_swap_dir = PATH_ROOT + dict_sys_ttSettings["PATH_LOG"] + "/mysqlUsers" global swapTimeStampDirPath (swapTimeStampDirPath, timestamp) = dirCreateTimestamp(_aws_swap_dir) """ Create a timestamp directory to store log files...STOP""" """********************************************************************************************************************""" """ Implement Logging...START""" print "Setting up logging..." try: import logging except: sys.exit("Error Encountered: \"import logging\"...failed. Exiting!" ) try: from ttLib.logger import get_handlers except:
except: sys.exit( "Download of ttSettings from S3 failed. Exiting! Error Encountered: %s." % str(sys.exc_info())) PATH_ROOT = dict_ttSettings["PATH_ROOT"] PATH_LOG = PATH_ROOT + dict_ttSettings["PATH_LOG"] import logging import logging.handlers import ttLib.logger as logger import ttLib.ttSys as ttSys #level1='logging.INFO' #print PATH_ROOT + PATH_LOG + "/dns" dir_backup = ttSys.dirCreateTimestamp(PATH_LOG + "/dns") print "Backup and logging directory created successfully..." my_logger = logging.getLogger('dnsOps') for h in my_logger.handlers: my_logger.removeHandler(h) log_file = dir_backup + '/dnsOps.log' loglevel = dict_ttSettings["log_level"] try: confirm_loglevel = raw_input( "\nCurrent loglevel is %s. Press [c/ C] to continue. To change the loglevel to 'DEBUG' enter [debug/ DEBUG]: " % loglevel) if confirm_loglevel.upper() == 'C': loglevel = "INFO" elif confirm_loglevel.upper() == "DEBUG": loglevel = "DEBUG" else:
#print"complete." #print dict_ttSettings except: sys.exit( "Download of ttSettings from S3 failed. Exiting! Error Encountered") print "\n" PATH_ROOT = dict_ttSettings["PATH_ROOT"] PATH_LOG = PATH_ROOT + dict_ttSettings["PATH_LOG"] import logging import logging.handlers import ttLib.logger as logger #level1='logging.INFO' #print PATH_ROOT + PATH_LOG + "/dns" (dir_backup, timestamp) = dirCreateTimestamp(PATH_LOG + "/dns") print "Backup and logging directory created successfully..." my_logger = logging.getLogger('dnsOps') for h in my_logger.handlers: my_logger.removeHandler(h) log_file = dir_backup + '/dnsOps.log' loglevel = dict_ttSettings["log_level"].upper() print "Received loglevel: %s" % loglevel loglevel = getattr(logging, loglevel.upper()) for h in logger.get_handlers('dnsOps', log_file): my_logger.addHandler(h) my_logger.setLevel(loglevel) print "Logger created successfully. Continuing..." my_logger.debug("Logger created successfully. Continuing...") #my_logger.debug("dict_ttSettings: "%dict_ttSettings)
print"complete." #print dict_ttSettings except: sys.exit("Download of ttSettings from S3 failed. Exiting! Error Encountered") PATH_ROOT = dict_ttSettings["PATH_ROOT"] PATH_LOG = PATH_ROOT + dict_ttSettings["PATH_LOG"] import logging import logging.handlers import ttLib.logger as logger import ttLib.ttSys as ttSys #level1='logging.INFO' #print PATH_ROOT + PATH_LOG + "/dns" dir_backup = ttSys.dirCreateTimestamp(PATH_LOG + "/dnsOps") print"Backup and logging directory created successfully..." my_logger = logging.getLogger('dnsOps') for h in my_logger.handlers: my_logger.removeHandler(h) log_file = dir_backup + '/dnsOps.log' loglevel = dict_ttSettings["log_level"].upper() print"Received loglevel: %s"%loglevel loglevel = getattr(logging, loglevel.upper()) for h in logger.get_handlers('dnsOps', log_file): my_logger.addHandler(h) my_logger.setLevel(loglevel) print"Logger created successfully. Continuing..." my_logger.debug("Logger created successfully. Continuing...") my_logger.debug("dict_ttSettings: "%dict_ttSettings)