|
@@ -30,7 +30,7 @@ müssen für springm beschreibbar sein
|
|
|
remotehost = 'hermes'
|
|
remotehost = 'hermes'
|
|
|
ssh_username = 'root'
|
|
ssh_username = 'root'
|
|
|
remoterepo = '/backupdisk/backupdisk/restic-repo'
|
|
remoterepo = '/backupdisk/backupdisk/restic-repo'
|
|
|
-json_remotefile = '/var/lib/restic/backupcopies.json'
|
|
|
|
|
|
|
+#json_remotefile = '/var/lib/restic/backupcopies.json'
|
|
|
json_localfile = '/tmp/backupcopies.json'
|
|
json_localfile = '/tmp/backupcopies.json'
|
|
|
|
|
|
|
|
# UUID ermitteln mit blkid
|
|
# UUID ermitteln mit blkid
|
|
@@ -54,22 +54,27 @@ jso = {}
|
|
|
|
|
|
|
|
def load_jsonfile( ):
|
|
def load_jsonfile( ):
|
|
|
try:
|
|
try:
|
|
|
- with SCPClient(ssh.get_transport()) as scp:
|
|
|
|
|
- scp.get(json_remotefile, local_path=json_localfile)
|
|
|
|
|
with open(json_localfile, 'r') as openfile:
|
|
with open(json_localfile, 'r') as openfile:
|
|
|
jso = json.load(openfile)
|
|
jso = json.load(openfile)
|
|
|
except:
|
|
except:
|
|
|
- print(f"Warning: could not get {json_remotefile} from {remotehost}")
|
|
|
|
|
|
|
+ print(f"Warning: could not open {json_localfile}. Exiting.")
|
|
|
|
|
+ sys.exit(1)
|
|
|
|
|
+ # try:
|
|
|
|
|
+ # with SCPClient(ssh.get_transport()) as scp:
|
|
|
|
|
+ # scp.get(json_remotefile, local_path=json_localfile)
|
|
|
|
|
+ # with open(json_localfile, 'r') as openfile:
|
|
|
|
|
+ # jso = json.load(openfile)
|
|
|
|
|
+ # except:
|
|
|
|
|
+ # print(f"Warning: could not get {json_remotefile} from {remotehost}")
|
|
|
|
|
|
|
|
def disc_free ( mountpoint, host ):
|
|
def disc_free ( mountpoint, host ):
|
|
|
- if host != False:
|
|
|
|
|
-# cmd = [ 'ssh', host, 'bash', '-c', f"df | grep {mountpoint} | cut -b 57-68,70-72" ]
|
|
|
|
|
|
|
+ if host != False: # remote host
|
|
|
cmd = [ 'ssh', host, 'bash', '-c', f"df | grep {mountpoint} | cut -b 52-61,64-68" ]
|
|
cmd = [ 'ssh', host, 'bash', '-c', f"df | grep {mountpoint} | cut -b 52-61,64-68" ]
|
|
|
s = subprocess.check_output( cmd ).decode('utf-8').strip().split(' ')
|
|
s = subprocess.check_output( cmd ).decode('utf-8').strip().split(' ')
|
|
|
- print("-".join(s))
|
|
|
|
|
- else:
|
|
|
|
|
- cmd = [ 'bash', '-c', f"df | grep {mountpoint} | cut -b 51-61,64-66" ]
|
|
|
|
|
|
|
+ else: # local host
|
|
|
|
|
+ cmd = [ 'bash', '-c', f"df | grep {mountpoint} | cut -b 57-66,69-72" ]
|
|
|
s = subprocess.check_output( cmd ).decode('utf-8').strip().split(' ')
|
|
s = subprocess.check_output( cmd ).decode('utf-8').strip().split(' ')
|
|
|
|
|
+ print("#".join(s))
|
|
|
return( { 'fill_level' : s[1], 'bytes_free' : s[0] } )
|
|
return( { 'fill_level' : s[1], 'bytes_free' : s[0] } )
|
|
|
|
|
|
|
|
def disc_blkid ( mapperdev, host ):
|
|
def disc_blkid ( mapperdev, host ):
|
|
@@ -103,6 +108,7 @@ def update_json ():
|
|
|
jso[now][blkid] = {}
|
|
jso[now][blkid] = {}
|
|
|
jso[now][blkid]['bytes_free'] = disc_free(args.localrepobasedir, False)['bytes_free']
|
|
jso[now][blkid]['bytes_free'] = disc_free(args.localrepobasedir, False)['bytes_free']
|
|
|
jso[now][blkid]['fill_level'] = disc_free(args.localrepobasedir, False)['fill_level']
|
|
jso[now][blkid]['fill_level'] = disc_free(args.localrepobasedir, False)['fill_level']
|
|
|
|
|
+ print(jso[now][blkid]['fill_level'])
|
|
|
jso[now][blkid]['color'] = snapcolors[blkid]
|
|
jso[now][blkid]['color'] = snapcolors[blkid]
|
|
|
|
|
|
|
|
jso['__summary'] = { 'last_backup_copy' : now,
|
|
jso['__summary'] = { 'last_backup_copy' : now,
|
|
@@ -117,11 +123,11 @@ def update_json ():
|
|
|
def write_json():
|
|
def write_json():
|
|
|
with open(json_localfile, 'w', encoding='utf-8') as f:
|
|
with open(json_localfile, 'w', encoding='utf-8') as f:
|
|
|
json.dump(jso, f, ensure_ascii=False, indent=4)
|
|
json.dump(jso, f, ensure_ascii=False, indent=4)
|
|
|
- try:
|
|
|
|
|
- with SCPClient(ssh.get_transport()) as scp:
|
|
|
|
|
- scp.put(json_localfile, json_remotefile)
|
|
|
|
|
- except:
|
|
|
|
|
- print(f"Error: could not copy {json_localfile} to {remotehost}:{json_remotefile}")
|
|
|
|
|
|
|
+ # try:
|
|
|
|
|
+ # with SCPClient(ssh.get_transport()) as scp:
|
|
|
|
|
+ # scp.put(json_localfile, json_remotefile)
|
|
|
|
|
+ # except:
|
|
|
|
|
+ # print(f"Error: could not copy {json_localfile} to {remotehost}:{json_remotefile}")
|
|
|
|
|
|
|
|
def rewrite_snapshots_json(host):
|
|
def rewrite_snapshots_json(host):
|
|
|
cmd = [ 'ssh', f"""{ssh_username}@{host}""", 'bash', '-c', "/usr/local/sbin/restic_json.sh" ]
|
|
cmd = [ 'ssh', f"""{ssh_username}@{host}""", 'bash', '-c', "/usr/local/sbin/restic_json.sh" ]
|