Correctly use the Click file in backups

This commit is contained in:
Joshua Boniface 2021-06-13 21:57:36 -04:00
parent 30a160d5ff
commit 7727221b59
1 changed files with 9 additions and 6 deletions

View File

@ -4252,7 +4252,7 @@ def cli_task():
@click.command(name='backup', short_help='Create JSON backup of cluster.') @click.command(name='backup', short_help='Create JSON backup of cluster.')
@click.option( @click.option(
'-f', '--file', 'filename', '-f', '--file', 'filename',
default=None, type=click.File(), default=None, type=click.File(mode='w'),
help='Write backup data to this file.' help='Write backup data to this file.'
) )
@cluster_req @cluster_req
@ -4262,11 +4262,14 @@ def task_backup(filename):
""" """
retcode, retdata = pvc_cluster.backup(config) retcode, retdata = pvc_cluster.backup(config)
if filename: if retcode:
with open(filename, 'wb') as fh: if filename is not None:
fh.write(retdata) json.dump(json.loads(retdata), filename)
retdata = 'Data written to {}'.format(filename) cleanup(retcode, 'Backup written to "{}".'.format(filename.name))
cleanup(retcode, retdata) else:
cleanup(retcode, retdata)
else:
cleanup(retcode, retdata)
############################################################################### ###############################################################################