bundles/backups-server: read backup snapshot info from file instead of asking zfs every time
This commit is contained in:
parent
22263eaf6f
commit
a7a59fd690
4 changed files with 56 additions and 19 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
from datetime import datetime
|
||||
from json import load
|
||||
from subprocess import check_output
|
||||
from sys import argv, exit
|
||||
from time import time
|
||||
|
||||
|
@ -18,29 +17,17 @@ try:
|
|||
with open(f'/etc/backup-server/config.json', 'r') as f:
|
||||
server_settings = load(f)
|
||||
|
||||
# get all existing snapshots for NODE
|
||||
for line in check_output('LC_ALL=C zfs list -H -t snapshot -o name', shell=True).splitlines():
|
||||
line = line.decode('UTF-8')
|
||||
with open(f'/etc/backup-server/backups.json', 'r') as f:
|
||||
backups = load(f)
|
||||
|
||||
if line.startswith('{}/{}@'.format(server_settings['zfs-base'], NODE)):
|
||||
_, snapname = line.split('@', 1)
|
||||
|
||||
if 'zfs-auto-snap' in snapname:
|
||||
# migration from auto-snapshots, ignore
|
||||
continue
|
||||
|
||||
ts, bucket = snapname.split('-', 1)
|
||||
snaps.add(int(ts))
|
||||
|
||||
if not snaps:
|
||||
if NODE not in backups:
|
||||
print('No backups found!')
|
||||
exit(2)
|
||||
|
||||
last_snap = sorted(snaps)[-1]
|
||||
delta = NOW - last_snap
|
||||
delta = NOW - backups[NODE]
|
||||
|
||||
print('Last backup was on {} UTC'.format(
|
||||
datetime.fromtimestamp(last_snap).strftime('%Y-%m-%d %H:%M:%S'),
|
||||
datetime.fromtimestamp(backups[NODE]).strftime('%Y-%m-%d %H:%M:%S'),
|
||||
))
|
||||
|
||||
# One day without backups is still okay. There may be fluctuations
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue