Compare commits

...

17 Commits

Author SHA1 Message Date
Clemens Schwaighofer
297c745df7 Borg MySQL backup: fix version detection for MariaDB variant
This one is from Debian 13
2025-09-18 09:58:51 +09:00
Clemens Schwaighofer
a2bf6b3331 Readme update for zabbix backup settings change 2025-08-21 10:40:56 +09:00
Clemens Schwaighofer
07896af1ae Zabbix port override settings fix
use OPT var prefix for options
add missing init in functions init
2025-08-20 22:37:37 +09:00
Clemens Schwaighofer
8de971b922 Fix Zabbix db port override settings 2025-08-20 22:16:49 +09:00
Clemens Schwaighofer
e7699015c5 Allow override of zabbix db port 2025-08-20 22:14:19 +09:00
Clemens Schwaighofer
28dd6cb911 Merge branch 'master' into development 2024-09-04 10:38:58 +09:00
Clemens Schwaighofer
ab47692848 borg backup default settings file sample update 2024-09-04 10:37:36 +09:00
Clemens Schwaighofer
4267cb5b32 Bug Fix in gitea backup for temp dir check 2024-09-04 10:37:16 +09:00
Clemens Schwaighofer
f24daba195 Add shellcheckrc 2024-09-03 12:40:39 +09:00
Clemens Schwaighofer
98890b87f5 gitea module fix chown call
do not use ".", use ":" for username and group separator
2024-06-11 10:33:47 +09:00
Clemens Schwaighofer
a5bc90bb89 Text fix in PostgreSQL backup module 2024-06-10 09:52:06 +09:00
Clemens Schwaighofer
5af6a84d5f Mysql/PostgreSQL module version string update 2024-06-07 15:08:49 +09:00
Clemens Schwaighofer
14d71f3053 Naming update for full update info text 2024-06-07 15:08:20 +09:00
Clemens Schwaighofer
24d4fb694f Typo in postgresql module for full dump filename 2024-06-07 14:25:00 +09:00
Clemens Schwaighofer
f9fbbcc6de Version fix for master script 2024-06-07 09:57:21 +09:00
Clemens Schwaighofer
64e876a9a4 Fix run time output template string 2024-06-07 09:56:51 +09:00
Clemens Schwaighofer
694e54ca9c Missed out duration calculation in postgresql run time output 2024-06-07 09:16:52 +09:00
9 changed files with 37 additions and 18 deletions

2
.shellcheckrc Normal file
View File

@@ -0,0 +1,2 @@
shell=bash
external-sources=true

View File

@@ -273,6 +273,8 @@ There are no control files for gitea backup
## zabbix config backup settings
The `zabbix-dump` dump script must be installed from: <https://github.com/gullevek/zabbix-backup>
### zabbix Config Variables
| Variable | Default | Description |
@@ -281,6 +283,7 @@ There are no control files for gitea backup
| ZABBIX_DATABASE | '' | Must be set as either psql or mysql |
| ZABBIX_CONFIG | '' | if not set uses default location |
| ZABBIX_UNKNOWN_TABLES | '' | if set, changed to -f (force) |
| ZABBIX_DB_PORT | '' | if set, sets -P parameter on zabbix backup script to override auto get from zabbix server config |
### zabbix Control files

View File

@@ -24,7 +24,7 @@ function version {
}
# version for all general files
VERSION="4.4.0";
VERSION="4.5.4";
# borg version and borg comamnd
BORG_VERSION="";
@@ -95,8 +95,8 @@ PRINTF_INFO_STRING="%-23s: %s\n";
PRINTF_MASTER_BLOCK="=== [%-8s: %19s] ==[%s]====================================>\n";
PRINTF_SUB_BLOCK="|-- [%-8s: %19s] --[%s]------------------------------------>\n";
PRINTF_SUBEXT_BLOCK="|-- [%-8s: %s: %19s] --[%s]------------------------------------>\n";
PRINTF_DB_SUB_BLOCK=">>- [%-8s: %s] ==[%s]=======================>\n";
PRINTF_DB_RUN_TIME_SUB_BLOCK=">>- [%-8s: %s] ==[%s]==[Run time: %s:]=======================>\n";
PRINTF_DB_SUB_BLOCK="|>- [%-8s: %s] ==[%s]=======================>\n";
PRINTF_DB_RUN_TIME_SUB_BLOCK=">>- [%-8s: %s] ==[%s]==[Run time: %s]=======================>\n";
# opt flags
OPT_VERBOSE="";
OPT_PROGRESS="";
@@ -163,9 +163,11 @@ ZABBIX_DUMP_BIN="";
ZABBIX_CONFIG="";
ZABBIX_DATABASE="";
ZABBIX_UNKNOWN_TABLES="";
ZABBIX_DB_PORT="";
OPT_ZABBIX_DUMP="";
OPT_ZABBIX_CONFIG="";
OPT_ZABBIX_UNKNOWN_TABLES="";
OPT_ZABBIX_DB_PORT="";
# default keep 7 days, 4 weeks, 6 months, 1 year
# if set 0, ignore/off
# note that for last/hourly it is needed to create a different

