updated backup_partition()
This commit is contained in:
parent
80cb9b8cea
commit
45f0b4d2b1
3 changed files with 32 additions and 29 deletions
|
|
@ -2,31 +2,21 @@
|
|||
|
||||
from functions.common import *
|
||||
|
||||
def backup_partition(bin=None, disk=None, par=None):
|
||||
# Bail early
|
||||
if bin is None:
|
||||
raise Exception('bin path not specified.')
|
||||
if disk is None:
|
||||
raise Exception('Disk not specified.')
|
||||
if par is None:
|
||||
raise Exception('Partition not specified.')
|
||||
def backup_partition(disk, partition):
|
||||
if par['Image Exists'] or par['Number'] in disk['Bad Partitions']:
|
||||
raise GenericAbort
|
||||
|
||||
print(' Partition {Number} Backup...\t\t'.format(**par), end='', flush=True)
|
||||
if par['Number'] in disk['Bad Partitions']:
|
||||
print_warning('Skipped.')
|
||||
else:
|
||||
cmd = '{bin}\\wimlib\\wimlib-imagex capture {Letter}:\\ "{Image Path}\\{Image File}" "{Image Name}" "{Image Name}" --compress=none'.format(bin=bin, **par)
|
||||
if par['Image Exists']:
|
||||
print_warning('Skipped.')
|
||||
else:
|
||||
try:
|
||||
os.makedirs('{Image Path}'.format(**par), exist_ok=True)
|
||||
run_program(cmd)
|
||||
print_success('Complete.')
|
||||
except subprocess.CalledProcessError as err:
|
||||
print_error('Failed.')
|
||||
par['Error'] = err.stderr.decode().splitlines()
|
||||
raise BackupError
|
||||
cmd = [
|
||||
global_vars['Tools']['wimlib-imagex'],
|
||||
'capture'
|
||||
'{}:\\'.format(par['Letter']),
|
||||
r'{}\{}'.format(par['Image Path'], par['Image File']),
|
||||
par['Image Name'], # Image name
|
||||
par['Image Name'], # Image description
|
||||
' --compress=none',
|
||||
]
|
||||
os.makedirs(par['Image Path'], exist_ok=True)
|
||||
run_program(cmd)
|
||||
|
||||
def prep_disk_for_backup(dest=None, disk=None, ticket_id=None):
|
||||
disk['Backup Warnings'] = '\n'
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ class BIOSKeyNotFoundError(Exception):
|
|||
class BinNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
class GenericAbort(Exception):
|
||||
pass
|
||||
|
||||
class GenericError(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -52,7 +55,7 @@ class NotInstalledError(Exception):
|
|||
class NoProfilesError(Exception):
|
||||
pass
|
||||
|
||||
class PathNotFoundException(Exception):
|
||||
class PathNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
class UnsupportedOSError(Exception):
|
||||
|
|
@ -432,7 +435,7 @@ def try_and_print(message='Trying...',
|
|||
err = traceback.format_exc()
|
||||
|
||||
# Return or raise?
|
||||
if bool(err) and not catch_all:
|
||||
if err and not catch_all:
|
||||
raise
|
||||
else:
|
||||
return {'CS': not bool(err), 'Error': err}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,14 @@ PE_TOOLS = {
|
|||
def menu_backup():
|
||||
"""Take backup images of partition(s) in the WIM format and save them to a backup share"""
|
||||
errors = False
|
||||
other_results = {
|
||||
'Error': {
|
||||
'CalledProcessError': 'Unknown Error',
|
||||
},
|
||||
'Warning': {
|
||||
'GenericAbort': 'Skipped',
|
||||
'GenericRepair': 'Repaired',
|
||||
}}
|
||||
|
||||
# Set ticket ID
|
||||
os.system('cls')
|
||||
|
|
@ -89,10 +97,12 @@ def menu_backup():
|
|||
# Backup partition(s)
|
||||
print('\n\nStarting task.\n')
|
||||
for par in disk['Partitions']:
|
||||
try:
|
||||
backup_partition(bin, disk, par)
|
||||
except BackupError:
|
||||
message = 'Partition {} Backup...'.format(par['Number'])
|
||||
result = try_and_print(message=message, function=backup_partition,
|
||||
other_results=other_results, disk=disk, partition=par)
|
||||
if not result['CS']:
|
||||
errors = True
|
||||
par['Error'] = result['Error']
|
||||
|
||||
# Verify backup(s)
|
||||
if disk['Valid Partitions'] > 1:
|
||||
|
|
|
|||
Loading…
Reference in a new issue