Skip to content

Commit

Permalink
feat: dump state for backup
Browse files Browse the repository at this point in the history
- Save custom certificates and custom routes in the backup for
  restoration.
- Save also acme.json and traefik.yaml for reference: when restored,
  they will be removed on the next backup run.
  • Loading branch information
DavidePrincipi committed Feb 17, 2025
1 parent 4f6932c commit 99f0c84
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
28 changes: 28 additions & 0 deletions imageroot/actions/restore-module/50restore_traefik
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

#
# Copyright (C) 2025 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

set -e

shopt -s nullglob

# Restore HTTP routes created from the UI:
for froute in state-backup/manual_flags/* ; do
route=$(basename "${froute}")
if [[ -f "state-backup/configs/${route}.yml" ]]; then
cp -vfT "state-backup/configs/${route}.yml" "configs/${route}.yml"
touch "manual_flags/${route}"
fi
done

# Restore uploaded certificates (dynamic config):
find state-backup/configs -type f -name 'cert_*.yml' -0 | \
xargs -0 -r -- cp -pvt configs/

# Restore uploaded certificates (certificates and private keys):
find state-backup/custom_certificates -type f -0 | \
xargs -0 -r -- cp -pvt custom_certificates/

6 changes: 3 additions & 3 deletions imageroot/bin/module-cleanup-state
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env sh
#!/bin/bash

#
# Copyright (C) 2023 Nethesis S.r.l.
# Copyright (C) 2025 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

rm -fv backup-custom-routes.json
rm -rf state.backup
17 changes: 17 additions & 0 deletions imageroot/bin/module-dump-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

#
# Copyright (C) 2025 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

set -e

rm -rf state-backup
mkdir -vp state-backup

cp -pvT traefik.yaml state-backup/
cp -prvT configs state-backup/configs/
cp -prvT manual_flags state-backup/manual_flags/
cp -prvT custom_certificates state-backup/custom_certificates/
cp -prvT acme/ state-backup/acme/
6 changes: 6 additions & 0 deletions imageroot/etc/state-include.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Restic include patterns for Traefik state
# Syntax reference: https://pkg.go.dev/path/filepath#Glob
# Restic --files-from: https://restic.readthedocs.io/en/stable/040_backup.html#including-files
#
state/state-backup

0 comments on commit 99f0c84

Please sign in to comment.