@@ -133,7 +133,11 @@ def awsFunction(self, fType, backupPath=None, snapshotID=None, bType=None):
133
133
command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s backup %s --password-file %s' % (
134
134
key , secret , self .website .domain , backupPath , self .passwordFile )
135
135
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
+
137
141
snapShotid = result .split (' ' )[- 2 ]
138
142
if bType == 'database' :
139
143
newSnapshot = JobSnapshots (job = self .jobid ,
@@ -172,7 +176,11 @@ def localFunction(self, backupPath, type, restore=None):
172
176
command = 'restic -r %s backup %s --password-file %s --exclude %s' % (
173
177
self .repoPath , backupPath , self .passwordFile , self .repoPath )
174
178
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
+
176
184
snapShotid = result .split (' ' )[- 2 ]
177
185
178
186
if type == 'database' :
@@ -191,13 +199,20 @@ def localFunction(self, backupPath, type, restore=None):
191
199
result = ProcessUtilities .outputExecutioner (command )
192
200
logging .statusWriter (self .statusPath , result , 1 )
193
201
202
+ return 1
203
+
204
+
194
205
def sftpFunction (self , backupPath , type , restore = None ):
195
206
if restore == None :
196
207
remotePath = '/home/backup/%s' % (self .website .domain )
197
208
command = 'export PATH=${PATH}:/usr/bin && restic -r %s:%s backup %s --password-file %s --exclude %s' % (
198
209
self .backupDestinations , remotePath , backupPath , self .passwordFile , self .repoPath )
199
210
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
+
201
216
snapShotid = result .split (' ' )[- 2 ]
202
217
203
218
if type == 'database' :
@@ -586,9 +601,11 @@ def backupData(self):
586
601
backupPath = '/home/%s' % (self .website .domain )
587
602
588
603
if self .backupDestinations == 'local' :
589
- self .localFunction (backupPath , 'data' )
604
+ if self .localFunction (backupPath , 'data' ) == 0 :
605
+ return 0
590
606
elif self .backupDestinations [:4 ] == 'sftp' :
591
- self .sftpFunction (backupPath , 'data' )
607
+ if self .sftpFunction (backupPath , 'data' ) == 0 :
608
+ return 0
592
609
else :
593
610
self .awsFunction ('backup' , backupPath , '' , 'data' )
594
611
@@ -676,20 +693,23 @@ def initiateRepo(self):
676
693
if self .backupDestinations == 'local' :
677
694
command = 'restic init --repo %s --password-file %s' % (self .repoPath , self .passwordFile )
678
695
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 )
680
698
681
699
elif self .backupDestinations [:4 ] == 'sftp' :
682
700
remotePath = '/home/backup/%s' % (self .website .domain )
683
701
command = 'export PATH=${PATH}:/usr/bin && restic init --repo %s:%s --password-file %s' % (
684
702
self .backupDestinations , remotePath , self .passwordFile )
685
703
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 )
687
706
else :
688
707
key , secret = self .getAWSData ()
689
708
command = 'export AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s && restic -r s3:s3.amazonaws.com/%s init --password-file %s' % (
690
709
key , secret , self .website .domain , self .passwordFile )
691
710
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 )
693
713
return 1
694
714
695
715
logging .statusWriter (self .statusPath ,
@@ -699,6 +719,23 @@ def initiateRepo(self):
699
719
logging .statusWriter (self .statusPath , '%s. [IncJobs.initiateRepo.47][5009]' % str (msg ), 1 )
700
720
return 0
701
721
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
+
702
739
def createBackup (self ):
703
740
self .statusPath = self .extraArgs ['tempPath' ]
704
741
website = self .extraArgs ['website' ]
@@ -708,12 +745,21 @@ def createBackup(self):
708
745
websiteSSLs = self .extraArgs ['websiteSSLs' ]
709
746
websiteDatabases = self .extraArgs ['websiteDatabases' ]
710
747
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.
712
758
713
- newJob = IncJob (website = self .website )
714
- newJob .save ()
759
+ self .website = Websites .objects .get (domain = website )
715
760
716
- self .jobid = newJob
761
+ self .jobid = IncJob (website = self .website )
762
+ self .jobid .save ()
717
763
718
764
self .passwordFile = '/home/%s/%s' % (self .website .domain , self .website .domain )
719
765
@@ -726,39 +772,26 @@ def createBackup(self):
726
772
727
773
command = 'chmod 600 %s' % (self .passwordFile )
728
774
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 )
733
775
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 )
744
777
745
778
if self .initiateRepo () == 0 :
746
- return
779
+ return 0
747
780
748
781
if self .prepareBackupMeta () == 0 :
749
- return
782
+ return 0
750
783
751
784
if websiteData :
752
785
if self .backupData () == 0 :
753
- return
786
+ return 0
754
787
755
788
if websiteDatabases :
756
789
if self .backupDatabases () == 0 :
757
- return
790
+ return 0
758
791
759
792
if websiteEmails :
760
793
if self .emailBackup () == 0 :
761
- return
794
+ return 0
762
795
763
796
self .metaBackup ()
764
797
0 commit comments