Compare commits

...

20 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
Clemens Schwaighofer
0ce5442bcf Bug fix for update fix script
Add missing / for BASE_FOLDER if not set.

Dropped old file module borg name
2022-03-28 11:54:21 +09:00
5 changed files with 83 additions and 26 deletions

View File

@@ -8,13 +8,20 @@
# pgsql # pgsql
# zabbix-settings- # zabbix-settings-
export BORG_BASE_DIR="borg/"; # debug and dry run
DEBUG=0;
DRYRUN=0; DRYRUN=0;
PGSQL_SUDO=1;
# options
OPT_REMOTE="";
PGSQL_SUDO_USER="postgres";
# basic settings needed
TARGET_USER=""; TARGET_USER="";
TARGET_HOST=""; TARGET_HOST="";
TARGET_PORT=""; TARGET_PORT="";
TARGET_BORG_PATH=""; TARGET_BORG_PATH="";
TARGET_FOLDER=""; TARGET_FOLDER="";
# base folder
BASE_FOLDER="/usr/local/scripts/borg/"; BASE_FOLDER="/usr/local/scripts/borg/";
# those are the valid modules # those are the valid modules
MODULE_LIST="file gitea mysql pgsql zabbix" MODULE_LIST="file gitea mysql pgsql zabbix"
@@ -22,11 +29,14 @@ MODULE_LIST="file gitea mysql pgsql zabbix"
# basic options # basic options
# -c for config file override # -c for config file override
# -n for dry run test # -n for dry run test
while getopts ":c:nd" opt; do while getopts ":c:snd" opt; do
case "${opt}" in case "${opt}" in
c|config) c|config)
BASE_FOLDER=${OPTARG}; BASE_FOLDER=${OPTARG};
;; ;;
s|nosudo)
PGSQL_SUDO=0;
;;
d|debug) d|debug)
DEBUG=1; DEBUG=1;
;; ;;
@@ -44,25 +54,30 @@ while getopts ":c:nd" opt; do
esac; esac;
done; done;
[[ "${BASE_FOLDER}" != */ ]] && BASE_FOLDER=${BASE_FOLDER}"/";
if [ ! -d "${BASE_FOLDER}" ]; then if [ ! -d "${BASE_FOLDER}" ]; then
echo "Base folder not found: ${BASE_FOLDER}"; echo "Base folder not found: ${BASE_FOLDER}";
exit 1; exit 1;
fi; fi;
SETTINGS_FILE="borg.backup.settings"; SETTINGS_FILE="borg.backup.settings";
if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
echo "Could not find: ${BASE_FOLDER}${SETTINGS_FILE}";
exit;
fi;
. "${BASE_FOLDER}${SETTINGS_FILE}"; . "${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}; ORIG_BACKUPFILE=${BACKUP_FILE};
for MODULE in ${MODULE_LIST}; do for MODULE in ${MODULE_LIST}; do
echo "************* MODULE: ${MODULE}"; echo "************* MODULE: ${MODULE}";
BACKUP_FILE=${ORIG_BACKUPFILE}; BACKUP_FILE=${ORIG_BACKUPFILE};
# if [ -f "${BASE_FOLDER}${SETTINGS_FILE_SUB}" ]; then BACKUP_FILE=${BACKUP_FILE/.borg/-${MODULE,,}.borg};
# . "${BASE_FOLDER}${SETTINGS_FILE_SUB}";
# fi;
# SETTINGS_FILE_SUB=$(echo "${SETTINGS_FILE}" | sed -e "s/\.settings/\.${MODULE,,}\.settings/");
if [ "${MODULE,,}" != "file" ]; then
BACKUP_FILE=${BACKUP_FILE/.borg/-${MODULE,,}.borg};
fi;
TARGET_FOLDER=${TARGET_FOLDER%/} TARGET_FOLDER=${TARGET_FOLDER%/}
TARGET_FOLDER=${TARGET_FOLDER#/} TARGET_FOLDER=${TARGET_FOLDER#/}
# and add slash front and back and escape the path # and add slash front and back and escape the path
@@ -81,23 +96,43 @@ for MODULE in ${MODULE_LIST}; do
fi; fi;
# we dont allow special characters, so we don't need to special escape it # we dont allow special characters, so we don't need to special escape it
REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}"; 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}"; 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 while read i; do
# for gitea, zabbix we do not ADD we RENAME # for gitea, zabbix we do not ADD we RENAME
if [ "${MODILE}" = "gitea" ]; then if [ "${MODULE}" = "gitea" ]; then
target_name=$(echo $i | sed -e 's/gitea-/gitea,/'); # if just date, add gitea,
elif [ "${MODILE}" = "zabbix" ]; then # else rename
target_name=$(echo $i | sed -e 's/zabbix-settings-/zabbix,settings-/'); 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 else
target_name="${MODULE},${i}"; target_name="${MODULE},${i}";
fi; fi;
echo "- Rename from: ${i} to: ${target_name}"; echo "- Rename from: ${i} to: ${target_name}";
if [ ${DEBUG} -eq 1 ]; then 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; fi;
if [ ${DRYRUN} -eq 0 ]; then 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; fi;
done; done;
done; done;

View File

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

View File

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

View File

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

View File

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