Skip to content

Commit aafad6d

Browse files
Fix backup/restore procedure
- Clean up volume before Restic restores it - Restore the "active from" timestamp - Restore the "active to" timestamp, by reading it from volume - Do not restore credentials and tokens: use new ones
1 parent f8e0d50 commit aafad6d

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed
Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
11
#!/usr/bin/env python3
22

33
#
4-
# Copyright (C) 2022 Nethesis S.r.l.
5-
# http://www.nethesis.it - [email protected]
6-
#
7-
# This script is part of NethServer.
8-
#
9-
# NethServer is free software: you can redistribute it and/or modify
10-
# it under the terms of the GNU General Public License as published by
11-
# the Free Software Foundation, either version 3 of the License,
12-
# or any later version.
13-
#
14-
# NethServer is distributed in the hope that it will be useful,
15-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
# GNU General Public License for more details.
18-
#
19-
# You should have received a copy of the GNU General Public License
20-
# along with NethServer. If not, see COPYING.
4+
# Copyright (C) 2024 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
216
#
227

238
import sys
249
import json
2510
import agent
11+
import os
2612

2713
request = json.load(sys.stdin)
2814

2915
original_environment = request['environment']
3016

3117
for evar in [
32-
"LOKI_API_AUTH_USERNAME",
33-
"LOKI_API_AUTH_PASSWORD",
34-
"LOKI_LOGS_INGRESS_TOKEN",
3518
"LOKI_RETENTION_PERIOD",
19+
"LOKI_ACTIVE_FROM",
20+
# NOTE: LOKI_ACTIVE_TO is restored by a later step
3621
]:
3722
agent.set_env(evar, original_environment[evar])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env sh
2+
3+
#
4+
# Copyright (C) 2024 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
exec 1>&2
9+
10+
# Stop the pod
11+
systemctl --user stop loki.service
12+
13+
# At index 20, volume contents are restored by Restic.
14+
podman volume rm loki-server-data
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright (C) 2024 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
import sys
9+
import agent
10+
import subprocess
11+
import os
12+
import sys
13+
14+
try:
15+
# Find the biggest modification timestamp among Loki's subdirs,
16+
# and print it in ISO8601 format. Note that the timezone requires
17+
# the ":" separator, otherwise the parsing fails.
18+
find_latest_change_script = """find /loki -type d |
19+
xargs -- stat -c %Y |
20+
awk 'BEGIN { ts = 0 } ; { ts = $1 > ts ? $1 : ts ; } ; END { print ts }' |
21+
xargs -IDATE -- date -u -d @DATE +%Y-%m-%dT%H:%M:%S.0+00:00
22+
"""
23+
proc_active_to = subprocess.run(["podman", "run", "-i",
24+
"--name=loki-server-restore", "--replace", "--rm",
25+
"--network=none", "--volume=loki-server-data:/loki:z",
26+
'--entrypoint=["ash","-s"]',
27+
os.environ["LOKI_IMAGE"],
28+
],
29+
stdout=subprocess.PIPE,
30+
stderr=sys.stderr,
31+
input=find_latest_change_script,
32+
text=True,
33+
check=True,
34+
)
35+
except Exception as ex:
36+
print(agent.SD_WARNING + "Cannot restore LOKI_ACTIVE_TO:", str(ex), file=sys.stderr)
37+
else:
38+
agent.set_env("LOKI_ACTIVE_TO", proc_active_to.stdout.strip())

imageroot/actions/restore-module/90restart renamed to imageroot/actions/restore-module/90start_server

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
# SPDX-License-Identifier: GPL-3.0-or-later
66
#
77

8-
systemctl --user restart loki.service
8+
exec 1>&2
9+
10+
systemctl --user start loki.service

0 commit comments

Comments
 (0)