bug fix: incremental backups

This commit is contained in:
Usman Nasir
2021-11-23 19:20:11 +05:00
parent b6775c8d27
commit f7327f345c

View File

@@ -119,7 +119,7 @@ class IncJobs(multi.Thread):
return 1 return 1
else: else:
if self.jobid.type[:8] == 'database': if self.jobid.type[:8] == 'database':
self.restoreTarget = '/home/cyberpanel/' self.restoreTarget = '/usr/local/CyberCP/tmp/'
elif self.jobid.type[:4] == 'data': elif self.jobid.type[:4] == 'data':
self.restoreTarget = '/home/' self.restoreTarget = '/home/'
elif self.jobid.type[:5] == 'email': elif self.jobid.type[:5] == 'email':
@@ -399,7 +399,7 @@ class IncJobs(multi.Thread):
## ##
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(self.path.split('/')[-1].rstrip('.sql'), if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(self.path.split('/')[-1].rstrip('.sql'),
'/home/cyberpanel', 'dummy', 'dummy') == 0: '/usr/local/CyberCP/tmp', 'dummy', 'dummy') == 0:
raise BaseException raise BaseException
else: else:
@@ -413,15 +413,17 @@ class IncJobs(multi.Thread):
if self.awsFunction('restore', '', self.jobid.snapshotid) == 0: if self.awsFunction('restore', '', self.jobid.snapshotid) == 0:
return 0 return 0
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(self.jobid.type.split(':')[1].rstrip('.sql'), if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(self.jobid.type.split(':')[1].rstrip('.sql'),
'/home/cyberpanel', 'dummy', 'dummy') == 0: '/home/%s' % (self.website), 'dummy', 'dummy') == 0:
raise BaseException('Can not restore database backup.') raise BaseException('Can not restore database backup.')
try: try:
if self.reconstruct == 'remote': if self.reconstruct == 'remote':
os.remove('/home/cyberpanel/%s' % (self.path.split('/')[-1])) os.remove('/usr/local/CyberCP/tmp/%s' % (self.path.split('/')[-1]))
else: else:
os.remove('/home/cyberpanel/%s.sql' % (self.jobid.type.split(':')[1])) os.remove('/usr/local/CyberCP/tmp/%s.sql' % (self.jobid.type.split(':')[1]))
os.remove('/home/%s/%s.sql' % (self.website.domain, self.jobid.type.split(':')[1]))
except BaseException as msg: except BaseException as msg:
logging.writeToFile(str(msg)) logging.writeToFile(str(msg))
@@ -646,23 +648,44 @@ class IncJobs(multi.Thread):
for items in databases: for items in databases:
if mysqlUtilities.mysqlUtilities.createDatabaseBackup(items.dbName, '/home/cyberpanel') == 0: ###
UploadPath = '/usr/local/CyberCP/tmp'
if not os.path.exists(UploadPath):
command = 'mkdir %s' % (UploadPath)
ProcessUtilities.executioner(command)
command = 'chown cyberpanel:cyberpanel %s' % (UploadPath)
ProcessUtilities.executioner(command)
command = 'chmod 711 %s' % (UploadPath)
ProcessUtilities.executioner(command)
###
if mysqlUtilities.mysqlUtilities.createDatabaseBackup(items.dbName, UploadPath) == 0:
return 0 return 0
dbPath = '/home/cyberpanel/%s.sql' % (items.dbName) dbPath = '%s/%s.sql' % (UploadPath, items.dbName)
dbPathNew = '/home/%s/%s.sql' % (self.website.domain, items.dbName)
command = 'cp %s %s' % (dbPath, dbPathNew)
ProcessUtilities.executioner(command, self.externalApp)
if self.backupDestinations == 'local': if self.backupDestinations == 'local':
if self.localFunction(dbPath, 'database') == 0: if self.localFunction(dbPathNew, 'database') == 0:
return 0 return 0
elif self.backupDestinations[:4] == 'sftp': elif self.backupDestinations[:4] == 'sftp':
if self.sftpFunction(dbPath, 'database') == 0: if self.sftpFunction(dbPathNew, 'database') == 0:
return 0 return 0
else: else:
if self.awsFunction('backup', dbPath, '', 'database') == 0: if self.awsFunction('backup', dbPathNew, '', 'database') == 0:
return 0 return 0
try: try:
os.remove('/home/cyberpanel/%s.sql' % (items.dbName)) os.remove('/usr/local/CyberCP/tmp/%s.sql' % (items.dbName))
os.remove(dbPathNew)
except BaseException as msg: except BaseException as msg:
logging.statusWriter(self.statusPath, logging.statusWriter(self.statusPath,
'Failed to delete database: %s. [IncJobs.backupDatabases.456]' % str(msg), 1) 'Failed to delete database: %s. [IncJobs.backupDatabases.456]' % str(msg), 1)
@@ -852,8 +875,6 @@ Subject: %s
if self.initiateRepo() == 0: if self.initiateRepo() == 0:
return 0 return 0
if self.prepareBackupMeta() == 0: if self.prepareBackupMeta() == 0:
return 0 return 0