New mount-backup-shares script
This commit is contained in:
parent
1cfa008b8e
commit
e96d491285
2 changed files with 77 additions and 9 deletions
|
|
@ -236,36 +236,65 @@ def mount_all_volumes():
|
||||||
|
|
||||||
def mount_backup_shares():
|
def mount_backup_shares():
|
||||||
"""Mount the backup shares unless labeled as already mounted."""
|
"""Mount the backup shares unless labeled as already mounted."""
|
||||||
|
if psutil.LINUX:
|
||||||
|
mounted_data = get_mounted_data()
|
||||||
for server in BACKUP_SERVERS:
|
for server in BACKUP_SERVERS:
|
||||||
# Blindly skip if we mounted earlier
|
if psutil.LINUX:
|
||||||
|
# Update mounted status
|
||||||
|
source = '//{IP}/{Share}'.format(**server)
|
||||||
|
dest = '/Backups/{Name}'.format(**server)
|
||||||
|
mounted_str = '(Already) Mounted {}'.format(dest)
|
||||||
|
data = mounted_data.get(source, {})
|
||||||
|
if dest == data.get('target', ''):
|
||||||
|
server['Mounted'] = True
|
||||||
|
elif psutil.WINDOWS:
|
||||||
|
mounted_str = '(Already) Mounted {Name}'.format(**server)
|
||||||
if server['Mounted']:
|
if server['Mounted']:
|
||||||
|
print_warning(mounted_str)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mount_network_share(server)
|
mount_network_share(server)
|
||||||
|
|
||||||
def mount_network_share(server):
|
def mount_network_share(server):
|
||||||
"""Mount a network share defined by server."""
|
"""Mount a network share defined by server."""
|
||||||
|
if psutil.WINDOWS:
|
||||||
|
cmd = r'net use \\{IP}\{Share} /user:{User} {Pass}'.format(**server)
|
||||||
|
cmd = cmd.split(' ')
|
||||||
|
warning = r'Failed to mount \\{Name}\{Share}, {IP} unreachable.'.format(
|
||||||
|
**server)
|
||||||
|
error = r'Failed to mount \\{Name}\{Share} ({IP})'.format(**server)
|
||||||
|
success = 'Mounted {Name}'.format(**server)
|
||||||
|
elif psutil.LINUX:
|
||||||
|
cmd = [
|
||||||
|
'sudo', 'mkdir', '-p',
|
||||||
|
'/Backups/{Name}'.format(**server)]
|
||||||
|
run_program(cmd)
|
||||||
|
cmd = [
|
||||||
|
'sudo', 'mount',
|
||||||
|
'//{IP}/{Share}'.format(**server),
|
||||||
|
'/Backups/{Name}'.format(**server),
|
||||||
|
'-o', 'username={User},password={Pass}'.format(**server)]
|
||||||
|
warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format(
|
||||||
|
**server)
|
||||||
|
error = 'Failed to mount /Backups/{Name}'.format(**server)
|
||||||
|
success = 'Mounted /Backups/{Name}'.format(**server)
|
||||||
|
|
||||||
# Test connection
|
# Test connection
|
||||||
try:
|
try:
|
||||||
ping(server['IP'])
|
ping(server['IP'])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print_error(
|
print_warning(warning)
|
||||||
r'Failed to mount \\{Name}\{Share}, {IP} unreachable.'.format(
|
|
||||||
**server))
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Mount
|
# Mount
|
||||||
cmd = r'net use \\{IP}\{Share} /user:{User} {Pass}'.format(**server)
|
|
||||||
cmd = cmd.split(' ')
|
|
||||||
try:
|
try:
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
except Exception:
|
except Exception:
|
||||||
print_warning(r'Failed to mount \\{Name}\{Share} ({IP})'.format(
|
print_error(error)
|
||||||
**server))
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
else:
|
else:
|
||||||
print_info('Mounted {Name}'.format(**server))
|
print_info(success)
|
||||||
server['Mounted'] = True
|
server['Mounted'] = True
|
||||||
|
|
||||||
def run_fast_copy(items, dest):
|
def run_fast_copy(items, dest):
|
||||||
|
|
|
||||||
39
.bin/Scripts/mount-backup-shares
Executable file
39
.bin/Scripts/mount-backup-shares
Executable file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/python3
|
||||||
|
#
|
||||||
|
## Wizard Kit: Backup share mount tool
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Init
|
||||||
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
sys.path.append(os.getcwd())
|
||||||
|
from functions.data import *
|
||||||
|
from functions.network import *
|
||||||
|
init_global_vars()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
# Prep
|
||||||
|
clear_screen()
|
||||||
|
|
||||||
|
# Connect
|
||||||
|
if not is_connected():
|
||||||
|
connect_to_network()
|
||||||
|
|
||||||
|
# Mount
|
||||||
|
if is_connected():
|
||||||
|
mount_backup_shares()
|
||||||
|
else:
|
||||||
|
# Couldn't connect
|
||||||
|
print_error('ERROR: No network connectivity.')
|
||||||
|
|
||||||
|
# Done
|
||||||
|
print_standard('\nDone.')
|
||||||
|
#pause("Press Enter to exit...")
|
||||||
|
exit_script()
|
||||||
|
except SystemExit:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
major_exception()
|
||||||
|
|
||||||
Loading…
Reference in a new issue