in VMBackup/main/workloadPatch/WorkloadPatch.py [0:0]
def preMaster(self):
global preSuccess
self.logger.log("WorkloadPatch: Entering pre mode for master")
if self.ipc_folder != None:
self.outfile = os.path.join(self.ipc_folder, "azbackupIPC.txt")
if os.path.exists(self.outfile):
os.remove(self.outfile)
else:
self.logger.log("WorkloadPatch: File for IPC does not exist at pre")
preSuccess = False
if 'mysql' in self.name.lower() or 'mariadb' in self.name.lower():
self.logger.log("WorkloadPatch: Create connection string for premaster mysql")
if self.outfile == "":
self.error_details.append(ErrorDetail(CommonVariables.FailedWorkloadIPCDirectoryMissing, "IPC directory missing"))
return None
prescript = os.path.join(self.temp_script_folder, self.scriptpath + "/preMysqlMaster.sql")
arg = self.sudo_user+" "+self.command+self.name+" "+self.cred_string+" -e\"set @timeout="+self.timeout+";set @outfile=\\\"\\\\\\\""+self.outfile+"\\\\\\\"\\\";source "+prescript+";\""
binary_thread = threading.Thread(target=self.thread_for_sql, args=[arg])
binary_thread.start()
self.waitForPreScriptCompletion()
elif 'oracle' in self.name.lower():
self.logger.log("WorkloadPatch: Pre- Inside oracle pre")
preOracle = self.command + "sqlplus" + " -S -R 2 /nolog @" + os.path.join(self.temp_script_folder, self.scriptpath + "/preOracleMaster.sql ")
args = "su - "+self.linux_user+" -c "+"\'"+preOracle+"\'"
self.logger.log("WorkloadPatch: argument passed for pre script:"+str(args))
process = subprocess.Popen(args, stdout=subprocess.PIPE, shell=True)
wait_counter = 5
while process.poll() == None and wait_counter>0:
wait_counter -= 1
sleep(2)
while True:
line= process.stdout.readline()
line = Utils.HandlerUtil.HandlerUtility.convert_to_string(line)
if(line != ''):
self.logger.log("WorkloadPatch: pre completed with output "+line.rstrip(), True)
else:
break
if('BEGIN BACKUP succeeded' in line):
preSuccess = True
break
if('LOG_MODE=' in line):
line = line.replace('\n','')
line_split = line.split('=')
self.logger.log("WorkloadPatch: log mode set is "+line_split[1], True)
if(line_split[1] == "ARCHIVELOG"):
self.pre_log_mode = "ARCHIVELOG"
self.logger.log("WorkloadPatch: Archive log mode for oracle")
else:
self.pre_log_mode = "NOARCHIVELOG"
self.logger.log("WorkloadPatch: No archive log mode for oracle")
if('STATUS=' in line):
line = line.replace('\n', '')
line_split = line.split('=')
self.logger.log("WorkloadPatch: database status is "+line_split[1], True)
if(line_split[1] == "OPEN"):
self.pre_database_status = "OPEN"
self.logger.log("WorkloadPatch: Database is open")
else:##handle other DB status if required
self.pre_database_status = "NOTOPEN"
self.logger.log("WorkloadPatch: Database is not open")
if(self.pre_log_mode == "NOARCHIVELOG" and self.pre_database_status == "OPEN"):
self.error_details.append(ErrorDetail(CommonVariables.FailedWorkloadDatabaseInNoArchiveLog, "Workload in no archive log mode"))
if(preSuccess == True):
self.logger.log("WorkloadPatch: pre success is true")
self.timeoutDaemon()
elif(self.pre_database_status == "NOTOPEN"):
self.logger.log("WorkloadPatch: Database in closed status, backup can be app consistent")
else:
self.logger.log("WorkloadPatch: Pre failed for oracle")
self.error_details.append(ErrorDetail(CommonVariables.FailedWorkloadPreError, "Workload Pre failed"))
self.logger.log("WorkloadPatch: Pre- Exiting pre mode for master")
elif 'postgres' in self.name.lower():
self.logger.log("WorkloadPatch: Pre- Inside postgres pre")
prePostgres = self.command + "psql " + self.cred_string + " -f " + os.path.join(os.getcwd(), "main/workloadPatch/"+self.scriptpath+"/prePostgresMaster.sql")
args = "su - "+self.linux_user+" -c "+"\'"+prePostgres+"\'"
self.logger.log("WorkloadPatch: argument passed for pre script:"+str(self.linux_user)+" "+str(self.command))
process = subprocess.Popen(args,stdout=subprocess.PIPE, shell=True)
wait_counter = 5
while process.poll() == None and wait_counter>0:
wait_counter -= 1
sleep(2)
while True:
line= process.stdout.readline()
line = Utils.HandlerUtil.HandlerUtility.convert_to_string(line)
if(line != ''):
self.logger.log("WorkloadPatch: pre completed with output "+line.rstrip(), True)
else:
break
self.timeoutDaemon()
self.logger.log("WorkloadPatch: Pre- Exiting pre mode for master postgres")
#Add new workload support here
else:
self.logger.log("WorkloadPatch: Unsupported workload name")
self.error_details.append(ErrorDetail(CommonVariables.FailedWorkloadInvalidWorkloadName, "Workload Not supported"))