diff --git a/rdiff-manager.py b/rdiff-manager.py index faf8cec864717c5129a5cb0c5f664c62d90565aa..fed0b134b24aa3ed8f7816ade88e41d9b148bfe2 100755 --- a/rdiff-manager.py +++ b/rdiff-manager.py @@ -43,20 +43,22 @@ class Host(object): self.include_file, 'root@%s::/' % (self.hostname), self.destination ] ) ) def run_all(self): - result = '' + output = '' + success = False try: # only add output if error occurs self.test_server() self.test_directory() # always print output - result += self.remove_old() - result += self.run_backup() + output += self.remove_old() + output += self.run_backup() + success = True except subprocess.CalledProcessError as e: - result += e.output.decode('utf-8') - result += 'Backup failed with error %d' % e.returncode + output += e.output.decode('utf-8') + output += 'Backup failed with error %d' % e.returncode except OSError as e: - result += 'Backup failed: %s (%d)' % (e.strerror, e.errno) - return result + output += 'Backup failed: %s (%d)' % (e.strerror, e.errno) + return {'success': success, 'output': output} def rdiff_backup(config): target = Host(config) @@ -82,12 +84,12 @@ if __name__ == '__main__': pool = Pool(concurrent_num) # Start the work and wait for it to finish - results = [ (host, pool.apply_async(rdiff_backup, (host, )) ) for host in hosts ] + results = { host['hostname']: pool.apply_async(rdiff_backup, (host, )) for host in hosts } pool.close() pool.join() - for host, r in results: - print("Backup results for", host['hostname']) - print(r.get()) + for host, r in results.items(): + print("Backup results for", host) + print(r.get()['output']) print('-' * 40) print()