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,9 @@
#
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
# 2026-04-12 v0.4
# mod: The PAR_BACKUPDIR environment variable changed to PAR_SOURCEDIR.
# mod: Introduced the SOURCEPATH environment variable to avoid hardcoding.
# 2025-05-21 v0.3.1
# fix: Wrong variable name (BASE_DIR instead of SERVICE_BASE) in a check.
# 2025-05-20 v0.3
@@ -26,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.
#
@@ -48,6 +51,7 @@ MSG_WRONGGIT="Fatal: unusable backup (git) folder"
# Other initialisations.
#
GITPATH="storage/backups/webcontent"
SOURCEPATH="storage/volumes/mediawiki_images"
YMLFILE="docker-compose.yml"
# Checks the dependencies.
@@ -74,7 +78,7 @@ 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 >/dev/null 2>&1; echo $?) -eq 0 ]; then
# We'll use v2 if it is available.
@@ -104,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/wordpress_html"
[[ -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
@@ -150,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.