diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index 8cb1783f..e2e76d7c 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -239,7 +239,7 @@ def mount_all_volumes(): line.append(info) return report -def mount_backup_shares(): +def mount_backup_shares(read_write=False): """Mount the backup shares unless labeled as already mounted.""" if psutil.LINUX: mounted_data = get_mounted_data() @@ -258,12 +258,22 @@ def mount_backup_shares(): print_warning(mounted_str) continue - mount_network_share(server) + mount_network_share(server, read_write) -def mount_network_share(server): +def mount_network_share(server, read_write=False): """Mount a network share defined by server.""" + if read_write: + username = server['RW-User'] + password = server['RW-Pass'] + else: + username = server['User'] + password = server['Pass'] if psutil.WINDOWS: - cmd = r'net use \\{IP}\{Share} /user:{User} {Pass}'.format(**server) + cmd = r'net use \\{ip}\{share} /user:{username} {password}'.format( + ip = server['IP'], + share = server['Share'], + username = username, + password = password) cmd = cmd.split(' ') warning = r'Failed to mount \\{Name}\{Share}, {IP} unreachable.'.format( **server) @@ -278,7 +288,10 @@ def mount_network_share(server): 'sudo', 'mount', '//{IP}/{Share}'.format(**server), '/Backups/{Name}'.format(**server), - '-o', 'username={User},password={Pass}'.format(**server)] + '-o', '{}username={},password={}'.format( + '' if read_write else 'ro,', + username, + password)] warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format( **server) error = 'Failed to mount /Backups/{Name}'.format(**server) @@ -514,7 +527,7 @@ def select_source(ticket_number): local_sources = [] remote_sources = [] sources = [] - mount_backup_shares() + mount_backup_shares(read_write=False) # Check for ticket folders on servers for server in BACKUP_SERVERS: diff --git a/.bin/Scripts/functions/windows_setup.py b/.bin/Scripts/functions/windows_setup.py index 5519e7cc..9efa0123 100644 --- a/.bin/Scripts/functions/windows_setup.py +++ b/.bin/Scripts/functions/windows_setup.py @@ -154,9 +154,12 @@ def format_mbr(disk): run_diskpart(script) def mount_windows_share(): - """Mount the Windows images share unless labeled as already mounted.""" + """Mount the Windows images share unless labeled as already mounted.""" if not WINDOWS_SERVER['Mounted']: - mount_network_share(WINDOWS_SERVER) + # Mounting read-write in case a backup was done in the same session + # and the server was left mounted read-write. This avoids throwing an + # error by trying to mount the same server with multiple credentials. + mount_network_share(WINDOWS_SERVER, read_write=True) def select_windows_version(): actions = [ diff --git a/.bin/Scripts/functions/winpe_menus.py b/.bin/Scripts/functions/winpe_menus.py index 1b8a546e..99bc3f8f 100644 --- a/.bin/Scripts/functions/winpe_menus.py +++ b/.bin/Scripts/functions/winpe_menus.py @@ -80,7 +80,7 @@ def menu_backup(): ticket_number = get_ticket_number() # Mount backup shares - mount_backup_shares() + mount_backup_shares(read_write=True) # Select destination destination = select_backup_destination(auto_select=False) diff --git a/.bin/Scripts/settings/main.py b/.bin/Scripts/settings/main.py index 24ae4ebc..86b0fcee 100644 --- a/.bin/Scripts/settings/main.py +++ b/.bin/Scripts/settings/main.py @@ -35,6 +35,8 @@ BACKUP_SERVERS = [ 'Share': 'Backups', 'User': 'restore', 'Pass': 'Abracadabra', + 'RW-User': 'backup', + 'RW-Pass': 'Abracadabra', }, { 'IP': '10.0.0.11', 'Name': 'ServerTwo', @@ -42,6 +44,8 @@ BACKUP_SERVERS = [ 'Share': 'Backups', 'User': 'restore', 'Pass': 'Abracadabra', + 'RW-User': 'backup', + 'RW-Pass': 'Abracadabra', }, ] CRASH_SERVER = { @@ -57,6 +61,8 @@ OFFICE_SERVER = { 'Share': 'Office', 'User': 'restore', 'Pass': 'Abracadabra', + 'RW-User': 'backup', + 'RW-Pass': 'Abracadabra', } QUICKBOOKS_SERVER = { 'IP': QUICKBOOKS_SERVER_IP, @@ -65,6 +71,8 @@ QUICKBOOKS_SERVER = { 'Share': 'QuickBooks', 'User': 'restore', 'Pass': 'Abracadabra', + 'RW-User': 'backup', + 'RW-Pass': 'Abracadabra', } WINDOWS_SERVER = { 'IP': '10.0.0.10', @@ -73,6 +81,8 @@ WINDOWS_SERVER = { 'Share': 'Windows', 'User': 'restore', 'Pass': 'Abracadabra', + 'RW-User': 'backup', + 'RW-Pass': 'Abracadabra', } if __name__ == '__main__':