initial import
This commit is contained in:
parent
3ed58b0021
commit
4b70c0023c
48 changed files with 1540 additions and 0 deletions
67
bin/teabak.sh
Executable file
67
bin/teabak.sh
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Create Gitea backups
|
||||
#
|
||||
# Prep
|
||||
# groupadd --system bkp
|
||||
# mkdir /var/xyzzy/backup
|
||||
# chmod 0750 /var/xyzzy/backup
|
||||
# chown git:bkp /var/xyzzy/backup
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
_VERSION="0.0.2"
|
||||
|
||||
BDTS=$(date +"%Y%m%d%H%M")
|
||||
BDIR="/var/xyzzy/backup"
|
||||
BFILE="${BDIR}/gitea-${BDTS}"
|
||||
|
||||
# gitea dump adds ".tar.xz" to the name dynamically
|
||||
BDMP="${BDIR}/gitea-${BDTS}.tar.xz"
|
||||
BGRP="bkp"
|
||||
|
||||
GCNF="/var/xyzzy/etc/gitea/app.ini"
|
||||
GBIN="/var/xyzzy/bin/gitea"
|
||||
GDATA="/var/xyzzy/gitea"
|
||||
|
||||
# healthchecks.io ping URL upon success, uses curl - "none" to disable
|
||||
HCPING="none"
|
||||
|
||||
# delete backups older than
|
||||
# see 'man find'; "+3" = 3*24h ago
|
||||
BDEL="-mtime +3"
|
||||
|
||||
# we need to chgrp/chmod to a foreign group
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
echo "Must run as root user"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# just to be sure
|
||||
cd "${BDIR}" || (echo "Cannot cd to ${BDIR}"; exit 1)
|
||||
|
||||
# runuser exits with the error code of the command
|
||||
_EC=1
|
||||
runuser -u git -- "${GBIN}" dump --config "${GCNF}" --tempdir "${BDIR}" \
|
||||
--work-path "${GDATA}" --skip-log --type tar.xz --file "${BFILE}"
|
||||
_EC=$?
|
||||
|
||||
# post processing
|
||||
if [[ $_EC -eq 0 ]]; then
|
||||
# gitea dump writes git:git 0600
|
||||
if [[ -f "${BDMP}" ]]; then
|
||||
chgrp "${BGRP}" "${BDMP}"
|
||||
chmod 0640 "${BDMP}"
|
||||
fi
|
||||
# delete older than BDEL backups
|
||||
# shellcheck disable=SC2086
|
||||
find "${BDIR}" -type f ${BDEL} \
|
||||
-regextype egrep \
|
||||
-regex '.*/gitea-[0-9]{12}\.tar\.xz' \
|
||||
-delete
|
||||
# ping healthchecks.io
|
||||
if [[ "${HCPING}" != "none" ]]; then
|
||||
curl -fsS -m 10 --retry 5 -o /dev/null "${HCPING}"
|
||||
fi
|
||||
fi
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue