From 1145f7033486e404e5683068b2045c5f5f5d2d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 24 Feb 2019 02:21:14 +0100 Subject: [PATCH] tools/qvm-backup: allow to disable compression Specify compression explicitly in the backup profile, not only when requested with --compress or --compress-filter. This will allow to disable compression with --no-compress option, as the default if no compression is specified in the profile is to use gzip. Fixes QubesOS/qubes-issues#4803 --- doc/manpages/qvm-backup.rst | 6 ++++- qubesadmin/tests/tools/qvm_backup.py | 34 ++++++++++++++++++++++------ qubesadmin/tools/qvm_backup.py | 10 ++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/doc/manpages/qvm-backup.rst b/doc/manpages/qvm-backup.rst index 04317f2..e09daa0 100644 --- a/doc/manpages/qvm-backup.rst +++ b/doc/manpages/qvm-backup.rst @@ -53,7 +53,11 @@ Options .. option:: --compress, -z - Compress the backup + Compress the backup. This is default. + +.. option:: --no-compress, + + Do not compress the backup. .. option:: --compress-filter, -Z diff --git a/qubesadmin/tests/tools/qvm_backup.py b/qubesadmin/tests/tools/qvm_backup.py index 48700a4..3077d5a 100644 --- a/qubesadmin/tests/tools/qvm_backup.py +++ b/qubesadmin/tests/tools/qvm_backup.py @@ -33,7 +33,8 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): profile = io.StringIO() qvm_backup.write_backup_profile(profile, args) expected_profile = ( - '{destination_path: /var/tmp, destination_vm: dom0, include: null}\n' + '{compression: true, destination_path: /var/tmp, ' + 'destination_vm: dom0, include: null}\n' ) self.assertEqual(profile.getvalue(), expected_profile) @@ -48,6 +49,7 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): profile = io.StringIO() qvm_backup.write_backup_profile(profile, args) expected_profile = ( + 'compression: true\n' 'destination_path: /var/tmp\n' 'destination_vm: dom0\n' 'include: [vm1, vm2]\n' @@ -61,6 +63,7 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): profile = io.StringIO() qvm_backup.write_backup_profile(profile, args) expected_profile = ( + 'compression: true\n' 'destination_path: /var/tmp\n' 'destination_vm: dom0\n' 'exclude: [vm1, vm2]\n' @@ -73,7 +76,20 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): profile = io.StringIO() qvm_backup.write_backup_profile(profile, args, passphrase='test123') expected_profile = ( - '{destination_path: /var/tmp, destination_vm: dom0, include: null, passphrase_text: test123}\n' + '{compression: true, destination_path: /var/tmp, ' + 'destination_vm: dom0, include: null,\n' + ' passphrase_text: test123}\n' + ) + self.assertEqual(profile.getvalue(), expected_profile) + + def test_004_write_backup_profile_no_compress(self): + args = qvm_backup.parser.parse_args(['--no-compress', '/var/tmp'], + app=self.app) + profile = io.StringIO() + qvm_backup.write_backup_profile(profile, args) + expected_profile = ( + '{compression: false, destination_path: /var/tmp, ' + 'destination_vm: dom0, include: null}\n' ) self.assertEqual(profile.getvalue(), expected_profile) @@ -93,7 +109,8 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): qvm_backup.main(['--save-profile', 'test-profile', '/var/tmp'], app=self.app) expected_profile = ( - '{destination_path: /var/tmp, destination_vm: dom0, include: null}\n' + '{compression: true, destination_path: /var/tmp, ' + 'destination_vm: dom0, include: null}\n' ) with open(profile_path) as f: self.assertEqual(expected_profile, f.read()) @@ -119,8 +136,9 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): qvm_backup.main(['--save-profile', 'test-profile', '/var/tmp'], app=self.app) expected_profile = ( - '{destination_path: /var/tmp, destination_vm: dom0, include: null, passphrase_text: some\n' - ' password}\n' + '{compression: true, destination_path: /var/tmp, ' + 'destination_vm: dom0, include: null,\n' + ' passphrase_text: some password}\n' ) with open(profile_path) as f: self.assertEqual(expected_profile, f.read()) @@ -177,6 +195,7 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): 'To perform the backup according to selected options, create ' 'backup profile (/tmp/profile_name.conf) in dom0 with following ' 'content:\n' + 'compression: true\n' 'destination_path: /var/tmp\n' 'destination_vm: dom0\n' 'exclude: [vm1]\n' @@ -210,8 +229,9 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): 'test-profile', '/var/tmp'], app=self.app) expected_profile = ( - '{destination_path: /var/tmp, destination_vm: dom0, include: null, passphrase_text: other\n' - ' passphrase}\n' + '{compression: true, destination_path: /var/tmp, ' + 'destination_vm: dom0, include: null,\n' + ' passphrase_text: other passphrase}\n' ) with open(profile_path) as f: self.assertEqual(expected_profile, f.read()) diff --git a/qubesadmin/tools/qvm_backup.py b/qubesadmin/tools/qvm_backup.py index 54eefb5..379ebf5 100644 --- a/qubesadmin/tools/qvm_backup.py +++ b/qubesadmin/tools/qvm_backup.py @@ -65,8 +65,11 @@ no_profile.add_argument("--passphrase-file", "-p", action="store", help="Read passphrase from a file, or use '-' to read " "from stdin") no_profile.add_argument("--compress", "-z", action="store_true", - dest="compression", default=False, - help="Compress the backup") + dest="compression", default=True, + help="Compress the backup (default)") +no_profile.add_argument("--no-compress", action="store_false", + dest="compression", + help="Do not compress the backup") no_profile.add_argument("--compress-filter", "-Z", action="store", dest="compression", help="Specify a non-default compression filter program " @@ -99,8 +102,7 @@ def write_backup_profile(output_stream, args, passphrase=None): profile_data['exclude'] = args.exclude_list if passphrase: profile_data['passphrase_text'] = passphrase - if args.compression: - profile_data['compression'] = args.compression + profile_data['compression'] = args.compression if args.appvm: profile_data['destination_vm'] = args.appvm else: