diff --git a/IncBackups/IncBackupsControl.py b/IncBackups/IncBackupsControl.py index e147873ad..6ea773e91 100644 --- a/IncBackups/IncBackupsControl.py +++ b/IncBackups/IncBackupsControl.py @@ -665,6 +665,9 @@ class IncJobs(multi.Thread): if mysqlUtilities.mysqlUtilities.createDatabaseBackup(items.dbName, UploadPath) == 0: return 0 + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Backup created for DB Incscheduler.backupDatabases') + dbPath = '%s/%s.sql' % (UploadPath, items.dbName) dbPathNew = '/home/%s/%s.sql' % (self.website.domain, items.dbName) diff --git a/plogical/mysqlUtilities.py b/plogical/mysqlUtilities.py index ad35f3f61..9d5cf87fb 100755 --- a/plogical/mysqlUtilities.py +++ b/plogical/mysqlUtilities.py @@ -292,27 +292,52 @@ password=%s if rustic == 0: + command = 'rm -f ' + tempStoragePath + "/" + databaseName + '.sql' + ProcessUtilities.executioner(command) + command = 'mysqldump --defaults-file=/home/cyberpanel/.my.cnf -u %s --host=%s --port %s %s' % (mysqluser, mysqlhost, mysqlport, databaseName) - if os.path.exists(ProcessUtilities.debugPath): - logging.CyberCPLogFileWriter.writeToFile(command) + # if os.path.exists(ProcessUtilities.debugPath): + # logging.CyberCPLogFileWriter.writeToFile(command) + # + # logging.CyberCPLogFileWriter.writeToFile(f'Get current executing uid {os.getuid()}') + # + # cmd = shlex.split(command) + # + # try: + # errorPath = '/home/cyberpanel/error-logs.txt' + # errorLog = open(errorPath, 'a') + # with open(tempStoragePath + "/" + databaseName + '.sql', 'w') as f: + # res = subprocess.call(cmd, stdout=f, stderr=errorLog, shell=SHELL) + # if res != 0: + # logging.CyberCPLogFileWriter.writeToFile( + # "Database: " + databaseName + "could not be backed! [createDatabaseBackup]") + # return 0 + # except subprocess.CalledProcessError as msg: + # logging.CyberCPLogFileWriter.writeToFile( + # "Database: " + databaseName + "could not be backed! Error: %s. [createDatabaseBackup]" % ( + # str(msg))) + # return 0 cmd = shlex.split(command) - try: - errorPath = '/home/cyberpanel/error-logs.txt' - errorLog = open(errorPath, 'a') - with open(tempStoragePath + "/" + databaseName + '.sql', 'w') as f: - res = subprocess.call(cmd, stdout=f, stderr=errorLog, shell=SHELL) - if res != 0: - logging.CyberCPLogFileWriter.writeToFile( - "Database: " + databaseName + "could not be backed! [createDatabaseBackup]") - return 0 - except subprocess.CalledProcessError as msg: - logging.CyberCPLogFileWriter.writeToFile( - "Database: " + databaseName + "could not be backed! Error: %s. [createDatabaseBackup]" % ( - str(msg))) - return 0 + with open(tempStoragePath + "/" + databaseName + '.sql', 'w') as f: + # Using subprocess.run to capture stdout and stderr + result = subprocess.run( + cmd, + stdout=f, + stderr=subprocess.PIPE, + shell=SHELL + ) + + # Check if the command was successful + if result.returncode != 0: + logging.CyberCPLogFileWriter.writeToFile( + "Database: " + databaseName + " could not be backed up! [createDatabaseBackup]" + ) + # Log stderr + logging.CyberCPLogFileWriter.writeToFile(result.stderr.decode('utf-8')) + return 0 else: SHELL = True