backups: move backup code to separate file
Also some major cleanups: Reduce some more code duplication (verify_hmac, simplify backup_restore_prepare). Rename backup_dir/backup_tmpdir variables to better match its purpose. Rename backup_do_copy back to backup_do. Require QubesVm object (instead of VM name) as appvm param.
This commit is contained in:
		
							parent
							
								
									657beaf655
								
							
						
					
					
						commit
						c781a522d8
					
				
							
								
								
									
										1279
									
								
								core/backup.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1279
									
								
								core/backup.py
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1452
									
								
								core/qubesutils.py
									
									
									
									
									
								
							
							
						
						
									
										1452
									
								
								core/qubesutils.py
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -22,7 +22,8 @@ | ||||
| 
 | ||||
| from qubes.qubes import QubesVmCollection | ||||
| from qubes.qubes import QubesException | ||||
| from qubes.qubesutils import backup_prepare, backup_do_copy, size_to_human | ||||
| from qubes.backup import backup_prepare, backup_do | ||||
| from qubes.qubesutils import size_to_human | ||||
| from optparse import OptionParser | ||||
| import os | ||||
| import sys | ||||
| @ -80,6 +81,8 @@ def main(): | ||||
|             files_to_backup, 0) | ||||
| 
 | ||||
|     if not options.appvm: | ||||
|         appvm = None | ||||
| 
 | ||||
|         stat = os.statvfs(base_backup_dir) | ||||
|         backup_fs_free_sz = stat.f_bsize * stat.f_bavail | ||||
|         print | ||||
| @ -88,6 +91,11 @@ def main(): | ||||
|             exit(1) | ||||
| 
 | ||||
|         print "-> Available space: {0}".format(size_to_human(backup_fs_free_sz)) | ||||
|     else: | ||||
|         appvm = qvm_collection.get_vm_by_name(options.appvm) | ||||
|         if appvm is None: | ||||
|             print >>sys.stderr, "ERROR: VM {0} does not exist".format(options.appvm) | ||||
|             exit(1) | ||||
| 
 | ||||
|     prompt = raw_input ("Do you want to proceed? [y/N] ") | ||||
|     if not (prompt == "y" or prompt == "Y"): | ||||
| @ -96,10 +104,10 @@ def main(): | ||||
|     passphrase = getpass.getpass("Please enter the pass phrase that will be used to encrypt/verify the backup: ") | ||||
| 
 | ||||
|     try: | ||||
|         backup_do_copy(base_backup_dir, files_to_backup, passphrase, | ||||
|         backup_do(base_backup_dir, files_to_backup, passphrase, | ||||
|                 progress_callback=print_progress, | ||||
|                 encrypt=options.encrypt, | ||||
|                 appvm=options.appvm) | ||||
|                 appvm=appvm) | ||||
|     except QubesException as e: | ||||
|         print >>sys.stderr, "ERROR: %s" % str(e) | ||||
|         exit(1) | ||||
|  | ||||
| @ -22,10 +22,10 @@ | ||||
| 
 | ||||
| from qubes.qubes import QubesVmCollection | ||||
| from qubes.qubes import QubesException | ||||
| from qubes.qubesutils import backup_restore_header | ||||
| from qubes.qubesutils import backup_restore_prepare  | ||||
| from qubes.qubesutils import backup_restore_print_summary | ||||
| from qubes.qubesutils import backup_restore_do | ||||
| from qubes.backup import backup_restore_header | ||||
| from qubes.backup import backup_restore_prepare | ||||
| from qubes.backup import backup_restore_print_summary | ||||
| from qubes.backup import backup_restore_do | ||||
| from optparse import OptionParser | ||||
| 
 | ||||
| import os | ||||
| @ -95,15 +95,28 @@ def main(): | ||||
|     if options.exclude: | ||||
|         restore_options['exclude'] = options.exclude | ||||
| 
 | ||||
|     appvm = None | ||||
|     if options.appvm is not None: | ||||
|         appvm = qvm_collection.get_vm_by_name(options.appvm) | ||||
|         if appvm is None: | ||||
|             print >>sys.stderr, "ERROR: VM {0} does not exist".format(options.appvm) | ||||
|             exit(1) | ||||
| 
 | ||||
|     passphrase = getpass.getpass("Please enter the pass phrase that will be used to decrypt/verify the backup: ") | ||||
| 
 | ||||
|     print >> sys.stderr, "Checking backup content..." | ||||
|     restore_tmpdir,qubes_xml = backup_restore_header(backup_dir, passphrase, options.decrypt, appvm=options.appvm) | ||||
|     restore_tmpdir,qubes_xml = backup_restore_header(backup_dir, passphrase, encrypted=options.decrypt, appvm=options.appvm) | ||||
| 
 | ||||
|     restore_info = None | ||||
|     try: | ||||
|         restore_info = backup_restore_prepare(backup_dir,os.path.join(restore_tmpdir, qubes_xml), passphrase, options=restore_options, host_collection=host_collection, encrypt=options.decrypt, appvm=options.appvm) | ||||
|         restore_info = backup_restore_prepare( | ||||
|                 backup_dir, | ||||
|                 os.path.join(restore_tmpdir, qubes_xml), | ||||
|                 passphrase, | ||||
|                 options=restore_options, | ||||
|                 host_collection=host_collection, | ||||
|                 encrypt=options.decrypt, | ||||
|                 appvm=appvm) | ||||
|     except QubesException as e: | ||||
|         print >> sys.stderr, "ERROR: %s" % str(e) | ||||
|         exit(1) | ||||
| @ -147,7 +160,7 @@ def main(): | ||||
| 
 | ||||
|     print "The above VMs will be copied and added to your system." | ||||
|     print "Exisiting VMs will not be removed." | ||||
|   | ||||
| 
 | ||||
|     if there_are_missing_templates: | ||||
|         print >> sys.stderr, "*** One or more template VM is missing on the host! ***" | ||||
|         if not (options.skip_broken or options.ignore_missing): | ||||
| @ -192,7 +205,13 @@ def main(): | ||||
|         exit (0) | ||||
| 
 | ||||
| 
 | ||||
|     backup_restore_do(backup_dir,restore_tmpdir, passphrase, restore_info, host_collection=host_collection, encrypted=options.decrypt, appvm=options.appvm) | ||||
|     backup_restore_do(backup_dir, | ||||
|             restore_tmpdir, | ||||
|             passphrase, | ||||
|             restore_info, | ||||
|             host_collection=host_collection, | ||||
|             encrypted=options.decrypt, | ||||
|             appvm=appvm) | ||||
| 
 | ||||
|     host_collection.unlock_db() | ||||
| 
 | ||||
|  | ||||
| @ -109,6 +109,8 @@ cp core/qubesutils.py $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/qubesutils.py[co] $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/guihelpers.py $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/guihelpers.py[co] $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/backup.py $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/backup.py[co] $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/__init__.py $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp core/__init__.py[co] $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| cp qmemman/qmemman*py $RPM_BUILD_ROOT%{python_sitearch}/qubes | ||||
| @ -272,6 +274,9 @@ fi | ||||
| %{python_sitearch}/qubes/guihelpers.py | ||||
| %{python_sitearch}/qubes/guihelpers.pyc | ||||
| %{python_sitearch}/qubes/guihelpers.pyo | ||||
| %{python_sitearch}/qubes/backup.py | ||||
| %{python_sitearch}/qubes/backup.pyc | ||||
| %{python_sitearch}/qubes/backup.pyo | ||||
| %{python_sitearch}/qubes/__init__.py | ||||
| %{python_sitearch}/qubes/__init__.pyc | ||||
| %{python_sitearch}/qubes/__init__.pyo | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Marek Marczykowski-Górecki
						Marek Marczykowski-Górecki