Updated gitea to be more powerful and configurable

This commit is contained in:
Eric Renfro 2023-12-13 13:59:28 -05:00
parent 9650d84857
commit cb7bcebc27
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
3 changed files with 64 additions and 8 deletions

View file

@ -1,22 +1,74 @@
#!/bin/bash
restoreDir=/etc/restore
giteaDir="$restoreDir/gitea"
giteaDir="/var/backups/gitea"
scriptDir="$(dirname "$0")"
hook_before() {
readConfig() {
if [[ -r "${scriptDir}/../config/gitea_backup.cfg" ]]; then
source "${scriptDir}/../config/gitea_backup.cfg"
fi
}
check() {
if [[ -d "$giteaDir" ]]; then
rm -rf "$giteaDir" || exit 1
echo "Cleaning out old Gitea backups..."
rm -f "$giteaDir"/* || return 1
else
mkdir -p "$giteaDir" | return 1
fi
if [[ -n "$GITEA_BIN" ]]; then
if [[ -x "${GITEA_BIN}" ]]; then
echo "Found Gitea in $GITEA_BIN"
else
echo "FATAL: Cannot execute Gitea"
return 3
fi
else
if ! which gitea &>/dev/null; then
echo "Cannot find Gitea in PATH"
return 2
fi
if [[ -x "$(which gitea)" ]]; then
GITEA_BIN="$(which gitea)"
echo "Found Gita in $GITEA_PATH"
else
echo "FATAL: Cannot execute Gitea"
return 3
fi
fi
GITEA_CONFIG=${GITEA_CONFIG:-/etc/gitea/app.ini}
if [[ ! -r "$GITEA_CONFIG" ]]; then
echo "ERROR: Cannot read gitea app.ini in $GITEA_CONFIG"
return 4
fi
GITEA_USER=${GITEA_USER:-git}
GITEA_HOME=${GITEA_HOME:-$(getent passwd ${GITEA_USER} | cut -f6 -d:)}
if [[ ! -d "$GITEA_HOME" ]]; then
echo "ERROR: Cannot find Gitea home directory"
return 5
fi
}
runBackups() {
local backupDate
backupDate=$(date +"%Y-%m-%d")
giteaHome=$(getent passwd git | cut -f6 -d:)
sudo -u "$GITEA_USER" "${GITEA_BIN}" dump -c "${GITEA_CONFIG}" --type tar.xz --file - > "${giteaDir}/gitea-dump-${backupDate}.tar.xz"
}
mkdir -p "$giteaDir"
sudo -u git "${giteaHome}/bin/gitea" dump --type tar.xz --file - > "${giteaDir}/gitea-dump-${backupDate}.tar.xz"
hook_before() {
check || exit $?
runBackups || exit $?
}
hook_after() {
rm -rf "$giteaDir" || exit 1
:
}
hook_fail() {

View file

@ -5,8 +5,6 @@ mysqlDir="$restoreDir/mysql"
scriptDir="$(dirname "$0")"
function readConfig() {
local $config
if [[ -r "${scriptDir}/../config/mysql_backup.cfg" ]]; then
source "${scriptDir}/../config/mysql_backup.cfg"
fi

View file

@ -0,0 +1,6 @@
# This configuration file is used for providing configuration parameters to
# the gitea backup agent.
# GITEA_BIN Default: Found in PATH
# GITEA_CONFIG Default: /etc/gitea/app.ini
# GITEA_USER Default: git
# GITEA_HOME Default: Home Directory of GITEA_USER