View File

@@ -3,7 +3,7 @@
# Backup gitea database, all git folders and gitea settings
MODULE="gitea"
MODULE_VERSION="1.2.0";
MODULE_VERSION="1.2.1";
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
@@ -34,7 +34,7 @@ if [ -z "${GITEA_WORKING_DIR}" ]; then
GITEA_WORKING_DIR="/var/tmp/gitea/";
fi;
# general temp folder for temporary data storage, this is not working output folder
if [ -z "${GITEA_TEMP_DIR}"]; then
if [ -z "${GITEA_TEMP_DIR}" ]; then
GITEA_TEMP_DIR="/var/tmp";
fi;
if [ -z "${GITEA_BIN}" ]; then
@@ -91,7 +91,7 @@ if [ ${DRYRUN} -eq 0 ]; then
if [ ! -d "${GITEA_WORKING_DIR}" ]; then
mkdir -p "${GITEA_WORKING_DIR}";
fi;
chown -R ${GIT_USER}. "${GITEA_WORKING_DIR}";
chown -R ${GIT_USER}: "${GITEA_WORKING_DIR}";
# this needs to be run in a folder that can be stat by git user
cd "${GITEA_WORKING_DIR}";
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};

View File

@@ -7,7 +7,7 @@
# set last edit date + time
MODULE="mysql"
MODULE_VERSION="1.1.3";
MODULE_VERSION="1.1.4";
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
@@ -62,10 +62,11 @@ if [ -z "${_MYSQL_OK}" ]; then
fi;
# below is for file name only
# set DB_VERSION (Distrib n.n.n-type)
# NEW: mysql Ver 15.1 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
# OLD: mysql Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using EditLine wrapper
# OLD: mysql Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using EditLine wrapper
# NEW: mysql Ver 15.1 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
# VARIANT: mysql from 11.8.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
_DB_VERSION_TYPE=$("${MYSQL_CMD}" --version);
_DB_VERSION=$(echo "${_DB_VERSION_TYPE}" | sed 's/.*Distrib \([0-9]\{1,\}\.[0-9]\{1,\}\)\.[0-9]\{1,\}.*/\1/');
_DB_VERSION=$(echo "${_DB_VERSION_TYPE}" | sed 's/.*\(Distrib\|from\) \([0-9]\{1,\}\.[0-9]\{1,\}\)\.[0-9]\{1,\}.*/\2/');
DB_VERSION=$(echo "${_DB_VERSION}" | cut -d " " -f 1);
# temporary until correct type detection is set
DB_TYPE="mysql";
@@ -126,7 +127,7 @@ if [ ! -z "${DATABASE_FULL_DUMP}" ]; then
${BORG_PRUNE};
fi;
DURATION=$[ $(date +'%s')-$LOCAL_START ];
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "databases" "${MODULE}" "$(convert_time ${DURATION})";
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "all databases" "${MODULE}" "$(convert_time ${DURATION})";
else
${MYSQL_CMD} ${MYSQL_DB_CONFIG_PARAM} -B -N -e "show databases" |
while read db; do

View File

@@ -7,7 +7,7 @@
# set last edit date + time
MODULE="pgsql"
MODULE_VERSION="1.2.3";
MODULE_VERSION="1.2.7";
DIR="${BASH_SOURCE%/*}"
@@ -105,7 +105,7 @@ if [ ! -z "${DATABASE_FULL_DUMP}" ]; then
LOCAL_START=$(date +'%s');
printf "${PRINTF_SUBEXT_BLOCK}" "BACKUP" "all databases" "$(date +'%F %T')" "${MODULE}";
# Filename
FILENAME-"all.${DB_USER}.NONE.${schema_flag}-${DB_VERSION}_${DB_HOST}_${DB_PORT}.c.sql"
FILENAME="all.${DB_USER}.NONE.${schema_flag}-${DB_VERSION}_${DB_HOST}_${DB_PORT}.c.sql"
# backup set:
BACKUP_SET_PREFIX="${MODULE},all-";
BACKUP_SET_NAME="${ONE_TIME_TAG}${BACKUP_SET_PREFIX}${schema_flag}-${BACKUP_SET}";
@@ -134,7 +134,7 @@ if [ ! -z "${DATABASE_FULL_DUMP}" ]; then
${BORG_PRUNE};
fi;
DURATION=$[ $(date +'%s')-$LOCAL_START ];
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "databases" "${MODULE}" "$(convert_time ${DURATION})";
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "all databases" "${MODULE}" "$(convert_time ${DURATION})";
else
# dump globals first
db="pg_globals";
@@ -170,7 +170,8 @@ else
echo "Prune repository with keep${KEEP_INFO:1}";
${BORG_PRUNE};
fi;
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "BACKUP" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
DURATION=$[ $(date +'%s')-$LOCAL_START ];
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
# get list of tables
for owner_db in $(${PG_PSQL} -U ${DB_USER} ${CONN_DB_HOST} ${CONN_DB_PORT} -d template1 -t -A -F "," -X -q -c "SELECT pg_catalog.pg_get_userbyid(datdba) AS owner, datname, pg_catalog.pg_encoding_to_char(encoding) AS encoding FROM pg_catalog.pg_database WHERE datname "\!"~ 'template(0|1)' ORDER BY datname;"); do
@@ -271,6 +272,7 @@ else
else
echo "- [E] ${db}";
fi;
DURATION=$[ $(date +'%s')-$LOCAL_START ];
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
done;
fi;

View File

@@ -40,12 +40,15 @@ COMPACT_INTERVAL="";
# if set to 1 then every time the script runs
# any other value it means ever n days, eg 90 would be every 90 days
CHECK_INTERVAL="";
# default is %Y-%m-%d
# default is {now:%Y-%m-%d}
# todays date, if more than one per day add -%H%M for hour/minute
# it can also be "{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S.%f}"
BACKUP_SET="";
# prune times, how many are kept in each time frame
KEEP_LAST="";
KEEP_HOURS="";
KEEP_DAYS="";
KEEP_WEEKS="";
KEEP_MONTHS="";
KEEP_YEARS="";
KEEP_WITHIN="";

View File

@@ -15,3 +15,5 @@ ZABBIX_DATABASE="";
ZABBIX_CONFIG="";
# unknown tables, default ignore, is set to true, will force backup them
ZABBIX_UNKNOWN_TABLES="";
# overide zabbix db port read from zabbix config, if not set read from zabbix config
ZABBIX_DB_PORT="";

View File

@@ -37,6 +37,10 @@ fi;
if [ "${ZABBIX_DATABASE}" = "psql" ]; then
OPT_ZABBIX_DUMP="-C";
fi;
OPT_ZABBIX_DB_PORT="";
if [ -n "${ZABBIX_DB_PORT}" ]; then
OPT_ZABBIX_DB_PORT="-P ${ZABBIX_DB_PORT}";
fi;
if [ "${ZABBIX_DATABASE}" != "psql" ] && [ "${ZABBIX_DATABASE}" != "mysql" ]; then
echo "[! $(date +'%F %T')] Zabbix dump must have database set to either psql or mysql";
. "${DIR}/borg.backup.functions.close.sh" 1;
@@ -70,13 +74,13 @@ fi;
printf "${PRINTF_SUB_BLOCK}" "BACKUP: zabbix settings" "$(date +'%F %T')" "${MODULE}";
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "${ZABBIX_DUMP_BIN} -t ${ZABBIX_DATABASE} ${OPT_ZABBIX_UNKNOWN_TABLES} ${OPT_ZABBIX_DUMP} ${OPT_ZABBIX_CONFIG} -o - | ${BORG_CALL}"
echo "${ZABBIX_DUMP_BIN} ${OPT_ZABBIX_DB_PORT} -t ${ZABBIX_DATABASE} ${OPT_ZABBIX_UNKNOWN_TABLES} ${OPT_ZABBIX_DUMP} ${OPT_ZABBIX_CONFIG} -o - | ${BORG_CALL}"
if [ -z "${ONE_TIME_TAG}" ]; then
echo "${BORG_PRUNE}";
fi;
fi;
if [ ${DRYRUN} -eq 0 ]; then
${ZABBIX_DUMP_BIN} -t ${ZABBIX_DATABASE} ${OPT_ZABBIX_UNKNOWN_TABLES} ${OPT_ZABBIX_DUMP} ${OPT_ZABBIX_CONFIG} -o - | ${BORG_CALL};
${ZABBIX_DUMP_BIN} ${OPT_ZABBIX_DB_PORT} -t ${ZABBIX_DATABASE} ${OPT_ZABBIX_UNKNOWN_TABLES} ${OPT_ZABBIX_DUMP} ${OPT_ZABBIX_CONFIG} -o - | ${BORG_CALL};
fi;
if [ -z "${ONE_TIME_TAG}" ]; then
printf "${PRINTF_SUB_BLOCK}" "PRUNE" "$(date +'%F %T')" "${MODULE}";