mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-06-15 00:31:59 +02:00
add function to list repo snapshots
This commit is contained in:
@@ -44,6 +44,16 @@ class CPBackupsV2:
|
||||
|
||||
self.repo = f"rclone:{self.data['BackendName']}:{self.data['domain']}"
|
||||
|
||||
|
||||
def FetchSnapShots(self):
|
||||
try:
|
||||
command = f'rustic -r {self.repo} snapshots --password "" --json 2>/dev/null'
|
||||
result = json.loads(
|
||||
ProcessUtilities.outputExecutioner(command, self.website.externalApp, True).rstrip('\n'))
|
||||
return 1, result
|
||||
except BaseException as msg:
|
||||
return 0, str(msg)
|
||||
|
||||
def SetupRcloneBackend(self, type, config):
|
||||
self.LocalRclonePath = f'/home/{self.website.domain}/.config/rclone'
|
||||
self.ConfigFilePath = f'{self.LocalRclonePath}/rclone.conf'
|
||||
@@ -509,6 +519,7 @@ pass = {ObsecurePassword}
|
||||
command = f'rustic -r {self.repo} backup {source} {self.FinalPathRuctic}/config.json --password "" {exclude} --json 2>/dev/null'
|
||||
result = json.loads(ProcessUtilities.outputExecutioner(command, self.website.externalApp, True).rstrip('\n'))
|
||||
|
||||
|
||||
try:
|
||||
SnapShotID = result['id'] ## snapshot id that we need to store in db
|
||||
files_new = result['summary']['files_new'] ## basically new files in backup
|
||||
|
||||
@@ -245,7 +245,7 @@ class mysqlUtilities:
|
||||
return str(msg)
|
||||
|
||||
@staticmethod
|
||||
def createDatabaseBackup(databaseName, tempStoragePath):
|
||||
def createDatabaseBackup(databaseName, tempStoragePath, rustic=0, RusticRepoName = None, RusticConfigPath = None):
|
||||
try:
|
||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||
|
||||
@@ -284,26 +284,42 @@ password=%s
|
||||
|
||||
os.chmod(cnfPath, 0o600)
|
||||
|
||||
command = 'mysqldump --defaults-extra-file=/home/cyberpanel/.my.cnf -u %s --host=%s --port %s %s' % (mysqluser, mysqlhost, mysqlport, databaseName)
|
||||
SHELL = False
|
||||
|
||||
if rustic == 0:
|
||||
|
||||
command = 'mysqldump --defaults-extra-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)
|
||||
|
||||
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
|
||||
|
||||
else:
|
||||
SHELL = True
|
||||
|
||||
command = f'mysqldump --defaults-extra-file=/home/cyberpanel/.my.cnf -u {mysqluser} --host={mysqlhost} --port {mysqlport} --add-drop-table --allow-keywords --complete-insert --quote-names --skip-comments {databaseName} | rustic -r {RusticRepoName} backup --stdin-filename {databaseName}.sql {RusticConfigPath} --password "" --json 2>/dev/null'
|
||||
|
||||
if os.path.exists(ProcessUtilities.debugPath):
|
||||
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||
|
||||
if os.path.exists(ProcessUtilities.debugPath):
|
||||
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||
|
||||
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)
|
||||
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
|
||||
return 1
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabaseBackup]")
|
||||
|
||||
Reference in New Issue
Block a user