From 88abaebd66a09e3ef1114422142732ef7559a5de Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Tue, 4 Jul 2017 15:36:13 +0200 Subject: [PATCH] One bconsole run per truncate run --- modules/bacula/files/volume-purge-action | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/bacula/files/volume-purge-action b/modules/bacula/files/volume-purge-action index fc6eef7d0..938d75c74 100755 --- a/modules/bacula/files/volume-purge-action +++ b/modules/bacula/files/volume-purge-action @@ -60,27 +60,28 @@ storages = set(r['mediatype'] for r in cursor.fetchall()) cmd = [] for s in storages: - c = 'truncate allpools storage=%s'%(s,) - cmd.append(c) + c = 'truncate allpools storage=%s'%(s,) + cmd.append(c) if args.nodo: print("\n".join(cmd)) sys.exit(0) -if args.verbose: - for c in cmd: - print("Will run: %s"%(c,)) -p = subprocess.Popen(['bconsole'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) -(out, err) = p.communicate("\n".join(cmd).encode()) -if p.returncode != 0: +for c in cmd: + if args.verbose: + print("Will run: %s"%(c,)) + + p = subprocess.Popen(['bconsole'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (out, err) = p.communicate(c.encode()) + if p.returncode != 0: raise Exception("bconsole failed. stdout:\n%s\nstderr:%s\n"%(out, err)) -if args.verbose: + if args.verbose: print("stdout:\n") sys.stdout.buffer.write(out) print("\n") -if err != b"": - print("bconsole said on stderr:\n", file=sys.stderr) - sys.stderr.buffer.write(out) - print("", file=sys.stderr) - sys.exit(1) + if err != b"": + print("bconsole said on stderr:\n", file=sys.stderr) + sys.stderr.buffer.write(out) + print("", file=sys.stderr) + sys.exit(1) -- 2.20.1