backup.py

changeset 15
aaf1a281a3fe
parent 14
5a988a2c2624
child 16
d0ffae5550ef
equal deleted inserted replaced
14:5a988a2c2624 15:aaf1a281a3fe
20 def translate_loglevel(x): 20 def translate_loglevel(x):
21 if x in loglevel_translation: 21 if x in loglevel_translation:
22 return loglevel_translation[x] 22 return loglevel_translation[x]
23 else: 23 else:
24 return logging.ERROR 24 return logging.ERROR
25
26 def safe_get_int(t, x):
27 if x in t:
28 tmp=t[x]
29 if isinstance(tmp, int):
30 return tmp
31 return None
32
25 33
26 class Backup: 34 class Backup:
27 35
28 def __decode_config(self, cfg): 36 def __decode_config(self, cfg):
29 loc0='backup target %d' % self.identifier 37 loc0='backup target %d' % self.identifier
102 logging.debug('Log listener thread waiting for entries') 110 logging.debug('Log listener thread waiting for entries')
103 success=True 111 success=True
104 for status in iter(self.borg_instance.read_log, None): 112 for status in iter(self.borg_instance.read_log, None):
105 logging.debug(str(status)) 113 logging.debug(str(status))
106 t=status['type'] 114 t=status['type']
107 #may_indicate_finished=False 115
116 errors_this_message=False
117 callback=None
118
108 if t=='progress_percent': 119 if t=='progress_percent':
109 if 'current' in status and 'total' in status: 120 current=safe_get_int(status, 'current')
121 total=safe_get_int(status, 'total')
122 if current is not None and total is not None:
110 with self.lock: 123 with self.lock:
111 self.current_operation.progress_current=status['current'] 124 self.current_operation.progress_current=current
112 self.current_operation.progress_total=status['total'] 125 self.current_operation.progress_total=total
113 status, callback=self.__status_unlocked() 126 status, callback=self.__status_unlocked()
114 if callback: 127
115 callback(self, status)
116 elif t=='archive_progress': 128 elif t=='archive_progress':
129 original_size=safe_get_int(status, 'original_size')
130 compressed_size=safe_get_int(status, 'compressed_size')
131 deduplicated_size=safe_get_int(status, 'deduplicated_size')
132 if original_size is not None and original_size is not None and deduplicated_size is not None:
133 with self.lock:
134 self.current_operation.original_size=original_size
135 self.current_operation.compressed_size=compressed_size
136 self.current_operation.deduplicated_size=deduplicated_size
137 status, callback=self.__status_unlocked()
138
139 elif t=='progress_message':
117 pass 140 pass
118 elif t=='progress_message': 141
119 #may_indicate_finished=True
120 pass
121 elif t=='file_status': 142 elif t=='file_status':
122 pass 143 pass
144
123 elif t=='log_message': 145 elif t=='log_message':
124 if 'levelname' not in status: 146 if 'levelname' not in status:
125 status['levelname']='ERROR' 147 status['levelname']='ERROR'
126 if 'message' not in status: 148 if 'message' not in status:
127 status['message']='UNKNOWN' 149 status['message']='UNKNOWN'
128 if 'name' not in status: 150 if 'name' not in status:
129 status['name']='borg' 151 status['name']='borg'
130 logging.log(translate_loglevel(status['levelname']), 152 lvl=translate_loglevel(status['levelname'])
131 status['name'] + ': ' + status['message']) 153 logging.log(lvl, status['name'] + ': ' + status['message'])
132 # set success=False? 154 if lvl>=logging.WARNING:
155 errors_this_message=True
133 elif t=='exception': 156 elif t=='exception':
134 success=False 157 errors_this_message=True
135 elif t=='unparsed_error': 158 elif t=='unparsed_error':
136 success=False 159 errors_this_message=True
160
161 if errors_this_message:
162 with self.lock:
163 self.current_operation.errors=True
164 status, callback=self.__status_unlocked()
165
166 if callback:
167 callback(self, status)
137 168
138 logging.debug('Waiting for borg subprocess to terminate in log thread') 169 logging.debug('Waiting for borg subprocess to terminate in log thread')
139 170
140 self.borg_instance.wait() 171 self.borg_instance.wait()
141 172
357 else: 388 else:
358 status={'type': 'nothing'} 389 status={'type': 'nothing'}
359 390
360 status['name']=self.name 391 status['name']=self.name
361 392
393 if 'errors' not in status:
394 status['errors']=False
395
362 if 'when_monotonic' in status: 396 if 'when_monotonic' in status:
363 status['when']=(status['when_monotonic'] 397 status['when']=(status['when_monotonic']
364 -time.monotonic()+time.time()) 398 -time.monotonic()+time.time())
365 399
366 return status, callback 400 return status, callback

mercurial