@@ -133,7 +133,11 @@ def awsFunction(self, fType, backupPath=None, snapshotID=None, bType=None):
133133 command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s backup %s --password-file %s' % (
134134 key , secret , self .website .domain , backupPath , self .passwordFile )
135135 result = ProcessUtilities .outputExecutioner (command )
136- logging .statusWriter (self .statusPath , result , 1 )
136+
137+ if result .find ('saved' ) == - 1 :
138+ logging .statusWriter (self .statusPath , '%s. [5009].' % (result ), 1 )
139+ return 0
140+
137141 snapShotid = result .split (' ' )[- 2 ]
138142 if bType == 'database' :
139143 newSnapshot = JobSnapshots (job = self .jobid ,
@@ -172,7 +176,11 @@ def localFunction(self, backupPath, type, restore=None):
172176 command = 'restic -r %s backup %s --password-file %s --exclude %s' % (
173177 self .repoPath , backupPath , self .passwordFile , self .repoPath )
174178 result = ProcessUtilities .outputExecutioner (command )
175- logging .statusWriter (self .statusPath , result , 1 )
179+
180+ if result .find ('saved' ) == - 1 :
181+ logging .statusWriter (self .statusPath , '%s. [5009].' % (result ), 1 )
182+ return 0
183+
176184 snapShotid = result .split (' ' )[- 2 ]
177185
178186 if type == 'database' :
@@ -191,13 +199,20 @@ def localFunction(self, backupPath, type, restore=None):
191199 result = ProcessUtilities .outputExecutioner (command )
192200 logging .statusWriter (self .statusPath , result , 1 )
193201
202+ return 1
203+
204+
194205 def sftpFunction (self , backupPath , type , restore = None ):
195206 if restore == None :
196207 remotePath = '/home/backup/%s' % (self .website .domain )
197208 command = 'export PATH=${PATH}:/usr/bin && restic -r %s:%s backup %s --password-file %s --exclude %s' % (
198209 self .backupDestinations , remotePath , backupPath , self .passwordFile , self .repoPath )
199210 result = ProcessUtilities .outputExecutioner (command )
200- logging .statusWriter (self .statusPath , result , 1 )
211+
212+ if result .find ('saved' ) == - 1 :
213+ logging .statusWriter (self .statusPath , '%s. [5009].' % (result ), 1 )
214+ return 0
215+
201216 snapShotid = result .split (' ' )[- 2 ]
202217
203218 if type == 'database' :
@@ -586,9 +601,11 @@ def backupData(self):
586601 backupPath = '/home/%s' % (self .website .domain )
587602
588603 if self .backupDestinations == 'local' :
589- self .localFunction (backupPath , 'data' )
604+ if self .localFunction (backupPath , 'data' ) == 0 :
605+ return 0
590606 elif self .backupDestinations [:4 ] == 'sftp' :
591- self .sftpFunction (backupPath , 'data' )
607+ if self .sftpFunction (backupPath , 'data' ) == 0 :
608+ return 0
592609 else :
593610 self .awsFunction ('backup' , backupPath , '' , 'data' )
594611
@@ -676,20 +693,23 @@ def initiateRepo(self):
676693 if self .backupDestinations == 'local' :
677694 command = 'restic init --repo %s --password-file %s' % (self .repoPath , self .passwordFile )
678695 result = ProcessUtilities .outputExecutioner (command )
679- logging .statusWriter (self .statusPath , result , 1 )
696+ if result .find ('config file already exists' ) == - 1 :
697+ logging .statusWriter (self .statusPath , result , 1 )
680698
681699 elif self .backupDestinations [:4 ] == 'sftp' :
682700 remotePath = '/home/backup/%s' % (self .website .domain )
683701 command = 'export PATH=${PATH}:/usr/bin && restic init --repo %s:%s --password-file %s' % (
684702 self .backupDestinations , remotePath , self .passwordFile )
685703 result = ProcessUtilities .outputExecutioner (command )
686- logging .statusWriter (self .statusPath , result , 1 )
704+ if result .find ('config file already exists' ) == - 1 :
705+ logging .statusWriter (self .statusPath , result , 1 )
687706 else :
688707 key , secret = self .getAWSData ()
689708 command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s init --password-file %s' % (
690709 key , secret , self .website .domain , self .passwordFile )
691710 result = ProcessUtilities .outputExecutioner (command )
692- logging .statusWriter (self .statusPath , result , 1 )
711+ if result .find ('config file already exists' ) == - 1 :
712+ logging .statusWriter (self .statusPath , result , 1 )
693713 return 1
694714
695715 logging .statusWriter (self .statusPath ,
@@ -699,6 +719,23 @@ def initiateRepo(self):
699719 logging .statusWriter (self .statusPath , '%s. [IncJobs.initiateRepo.47][5009]' % str (msg ), 1 )
700720 return 0
701721
722+ def sendEmail (self , password ):
723+ SUBJECT = "Backup Repository password for %s" % (self .website .domain )
724+ text = """Password: %s
725+ This is password for your incremental backup repository, please save it in safe place as it will be required when you want to restore backup for this site on remote server.
726+ """ % (password )
727+
728+ sender = 'cyberpanel@%s' % (self .website .domain )
729+ TO = [self .website .adminEmail ]
730+ message = """\
731+ From: %s
732+ To: %s
733+ Subject: %s
734+
735+ %s
736+ """ % (sender , ", " .join (TO ), SUBJECT , text )
737+ mailUtilities .SendEmail (sender , TO , message )
738+
702739 def createBackup (self ):
703740 self .statusPath = self .extraArgs ['tempPath' ]
704741 website = self .extraArgs ['website' ]
@@ -708,12 +745,21 @@ def createBackup(self):
708745 websiteSSLs = self .extraArgs ['websiteSSLs' ]
709746 websiteDatabases = self .extraArgs ['websiteDatabases' ]
710747
711- self .website = Websites .objects .get (domain = website )
748+ ### Checking if restic is installed before moving on
749+
750+ command = 'restic'
751+ if ProcessUtilities .outputExecutioner (command ).find ('restic is a backup program which' ) == - 1 :
752+ logging .statusWriter (self .statusPath , 'It seems restic is not installed, for incremental backups to work '
753+ 'restic must be installed. You can manually install restic using this '
754+ 'guide -> http://go.cyberpanel.net/restic. [5009]' , 1 )
755+ return 0
756+
757+ ## Restic check completed.
712758
713- newJob = IncJob (website = self .website )
714- newJob .save ()
759+ self .website = Websites .objects .get (domain = website )
715760
716- self .jobid = newJob
761+ self .jobid = IncJob (website = self .website )
762+ self .jobid .save ()
717763
718764 self .passwordFile = '/home/%s/%s' % (self .website .domain , self .website .domain )
719765
@@ -726,39 +772,26 @@ def createBackup(self):
726772
727773 command = 'chmod 600 %s' % (self .passwordFile )
728774 ProcessUtilities .executioner (command )
729- SUBJECT = "Backup Repository password for %s" % (self .website .domain )
730- text = """Password: %s
731- This is password for your incremental backup repository, please save it in safe place as it will be required when you want to restore backup for this site on remote server.
732- """ % (password )
733775
734- sender = 'cyberpanel@%s' % (self .website .domain )
735- TO = [self .website .adminEmail ]
736- message = """\
737- From: %s
738- To: %s
739- Subject: %s
740-
741- %s
742- """ % (sender , ", " .join (TO ), SUBJECT , text )
743- mailUtilities .SendEmail (sender , TO , message )
776+ self .sendEmail (password )
744777
745778 if self .initiateRepo () == 0 :
746- return
779+ return 0
747780
748781 if self .prepareBackupMeta () == 0 :
749- return
782+ return 0
750783
751784 if websiteData :
752785 if self .backupData () == 0 :
753- return
786+ return 0
754787
755788 if websiteDatabases :
756789 if self .backupDatabases () == 0 :
757- return
790+ return 0
758791
759792 if websiteEmails :
760793 if self .emailBackup () == 0 :
761- return
794+ return 0
762795
763796 self .metaBackup ()
764797
0 commit comments