From 8a214d0974f9f2ac3487a132c5d77f25dc074cae Mon Sep 17 00:00:00 2001 From: Davide Principi Date: Wed, 10 Apr 2024 18:34:19 +0200 Subject: [PATCH] Fix backup/restore procedure - Restore the "active from" timestamp - Add to backup/restore the "active to" timestamp --- imageroot/actions/restore-module/06copyenv | 23 +++++-------------- .../restore-module/50restore_active_to | 20 ++++++++++++++++ imageroot/bin/module-cleanup-state | 13 +++++++++++ imageroot/bin/module-dump-state | 13 +++++++++++ imageroot/etc/state-include.conf | 1 + 5 files changed, 53 insertions(+), 17 deletions(-) create mode 100755 imageroot/actions/restore-module/50restore_active_to create mode 100755 imageroot/bin/module-cleanup-state create mode 100755 imageroot/bin/module-dump-state 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/50restore_active_to b/imageroot/actions/restore-module/50restore_active_to new file mode 100755 index 0000000..4ebaa2e --- /dev/null +++ b/imageroot/actions/restore-module/50restore_active_to @@ -0,0 +1,20 @@ +#!/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 datetime +import os + +if "LOKI_ACTIVE_TO" in original_environment: + agent.set_env("LOKI_ACTIVE_TO", original_environment["LOKI_ACTIVE_TO"]) +else: + try: + agent.set_env("LOKI_ACTIVE_TO", datetime.datetime.fromtimestamp(os.stat('active_to.tstamp').st_mtime).astimezone().isoformat()) + except Exception as ex: + print(agent.SD_WARNING + "Cannot restore LOKI_ACTIVE_TO:", str(ex), file=sys.stderr) diff --git a/imageroot/bin/module-cleanup-state b/imageroot/bin/module-cleanup-state new file mode 100755 index 0000000..930eef5 --- /dev/null +++ b/imageroot/bin/module-cleanup-state @@ -0,0 +1,13 @@ +#!/bin/bash + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +set -e + +# Redirect any output to the journal (stderr) +exec 1>&2 + +rm -vf active_to.tstamp diff --git a/imageroot/bin/module-dump-state b/imageroot/bin/module-dump-state new file mode 100755 index 0000000..09ec312 --- /dev/null +++ b/imageroot/bin/module-dump-state @@ -0,0 +1,13 @@ +#!/bin/bash + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +set -e + +# Redirect any output to the journal (stderr) +exec 1>&2 + +touch active_to.tstamp diff --git a/imageroot/etc/state-include.conf b/imageroot/etc/state-include.conf index 2034dab..f608bc6 100644 --- a/imageroot/etc/state-include.conf +++ b/imageroot/etc/state-include.conf @@ -1 +1,2 @@ volumes/loki-server-data +state/active_to.tstamp