Skip to content

Commit

Permalink
Add scripts for restoring and dumping the piler database
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Apr 25, 2024
1 parent 4469f88 commit a48036c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
41 changes: 41 additions & 0 deletions imageroot/actions/restore-module/40restoreDB
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

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

set -e -o pipefail
exec 1>&2 # Redirect any output to the journal (stderr)

# Prepare an initialization script that restores the dump file
mkdir -vp initdb.d
mv -v piler.sql initdb.d
#do the bash file to restore and exit once done
cat - >initdb.d/zz_piler_restore.sh <<'EOS'
# Print additional information:
mysql --version
# The script is sourced, override entrypoint args and exit:
set -- true
docker_temp_server_stop
exit 0
EOS

# once we exit we remove initdb.d
trap 'rm -rfv initdb.d/' EXIT

# we start a container to initiate a database and load the dump
# at the end of piler_restore.sh the dump is loaded and
# we exit the container
podman run \
--rm \
--interactive \
--network=none \
--volume=./initdb.d:/docker-entrypoint-initdb.d:z \
--volume mysql-data:/var/lib/mysql/:Z \
--env MARIADB_ROOT_PASSWORD=Nethesis,1234 \
--env MARIADB_DATABASE=piler \
--env MARIADB_USER=piler \
--env MARIADB_PASSWORD=piler \
--replace --name=restore_db \
${MARIADB_IMAGE}
8 changes: 8 additions & 0 deletions imageroot/bin/module-cleanup-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

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

rm -vf piler.sql
21 changes: 21 additions & 0 deletions imageroot/bin/module-dump-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

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

set -e

if ! systemctl --user -q is-active piler.service; then
exit 0
fi

podman exec mariadb-app mysqldump \
--databases piler \
--default-character-set=utf8mb4 \
--skip-dump-date \
--ignore-table=mysql.event \
--single-transaction \
--quick \
--add-drop-table > piler.sql
11 changes: 9 additions & 2 deletions imageroot/etc/state-include.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#
# SOGo state/backup include patterns for Restic
# Syntax reference: https://pkg.go.dev/path/filepath#Glob
# Restic --files-from: https://restic.readthedocs.io/en/stable/040_backup.html#including-files
#
state/piler.sql
volumes/mysql-conf.d
volumes/mysql-data
volumes/piler_var
volumes/piler_manticore
volumes/piler_store
volumes/piler_etc

0 comments on commit a48036c

Please sign in to comment.