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
This commit is contained in:
parent
5e4831ede4
commit
1145f70334
@ -53,7 +53,11 @@ Options
|
|||||||
|
|
||||||
.. option:: --compress, -z
|
.. option:: --compress, -z
|
||||||
|
|
||||||
Compress the backup
|
Compress the backup. This is default.
|
||||||
|
|
||||||
|
.. option:: --no-compress,
|
||||||
|
|
||||||
|
Do not compress the backup.
|
||||||
|
|
||||||
.. option:: --compress-filter, -Z
|
.. option:: --compress-filter, -Z
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase):
|
|||||||
profile = io.StringIO()
|
profile = io.StringIO()
|
||||||
qvm_backup.write_backup_profile(profile, args)
|
qvm_backup.write_backup_profile(profile, args)
|
||||||
expected_profile = (
|
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)
|
self.assertEqual(profile.getvalue(), expected_profile)
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase):
|
|||||||
profile = io.StringIO()
|
profile = io.StringIO()
|
||||||
qvm_backup.write_backup_profile(profile, args)
|
qvm_backup.write_backup_profile(profile, args)
|
||||||
expected_profile = (
|
expected_profile = (
|
||||||
|
'compression: true\n'
|
||||||
'destination_path: /var/tmp\n'
|
'destination_path: /var/tmp\n'
|
||||||
'destination_vm: dom0\n'
|
'destination_vm: dom0\n'
|
||||||
'include: [vm1, vm2]\n'
|
'include: [vm1, vm2]\n'
|
||||||
@ -61,6 +63,7 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase):
|
|||||||
profile = io.StringIO()
|
profile = io.StringIO()
|
||||||
qvm_backup.write_backup_profile(profile, args)
|
qvm_backup.write_backup_profile(profile, args)
|
||||||
expected_profile = (
|
expected_profile = (
|
||||||
|
'compression: true\n'
|
||||||
'destination_path: /var/tmp\n'
|
'destination_path: /var/tmp\n'
|
||||||
'destination_vm: dom0\n'
|
'destination_vm: dom0\n'
|
||||||
'exclude: [vm1, vm2]\n'
|
'exclude: [vm1, vm2]\n'
|
||||||
@ -73,7 +76,20 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase):
|
|||||||
profile = io.StringIO()
|
profile = io.StringIO()
|
||||||
qvm_backup.write_backup_profile(profile, args, passphrase='test123')
|
qvm_backup.write_backup_profile(profile, args, passphrase='test123')
|
||||||
expected_profile = (
|
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)
|
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'],
|
qvm_backup.main(['--save-profile', 'test-profile', '/var/tmp'],
|
||||||
app=self.app)
|
app=self.app)
|
||||||
expected_profile = (
|
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:
|
with open(profile_path) as f:
|
||||||
self.assertEqual(expected_profile, f.read())
|
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'],
|
qvm_backup.main(['--save-profile', 'test-profile', '/var/tmp'],
|
||||||
app=self.app)
|
app=self.app)
|
||||||
expected_profile = (
|
expected_profile = (
|
||||||
'{destination_path: /var/tmp, destination_vm: dom0, include: null, passphrase_text: some\n'
|
'{compression: true, destination_path: /var/tmp, '
|
||||||
' password}\n'
|
'destination_vm: dom0, include: null,\n'
|
||||||
|
' passphrase_text: some password}\n'
|
||||||
)
|
)
|
||||||
with open(profile_path) as f:
|
with open(profile_path) as f:
|
||||||
self.assertEqual(expected_profile, f.read())
|
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 '
|
'To perform the backup according to selected options, create '
|
||||||
'backup profile (/tmp/profile_name.conf) in dom0 with following '
|
'backup profile (/tmp/profile_name.conf) in dom0 with following '
|
||||||
'content:\n'
|
'content:\n'
|
||||||
|
'compression: true\n'
|
||||||
'destination_path: /var/tmp\n'
|
'destination_path: /var/tmp\n'
|
||||||
'destination_vm: dom0\n'
|
'destination_vm: dom0\n'
|
||||||
'exclude: [vm1]\n'
|
'exclude: [vm1]\n'
|
||||||
@ -210,8 +229,9 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase):
|
|||||||
'test-profile', '/var/tmp'],
|
'test-profile', '/var/tmp'],
|
||||||
app=self.app)
|
app=self.app)
|
||||||
expected_profile = (
|
expected_profile = (
|
||||||
'{destination_path: /var/tmp, destination_vm: dom0, include: null, passphrase_text: other\n'
|
'{compression: true, destination_path: /var/tmp, '
|
||||||
' passphrase}\n'
|
'destination_vm: dom0, include: null,\n'
|
||||||
|
' passphrase_text: other passphrase}\n'
|
||||||
)
|
)
|
||||||
with open(profile_path) as f:
|
with open(profile_path) as f:
|
||||||
self.assertEqual(expected_profile, f.read())
|
self.assertEqual(expected_profile, f.read())
|
||||||
|
@ -65,8 +65,11 @@ no_profile.add_argument("--passphrase-file", "-p", action="store",
|
|||||||
help="Read passphrase from a file, or use '-' to read "
|
help="Read passphrase from a file, or use '-' to read "
|
||||||
"from stdin")
|
"from stdin")
|
||||||
no_profile.add_argument("--compress", "-z", action="store_true",
|
no_profile.add_argument("--compress", "-z", action="store_true",
|
||||||
dest="compression", default=False,
|
dest="compression", default=True,
|
||||||
help="Compress the backup")
|
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",
|
no_profile.add_argument("--compress-filter", "-Z", action="store",
|
||||||
dest="compression",
|
dest="compression",
|
||||||
help="Specify a non-default compression filter program "
|
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
|
profile_data['exclude'] = args.exclude_list
|
||||||
if passphrase:
|
if passphrase:
|
||||||
profile_data['passphrase_text'] = passphrase
|
profile_data['passphrase_text'] = passphrase
|
||||||
if args.compression:
|
profile_data['compression'] = args.compression
|
||||||
profile_data['compression'] = args.compression
|
|
||||||
if args.appvm:
|
if args.appvm:
|
||||||
profile_data['destination_vm'] = args.appvm
|
profile_data['destination_vm'] = args.appvm
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user