@@ -135,7 +135,7 @@ def createLocalBackup(virtualHost, backupLogPath):
135135 return 0 , str (msg )
136136
137137 @staticmethod
138- def createBackup (virtualHost , ipAddress , backupLogPath , port ):
138+ def createBackup (virtualHost , ipAddress , backupLogPath , port = '22' , user = 'root' ):
139139 try :
140140
141141 backupSchedule .remoteBackupLogging (backupLogPath , "Preparing to create backup for: " + virtualHost )
@@ -152,7 +152,7 @@ def createBackup(virtualHost, ipAddress, backupLogPath , port):
152152
153153 backupSchedule .remoteBackupLogging (backupLogPath , "Preparing to send backup for: " + virtualHost + " to " + ipAddress )
154154
155- backupSchedule .sendBackup (backupPath + ".tar.gz" , ipAddress , backupLogPath , port )
155+ backupSchedule .sendBackup (backupPath + ".tar.gz" , ipAddress , backupLogPath , port , user )
156156
157157 backupSchedule .remoteBackupLogging (backupLogPath , "Backup for: " + virtualHost + " is sent to " + ipAddress )
158158
@@ -180,7 +180,7 @@ def createBackup(virtualHost, ipAddress, backupLogPath , port):
180180 logging .CyberCPLogFileWriter .writeToFile (str (msg ) + " [backupSchedule.createBackup]" )
181181
182182 @staticmethod
183- def sendBackup (backupPath , IPAddress , backupLogPath , port ):
183+ def sendBackup (backupPath , IPAddress , backupLogPath , port = '22' , user = 'root' ):
184184 try :
185185
186186 ## IPAddress of local server
@@ -193,7 +193,7 @@ def sendBackup(backupPath, IPAddress, backupLogPath , port):
193193 ##
194194
195195 writeToFile = open (backupLogPath , "a" )
196- command = "sudo scp -o StrictHostKeyChecking=no -P " + port + " -i /root/.ssh/cyberpanel " + backupPath + " root@" + IPAddress + ":/home /backup/" + ipAddressLocal + "/" + time .strftime ("%a-%b" ) + "/"
196+ command = "sudo scp -o StrictHostKeyChecking=no -P " + port + " -i /root/.ssh/cyberpanel " + backupPath + " " + user + "@" + IPAddress + ":~ /backup/" + ipAddressLocal + "/" + time .strftime ("%a-%b" ) + "/"
197197 subprocess .call (shlex .split (command ), stdout = writeToFile )
198198
199199 ## Remove backups already sent to remote destinations
@@ -222,6 +222,10 @@ def prepare():
222222 data = open (destinations ,'r' ).readlines ()
223223 ipAddress = data [0 ].strip ("\n " )
224224 port = data [1 ].strip ("\n " )
225+ user = data [2 ].strip ("\n " )
226+
227+ # Set the user to root if not specified aka empty
228+ user = user if bool (user ) is not False else 'root'
225229
226230 ## IPAddress of local server
227231
@@ -241,16 +245,16 @@ def prepare():
241245 "Connection to: " + ipAddress + " Failed, please resetup this destination from CyberPanel, aborting." )
242246 return 0
243247 else :
244- ## Create backup dir on remote server
248+ ## Create backup dir on remote server in ~/backup
245249
246- command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root @" + ipAddress + " mkdir -p /home /backup/" + ipAddressLocal + "/" + time .strftime (
250+ command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel " + user + " @" + ipAddress + " mkdir -p ~ /backup/" + ipAddressLocal + "/" + time .strftime (
247251 "%a-%b" )
248252 subprocess .call (shlex .split (command ))
249253 pass
250254
251255 for virtualHost in os .listdir ("/home" ):
252256 if match (r'^[a-zA-Z0-9-]*[a-zA-Z0-9-]{0,61}[a-zA-Z0-9-](?:\.[a-zA-Z0-9-]{2,})+$' , virtualHost , M | I ):
253- backupSchedule .createBackup (virtualHost , ipAddress , backupLogPath , port )
257+ backupSchedule .createBackup (virtualHost , ipAddress , backupLogPath , port , user )
254258
255259
256260 backupSchedule .remoteBackupLogging (backupLogPath , "Remote backup job completed.\n " )
0 commit comments