diff --git a/imageroot/actions/restore-module/06copyenv b/imageroot/actions/restore-module/06copyenv index f861062..d99ab11 100755 --- a/imageroot/actions/restore-module/06copyenv +++ b/imageroot/actions/restore-module/06copyenv @@ -1,28 +1,14 @@ #!/usr/bin/env python3 # -# Copyright (C) 2022 Nethesis S.r.l. -# http://www.nethesis.it - nethserver@nethesis.it -# -# This script is part of NethServer. -# -# NethServer is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, -# or any later version. -# -# NethServer is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with NethServer. If not, see COPYING. +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later # import sys import json import agent +import os request = json.load(sys.stdin) @@ -33,5 +19,8 @@ for evar in [ "LOKI_API_AUTH_PASSWORD", "LOKI_LOGS_INGRESS_TOKEN", "LOKI_RETENTION_PERIOD", + "LOKI_ACTIVE_FROM", ]: agent.set_env(evar, original_environment[evar]) + +# NOTE: LOKI_ACTIVE_TO is value restored after restic run diff --git a/imageroot/actions/restore-module/95restore_active_to b/imageroot/actions/restore-module/95restore_active_to new file mode 100755 index 0000000..f2a49a8 --- /dev/null +++ b/imageroot/actions/restore-module/95restore_active_to @@ -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)