def runBackup( self ): """Begin rsync backup. This will process each path in self.rsyncPaths and use rsync to 'pull' the contents to the backup server. """ # First make the folder to store the backups (and logs) on the backup server # as rsync will not log to the as-of-yet uncreated folder command = ['mkdir', '-p', self.backupPath] self.log("Creating remote backup path.") stdin, stdout, stderr = self.sshExecute( ' '.join(command), exitOnException=True ) errors = '\n'.join(stderr.readlines()) if errors: self.error("Failed to make the remote backup directory:\n" + errors, exit=True) # loop through the paths and rsync them one by one # In the future this will be replaced by using an 'includes' file and one command only for path in self.rsyncPaths: command = [ 'rsync', "-e'ssh -i "+self.ssh_key+"'" ] command.extend( self.rsyncArgs ) command.extend( [ '--log-file=' + str(self.logFile) ] ) command.extend( [ self.liveUser + '@' + self.liveHost + ':"\'' + path + '\'"', '"'+self.backupPath+'"' ] ) self.log("Using: " + ' '.join( command )) #Consider using 'exitOnException=False' so that this doesn't die and exit #if only one rsync path fails to be backed up self.runCommandTransport( ' '.join( command ), self.logFile, exitOnException=True ) #Transfer the main log to the backup server for storage self.log("Transferring the main log to the server.", 'debug') os.system( "cp -f " + global_log_file + " /tmp/temp_backup.log" ) self.transferFile( "/tmp/temp_backup.log", "/logs/" + str(self.ap) + "_" + global_log_file[ global_log_file.rfind('/') + 1 : ], putOnServer=True ) #Cleanup self.closeSession() if self.progress_window != None: self.gobject.idle_add(self.progress_window.complete)
def runRestore( self ): """Begin rsync restore. This will restore everything for the particular appointment number to the root of the local drive. """ # First make sure the folder on the backup server exists for the appointment specified self.log( "Checking if there are backups on the remote server." ) if not self.remotePathExists( self.backupPath ): self.error("No backups for " + str(self.ap) + " on backup server!", exit=True) if self.rsyncPaths[-1] != "/": self.rsyncPaths += "/" command = [ 'rsync', "-e'ssh -i "+self.ssh_key+"'" ] command.extend( self.rsyncArgs ) command.extend( [ '--log-file=' + self.restoreLogFull ] ) # self.rsyncPaths should be the path to the drive we are restoring to (in a string) command.extend( [ '"' + self.backupPath + '"', self.liveUser + '@' + self.liveHost + ':"\'' + self.rsyncPaths + '\'"' ] ) command.extend( [ '--exclude "' + self.restoreLog + '"' ] ) self.log("Using: " + ' '.join( command )) self.runCommandTransport( ' '.join( command ), self.restoreLogFull, exitOnException=True ) # Transfer the restore log self.log("Copying restore log to local machine: " + self.restoreLog) self.transferFile( self.rsyncPaths + self.restoreLog, self.restoreLogFull, False ) #Transfer the main log to the backup server for storage self.log("Transferring the main log to the backup server.", 'debug') os.system( "cp -f " + global_log_file + " /tmp/temp_backup.log" ) self.transferFile( "/tmp/temp_backup.log", "/logs/" + str(self.ap) + "_" + global_log_file[ global_log_file.rfind('/') + 1 : ], putOnServer=True ) # Cleanup self.closeSession() if self.progress_window != None: self.gobject.idle_add(self.progress_window.complete)