Gitbackup export facility and minor improvements.

This commit is contained in:
2026-04-12 19:15:39 +02:00
parent c6c4d2794f
commit bb796024e3
9 changed files with 572 additions and 21 deletions
@@ -11,6 +11,11 @@
#
# Author: Kovács Zoltán <kovacsz@marcusconsulting.hu>
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
# 2026-04-12 v0.5
# mod: The PAR_BACKUPDIR environment variable changed to PAR_SOURCEDIR.
# mod: Introduced the SOURCEPATH environment variable to avoid hardcoding.
# 2025-05-20 v0.4
# fix: Wrong output redirection order (>/dev/null 2>&1 was reversed).
# 2025-01-18 v0.3
# fix: a typo (BASE_DIR instead of SERVICE_BASE).
# 2024-09-10 v0.2
@@ -24,7 +29,7 @@ BOTEMAIL=${BOTEMAIL:-"backupbot@example.com"} # Git repo owner's email (fake)
BOTNAME=${BOTNAME:-"Backup Bot"} # Git repo owner's name (fake)
SERVICE_BASE=${PAR_BASEDIR:-""} # Corresponding service's base
GITDIR=${PAR_GITDIR:-""} # Folder containing .git
SOURCEDIR=${PAR_BACKUPDIR:-""} # Folder to backup into git
SOURCEDIR=${PAR_SOURCEDIR:-""} # Folder to backup into git
# Basic environment settings.
#
@@ -46,6 +51,7 @@ MSG_WRONGGIT="Fatal: unusable backup (git) folder"
# Other initialisations.
#
GITPATH="storage/backups/attachments"
SOURCEPATH="storage/volumes/redmine_files"
YMLFILE="docker-compose.yml"
# Checks the dependencies.
@@ -72,9 +78,9 @@ while [ -h "$SOURCE" ]; do
# relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$SCRPATH/$SOURCE"
done; SCRPATH="$( cd -P "$("$DIRNAME" "$SOURCE" )" && echo "$PWD" )" #"
# Let's find which version of docker-compose is installed.
if [ $($DOCKER compose version 2>&1 >/dev/null; echo $?) -eq 0 ]; then
if [ $($DOCKER compose version >/dev/null 2>&1; echo $?) -eq 0 ]; then
# We'll use v2 if it is available.
DOCKER_COMPOSE="$DOCKER"
commandstring="compose"
@@ -102,14 +108,12 @@ TEST_DIR="$("$DIRNAME" "$TEST_DIR")"
if [ -z "$SERVICE_BASE" -o ! -r "$SERVICE_BASE/$YMLFILE" ]; then
echo "$MSG_MISSINGYML" >&2; exit 1
fi
# Sets the absolute paths.
BACKUPDIR="${PAR_BACKUPDIR:-$SERVICE_BASE/$BACKUPDIR}"
# Locates the source folder.
#
# Maybe given as a command line parameter.
[[ -n "$1" ]] && SOURCEDIR="$1" && shift
[[ -z "$SOURCEDIR" ]] && SOURCEDIR="$SERVICE_BASE/storage/volumes/redmine_files"
[[ -z "$SOURCEDIR" ]] && SOURCEDIR="$SERVICE_BASE/$SOURCEPATH"
# Gives up here if doesn't found.
if [ -z "$SOURCEDIR" -o ! -d "$("$READLINK" -e "$SOURCEDIR")" ]; then
echo "$MSG_MISSINGSOURCE $SOURCEDIR"; exit 1
@@ -148,6 +152,7 @@ if [ ! -d "$GITDIR/.git" ]; then
fi
# Stages all the files and non-empty folders.
"$GIT" --git-dir="$GITDIR/.git" --work-tree="$SOURCEDIR" add . >/dev/null
# Stores the file system metadata as well, if the tool has been installed.
if [ ! -z "$(which metastore)" -a -x "$(which metastore)" ]; then
# This commamd silently creates the metastore file if it doesnt' exist yet.