Skip to content
Snippets Groups Projects
Commit 6b9c3bd4 authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

fix(test): rewrite latest backup check for multiple paths

parent beab86c9
No related branches found
No related tags found
No related merge requests found
......@@ -67,22 +67,38 @@ def test_last_backup_is_recent(server: str) -> bool:
print("Checking latest backup age:")
client = socket.gethostname()
path = "/backup/{}/home/latest".format(client)
cmd = "ssh -o StrictHostKeyChecking=no {} ls -l {} | grep latest".format(
server, path
)
status, out = subprocess.getstatusoutput(cmd)
if status == 0:
date = out.strip().split(" ")[-1]
pdate = datetime.strptime(date, "%Y-%m-%d-%H%M%S")
if (datetime.now() - pdate).days > MAX_AGE:
u.error("older than {} days".format(MAX_AGE))
return False
u.success("less than {} days old".format(MAX_AGE))
return True
out = out or "no output"
u.error("SSH access not working (code: {}): {}".format(status, out))
# set backup potential directories path
paths = [
"/backup/{}/home/latest".format(client),
"/backup/data/latest",
]
# test each possible path
for path in paths:
# build and run commands
find = "find -L {} {} {} {} {}".format(
path,
"-maxdepth 0",
"-xtype l",
"-name latest",
"-exec realpath {} +" # must always be last arg
)
cmd = "ssh -o StrictHostKeyChecking=no {} '{}'".format(server, find)
status, out = subprocess.getstatusoutput(cmd)
if status == 0:
# get directory name and convert to datetime
last = out.strip().split("/")[-1]
date = datetime.strptime(last, "%Y-%m-%d-%H%M%S")
# check age
if (datetime.now() - date).days > MAX_AGE:
u.error("older than {} days".format(MAX_AGE))
return False
u.success("less than {} days old".format(MAX_AGE))
return True
# if we reach here, nothing have been found
u.error("latest backup directory not found")
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment