-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Restore the "active from" timestamp - Add to backup/restore the "active to" timestamp
- Loading branch information
1 parent
abc7c42
commit fc2276e
Showing
2 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import sys | ||
import json | ||
import agent | ||
import subprocess | ||
|
||
try: | ||
# Find the biggest modification timestamp among Loki's subdirs, | ||
# and print it in ISO8601 format. Note that the timezone requires | ||
# the ":" separator, otherwise the parsing fails. | ||
find_latest_change_script = """find /loki -type d | | ||
xargs -- stat -c %Y | | ||
awk 'BEGIN { ts = 0 } ; { ts = $1 > ts ? $1 : ts ; } ; END { print ts }' | | ||
xargs -IDATE -- date -u -d @DATE +%Y-%m-%dT%H:%M:%S.0+00:00 | ||
""" | ||
proc_active_to = subprocess.run(["podman", "exec", "-i", "loki-server", "ash", "-s"], | ||
capture_output=True, | ||
input=find_latest_change_script, | ||
text=True, | ||
check=True, | ||
) | ||
except Exception as ex: | ||
print(agent.SD_WARNING + "Cannot restore LOKI_ACTIVE_TO:", str(ex), file=sys.stderr) | ||
else: | ||
agent.set_env("LOKI_ACTIVE_TO", proc_active_to.stdout.strip()) |