Compare commits

...

19 Commits

Author SHA1 Message Date
Clemens Schwaighofer
86b0fa122a Add empty KEEP option for error with -T 2022-03-30 20:27:46 +09:00
Clemens Schwaighofer
32c320be27 Fix close call int compare 2022-03-30 14:48:52 +09:00
Clemens Schwaighofer
500ab01790 Bug fix for unset var in close call 2022-03-30 11:35:19 +09:00
Clemens Schwaighofer
ab58ab3ad0 Update postgresql module version 2022-03-30 09:48:37 +09:00
Clemens Schwaighofer
7767eb58df Override sudo for postgresql in upgrade script 2022-03-30 09:32:57 +09:00
Clemens Schwaighofer
38f467de96 PostgreSQL backup add schema or data dump in either default direction 2022-03-29 11:21:06 +09:00
Clemens Schwaighofer
8f91690f6a Upgrade script for zabbix fix if no zabbix prefix set at all 2022-03-29 10:53:59 +09:00
Clemens Schwaighofer
e860573e0c Fix upgrade script gitea module rename check 2022-03-29 10:28:26 +09:00
Clemens Schwaighofer
f990e86949 update script gitea block fix for missing module name 2022-03-29 10:25:12 +09:00
Clemens Schwaighofer
c929987900 variable name wrong for module check in upgrade script 2022-03-29 10:20:52 +09:00
Clemens Schwaighofer
6cb941818c Repository ID via config only works with local repos, drop that and keep repo ID in -i option only 2022-03-29 10:01:00 +09:00
Clemens Schwaighofer
edaf41f1af Repository ID info, borg command call via variable
The main info block gets Repository ID as info too (for cache/etc
folders check)

Missing borg command as variable for borg list command.
2022-03-29 09:57:12 +09:00
Clemens Schwaighofer
c7f2197614 add -E to sudo for upgrade script to keep enviroment variables for postgres run 2022-03-29 09:16:03 +09:00
Clemens Schwaighofer
88ea600e1d Mising remote path option in update script 2022-03-29 08:55:19 +09:00
Clemens Schwaighofer
f396032728 Add remote override path for borg backup in update script 2022-03-29 08:53:37 +09:00
Clemens Schwaighofer
18cbcea2b0 Archive print page make archive space 45 chars wide 2022-03-29 07:01:31 +09:00
Clemens Schwaighofer
a0537a24d3 PostgreSQL sudo for upgrade script 2022-03-29 06:46:23 +09:00
Clemens Schwaighofer
89897eb676 Add base BORG export variables in upgrade script 2022-03-29 06:36:06 +09:00
Clemens Schwaighofer
e1787fcfb3 Add missing DEBUG var setting for borg update wrapper script 2022-03-28 12:37:33 +09:00
5 changed files with 78 additions and 18 deletions

View File

@@ -8,13 +8,20 @@
# pgsql
# zabbix-settings-
export BORG_BASE_DIR="borg/";
# debug and dry run
DEBUG=0;
DRYRUN=0;
PGSQL_SUDO=1;
# options
OPT_REMOTE="";
PGSQL_SUDO_USER="postgres";
# basic settings needed
TARGET_USER="";
TARGET_HOST="";
TARGET_PORT="";
TARGET_BORG_PATH="";
TARGET_FOLDER="";
# base folder
BASE_FOLDER="/usr/local/scripts/borg/";
# those are the valid modules
MODULE_LIST="file gitea mysql pgsql zabbix"
@@ -22,10 +29,13 @@ MODULE_LIST="file gitea mysql pgsql zabbix"
# basic options
# -c for config file override
# -n for dry run test
while getopts ":c:nd" opt; do
while getopts ":c:snd" opt; do
case "${opt}" in
c|config)
BASE_FOLDER=${OPTARG}"/";
BASE_FOLDER=${OPTARG};
;;
s|nosudo)
PGSQL_SUDO=0;
;;
d|debug)
DEBUG=1;
@@ -55,6 +65,14 @@ if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
exit;
fi;
. "${BASE_FOLDER}${SETTINGS_FILE}";
if [ ! -z "${TARGET_BORG_PATH}" ]; then
OPT_REMOTE="--remote-path="$(printf "%q" "${TARGET_BORG_PATH}");
fi;
export BORG_BASE_DIR="${BASE_FOLDER}";
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="yes";
export BORG_RELOCATED_REPO_ACCESS_IS_OK="yes";
ORIG_BACKUPFILE=${BACKUP_FILE};
for MODULE in ${MODULE_LIST}; do
echo "************* MODULE: ${MODULE}";
@@ -78,23 +96,43 @@ for MODULE in ${MODULE_LIST}; do
fi;
# we dont allow special characters, so we don't need to special escape it
REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}";
# set sudo prefix for postgres so the cache folder stays the same
# if run as root then the foloders below have to have the user set to postgres again
# .config/borg/security/<postgresql repo id>
# .cache/borg/<postgresql repo id>
CMD_PREFIX="";
# only sudo to pgsql if sudo is set to true
if [ "${MODULE}" = "pgsql" ] && [ "${PGSQL_SUDO}" = "1" ]; then
CMD_PREFIX="sudo -E -u ${PGSQL_SUDO_USER} ";
fi;
echo "==== REPOSITORY: ${REPOSITORY}";
borg list --format '{archive}{NL}' ${REPOSITORY}|grep -v "${MODULE},"|
borg list ${OPT_REMOTE} --format '{archive}{NL}' ${REPOSITORY}|grep -v "${MODULE},"|
while read i; do
# for gitea, zabbix we do not ADD we RENAME
if [ "${MODILE}" = "gitea" ]; then
target_name=$(echo $i | sed -e 's/gitea-/gitea,/');
elif [ "${MODILE}" = "zabbix" ]; then
target_name=$(echo $i | sed -e 's/zabbix-settings-/zabbix,settings-/');
if [ "${MODULE}" = "gitea" ]; then
# if just date, add gitea,
# else rename
if [ ! -z "${i##gitea*}" ]; then
target_name="${MODULE},${i}";
else
target_name=$(echo $i | sed -e 's/gitea-/gitea,/');
fi;
elif [ "${MODULE}" = "zabbix" ]; then
# if zabbix is missing, prefix
if [ ! -z "${i##zabbix*}" ]; then
target_name="${MODULE},${i}";
else
target_name=$(echo $i | sed -e 's/zabbix-settings-/zabbix,settings-/');
fi;
else
target_name="${MODULE},${i}";
fi;
echo "- Rename from: ${i} to: ${target_name}";
if [ ${DEBUG} -eq 1 ]; then
echo "borg rename -p -v ${REPOSITORY}::${i} ${target_name}";
echo "${CMD_PREFIX}borg rename ${OPT_REMOTE} -p -v ${REPOSITORY}::${i} ${target_name}";
fi;
if [ ${DRYRUN} -eq 0 ]; then
borg rename -p -v ${REPOSITORY}::${i} ${target_name};
${CMD_PREFIX}borg rename ${OPT_REMOTE} -p -v ${REPOSITORY}::${i} ${target_name};
fi;
done;
done;

View File

@@ -133,7 +133,7 @@ if [ ! -w "${HOME}" ] || [ "${HOME}" = '/' ]; then
fi;
# keep optionfs (for files)
KEEP_OPTIONS=();
KEEP_OPTIONS=("");
# keep info string (for files)
KEEP_INFO="";
# override standard keep for tagged backups
@@ -304,14 +304,14 @@ fi;
# PRINT OUT current data, only do this if REPO exists
if [ ${PRINT} -eq 1 ]; then
echo "--- [PRINT : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
FORMAT="{archive} {comment:6} {start} - {end} [{id}] ({username}@{hostname}){NL}"
FORMAT="{archive:<45} {comment:6} {start} - {end} [{id}] ({username}@{hostname}){NL}"
# show command on debug or dry run
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} list ${OPT_REMOTE} --format ${FORMAT} ${REPOSITORY}";
fi;
# run info command if not a dry drun
if [ ${DRYRUN} -eq 0 ]; then
borg list ${OPT_REMOTE} --format "${FORMAT}" ${REPOSITORY} ;
${BORG_COMMAND} list ${OPT_REMOTE} --format "${FORMAT}" ${REPOSITORY} ;
fi;
if [ ${VERBOSE} -eq 1 ]; then
echo "";

View File

@@ -3,7 +3,7 @@
# unset borg settings
unset BORG_BASE_DIR BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK BORG_RELOCATED_REPO_ACCESS_IS_OK
# error abort without duration and error notice
if [ $1 == 1 ]; then
if [ $# -ge 1 ] && [ $1 -eq 1 ]; then
echo "=== [ERROR: $(date +'%F %T')] ==[${MODULE}]====================================>";
else
DURATION=$[ $(date +'%s')-$START ];

View File

@@ -19,7 +19,7 @@ function version {
}
# version for all general files
VERSION="4.1.1";
VERSION="4.2.3";
# borg version and borg comamnd
BORG_VERSION="";

View File

@@ -10,7 +10,7 @@
# set last edit date + time
MODULE="pgsql"
MODULE_VERSION="1.1.1";
MODULE_VERSION="1.2.0";
DIR="${BASH_SOURCE%/*}"
@@ -22,6 +22,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
INCLUDE_FILE="borg.backup.pgsql.include";
EXCLUDE_FILE="borg.backup.pgsql.exclude";
SCHEMA_ONLY_FILE="borg.backup.pgsql.schema-only";
DATA_ONLY_FILE="borg.backup.pgsql.data-only";
# init check file
BACKUP_INIT_CHECK="borg.backup.pgsql.init";
@@ -195,9 +196,13 @@ else
fi;
if [ ${include} -eq 1 ] && [ ${exclude} -eq 0 ]; then
# set dump type
SCHEMA_ONLY=''; # empty for all
schema_flag='data'; # or data
SCHEMA_ONLY='';
schema_flag=''; # schema or data
# schema exclude over data exclude, can't have both
if [ -s "${BASE_FOLDER}${SCHEMA_ONLY_FILE}" ]; then
# default is data dump
SCHEMA_ONLY='';
schema_flag='data';
while read schema_db; do
if [ "${db}" = "${schema_db}" ]; then
SCHEMA_ONLY='-s';
@@ -206,6 +211,23 @@ else
break;
fi;
done<"${BASE_FOLDER}${SCHEMA_ONLY_FILE}";
elif [ -s "${BASE_FOLDER}${DATA_ONLY_FILE}" ]; then
# default to schema, unless in data list
SCHEMA_ONLY='-s';
schema_flag='schema';
while read data_db; do
if [ "${db}" = "${data_db}" ]; then
SCHEMA_ONLY='';
schema_flag='data';
# skip out
break;
fi;
done<"${BASE_FOLDER}${DATA_ONLY_FILE}";
fi;
# if nothing is set, default to data
if [ -z "${schema_flag}" ]; then
SCHEMA_ONLY=''
schema_flag="data";
fi;
# Filename
# Database.User.Encoding.pgsql|data|schema-Version_Host_Port_YearMonthDay_HourMinute_Counter.Fromat(c).sql