@@ -43,8 +43,14 @@ def __init__(self, data):
4343 ## Set up the repo name to be used
4444
4545 self .repo = f"rclone:{ self .data ['BackendName' ]} :{ self .data ['domain' ]} "
46+
47+ ### This will contain list of all snapshots id generated and it will be merged
48+
4649 self .snapshots = []
4750
51+ ##
52+
53+ self .StatusFile = f'/home/cyberpanel/{ self .website .domain } _rustic_backup_log'
4854
4955 def FetchSnapShots (self ):
5056 try :
@@ -75,7 +81,7 @@ def SetupRcloneBackend(self, type, config):
7581'''
7682
7783 command = f"echo '{ content } ' > { self .ConfigFilePath } "
78- ProcessUtilities .executioner (command , self .website .externalApp , True )
84+ # ProcessUtilities.executioner(command, self.website.externalApp, True)
7985
8086 command = f"chmod 600 { self .ConfigFilePath } "
8187 ProcessUtilities .executioner (command , self .website .externalApp )
@@ -87,25 +93,30 @@ def FetchCurrentTimeStamp():
8793
8894 def UpdateStatus (self , message , status ):
8995
90- from websiteFunctions .models import Backupsv2 , BackupsLogsv2
91- self .buv2 = Backupsv2 .objects .get (fileName = self .buv2 .fileName )
92- self .buv2 .status = status
93- self .buv2 .save ()
94-
95- BackupsLogsv2 (message = message , owner = self .buv2 ).save ()
96-
9796 if status == CPBackupsV2 .FAILED :
98- self .buv2 .website .BackupLock = 0
99- self .buv2 .website .save ()
100-
97+ self .website .BackupLock = 0
98+ self .website .save ()
10199 ### delete leftover dbs if backup fails
102100
103101 command = f'rm -f { self .FinalPathRuctic } /*.sql'
104102 ProcessUtilities .executioner (command , None , True )
105103
104+ file = open (self .StatusFile , 'a' )
105+ file .writelines ("[" + time .strftime (
106+ "%m.%d.%Y_%H-%M-%S" ) + ":FAILED] " + message + "\n " )
107+ file .close ()
106108 elif status == CPBackupsV2 .COMPLETED :
107- self .buv2 .website .BackupLock = 0
108- self .buv2 .website .save ()
109+ self .website .BackupLock = 0
110+ self .website .save ()
111+ file = open (self .StatusFile , 'a' )
112+ file .writelines ("[" + time .strftime (
113+ "%m.%d.%Y_%H-%M-%S" ) + ":COMPLETED] " + message + "\n " )
114+ file .close ()
115+ else :
116+ file = open (self .StatusFile , 'a' )
117+ file .writelines ("[" + time .strftime (
118+ "%m.%d.%Y_%H-%M-%S" ) + ":INFO] " + message + "\n " )
119+ file .close ()
109120
110121 ## parent is used to link this snapshot with master snapshot
111122 def BackupConfig (self ):
@@ -140,6 +151,8 @@ def BackupConfig(self):
140151 command = f'chown cyberpanel:cyberpanel { self .FinalPathRuctic } /config.json'
141152 ProcessUtilities .executioner (command )
142153
154+ return 1
155+
143156 def MergeSnapshots (self ):
144157 snapshots = ''
145158 for snapshot in self .snapshots :
@@ -181,7 +194,6 @@ def InitiateBackup(self):
181194 Disk1 = f"du -sm /home/{ self .website .domain } /"
182195 Disk2 = "2>/dev/null | awk '{print $1}'"
183196
184-
185197 self .WebsiteDiskUsage = int (ProcessUtilities .outputExecutioner (f"{ Disk1 } { Disk2 } " , 'root' , True ).rstrip ('\n ' ))
186198
187199 self .CurrentFreeSpaceOnDisk = int (ProcessUtilities .outputExecutioner ("df -m / | awk 'NR==2 {print $4}'" , 'root' , True ).rstrip ('\n ' ))
@@ -195,37 +207,38 @@ def InitiateBackup(self):
195207 statusRes , message = self .InstallRustic ()
196208
197209 if statusRes == 0 :
198- self .UpdateStatus (f'Failed to install Rustic, error: { message } ' ,
199- CPBackupsV2 .FAILED )
210+ self .UpdateStatus (f'Failed to install Rustic, error: { message } ' , CPBackupsV2 .FAILED )
200211 return 0
201212
202213
203- self . buv2 = Backupsv2 (website = self .website , fileName = 'backup-' + self .data ['domain' ] + "-" + time .strftime ("%m.%d.%Y_%H-%M-%S" ), status = CPBackupsV2 .RUNNING , BasePath = self .data ['BasePath' ])
204- self .buv2 .save ()
214+ # = Backupsv2(website=self.website, fileName='backup-' + self.data['domain'] + "-" + time.strftime("%m.%d.%Y_%H-%M-%S"), status=CPBackupsV2.RUNNING, BasePath=self.data['BasePath'])
215+ # self.buv2.save()
205216
206- self .FinalPath = f"{ self .data ['BasePath' ]} /{ self .buv2 .fileName } "
217+ # self.FinalPath = f"{self.data['BasePath']}/{self.buv2.fileName}"
207218
208219 ### Rustic backup final path
209220
210221 self .FinalPathRuctic = f"{ self .data ['BasePath' ]} /{ self .website .domain } "
211222
212223
213- command = f"mkdir -p { self .FinalPath } "
214- ProcessUtilities .executioner (command )
224+ #command = f"mkdir -p {self.FinalPath}"
225+ #ProcessUtilities.executioner(command)
226+
215227
216- command = f"mkdir -p { self .FinalPathRuctic } "
217- ProcessUtilities .executioner (command )
218228
219229 #command = f"chown {website.externalApp}:{website.externalApp} {self.FinalPath}"
220230 #ProcessUtilities.executioner(command)
221231
222- command = f'chown cyberpanel:cyberpanel { self .FinalPath } '
223- ProcessUtilities .executioner (command )
232+ # command = f'chown cyberpanel:cyberpanel {self.FinalPath}'
233+ # ProcessUtilities.executioner(command)
224234
225- command = f'chown cyberpanel:cyberpanel { self .FinalPathRuctic } '
235+ #command = f"chmod 711 {self.FinalPath}"
236+ #ProcessUtilities.executioner(command)
237+
238+ command = f"mkdir -p { self .FinalPathRuctic } "
226239 ProcessUtilities .executioner (command )
227240
228- command = f"chmod 711 { self .FinalPath } "
241+ command = f'chown cyberpanel:cyberpanel { self .FinalPathRuctic } '
229242 ProcessUtilities .executioner (command )
230243
231244 command = f"chmod 711 { self .FinalPathRuctic } "
@@ -334,8 +347,8 @@ def InitiateBackup(self):
334347 command = f"chmod 600 { self .FinalPathRuctic } /config.json"
335348 ProcessUtilities .executioner (command )
336349
337- self .BackupConfig ()
338-
350+ if self .BackupConfig () == 0 :
351+ return 0
339352
340353 self .UpdateStatus ('Backup config created,5' , CPBackupsV2 .RUNNING )
341354 except BaseException as msg :
@@ -372,8 +385,6 @@ def InitiateBackup(self):
372385
373386 self .UpdateStatus ('Completed' , CPBackupsV2 .COMPLETED )
374387
375- print (self .FinalPath )
376-
377388 break
378389 except BaseException as msg :
379390 self .UpdateStatus (f'Failed, Error: { str (msg )} ' , CPBackupsV2 .FAILED )
@@ -388,41 +399,6 @@ def InitiateBackup(self):
388399 self .website .BackupLock = 0
389400 self .website .save ()
390401
391- # def BackupDataBases(self):
392- #
393- # ### This function will backup databases of the website, also need to take care of database that we need to exclude
394- # ### excluded databases are in a list self.data['ExcludedDatabases'] only backup databases if backupdatabase check is on
395- # ## For example if self.data['BackupDatabase'] is one then only run this function otherwise not
396- #
397- # command = f'chown {self.website.externalApp}:{self.website.externalApp} {self.FinalPathRuctic}'
398- # ProcessUtilities.executioner(command)
399- #
400- # command = f'rustic init -r {self.FinalPathRuctic} --password ""'
401- # ProcessUtilities.executioner(command, self.website.externalApp)
402- #
403- # command = f'chown cyberpanel:cyberpanel {self.FinalPathRuctic}'
404- # ProcessUtilities.executioner(command)
405- #
406- # from plogical.mysqlUtilities import mysqlUtilities
407- #
408- # for dbs in self.config['databases']:
409- #
410- # ### Pending: Need to only backup database present in the list of databases that need backing up
411- #
412- # for key, value in dbs.items():
413- # print(f'DB {key}')
414- #
415- # if mysqlUtilities.createDatabaseBackup(key, self.FinalPath) == 0:
416- # self.UpdateStatus(f'Failed to create backup for database {key}.', CPBackupsV2.RUNNING)
417- # return 0
418- #
419- # for dbUsers in value:
420- # print(f'User: {dbUsers["user"]}, Host: {dbUsers["host"]}, Pass: {dbUsers["password"]}')
421- #
422- #
423- #
424- # return 1
425-
426402 def BackupDataBasesRustic (self ):
427403
428404 ### This function will backup databases of the website, also need to take care of database that we need to exclude
@@ -500,34 +476,8 @@ def BackupDataBasesRustic(self):
500476 self .UpdateStatus (f'Failed to create backup for database { key } .' , CPBackupsV2 .FAILED )
501477 return 0
502478
503-
504479 return 1
505480
506- # def BackupData(self):
507- #
508- # ### This function will backup data of the website, also need to take care of directories that we need to exclude
509- # ### excluded directories are in a list self.data['ExcludedDirectories'] only backup data if backupdata check is on
510- # ## For example if self.data['BackupData'] is one then only run this function otherwise not
511- #
512- # destination = f'{self.FinalPath}/data'
513- # source = f'/home/{self.website.domain}'
514- #
515- # ## Pending add user provided folders in the exclude list
516- #
517- # exclude = f'--exclude=.cache --exclude=.cache --exclude=.cache --exclude=.wp-cli ' \
518- # f'--exclude=backup --exclude=incbackup --exclude=incbackup --exclude=logs --exclude=lscache'
519- #
520- # command = f'mkdir -p {destination}'
521- # ProcessUtilities.executioner(command, 'cyberpanel')
522- #
523- # command = f'chown {self.website.externalApp}:{self.website.externalApp} {destination}'
524- # ProcessUtilities.executioner(command)
525- #
526- # command = f'rsync -av {exclude} {source}/ {destination}/'
527- # ProcessUtilities.executioner(command, self.website.externalApp)
528- #
529- # return 1
530-
531481 def BackupRustic (self ):
532482
533483 ### This function will backup data of the website, also need to take care of directories that we need to exclude
@@ -640,6 +590,66 @@ def BackupEmailsRustic(self):
640590 #
641591 # return 1
642592
593+ # def BackupDataBases(self):
594+ #
595+ # ### This function will backup databases of the website, also need to take care of database that we need to exclude
596+ # ### excluded databases are in a list self.data['ExcludedDatabases'] only backup databases if backupdatabase check is on
597+ # ## For example if self.data['BackupDatabase'] is one then only run this function otherwise not
598+ #
599+ # command = f'chown {self.website.externalApp}:{self.website.externalApp} {self.FinalPathRuctic}'
600+ # ProcessUtilities.executioner(command)
601+ #
602+ # command = f'rustic init -r {self.FinalPathRuctic} --password ""'
603+ # ProcessUtilities.executioner(command, self.website.externalApp)
604+ #
605+ # command = f'chown cyberpanel:cyberpanel {self.FinalPathRuctic}'
606+ # ProcessUtilities.executioner(command)
607+ #
608+ # from plogical.mysqlUtilities import mysqlUtilities
609+ #
610+ # for dbs in self.config['databases']:
611+ #
612+ # ### Pending: Need to only backup database present in the list of databases that need backing up
613+ #
614+ # for key, value in dbs.items():
615+ # print(f'DB {key}')
616+ #
617+ # if mysqlUtilities.createDatabaseBackup(key, self.FinalPath) == 0:
618+ # self.UpdateStatus(f'Failed to create backup for database {key}.', CPBackupsV2.RUNNING)
619+ # return 0
620+ #
621+ # for dbUsers in value:
622+ # print(f'User: {dbUsers["user"]}, Host: {dbUsers["host"]}, Pass: {dbUsers["password"]}')
623+ #
624+ #
625+ #
626+ # return 1
627+
628+ # def BackupData(self):
629+ #
630+ # ### This function will backup data of the website, also need to take care of directories that we need to exclude
631+ # ### excluded directories are in a list self.data['ExcludedDirectories'] only backup data if backupdata check is on
632+ # ## For example if self.data['BackupData'] is one then only run this function otherwise not
633+ #
634+ # destination = f'{self.FinalPath}/data'
635+ # source = f'/home/{self.website.domain}'
636+ #
637+ # ## Pending add user provided folders in the exclude list
638+ #
639+ # exclude = f'--exclude=.cache --exclude=.cache --exclude=.cache --exclude=.wp-cli ' \
640+ # f'--exclude=backup --exclude=incbackup --exclude=incbackup --exclude=logs --exclude=lscache'
641+ #
642+ # command = f'mkdir -p {destination}'
643+ # ProcessUtilities.executioner(command, 'cyberpanel')
644+ #
645+ # command = f'chown {self.website.externalApp}:{self.website.externalApp} {destination}'
646+ # ProcessUtilities.executioner(command)
647+ #
648+ # command = f'rsync -av {exclude} {source}/ {destination}/'
649+ # ProcessUtilities.executioner(command, self.website.externalApp)
650+ #
651+ # return 1
652+
643653 def InstallRustic (self ):
644654 try :
645655
0 commit comments