From 7727221b59c438a6356741a9ca4a0297cb66e6f1 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 13 Jun 2021 21:57:36 -0400 Subject: [PATCH] Correctly use the Click file in backups --- client-cli/pvc.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client-cli/pvc.py b/client-cli/pvc.py index 8a09ed63..edce8744 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -4252,7 +4252,7 @@ def cli_task(): @click.command(name='backup', short_help='Create JSON backup of cluster.') @click.option( '-f', '--file', 'filename', - default=None, type=click.File(), + default=None, type=click.File(mode='w'), help='Write backup data to this file.' ) @cluster_req @@ -4262,11 +4262,14 @@ def task_backup(filename): """ retcode, retdata = pvc_cluster.backup(config) - if filename: - with open(filename, 'wb') as fh: - fh.write(retdata) - retdata = 'Data written to {}'.format(filename) - cleanup(retcode, retdata) + if retcode: + if filename is not None: + json.dump(json.loads(retdata), filename) + cleanup(retcode, 'Backup written to "{}".'.format(filename.name)) + else: + cleanup(retcode, retdata) + else: + cleanup(retcode, retdata) ###############################################################################