Merge branch 'development' into refactor/TTD-3115/shellcheck-cleanup

This commit is contained in:
Clemens Schwaighofer
2026-04-28 11:51:57 +09:00
6 changed files with 162 additions and 12 deletions
+22 -3
View File
@@ -254,23 +254,42 @@ backup.borg.mysql.schema-only
## gitea backup settings ## gitea backup settings
Note that the backup needs the GIT_USER set that runs gitea. Note that the backup needs the GITEA_GIT_USER set that runs gitea.
This user is neede to create the temporary dump folder and access for the git files and database. This user is neede to create the temporary dump folder and access for the git files and database.
### gitea Config Variables ### gitea Config Variables
| Variable | Default | Description | | Variable | Default | Description |
| - | - | - | | - | - | - |
| GIT_USER | git | The user that runs gitea | | GITEA_GIT_USER | git | The user that runs gitea |
| GITEA_WORKING_DIR | /var/tmp/gitea/ | Where the temporary dump files from the backup are stored, as user git | | GITEA_WORKING_DIR | /var/tmp/gitea/ | Where the temporary dump files from the backup are stored, as user git |
| GITEA_TEMP_DIR | /var/tmp/ | General temporary folder | | GITEA_TEMP_DIR | /var/tmp/ | General temporary folder |
| GITEA_BIN | /usr/local/bin/gitea | Where the gitea binary is located | | GITEA_BIN | /usr/local/bin/gitea | Where the gitea binary is located |
| GITEA_CONFIG | /etc/gitea/app.ini | The configuration file for gitea | | GITEA_CONFIG | /etc/gitea/app.ini or /var/lib/gitea/custom/conf/app.ini | The configuration file for gitea |
### gitea Control files ### gitea Control files
There are no control files for gitea backup There are no control files for gitea backup
## forgejo backup settings
Note that the backup needs the FORGEJO_GIT_USER set that runs forgejo.
This user is neede to create the temporary dump folder and access for the git files and database.
### forgejo Config Variables
| Variable | Default | Description |
| - | - | - |
| FORGEJO_GIT_USER | git | The user that runs forgejo |
| FORGEJO_WORKING_DIR | /var/tmp/forgejo/ | Where the temporary dump files from the backup are stored, as user git |
| FORGEJO_TEMP_DIR | /var/tmp/ | General temporary folder |
| FORGEJO_BIN | /usr/local/bin/forgejo | Where the forgejo binary is located |
| FORGEJO_CONFIG | /etc/forgejo/app.ini or /var/lib/forgejo/custom/conf/app.ini | The configuration file for forgejo |
### forgejo Control files
There are no control files for forgejo backup
## zabbix config backup settings ## zabbix config backup settings
The `zabbix-dump` dump script must be installed from: <https://github.com/gullevek/zabbix-backup> The `zabbix-dump` dump script must be installed from: <https://github.com/gullevek/zabbix-backup>
+9
View File
@@ -0,0 +1,9 @@
# Borg backup wrapper scripts settings: forgejo
# rename to borg.backup.forgejo.settings to use
FORGEJO_GIT_USER="";
FORGEJO_WORKING_DIR="";
FORGEJO_TEMP_DIR="";
FORGEJO_BIN="";
FORGEJO_CONFIG="";
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# allow variables in printf format string
# shellcheck disable=SC2059
# Backup forgejo database, all git folders and forgejo settings
MODULE="forgejo"
MODULE_VERSION="1.0.0";
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
# init system
. "${DIR}/borg.backup.functions.init.sh";
# init verify, compact and check file
BACKUP_INIT_FILE="borg.backup.${MODULE}.init";
BACKUP_COMPACT_FILE="borg.backup.${MODULE}.compact";
BACKUP_CHECK_FILE="borg.backup.${MODULE}.check";
# lock file
BACKUP_LOCK_FILE="borg.backup.${MODULE}.lock";
# verify valid data
. "${DIR}/borg.backup.functions.verify.sh";
# if info print info and then abort run
. "${DIR}/borg.backup.functions.info.sh";
# NOTE: because a tmp directory is needed it is more recommended
# to run this as root and have only the dump command itself run as FORGEJO_GIT_USER
# set git user
if [ -z "${FORGEJO_GIT_USER}" ]; then
FORGEJO_GIT_USER="git";
fi;
# set FORGEJO_* if not set
if [ -z "${FORGEJO_WORKING_DIR}" ]; then
# run forgejo backup (user mktemp?)
FORGEJO_WORKING_DIR="/var/tmp/forgejo/";
fi;
# general temp folder for temporary data storage, this is not working output folder
if [ -z "${FORGEJO_TEMP_DIR}" ]; then
FORGEJO_TEMP_DIR="/var/tmp";
fi;
if [ -z "${FORGEJO_BIN}" ]; then
FORGEJO_BIN="/usr/local/bin/forgejo";
fi;
if [ -z "${FORGEJO_CONFIG}" ]; then
FORGEJO_CONFIG="/etc/forgejo/app.ini"
fi;
# This one is not advertised in the config file as it is not recommended to change
if [ -z "${FORGEJO_EXPORT_TYPE}" ]; then
FORGEJO_EXPORT_TYPE="zip";
fi;
if [ ! -f "${FORGEJO_BIN}" ]; then
echo "[! $(date +'%F %T')] Cannot find forgejo binary";
. "${DIR}/borg.backup.functions.close.sh" 1;
exit 1;
fi;
if [ ! -f "${FORGEJO_CONFIG}" ]; then
echo "[! $(date +'%F %T')] Cannot find forgejo config";
. "${DIR}/borg.backup.functions.close.sh" 1;
exit 1;
fi;
# some basic checks with abort
if [ ! -d "${FORGEJO_TEMP_DIR}" ]; then
echo "Temp directory does not exist: ${FORGEJO_TEMP_DIR}";
exit;
fi;
# we should check FORGEJO_EXPORT_TYPE too at some point for an allow list
# At the moment warn if not zip
if [ "${FORGEJO_EXPORT_TYPE}" != "zip" ]; then
echo "[!!!!] The forgejo export type has been changed from 'zip' to '${FORGEJO_EXPORT_TYPE}'. This can either break or make exports take very ling";
fi;
# Filename
FILENAME="forgejo.backup.zip";
# backup set and prefix
BACKUP_SET_PREFIX="${MODULE},";
BACKUP_SET_NAME="${ONE_TIME_TAG}${BACKUP_SET_PREFIX}${BACKUP_SET}";
# borg call
BORG_CALL=$(echo "${_BORG_CALL}" | sed -e "s/##FILENAME##/${FILENAME}/" | sed -e "s/##BACKUP_SET##/${BACKUP_SET_NAME}/");
BORG_PRUNE=$(echo "${_BORG_PRUNE}" | sed -e "s/##BACKUP_SET_PREFIX##/${BACKUP_SET_PREFIX}/");
printf "${PRINTF_SUB_BLOCK}" "BACKUP: git data and database" "$(date +'%F %T')" "${MODULE}";
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "sudo -u ${FORGEJO_GIT_USER} ${FORGEJO_BIN} dump -c ${FORGEJO_CONFIG} -w ${FORGEJO_WORKING_DIR} -t ${FORGEJO_TEMP_DIR} --type ${FORGEJO_EXPORT_TYPE} -L -f - | ${BORG_CALL}";
if [ -z "${ONE_TIME_TAG}" ]; then
echo "${BORG_PRUNE}";
fi;
fi;
if [ ${DRYRUN} -eq 0 ]; then
(
# below was an old workaround
#export USER="${LOGNAME}" # workaround for broken forgejo EUID check
# make sure temp folder is there and is set as git. user
if [ ! -d "${FORGEJO_WORKING_DIR}" ]; then
mkdir -p "${FORGEJO_WORKING_DIR}";
fi;
chown -R ${FORGEJO_GIT_USER}: "${FORGEJO_WORKING_DIR}";
# this needs to be run in a folder that can be stat by git user
cd "${FORGEJO_WORKING_DIR}" || exit 1;
sudo -u ${FORGEJO_GIT_USER} ${FORGEJO_BIN} dump -c ${FORGEJO_CONFIG} -w ${FORGEJO_WORKING_DIR} -t ${FORGEJO_TEMP_DIR} --type ${FORGEJO_EXPORT_TYPE} -L -f - | ${BORG_CALL};
) 2>&1 | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' # remove all ESC strings
fi;
if [ -z "${ONE_TIME_TAG}" ]; then
printf "${PRINTF_SUB_BLOCK}" "PRUNE" "$(date +'%F %T')" "${MODULE}";
echo "Prune repository with keep${KEEP_INFO:1}";
${BORG_PRUNE};
# if this is borg version >1.2 we need to run compact after prune
. "${DIR}/borg.backup.functions.compact.sh" "auto";
# check in auto mode
. "${DIR}/borg.backup.functions.check.sh" "auto";
fi;
. "${DIR}/borg.backup.functions.close.sh";
# __END__
+9 -2
View File
@@ -32,7 +32,7 @@ function version {
} }
# version for all general files # version for all general files
VERSION="4.8.0"; VERSION="4.9.0";
# borg version and borg comamnd # borg version and borg comamnd
BORG_VERSION=""; BORG_VERSION="";
@@ -166,12 +166,19 @@ DATABASE_HOST="";
MYSQL_DB_CONFIG=""; MYSQL_DB_CONFIG="";
MYSQL_DB_CONFIG_PARAM=""; MYSQL_DB_CONFIG_PARAM="";
# gitea module # gitea module
GIT_USER=""; GITEA_GIT_USER="";
GITEA_WORKING_DIR=""; GITEA_WORKING_DIR="";
GITEA_TEMP_DIR=""; GITEA_TEMP_DIR="";
GITEA_BIN=""; GITEA_BIN="";
GITEA_CONFIG=""; GITEA_CONFIG="";
GITEA_EXPORT_TYPE=""; GITEA_EXPORT_TYPE="";
# forgejo module
FORGEJO_GIT_USER="";
FORGEJO_WORKING_DIR="";
FORGEJO_TEMP_DIR="";
FORGEJO_BIN="";
FORGEJO_CONFIG="";
FORGEJO_EXPORT_TYPE="";
# zabbix module # zabbix module
ZABBIX_DUMP_BIN=""; ZABBIX_DUMP_BIN="";
ZABBIX_CONFIG=""; ZABBIX_CONFIG="";
+1 -1
View File
@@ -2,7 +2,7 @@
# rename to borg.backup.gitea.settings to use # rename to borg.backup.gitea.settings to use
GIT_USER=""; GITEA_GIT_USER="";
GITEA_WORKING_DIR=""; GITEA_WORKING_DIR="";
GITEA_TEMP_DIR=""; GITEA_TEMP_DIR="";
GITEA_BIN=""; GITEA_BIN="";
+6 -6
View File
@@ -26,10 +26,10 @@ BACKUP_LOCK_FILE="borg.backup.${MODULE}.lock";
. "${DIR}/borg.backup.functions.info.sh"; . "${DIR}/borg.backup.functions.info.sh";
# NOTE: because a tmp directory is needed it is more recommended # NOTE: because a tmp directory is needed it is more recommended
# to run this as root and have only the dump command itself run as GIT_USER # to run this as root and have only the dump command itself run as GITEA_GIT_USER
# set git user # set git user
if [ -z "${GIT_USER}" ]; then if [ -z "${GITEA_GIT_USER}" ]; then
GIT_USER="git"; GITEA_GIT_USER="git";
fi; fi;
# set GITEA_* if not set # set GITEA_* if not set
if [ -z "${GITEA_WORKING_DIR}" ]; then if [ -z "${GITEA_WORKING_DIR}" ]; then
@@ -81,7 +81,7 @@ BORG_CALL=$(echo "${_BORG_CALL}" | sed -e "s/##FILENAME##/${FILENAME}/" | sed -e
BORG_PRUNE=$(echo "${_BORG_PRUNE}" | sed -e "s/##BACKUP_SET_PREFIX##/${BACKUP_SET_PREFIX}/"); BORG_PRUNE=$(echo "${_BORG_PRUNE}" | sed -e "s/##BACKUP_SET_PREFIX##/${BACKUP_SET_PREFIX}/");
printf "${PRINTF_SUB_BLOCK}" "BACKUP: git data and database" "$(date +'%F %T')" "${MODULE}"; printf "${PRINTF_SUB_BLOCK}" "BACKUP: git data and database" "$(date +'%F %T')" "${MODULE}";
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "sudo -u ${GIT_USER} ${GITEA_BIN} dump -c ${GITEA_CONFIG} -w ${GITEA_WORKING_DIR} -t ${GITEA_TEMP_DIR} --type ${GITEA_EXPORT_TYPE} -L -f - | ${BORG_CALL}"; echo "sudo -u ${GITEA_GIT_USER} ${GITEA_BIN} dump -c ${GITEA_CONFIG} -w ${GITEA_WORKING_DIR} -t ${GITEA_TEMP_DIR} --type ${GITEA_EXPORT_TYPE} -L -f - | ${BORG_CALL}";
if [ -z "${ONE_TIME_TAG}" ]; then if [ -z "${ONE_TIME_TAG}" ]; then
echo "${BORG_PRUNE}"; echo "${BORG_PRUNE}";
fi; fi;
@@ -94,10 +94,10 @@ if [ ${DRYRUN} -eq 0 ]; then
if [ ! -d "${GITEA_WORKING_DIR}" ]; then if [ ! -d "${GITEA_WORKING_DIR}" ]; then
mkdir -p "${GITEA_WORKING_DIR}"; mkdir -p "${GITEA_WORKING_DIR}";
fi; fi;
chown -R ${GIT_USER}: "${GITEA_WORKING_DIR}"; chown -R ${GITEA_GIT_USER}: "${GITEA_WORKING_DIR}";
# this needs to be run in a folder that can be stat by git user # this needs to be run in a folder that can be stat by git user
cd "${GITEA_WORKING_DIR}" || exit 1; cd "${GITEA_WORKING_DIR}" || exit 1;
sudo -u ${GIT_USER} ${GITEA_BIN} dump -c ${GITEA_CONFIG} -w ${GITEA_WORKING_DIR} -t ${GITEA_TEMP_DIR} --type ${GITEA_EXPORT_TYPE} -L -f - | ${BORG_CALL}; sudo -u ${GITEA_GIT_USER} ${GITEA_BIN} dump -c ${GITEA_CONFIG} -w ${GITEA_WORKING_DIR} -t ${GITEA_TEMP_DIR} --type ${GITEA_EXPORT_TYPE} -L -f - | ${BORG_CALL};
) 2>&1 | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' # remove all ESC strings ) 2>&1 | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' # remove all ESC strings
fi; fi;
if [ -z "${ONE_TIME_TAG}" ]; then if [ -z "${ONE_TIME_TAG}" ]; then