From ab8236ece01b13688b00c65b271b973806c00420 Mon Sep 17 00:00:00 2001 From: Benoit Donneaux Date: Thu, 27 Jun 2024 16:26:03 +0200 Subject: [PATCH] Add a trac_dump helper to extract required data Signed-off-by: Benoit Donneaux --- docker-compose.yml | 1 + docker/trac/Dockerfile | 2 +- helpers/trac_dump.sh | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 helpers/trac_dump.sh diff --git a/docker-compose.yml b/docker-compose.yml index 8bdc5d9..59012c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: - ./trac/trac.htdigest:/home/trac/trac.htdigest - ./trac/repos:/home/source/git - ./trac/backup:/var/lib/appdata/backup + - ./helpers:/var/lib/appdata/helpers working_dir: /var/lib/appdata stdin_open: true tty: true diff --git a/docker/trac/Dockerfile b/docker/trac/Dockerfile index 19bef8b..a1e0b65 100644 --- a/docker/trac/Dockerfile +++ b/docker/trac/Dockerfile @@ -12,7 +12,7 @@ ENV DEBIAN_FRONTEND="noninteractive" # Application level requirements # ################################## # Install required packages -RUN INSTALL_PKGS="git gcc libssl-dev" && \ +RUN INSTALL_PKGS="git gcc libssl-dev sqlite3" && \ apt-get -q clean && \ apt-get -q update && \ apt-get install -y $INSTALL_PKGS && \ diff --git a/helpers/trac_dump.sh b/helpers/trac_dump.sh new file mode 100755 index 0000000..3de375f --- /dev/null +++ b/helpers/trac_dump.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# Configure bash behavior +set -o errexit # exit on failed command +set -o nounset # exit on undeclared variables +set -o pipefail # exit on any failed command in pipes + +# Verbosity settings +: ${VERBOSE=1} +SH=("/usr/bin/env" "bash") +if [ ${VERBOSE} -ge 2 ]; then + SH=("${SH[@]}" "-x") + set -o xtrace +fi + +# Set magic variables for current file & dir +__DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__FILE="${__DIR}/$(basename "${BASH_SOURCE[0]}")" +__BASE="$(basename ${__FILE} .sh)" +__ROOT="$(cd "$(dirname "${__DIR}")" && pwd)" +__CWD="$(pwd)" + +# Parse the arguments +TRAC_DIR=${1?Path to trac directory is missing as first argument!} +DUMP_DIR=${2?Path to dump directory is missing as second argument!} +shift +shift + +trac-admin "${TRAC_DIR}" hotcopy "${DUMP_DIR}" + +echo "Purging sessions ..." +trac-admin "${DUMP_DIR}" session purge "0 days ago" +echo "Purge sessions done" + +echo "Vacuuming the DB ..." +sqlite3 "${DUMP_DIR}/db/trac.db" 'VACUUM;' +echo "Vaccum done" + +echo "Purging logs ..." +rm -f "${DUMP_DIR}/log/*" +echo "Purge log done" + +echo "Dumping additional files ..." +for SRC in "${@}"; do + echo " ${SRC} ..." + cp -a "${SRC}" "${DUMP_DIR}" +done +echo "Dump additional files done"