Compare commits
17 Commits
acd5d369eb
...
v4.7.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32a75626bb | ||
|
|
12ff648504 | ||
|
|
69be76e34c | ||
|
|
4a95049d4f | ||
|
|
d0e96a82e0 | ||
|
|
e5c5df6013 | ||
|
|
6023fac636 | ||
|
|
9e0db8bae9 | ||
|
|
8a8de773df | ||
|
|
f41dd1b723 | ||
|
|
c5d88a64e1 | ||
|
|
943d1c551e | ||
|
|
45e1e29d22 | ||
|
|
1f8d38720c | ||
|
|
7e4dc8d500 | ||
|
|
297c745df7 | ||
|
|
a2bf6b3331 |
@@ -141,7 +141,7 @@ All below have default values if not set in the main settings file
|
|||||||
|
|
||||||
* COMPRESSION: zstd
|
* COMPRESSION: zstd
|
||||||
* COMPRESSION_LEVEL: 3
|
* COMPRESSION_LEVEL: 3
|
||||||
* ENCRYPTION: none
|
* ENCRYPTION: keyfile (with no password)
|
||||||
* FORCE_VERIFY: false
|
* FORCE_VERIFY: false
|
||||||
* COMPACT_INTERVAL: 1
|
* COMPACT_INTERVAL: 1
|
||||||
* CHECK_INTERVAL: none
|
* CHECK_INTERVAL: none
|
||||||
@@ -273,6 +273,8 @@ There are no control files for gitea backup
|
|||||||
|
|
||||||
## zabbix config backup settings
|
## zabbix config backup settings
|
||||||
|
|
||||||
|
The `zabbix-dump` dump script must be installed from: <https://github.com/gullevek/zabbix-backup>
|
||||||
|
|
||||||
### zabbix Config Variables
|
### zabbix Config Variables
|
||||||
|
|
||||||
| Variable | Default | Description |
|
| 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_DATABASE | '' | Must be set as either psql or mysql |
|
||||||
| ZABBIX_CONFIG | '' | if not set uses default location |
|
| ZABBIX_CONFIG | '' | if not set uses default location |
|
||||||
| ZABBIX_UNKNOWN_TABLES | '' | if set, changed to -f (force) |
|
| 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
|
### zabbix Control files
|
||||||
|
|
||||||
|
|||||||
@@ -31,16 +31,16 @@ MODULE_LIST="file gitea mysql pgsql zabbix"
|
|||||||
# -n for dry run test
|
# -n for dry run test
|
||||||
while getopts ":c:snd" 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
|
s|nosudo)
|
||||||
PGSQL_SUDO=0;
|
PGSQL_SUDO=0;
|
||||||
;;
|
;;
|
||||||
d) # debug
|
d|debug)
|
||||||
DEBUG=1;
|
DEBUG=1;
|
||||||
;;
|
;;
|
||||||
n) # dryrun
|
n|dryrun)
|
||||||
DRYRUN=1;
|
DRYRUN=1;
|
||||||
;;
|
;;
|
||||||
:)
|
:)
|
||||||
@@ -64,7 +64,6 @@ if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
|
|||||||
echo "Could not find: ${BASE_FOLDER}${SETTINGS_FILE}";
|
echo "Could not find: ${BASE_FOLDER}${SETTINGS_FILE}";
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
# shellcheck source="borg.backup.settings"
|
|
||||||
. "${BASE_FOLDER}${SETTINGS_FILE}";
|
. "${BASE_FOLDER}${SETTINGS_FILE}";
|
||||||
|
|
||||||
if [ -n "${TARGET_BORG_PATH}" ]; then
|
if [ -n "${TARGET_BORG_PATH}" ]; then
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
# Plain file backup
|
# Plain file backup
|
||||||
|
|
||||||
# set last edit date + time
|
# set last edit date + time
|
||||||
@@ -35,7 +38,7 @@ FOLDERS=();
|
|||||||
# this if for debug output with quoted folders
|
# this if for debug output with quoted folders
|
||||||
FOLDERS_Q=();
|
FOLDERS_Q=();
|
||||||
# include list
|
# include list
|
||||||
while read include_folder; do
|
while read -r include_folder; do
|
||||||
# strip any leading spaces from that folder
|
# strip any leading spaces from that folder
|
||||||
include_folder=$(echo "${include_folder}" | sed -e 's/^[ \t]*//');
|
include_folder=$(echo "${include_folder}" | sed -e 's/^[ \t]*//');
|
||||||
# check that those folders exist, warn on error,
|
# check that those folders exist, warn on error,
|
||||||
@@ -111,7 +114,7 @@ if [ -s "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
|||||||
if [ -n "${exclude_folder}" ]; then
|
if [ -n "${exclude_folder}" ]; then
|
||||||
# if it DOES NOT start with a / we assume free folder and add as is
|
# if it DOES NOT start with a / we assume free folder and add as is
|
||||||
if [[ "${exclude_folder}" != /* ]]; then
|
if [[ "${exclude_folder}" != /* ]]; then
|
||||||
echo "${exclude_folder}" >> ${TMP_EXCLUDE_FILE};
|
echo "${exclude_folder}" >> "${TMP_EXCLUDE_FILE}";
|
||||||
echo "+ [E] General exclude: '${exclude_folder}'";
|
echo "+ [E] General exclude: '${exclude_folder}'";
|
||||||
# if this is a glob, do a double check that the base folder actually exists (?)
|
# if this is a glob, do a double check that the base folder actually exists (?)
|
||||||
elif [[ "${exclude_folder}" =~ $REGEX_GLOB ]]; then
|
elif [[ "${exclude_folder}" =~ $REGEX_GLOB ]]; then
|
||||||
@@ -121,7 +124,7 @@ if [ -s "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
|||||||
if [ ! -d "${_exclude_folder}" ]; then
|
if [ ! -d "${_exclude_folder}" ]; then
|
||||||
echo "- [E] Exclude folder with glob '${exclude_folder}' does not exist or is not accessable";
|
echo "- [E] Exclude folder with glob '${exclude_folder}' does not exist or is not accessable";
|
||||||
else
|
else
|
||||||
echo "${exclude_folder}" >> ${TMP_EXCLUDE_FILE};
|
echo "${exclude_folder}" >> "${TMP_EXCLUDE_FILE}";
|
||||||
echo "+ [E] Exclude folder with glob '${exclude_folder}'";
|
echo "+ [E] Exclude folder with glob '${exclude_folder}'";
|
||||||
fi;
|
fi;
|
||||||
# do a warning for a possible invalid folder
|
# do a warning for a possible invalid folder
|
||||||
@@ -129,7 +132,7 @@ if [ -s "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
|||||||
elif [ ! -d "${exclude_folder}" ] && [ ! -e "${exclude_folder}" ]; then
|
elif [ ! -d "${exclude_folder}" ] && [ ! -e "${exclude_folder}" ]; then
|
||||||
echo "- [E] Exclude folder or file '${exclude_folder}' does not exist or is not accessable";
|
echo "- [E] Exclude folder or file '${exclude_folder}' does not exist or is not accessable";
|
||||||
else
|
else
|
||||||
echo "${exclude_folder}" >> ${TMP_EXCLUDE_FILE};
|
echo "${exclude_folder}" >> "${TMP_EXCLUDE_FILE}";
|
||||||
# if it is a folder, remove the last / or the symlink check will not work
|
# if it is a folder, remove the last / or the symlink check will not work
|
||||||
if [ -d "${exclude_folder}" ]; then
|
if [ -d "${exclude_folder}" ]; then
|
||||||
_exclude_folder=${exclude_folder%/*};
|
_exclude_folder=${exclude_folder%/*};
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
if [ -z "${MODULE}" ]; then
|
if [ -z "${MODULE}" ]; then
|
||||||
echo "Script cannot be run on its own";
|
echo "Script cannot be run on its own";
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -18,13 +21,13 @@ if [ $# -ge 1 ] && [ "$1" = "auto" ]; then
|
|||||||
# get current date timestmap
|
# get current date timestmap
|
||||||
CURRENT_DATE=$(date +%s);
|
CURRENT_DATE=$(date +%s);
|
||||||
# if =1 always ok
|
# if =1 always ok
|
||||||
if [ ${CHECK_INTERVAL} -eq 1 ]; then
|
if [ "${CHECK_INTERVAL}" -eq 1 ]; then
|
||||||
RUN_CHECK=1;
|
RUN_CHECK=1;
|
||||||
# always add verify data for automatic check
|
# always add verify data for automatic check
|
||||||
OPT_CHECK_VERIFY_DATA="--verify-data";
|
OPT_CHECK_VERIFY_DATA="--verify-data";
|
||||||
# set new check time here
|
# set new check time here
|
||||||
echo ${CURRENT_DATE} > "${BASE_FOLDER}${BACKUP_CHECK_FILE}";
|
echo "${CURRENT_DATE}" > "${BASE_FOLDER}${BACKUP_CHECK_FILE}";
|
||||||
elif [ ${CHECK_INTERVAL} -gt 1 ]; then
|
elif [ "${CHECK_INTERVAL}" -gt 1 ]; then
|
||||||
# else load last timestamp and check if today - last time stamp > days
|
# else load last timestamp and check if today - last time stamp > days
|
||||||
if [ -z "${LAST_CHECK_DATE}" ]; then
|
if [ -z "${LAST_CHECK_DATE}" ]; then
|
||||||
LAST_CHECK_DATE=$(cat "${BASE_FOLDER}${BACKUP_CHECK_FILE}" 2>/dev/null | sed -e 's/ //g');
|
LAST_CHECK_DATE=$(cat "${BASE_FOLDER}${BACKUP_CHECK_FILE}" 2>/dev/null | sed -e 's/ //g');
|
||||||
@@ -34,19 +37,19 @@ if [ $# -ge 1 ] && [ "$1" = "auto" ]; then
|
|||||||
LAST_CHECK_DATE=0;
|
LAST_CHECK_DATE=0;
|
||||||
fi;
|
fi;
|
||||||
# if the difference greate than check date, run. CHECK INTERVAL is in days
|
# if the difference greate than check date, run. CHECK INTERVAL is in days
|
||||||
if [ $(($CURRENT_DATE-$LAST_CHECK_DATE)) -ge $((${CHECK_INTERVAL}*86400)) ]; then
|
if [ $((CURRENT_DATE - LAST_CHECK_DATE)) -ge $((CHECK_INTERVAL * 86400)) ]; then
|
||||||
RUN_CHECK=1;
|
RUN_CHECK=1;
|
||||||
# always add verify data for automatic check
|
# always add verify data for automatic check
|
||||||
OPT_CHECK_VERIFY_DATA="--verify-data";
|
OPT_CHECK_VERIFY_DATA="--verify-data";
|
||||||
# set new check time here
|
# set new check time here
|
||||||
echo ${CURRENT_DATE} > "${BASE_FOLDER}${BACKUP_CHECK_FILE}";
|
echo "${CURRENT_DATE}" > "${BASE_FOLDER}${BACKUP_CHECK_FILE}";
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
elif [ ${CHECK} -eq 1 ]; then
|
elif [ "${CHECK}" -eq 1 ]; then
|
||||||
RUN_CHECK=1;
|
RUN_CHECK=1;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
if [ ${RUN_CHECK} -eq 1 ]; then
|
if [ "${RUN_CHECK}" -eq 1 ]; then
|
||||||
# run borg check command
|
# run borg check command
|
||||||
IFS=${_IFS};
|
IFS=${_IFS};
|
||||||
printf "${PRINTF_SUB_BLOCK}" "CHECK" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUB_BLOCK}" "CHECK" "$(date +'%F %T')" "${MODULE}";
|
||||||
@@ -58,21 +61,21 @@ if [ ${RUN_CHECK} -eq 1 ]; then
|
|||||||
OPT_GLOB="-P ${CHECK_PREFIX}";
|
OPT_GLOB="-P ${CHECK_PREFIX}";
|
||||||
fi;
|
fi;
|
||||||
# debug/dryrun
|
# debug/dryrun
|
||||||
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} check ${OPT_REMOTE} ${OPT_PROGRESS} ${OPT_CHECK_VERIFY_DATA} ${OPT_GLOB} ${REPOSITORY}";
|
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} ${OPT_CHECK_VERIFY_DATA} ${OPT_GLOB} ${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
|
||||||
# if glob add glob command directly
|
# if glob add glob command directly
|
||||||
if [[ "${CHECK_PREFIX}" =~ $REGEX_GLOB ]]; then
|
if [[ "${CHECK_PREFIX}" =~ $REGEX_GLOB ]]; then
|
||||||
${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} ${OPT_CHECK_VERIFY_DATA} -a "${CHECK_PREFIX}" ${REPOSITORY};
|
${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} ${OPT_CHECK_VERIFY_DATA} -a "${CHECK_PREFIX}" "${REPOSITORY}";
|
||||||
else
|
else
|
||||||
${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} ${OPT_CHECK_VERIFY_DATA} ${OPT_GLOB} ${REPOSITORY};
|
${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} ${OPT_CHECK_VERIFY_DATA} ${OPT_GLOB} "${REPOSITORY}";
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
# print additional info for use --repair command
|
# print additional info for use --repair command
|
||||||
# but only for manual checks
|
# but only for manual checks
|
||||||
if [ ${VERBOSE} -eq 1 ] && [ ${CHECK} -eq 1 ]; then
|
if [ "${VERBOSE}" -eq 1 ] && [ "${CHECK}" -eq 1 ]; then
|
||||||
echo "";
|
echo "";
|
||||||
echo "In case of needed repair: "
|
echo "In case of needed repair: "
|
||||||
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} --repair ${OPT_GLOB} ${REPOSITORY}";
|
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} check ${OPT_REMOTE} ${OPT_PROGRESS} --repair ${OPT_GLOB} ${REPOSITORY}";
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
if [ -z "${MODULE}" ]; then
|
if [ -z "${MODULE}" ]; then
|
||||||
echo "Script cannot be run on its own";
|
echo "Script cannot be run on its own";
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -16,7 +19,7 @@ if [ $# -ge 1 ] && [ "$1" = "1" ]; then
|
|||||||
printf "${PRINTF_MASTER_BLOCK}" "ERROR" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_MASTER_BLOCK}" "ERROR" "$(date +'%F %T')" "${MODULE}";
|
||||||
else
|
else
|
||||||
# running time calculation
|
# running time calculation
|
||||||
DURATION=$(( $(date +'%s')-START ));
|
DURATION=$(( $(date +'%s') - START ));
|
||||||
echo "=== [Run time: $(convert_time ${DURATION})]";
|
echo "=== [Run time: $(convert_time ${DURATION})]";
|
||||||
printf "${PRINTF_MASTER_BLOCK}" "END" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_MASTER_BLOCK}" "END" "$(date +'%F %T')" "${MODULE}";
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
if [ -z "${MODULE}" ]; then
|
if [ -z "${MODULE}" ]; then
|
||||||
echo "Script cannot be run on its own";
|
echo "Script cannot be run on its own";
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -32,7 +35,7 @@ if [ "$(version "$BORG_VERSION")" -ge "$(version "1.2.0")" ]; then
|
|||||||
LAST_COMPACT_DATE=0;
|
LAST_COMPACT_DATE=0;
|
||||||
fi;
|
fi;
|
||||||
# if the difference greate than compact date, run. COMPACT INTERVAL is in days
|
# if the difference greate than compact date, run. COMPACT INTERVAL is in days
|
||||||
if [ $((CURRENT_DATE-LAST_COMPACT_DATE)) -ge $((COMPACT_INTERVAL*86400)) ]; then
|
if [ $((CURRENT_DATE - LAST_COMPACT_DATE)) -ge $((COMPACT_INTERVAL * 86400)) ]; then
|
||||||
RUN_COMPACT=1;
|
RUN_COMPACT=1;
|
||||||
# set new compact time here
|
# set new compact time here
|
||||||
echo "${CURRENT_DATE}" > "${BASE_FOLDER}${BACKUP_COMPACT_FILE}";
|
echo "${CURRENT_DATE}" > "${BASE_FOLDER}${BACKUP_COMPACT_FILE}";
|
||||||
@@ -42,10 +45,9 @@ if [ "$(version "$BORG_VERSION")" -ge "$(version "1.2.0")" ]; then
|
|||||||
RUN_COMPACT=1;
|
RUN_COMPACT=1;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
if [ ${RUN_COMPACT} -eq 1 ]; then
|
if [ "${RUN_COMPACT}" -eq 1 ]; then
|
||||||
# reset to normal IFS, so command works here
|
# reset to normal IFS, so command works here
|
||||||
IFS=${_IFS};
|
IFS=${_IFS};
|
||||||
# shellcheck disable=SC2059
|
|
||||||
printf "${PRINTF_SUB_BLOCK}" "COMPACT" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUB_BLOCK}" "COMPACT" "$(date +'%F %T')" "${MODULE}";
|
||||||
BORG_COMPACT="${BORG_COMMAND} compact ${OPT_REMOTE} -v ${OPT_PROGRESS} ${REPOSITORY}";
|
BORG_COMPACT="${BORG_COMMAND} compact ${OPT_REMOTE} -v ${OPT_PROGRESS} ${REPOSITORY}";
|
||||||
if [ "${DEBUG}" -eq 1 ]; then
|
if [ "${DEBUG}" -eq 1 ]; then
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
if [ -z "${MODULE}" ]; then
|
if [ -z "${MODULE}" ]; then
|
||||||
echo "Script cannot be run on its own";
|
echo "Script cannot be run on its own";
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -13,10 +16,15 @@ if [ "${INFO}" -eq 1 ]; then
|
|||||||
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_COMMAND} info ${OPT_REMOTE} ${REPOSITORY};
|
${BORG_COMMAND} info ${OPT_REMOTE} "${REPOSITORY}";
|
||||||
|
if [ "${VERBOSE}" -eq 1 ]; then
|
||||||
|
# print key information
|
||||||
|
echo "------------------------------------------------------------------------------";
|
||||||
|
${BORG_COMMAND} key export "${REPOSITORY}";
|
||||||
|
fi;
|
||||||
fi;
|
fi;
|
||||||
if [ "${MODULE}" = "files" ]; then
|
if [ "${MODULE}" = "files" ]; then
|
||||||
if [ "$FOLDER_OK" -eq 1 ]; then
|
if [ "${FOLDER_OK}" -eq 1 ]; then
|
||||||
echo "--- [Run command]:";
|
echo "--- [Run command]:";
|
||||||
#IFS="#";
|
#IFS="#";
|
||||||
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${COMMAND} ${FOLDERS_Q[*]}";
|
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${COMMAND} ${FOLDERS_Q[*]}";
|
||||||
|
|||||||
@@ -5,16 +5,24 @@ if [ -z "${MODULE}" ]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
# E: inherit trap ERR
|
||||||
|
# T: DEBUG and RETURN traps are inherited
|
||||||
|
# u: unset variables ere error
|
||||||
set -ETu #-e -o pipefail
|
set -ETu #-e -o pipefail
|
||||||
trap cleanup SIGINT SIGTERM ERR
|
trap _catch ERR
|
||||||
|
trap _cleanup SIGINT SIGTERM
|
||||||
|
|
||||||
cleanup() {
|
_cleanup() {
|
||||||
# script cleanup here
|
# script cleanup here
|
||||||
echo "Some part of the script failed with an error: $? @LINE: $(caller)";
|
echo "Script abort: $? @LINE: $(caller)";
|
||||||
# unset exported vars
|
# unset exported vars
|
||||||
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;
|
||||||
# end trap
|
# end trap
|
||||||
trap - SIGINT SIGTERM ERR
|
trap - SIGINT SIGTERM
|
||||||
|
}
|
||||||
|
_catch() {
|
||||||
|
local last_exit_code=$?;
|
||||||
|
echo "Some part of the script failed with ERROR: $last_exit_code @COMMAND: '$BASH_COMMAND' @LINE: $(caller)" >&2;
|
||||||
}
|
}
|
||||||
# on exit unset any exported var
|
# on exit unset any exported var
|
||||||
trap "unset BORG_BASE_DIR BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK BORG_RELOCATED_REPO_ACCESS_IS_OK" EXIT;
|
trap "unset BORG_BASE_DIR BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK BORG_RELOCATED_REPO_ACCESS_IS_OK" EXIT;
|
||||||
@@ -24,7 +32,7 @@ function version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# version for all general files
|
# version for all general files
|
||||||
VERSION="4.5.4";
|
VERSION="4.7.2";
|
||||||
|
|
||||||
# borg version and borg comamnd
|
# borg version and borg comamnd
|
||||||
BORG_VERSION="";
|
BORG_VERSION="";
|
||||||
@@ -85,7 +93,7 @@ REGEX="";
|
|||||||
REGEX_COMMENT="^[\ \t]*#";
|
REGEX_COMMENT="^[\ \t]*#";
|
||||||
REGEX_GLOB='\*';
|
REGEX_GLOB='\*';
|
||||||
REGEX_NUMERIC="^[0-9]{1,2}$";
|
REGEX_NUMERIC="^[0-9]{1,2}$";
|
||||||
REGEX_ERROR="^Some part of the script failed with an error:";
|
REGEX_ERROR="^Some part of the script failed with ERROR:";
|
||||||
PRUNE_DEBUG="";
|
PRUNE_DEBUG="";
|
||||||
INIT_REPOSITORY=0;
|
INIT_REPOSITORY=0;
|
||||||
FOLDER_OK=0;
|
FOLDER_OK=0;
|
||||||
@@ -125,7 +133,7 @@ COMPRESSION_LEVEL="";
|
|||||||
SUB_COMPRESSION="";
|
SUB_COMPRESSION="";
|
||||||
SUB_COMPRESSION_LEVEL="";
|
SUB_COMPRESSION_LEVEL="";
|
||||||
# encryption settings
|
# encryption settings
|
||||||
DEFAULT_ENCRYPTION="none";
|
DEFAULT_ENCRYPTION="keyfile";
|
||||||
ENCRYPTION="";
|
ENCRYPTION="";
|
||||||
# force verify always
|
# force verify always
|
||||||
DEFAULT_FORCE_VERIFY="false";
|
DEFAULT_FORCE_VERIFY="false";
|
||||||
@@ -334,12 +342,12 @@ if [ ${VERIFY} -eq 1 ] || [ ${INIT} -eq 1 ] && [ ${INFO} -eq 1 ]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
# print -P cannot be run with -i/-C/-I together
|
# print -P cannot be run with -i/-C/-I together
|
||||||
if [ ${PRINT} -eq 1 ] && ([ ${INIT} -eq 1 ] || [ ${VERIFY} -eq 1 ] || [ ${INFO} -eq 1 ]); then
|
if [ ${PRINT} -eq 1 ] && { [ ${INIT} -eq 1 ] || [ ${VERIFY} -eq 1 ] || [ ${INFO} -eq 1 ]; }; then
|
||||||
echo "Cannot have -P print option and -i info, -V verify or -I initizalize option at the same time";
|
echo "Cannot have -P print option and -i info, -V verify or -I initizalize option at the same time";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
# if tag is set, you can't have init, verify, info, etc
|
# if tag is set, you can't have init, verify, info, etc
|
||||||
if [ -n "${ONE_TIME_TAG}" ] && ([ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${VERIFY} -eq 1 ] || [ ${INFO} -eq 1 ]); then
|
if [ -n "${ONE_TIME_TAG}" ] && { [ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${VERIFY} -eq 1 ] || [ ${INFO} -eq 1 ]; }; then
|
||||||
echo "Cannot have -T '${ONE_TIME_TAG}' option with -i info, -V verify, -I initialize or -P print option at the same time";
|
echo "Cannot have -T '${ONE_TIME_TAG}' option with -i info, -V verify, -I initialize or -P print option at the same time";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
@@ -348,18 +356,18 @@ if [ -n "${ONE_TIME_TAG}" ] && ! [[ "${ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+$ ]]; th
|
|||||||
echo "One time tag '${ONE_TIME_TAG}' must be alphanumeric with dashes and underscore only.";
|
echo "One time tag '${ONE_TIME_TAG}' must be alphanumeric with dashes and underscore only.";
|
||||||
exit 1;
|
exit 1;
|
||||||
elif [ -n "${ONE_TIME_TAG}" ]; then
|
elif [ -n "${ONE_TIME_TAG}" ]; then
|
||||||
# all ok, attach . at the end
|
# all ok, attach '.' at the end
|
||||||
ONE_TIME_TAG=${ONE_TIME_TAG}".";
|
ONE_TIME_TAG=${ONE_TIME_TAG}".";
|
||||||
fi;
|
fi;
|
||||||
# if -D, cannot be with -T, -i, -C, -I, -P
|
# if -D, cannot be with -T, -i, -C, -I, -P
|
||||||
if [ -n "${DELETE_ONE_TIME_TAG}" ] && ([ -n "${ONE_TIME_TAG}" ] || [ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${VERIFY} -eq 1 ] || [ ${INFO} -eq 1 ]); then
|
if [ -n "${DELETE_ONE_TIME_TAG}" ] && { [ -n "${ONE_TIME_TAG}" ] || [ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${VERIFY} -eq 1 ] || [ ${INFO} -eq 1 ]; }; then
|
||||||
echo "Cannot have -D delete tag option with -T one time tag, -i info, -V verify, -I initialize or -P print option at the same time";
|
echo "Cannot have -D delete tag option with -T one time tag, -i info, -V verify, -I initialize or -P print option at the same time";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
# -D also must be in valid backup set format
|
# -D also must be in valid backup set format
|
||||||
# ! [[ "${DELETE_ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+\.${MODULE},(\*-)?[0-9]{4}-[0-9]{2}-[0-9]{2}T\*$ ]]
|
# ! [[ "${DELETE_ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+\.${MODULE},(\*-)?[0-9]{4}-[0-9]{2}-[0-9]{2}T\*$ ]]
|
||||||
if [ -n "${DELETE_ONE_TIME_TAG}" ] && ! [[ "${DELETE_ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+\.${MODULE},([A-Za-z0-9_-]+-)?[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$ ]] && ! [[ "${DELETE_ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+\.${MODULE},(\*-)?[0-9]{4}-[0-9]{2}-[0-9]{2}T\*$ ]]; then
|
if [ -n "${DELETE_ONE_TIME_TAG}" ] && ! [[ "${DELETE_ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+\.${MODULE},([A-Za-z0-9_-]+-)?[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$ ]] && ! [[ "${DELETE_ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+\.${MODULE},(\*-)?[0-9]{4}-[0-9]{2}-[0-9]{2}T\*$ ]]; then
|
||||||
echo "Delete one time tag '${DELETE_ONE_TIME_TAG}' is in an invalid format. "
|
echo "Delete one time tag '${DELETE_ONE_TIME_TAG}' is in an invalid format."
|
||||||
echo "Please verify existing tags with -P option."
|
echo "Please verify existing tags with -P option."
|
||||||
echo "For a globing be sure it is in the format of: TAG.MODULE,*-YYYY-MM-DDT*";
|
echo "For a globing be sure it is in the format of: TAG.MODULE,*-YYYY-MM-DDT*";
|
||||||
echo "Note the dash (-) after the first *, also time (T) is a globa (*) must."
|
echo "Note the dash (-) after the first *, also time (T) is a globa (*) must."
|
||||||
@@ -599,11 +607,26 @@ fi;
|
|||||||
# if ENCRYPTION is empty or not in the valid list fall back to none
|
# if ENCRYPTION is empty or not in the valid list fall back to none
|
||||||
# NOTE This is currently set in default and doesn't need to be set on empty
|
# NOTE This is currently set in default and doesn't need to be set on empty
|
||||||
# only ivalid should be checked
|
# only ivalid should be checked
|
||||||
#if [ -z "${ENCRYPTION}" ]; then
|
if
|
||||||
# ENCRYPTION="none";
|
[ "${ENCRYPTION}" = "authenticated" ] ||
|
||||||
#else
|
[ "${ENCRYPTION}" = "repokey" ] ||
|
||||||
# TODO check for invalid encryption string
|
[ "${ENCRYPTION}" = "authenticated-blake2" ] ||
|
||||||
#fi;
|
[ "${ENCRYPTION}" = "repokey-blake2" ] ;
|
||||||
|
then
|
||||||
|
# if "authenticated" or "repokey" a password must be set
|
||||||
|
if [[ ! -v BORG_PASSPHRASE ]] && [[ ! -v BORG_PASSCOMMAND ]] && [[ ! -v BORG_PASSPHRASE_FD ]]; then
|
||||||
|
echo "Encryption method '${ENCRYPTION}' requires a BORG_PASSPHRASE, BORG_PASSCOMMAND or BORG_PASSPHRASE_FD to be set.";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
elif [ "${ENCRYPTION}" = "keyfile" ] || [ "${ENCRYPTION}" = "keyfile-blake2" ]; then
|
||||||
|
# if no password, set empty password
|
||||||
|
if [[ ! -v BORG_PASSPHRASE ]] && [[ ! -v BORG_PASSCOMMAND ]] && [[ ! -v BORG_PASSPHRASE_FD ]]; then
|
||||||
|
export BORG_PASSPHRASE="";
|
||||||
|
fi;
|
||||||
|
elif [ "${ENCRYPTION}" != "none" ]; then
|
||||||
|
echo "Encryption method '${ENCRYPTION}' is not valid.";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
## FUNCTIONS
|
## FUNCTIONS
|
||||||
|
|
||||||
@@ -618,22 +641,22 @@ function convert_time
|
|||||||
{
|
{
|
||||||
timestamp=${1};
|
timestamp=${1};
|
||||||
# round to four digits for ms
|
# round to four digits for ms
|
||||||
timestamp=$(printf "%1.4f" $timestamp);
|
timestamp=$(printf "%1.4f" "$timestamp");
|
||||||
# get the ms part and remove any leading 0
|
# get the ms part and remove any leading 0
|
||||||
ms=$(echo ${timestamp} | cut -d "." -f 2 | sed -e 's/^0*//');
|
ms=$(echo "${timestamp}" | cut -d "." -f 2 | sed -e 's/^0*//');
|
||||||
timestamp=$(echo ${timestamp} | cut -d "." -f 1);
|
timestamp=$(echo "${timestamp}" | cut -d "." -f 1);
|
||||||
timegroups=(86400 3600 60 1); # day, hour, min, sec
|
timegroups=(86400 3600 60 1); # day, hour, min, sec
|
||||||
timenames=("d" "h" "m" "s"); # day, hour, min, sec
|
timenames=("d" "h" "m" "s"); # day, hour, min, sec
|
||||||
output=( );
|
output=( );
|
||||||
time_string=;
|
time_string=;
|
||||||
for timeslice in ${timegroups[@]}; do
|
for timeslice in "${timegroups[@]}"; do
|
||||||
# floor for the division, push to output
|
# floor for the division, push to output
|
||||||
output[${#output[*]}]=$(awk "BEGIN {printf \"%d\", ${timestamp}/${timeslice}}");
|
output[${#output[*]}]=$(awk "BEGIN {printf \"%d\", ${timestamp}/${timeslice}}");
|
||||||
timestamp=$(awk "BEGIN {printf \"%d\", ${timestamp}%${timeslice}}");
|
timestamp=$(awk "BEGIN {printf \"%d\", ${timestamp}%${timeslice}}");
|
||||||
done;
|
done;
|
||||||
|
|
||||||
for ((i=0; i<${#output[@]}; i++)); do
|
for ((i=0; i<${#output[@]}; i++)); do
|
||||||
if [ ${output[$i]} -gt 0 ] || [ -n "$time_string" ]; then
|
if [ "${output[$i]}" -gt 0 ] || [ -n "$time_string" ]; then
|
||||||
if [ -n "${time_string}" ]; then
|
if [ -n "${time_string}" ]; then
|
||||||
time_string=${time_string}" ";
|
time_string=${time_string}" ";
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
if [ -z "${MODULE}" ]; then
|
if [ -z "${MODULE}" ]; then
|
||||||
echo "Script cannot be run on its own";
|
echo "Script cannot be run on its own";
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -10,7 +13,7 @@ START=$(date +'%s');
|
|||||||
# set init date, or today if not file is set
|
# set init date, or today if not file is set
|
||||||
BACKUP_INIT_DATE='';
|
BACKUP_INIT_DATE='';
|
||||||
if [ -f "${BASE_FOLDER}${BACKUP_INIT_FILE}" ]; then
|
if [ -f "${BASE_FOLDER}${BACKUP_INIT_FILE}" ]; then
|
||||||
BACKUP_INIT_DATE=$(printf '%(%c)T' $(cat "${BASE_FOLDER}${BACKUP_INIT_FILE}" 2>/dev/null));
|
BACKUP_INIT_DATE=$(printf '%(%c)T' "$(cat "${BASE_FOLDER}${BACKUP_INIT_FILE}" 2>/dev/null)");
|
||||||
fi;
|
fi;
|
||||||
# start logging from here
|
# start logging from here
|
||||||
exec &> >(tee -a "${LOG}");
|
exec &> >(tee -a "${LOG}");
|
||||||
@@ -36,7 +39,7 @@ if [ "$(version "$BORG_VERSION")" -ge "$(version "1.2.0")" ]; then
|
|||||||
if [ -f "${BASE_FOLDER}${BACKUP_COMPACT_FILE}" ]; then
|
if [ -f "${BASE_FOLDER}${BACKUP_COMPACT_FILE}" ]; then
|
||||||
LAST_COMPACT_DATE=$(cat "${BASE_FOLDER}${BACKUP_COMPACT_FILE}" 2>/dev/null);
|
LAST_COMPACT_DATE=$(cat "${BASE_FOLDER}${BACKUP_COMPACT_FILE}" 2>/dev/null);
|
||||||
printf "${PRINTF_INFO_STRING}" "Module last compact" \
|
printf "${PRINTF_INFO_STRING}" "Module last compact" \
|
||||||
"$(printf '%(%c)T' ${LAST_COMPACT_DATE}) ($(convert_time $(($(date +%s)-${LAST_COMPACT_DATE}))) ago)";
|
"$(printf '%(%c)T' "${LAST_COMPACT_DATE}") ($(convert_time $(($(date +%s) - LAST_COMPACT_DATE))) ago)";
|
||||||
else
|
else
|
||||||
printf "${PRINTF_INFO_STRING}" "Module last compact" "No compact run yet"
|
printf "${PRINTF_INFO_STRING}" "Module last compact" "No compact run yet"
|
||||||
fi;
|
fi;
|
||||||
@@ -49,7 +52,7 @@ if [ "${CHECK_INTERVAL##*[!0-9]*}" ]; then
|
|||||||
if [ -f "${BASE_FOLDER}${BACKUP_CHECK_FILE}" ]; then
|
if [ -f "${BASE_FOLDER}${BACKUP_CHECK_FILE}" ]; then
|
||||||
LAST_CHECK_DATE=$(cat "${BASE_FOLDER}${BACKUP_CHECK_FILE}" 2>/dev/null);
|
LAST_CHECK_DATE=$(cat "${BASE_FOLDER}${BACKUP_CHECK_FILE}" 2>/dev/null);
|
||||||
printf "${PRINTF_INFO_STRING}" "Module last check" \
|
printf "${PRINTF_INFO_STRING}" "Module last check" \
|
||||||
"$(printf '%(%c)T' ${LAST_CHECK_DATE}) ($(convert_time $(($(date +%s)-${LAST_CHECK_DATE}))) ago)";
|
"$(printf '%(%c)T' "${LAST_CHECK_DATE}") ($(convert_time $(($(date +%s) - LAST_CHECK_DATE))) ago)";
|
||||||
else
|
else
|
||||||
printf "${PRINTF_INFO_STRING}" "Module last check" "No check run yet";
|
printf "${PRINTF_INFO_STRING}" "Module last check" "No check run yet";
|
||||||
fi;
|
fi;
|
||||||
@@ -152,10 +155,10 @@ if [ -n "${COMPRESSION}" ]; then
|
|||||||
# fi;
|
# fi;
|
||||||
error_message="[! $(date +'%F %T')] Compression level for ${COMPRESSION} needs to be a numeric value between ${MIN_COMPRESSION} and ${MAX_COMPRESSION}: ${COMPRESSION_LEVEL}";
|
error_message="[! $(date +'%F %T')] Compression level for ${COMPRESSION} needs to be a numeric value between ${MIN_COMPRESSION} and ${MAX_COMPRESSION}: ${COMPRESSION_LEVEL}";
|
||||||
if ! [[ "${COMPRESSION_LEVEL}" =~ ${REGEX_NUMERIC} ]]; then
|
if ! [[ "${COMPRESSION_LEVEL}" =~ ${REGEX_NUMERIC} ]]; then
|
||||||
echo ${error_message};
|
echo "${error_message}";
|
||||||
exit 1;
|
exit 1;
|
||||||
elif [ ${COMPRESSION_LEVEL} -lt ${MIN_COMPRESSION} ] || [ ${COMPRESSION_LEVEL} -gt ${MAX_COMPRESSION} ]; then
|
elif [ "${COMPRESSION_LEVEL}" -lt "${MIN_COMPRESSION}" ] || [ "${COMPRESSION_LEVEL}" -gt "${MAX_COMPRESSION}" ]; then
|
||||||
echo ${error_message};
|
echo "${error_message}";
|
||||||
exit 1;
|
exit 1;
|
||||||
else
|
else
|
||||||
OPT_COMPRESSION=${OPT_COMPRESSION}","${COMPRESSION_LEVEL};
|
OPT_COMPRESSION=${OPT_COMPRESSION}","${COMPRESSION_LEVEL};
|
||||||
@@ -288,20 +291,18 @@ COMMAND_INFO="${COMMAND_EXPORT}${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY}"
|
|||||||
# if this is user@host, we need to use ssh command to verify if the file is there
|
# if this is user@host, we need to use ssh command to verify if the file is there
|
||||||
# else a normal verify is ok
|
# else a normal verify is ok
|
||||||
# unless explicit given, verify is skipped
|
# unless explicit given, verify is skipped
|
||||||
|
# MARK: VERIFY / INFO
|
||||||
if [ "${VERIFY}" -eq 1 ] || [ "${INIT}" -eq 1 ]; then
|
if [ "${VERIFY}" -eq 1 ] || [ "${INIT}" -eq 1 ]; then
|
||||||
printf "${PRINTF_SUB_BLOCK}" "VERIFY" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUB_BLOCK}" "VERIFY" "$(date +'%F %T')" "${MODULE}";
|
||||||
if [ -n "${TARGET_SERVER}" ]; then
|
if [ "${DEBUG}" -eq 1 ]; then
|
||||||
if [ "${DEBUG}" -eq 1 ]; then
|
echo "${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1 ";
|
||||||
echo "${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep \"Repository ID:\"";
|
fi;
|
||||||
fi;
|
# use borg info and verify if it returns "Repository ID:" in the first line
|
||||||
# use borg info and verify if it returns "Repository ID:" in the first line
|
REPO_VERIFY=$(${BORG_COMMAND} info ${OPT_REMOTE} "${REPOSITORY}" 2>&1);
|
||||||
REPO_VERIFY=$(${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep "Repository ID:");
|
__last_error=$?;
|
||||||
# this is currently a hack to work round the error code in borg info
|
# on any error in verify command force new INIT
|
||||||
# this checks if REPO_VERIFY holds this error message and then starts init
|
if [[ $__last_error -ne 0 ]]; then
|
||||||
if [[ -z "${REPO_VERIFY}" ]] || [[ "${REPO_VERIFY}" =~ ${REGEX_ERROR} ]]; then
|
echo "[!] Repository verify error: ${REPO_VERIFY}";
|
||||||
INIT_REPOSITORY=1;
|
|
||||||
fi;
|
|
||||||
elif [ ! -d "${REPOSITORY}" ]; then
|
|
||||||
INIT_REPOSITORY=1;
|
INIT_REPOSITORY=1;
|
||||||
fi;
|
fi;
|
||||||
# if verrify but no init and repo is there but init file is missing set it
|
# if verrify but no init and repo is there but init file is missing set it
|
||||||
@@ -325,14 +326,29 @@ if [ "${VERIFY}" -eq 1 ] || [ "${INIT}" -eq 1 ]; then
|
|||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
|
# MARK: INIT
|
||||||
if [ "${INIT}" -eq 1 ] && [ "${INIT_REPOSITORY}" -eq 1 ]; then
|
if [ "${INIT}" -eq 1 ] && [ "${INIT_REPOSITORY}" -eq 1 ]; then
|
||||||
|
|
||||||
printf "${PRINTF_SUB_BLOCK}" "INIT" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUB_BLOCK}" "INIT" "$(date +'%F %T')" "${MODULE}";
|
||||||
if [ "${DEBUG}" -eq 1 ] || [ "${DRYRUN}" -eq 1 ]; then
|
if [ "${DEBUG}" -eq 1 ] || [ "${DRYRUN}" -eq 1 ]; then
|
||||||
echo "${BORG_COMMAND} init ${OPT_REMOTE} -e ${ENCRYPTION} ${OPT_VERBOSE} ${REPOSITORY}";
|
echo "${BORG_COMMAND} init ${OPT_REMOTE} -e ${ENCRYPTION} ${OPT_VERBOSE} ${REPOSITORY}";
|
||||||
|
echo "${BORG_COMMAND} key export ${REPOSITORY}";
|
||||||
|
echo "${BORG_COMMAND} key export --paper ${REPOSITORY}";
|
||||||
fi
|
fi
|
||||||
if [ "${DRYRUN}" -eq 0 ]; then
|
if [ "${DRYRUN}" -eq 0 ]; then
|
||||||
# should trap and exit properly here
|
# should trap and exit properly here
|
||||||
${BORG_COMMAND} init ${OPT_REMOTE} -e ${ENCRYPTION} ${OPT_VERBOSE} ${REPOSITORY};
|
${BORG_COMMAND} init ${OPT_REMOTE} -e "${ENCRYPTION}" ${OPT_VERBOSE} "${REPOSITORY}";
|
||||||
|
# show the key file
|
||||||
|
if [ "${ENCRYPTION}" = "keyfile" ]; then
|
||||||
|
echo "--- [ENCRYPTION KEY] --[START]-------------------------------------------------->";
|
||||||
|
echo "Store the key and password in a safe place";
|
||||||
|
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";borg key export [--paper] ${REPOSITORY}";
|
||||||
|
echo "----[BORG KEY] -------------------------------->";
|
||||||
|
${BORG_COMMAND} key export "${REPOSITORY}";
|
||||||
|
echo "----[BORG KEY:paper] -------------------------->";
|
||||||
|
${BORG_COMMAND} key export --paper "${REPOSITORY}";
|
||||||
|
echo "--- [ENCRYPTION KEY] --[END ]-------------------------------------------------->";
|
||||||
|
fi;
|
||||||
# write init file
|
# write init file
|
||||||
date +%s > "${BASE_FOLDER}${BACKUP_INIT_FILE}";
|
date +%s > "${BASE_FOLDER}${BACKUP_INIT_FILE}";
|
||||||
echo "Repository initialized";
|
echo "Repository initialized";
|
||||||
@@ -343,7 +359,7 @@ if [ "${INIT}" -eq 1 ] && [ "${INIT_REPOSITORY}" -eq 1 ]; then
|
|||||||
# exit after init
|
# exit after init
|
||||||
exit;
|
exit;
|
||||||
elif [ "${INIT}" -eq 1 ] && [ "${INIT_REPOSITORY}" -eq 0 ]; then
|
elif [ "${INIT}" -eq 1 ] && [ "${INIT_REPOSITORY}" -eq 0 ]; then
|
||||||
echo "[! $(date +'%F %T')] Repository already initialized";
|
echo "[!] ($(date +'%F %T')) Repository already initialized";
|
||||||
echo "For more information run:"
|
echo "For more information run:"
|
||||||
echo "${COMMAND_INFO}";
|
echo "${COMMAND_INFO}";
|
||||||
. "${DIR}/borg.backup.functions.close.sh" 1;
|
. "${DIR}/borg.backup.functions.close.sh" 1;
|
||||||
@@ -352,12 +368,13 @@ fi;
|
|||||||
|
|
||||||
# verify for init file
|
# verify for init file
|
||||||
if [ ! -f "${BASE_FOLDER}${BACKUP_INIT_FILE}" ]; then
|
if [ ! -f "${BASE_FOLDER}${BACKUP_INIT_FILE}" ]; then
|
||||||
echo "[! $(date +'%F %T')] It seems the repository has never been initialized."
|
echo "[!] ($(date +'%F %T')) It seems the repository has never been initialized."
|
||||||
echo "Please run -I to initialize or if already initialzed run with -C for init update."
|
echo "Please run -I to initialize or if already initialzed run with -C for init update."
|
||||||
. "${DIR}/borg.backup.functions.close.sh" 1;
|
. "${DIR}/borg.backup.functions.close.sh" 1;
|
||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
# MARK: LIST / PRINT
|
||||||
# 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
|
||||||
printf "${PRINTF_SUB_BLOCK}" "PRINT" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUB_BLOCK}" "PRINT" "$(date +'%F %T')" "${MODULE}";
|
||||||
@@ -368,7 +385,7 @@ if [ "${PRINT}" -eq 1 ]; then
|
|||||||
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_COMMAND} 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 "";
|
||||||
@@ -434,7 +451,7 @@ if [ -n "${DELETE_ONE_TIME_TAG}" ]; then
|
|||||||
# not that compact only works on borg 1.2
|
# not that compact only works on borg 1.2
|
||||||
if [ "$(version "$BORG_VERSION")" -ge "$(version "1.2.0")" ]; then
|
if [ "$(version "$BORG_VERSION")" -ge "$(version "1.2.0")" ]; then
|
||||||
if [ "${DRYRUN}" -eq 0 ]; then
|
if [ "${DRYRUN}" -eq 0 ]; then
|
||||||
${BORG_COMMAND} compact ${OPT_REMOTE} ${REPOSITORY};
|
${BORG_COMMAND} compact ${OPT_REMOTE} "${REPOSITORY}";
|
||||||
fi;
|
fi;
|
||||||
if [ "${DEBUG}" -eq 1 ]; then
|
if [ "${DEBUG}" -eq 1 ]; then
|
||||||
echo "${BORG_COMMAND} compact ${OPT_REMOTE} ${REPOSITORY}";
|
echo "${BORG_COMMAND} compact ${OPT_REMOTE} ${REPOSITORY}";
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
# Backup gitea database, all git folders and gitea settings
|
# Backup gitea database, all git folders and gitea settings
|
||||||
|
|
||||||
MODULE="gitea"
|
MODULE="gitea"
|
||||||
MODULE_VERSION="1.2.1";
|
MODULE_VERSION="1.2.2";
|
||||||
|
|
||||||
DIR="${BASH_SOURCE%/*}"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||||
@@ -93,7 +96,7 @@ if [ ${DRYRUN} -eq 0 ]; then
|
|||||||
fi;
|
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
|
# this needs to be run in a folder that can be stat by git user
|
||||||
cd "${GITEA_WORKING_DIR}";
|
cd "${GITEA_WORKING_DIR}" || exit 1;
|
||||||
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};
|
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};
|
||||||
) 2>&1 | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' # remove all ESC strings
|
) 2>&1 | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' # remove all ESC strings
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
# Backup MySQL/MariaDB
|
# Backup MySQL/MariaDB
|
||||||
# default is per table dump, can be set to one full dump
|
# default is per table dump, can be set to one full dump
|
||||||
# config override set in borg.backup.mysql.settings
|
# config override set in borg.backup.mysql.settings
|
||||||
@@ -7,7 +10,7 @@
|
|||||||
|
|
||||||
# set last edit date + time
|
# set last edit date + time
|
||||||
MODULE="mysql"
|
MODULE="mysql"
|
||||||
MODULE_VERSION="1.1.4";
|
MODULE_VERSION="1.1.5";
|
||||||
|
|
||||||
DIR="${BASH_SOURCE%/*}"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||||
@@ -62,10 +65,11 @@ if [ -z "${_MYSQL_OK}" ]; then
|
|||||||
fi;
|
fi;
|
||||||
# below is for file name only
|
# below is for file name only
|
||||||
# set DB_VERSION (Distrib n.n.n-type)
|
# 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_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);
|
DB_VERSION=$(echo "${_DB_VERSION}" | cut -d " " -f 1);
|
||||||
# temporary until correct type detection is set
|
# temporary until correct type detection is set
|
||||||
DB_TYPE="mysql";
|
DB_TYPE="mysql";
|
||||||
@@ -125,11 +129,11 @@ if [ -n "${DATABASE_FULL_DUMP}" ]; then
|
|||||||
echo "Prune repository with keep${KEEP_INFO:1}";
|
echo "Prune repository with keep${KEEP_INFO:1}";
|
||||||
${BORG_PRUNE};
|
${BORG_PRUNE};
|
||||||
fi;
|
fi;
|
||||||
DURATION=$[ $(date +'%s')-$LOCAL_START ];
|
DURATION=$(( $(date +'%s') - LOCAL_START ));
|
||||||
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "all databases" "${MODULE}" "$(convert_time ${DURATION})";
|
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "all databases" "${MODULE}" "$(convert_time ${DURATION})";
|
||||||
else
|
else
|
||||||
${MYSQL_CMD} ${MYSQL_DB_CONFIG_PARAM} -B -N -e "show databases" |
|
${MYSQL_CMD} ${MYSQL_DB_CONFIG_PARAM} -B -N -e "show databases" |
|
||||||
while read db; do
|
while read -r db; do
|
||||||
LOCAL_START=$(date +'%s');
|
LOCAL_START=$(date +'%s');
|
||||||
printf "${PRINTF_DB_SUB_BLOCK}" "DB" "${db}" "${MODULE}";
|
printf "${PRINTF_DB_SUB_BLOCK}" "DB" "${db}" "${MODULE}";
|
||||||
printf "${PRINTF_SUBEXT_BLOCK}" "BACKUP" "${db}" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUBEXT_BLOCK}" "BACKUP" "${db}" "$(date +'%F %T')" "${MODULE}";
|
||||||
@@ -147,7 +151,7 @@ else
|
|||||||
fi;
|
fi;
|
||||||
exclude=0;
|
exclude=0;
|
||||||
if [ -f "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
if [ -f "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
||||||
while read excl_db; do
|
while read -r excl_db; do
|
||||||
if [ "${db}" = "${excl_db}" ]; then
|
if [ "${db}" = "${excl_db}" ]; then
|
||||||
exclude=1;
|
exclude=1;
|
||||||
break;
|
break;
|
||||||
@@ -177,7 +181,7 @@ else
|
|||||||
SCHEMA_ONLY=''; # empty for all
|
SCHEMA_ONLY=''; # empty for all
|
||||||
schema_flag='data'; # or data
|
schema_flag='data'; # or data
|
||||||
if [ -s "${BASE_FOLDER}${SCHEMA_ONLY_FILE}" ]; then
|
if [ -s "${BASE_FOLDER}${SCHEMA_ONLY_FILE}" ]; then
|
||||||
while read schema_db; do
|
while read -r schema_db; do
|
||||||
if [ "${db}" = "${schema_db}" ]; then
|
if [ "${db}" = "${schema_db}" ]; then
|
||||||
SCHEMA_ONLY='--no-data';
|
SCHEMA_ONLY='--no-data';
|
||||||
schema_flag='schema';
|
schema_flag='schema';
|
||||||
@@ -217,7 +221,7 @@ else
|
|||||||
else
|
else
|
||||||
echo "- [E] ${db}";
|
echo "- [E] ${db}";
|
||||||
fi;
|
fi;
|
||||||
DURATION=$[ $(date +'%s')-$LOCAL_START ];
|
DURATION=$(( $(date +'%s') - LOCAL_START ));
|
||||||
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
|
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
|
||||||
done;
|
done;
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
# Backup PostgreSQL
|
# Backup PostgreSQL
|
||||||
# default is per table dump, can be set to one full dump
|
# default is per table dump, can be set to one full dump
|
||||||
# config override set in borg.backup.pgsql.settings
|
# config override set in borg.backup.pgsql.settings
|
||||||
@@ -7,7 +10,7 @@
|
|||||||
|
|
||||||
# set last edit date + time
|
# set last edit date + time
|
||||||
MODULE="pgsql"
|
MODULE="pgsql"
|
||||||
MODULE_VERSION="1.2.7";
|
MODULE_VERSION="1.2.8";
|
||||||
|
|
||||||
|
|
||||||
DIR="${BASH_SOURCE%/*}"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
@@ -120,7 +123,7 @@ if [ -n "${DATABASE_FULL_DUMP}" ]; then
|
|||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
if [ ${DRYRUN} -eq 0 ]; then
|
if [ ${DRYRUN} -eq 0 ]; then
|
||||||
$(${PG_DUMPALL} -U ${DB_USER} ${CONN_DB_HOST} ${CONN_DB_PORT} ${SCHEMA_ONLY} -c | ${BORG_CALL});
|
${PG_DUMPALL} -U ${DB_USER} ${CONN_DB_HOST} ${CONN_DB_PORT} ${SCHEMA_ONLY} -c | ${BORG_CALL};
|
||||||
_backup_error=$?;
|
_backup_error=$?;
|
||||||
if [ $_backup_error -ne 0 ]; then
|
if [ $_backup_error -ne 0 ]; then
|
||||||
echo "[! $(date +'%F %T')] Backup creation failed for full dump with error code: ${_backup_error}";
|
echo "[! $(date +'%F %T')] Backup creation failed for full dump with error code: ${_backup_error}";
|
||||||
@@ -133,7 +136,7 @@ if [ -n "${DATABASE_FULL_DUMP}" ]; then
|
|||||||
echo "Prune repository with keep${KEEP_INFO:1}";
|
echo "Prune repository with keep${KEEP_INFO:1}";
|
||||||
${BORG_PRUNE};
|
${BORG_PRUNE};
|
||||||
fi;
|
fi;
|
||||||
DURATION=$[ $(date +'%s')-$LOCAL_START ];
|
DURATION=$(( $(date +'%s') - LOCAL_START ));
|
||||||
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "all databases" "${MODULE}" "$(convert_time ${DURATION})";
|
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "all databases" "${MODULE}" "$(convert_time ${DURATION})";
|
||||||
else
|
else
|
||||||
# dump globals first
|
# dump globals first
|
||||||
@@ -170,21 +173,21 @@ else
|
|||||||
echo "Prune repository with keep${KEEP_INFO:1}";
|
echo "Prune repository with keep${KEEP_INFO:1}";
|
||||||
${BORG_PRUNE};
|
${BORG_PRUNE};
|
||||||
fi;
|
fi;
|
||||||
DURATION=$[ $(date +'%s')-$LOCAL_START ];
|
DURATION=$(( $(date +'%s') - LOCAL_START ));
|
||||||
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
|
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
|
||||||
|
|
||||||
# get list of tables
|
# 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
|
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
|
||||||
LOCAL_START=$(date +'%s');
|
LOCAL_START=$(date +'%s');
|
||||||
# get the user who owns the DB too
|
# get the user who owns the DB too
|
||||||
owner=$(echo ${owner_db} | cut -d "," -f 1);
|
owner=$(echo "${owner_db}" | cut -d "," -f 1);
|
||||||
db=$(echo ${owner_db} | cut -d "," -f 2);
|
db=$(echo "${owner_db}" | cut -d "," -f 2);
|
||||||
encoding=$(echo ${owner_db} | cut -d "," -f 3);
|
encoding=$(echo "${owner_db}" | cut -d "," -f 3);
|
||||||
printf "${PRINTF_DB_SUB_BLOCK}" "DB" "${db}" "${MODULE}";
|
printf "${PRINTF_DB_SUB_BLOCK}" "DB" "${db}" "${MODULE}";
|
||||||
printf "${PRINTF_SUBEXT_BLOCK}" "BACKUP" "${db}" "$(date +'%F %T')" "${MODULE}";
|
printf "${PRINTF_SUBEXT_BLOCK}" "BACKUP" "${db}" "$(date +'%F %T')" "${MODULE}";
|
||||||
include=0;
|
include=0;
|
||||||
if [ -s "${BASE_FOLDER}${INCLUDE_FILE}" ]; then
|
if [ -s "${BASE_FOLDER}${INCLUDE_FILE}" ]; then
|
||||||
while read incl_db; do
|
while read -r incl_db; do
|
||||||
if [ "${db}" = "${incl_db}" ]; then
|
if [ "${db}" = "${incl_db}" ]; then
|
||||||
include=1;
|
include=1;
|
||||||
break;
|
break;
|
||||||
@@ -195,7 +198,7 @@ else
|
|||||||
fi;
|
fi;
|
||||||
exclude=0;
|
exclude=0;
|
||||||
if [ -f "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
if [ -f "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
|
||||||
while read excl_db; do
|
while read -r excl_db; do
|
||||||
if [ "${db}" = "${excl_db}" ]; then
|
if [ "${db}" = "${excl_db}" ]; then
|
||||||
exclude=1;
|
exclude=1;
|
||||||
break;
|
break;
|
||||||
@@ -211,7 +214,7 @@ else
|
|||||||
# default is data dump
|
# default is data dump
|
||||||
SCHEMA_ONLY='';
|
SCHEMA_ONLY='';
|
||||||
schema_flag='data';
|
schema_flag='data';
|
||||||
while read schema_db; do
|
while read -r schema_db; do
|
||||||
if [ "${db}" = "${schema_db}" ]; then
|
if [ "${db}" = "${schema_db}" ]; then
|
||||||
SCHEMA_ONLY='-s';
|
SCHEMA_ONLY='-s';
|
||||||
schema_flag='schema';
|
schema_flag='schema';
|
||||||
@@ -223,7 +226,7 @@ else
|
|||||||
# default to schema, unless in data list
|
# default to schema, unless in data list
|
||||||
SCHEMA_ONLY='-s';
|
SCHEMA_ONLY='-s';
|
||||||
schema_flag='schema';
|
schema_flag='schema';
|
||||||
while read data_db; do
|
while read -r data_db; do
|
||||||
if [ "${db}" = "${data_db}" ]; then
|
if [ "${db}" = "${data_db}" ]; then
|
||||||
SCHEMA_ONLY='';
|
SCHEMA_ONLY='';
|
||||||
schema_flag='data';
|
schema_flag='data';
|
||||||
@@ -256,7 +259,7 @@ else
|
|||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
if [ ${DRYRUN} -eq 0 ]; then
|
if [ ${DRYRUN} -eq 0 ]; then
|
||||||
${PG_DUMP} -U ${DB_USER} ${CONN_DB_HOST} ${CONN_DB_PORT} -c ${SCHEMA_ONLY} --format=c ${db} | ${BORG_CALL};
|
${PG_DUMP} -U ${DB_USER} ${CONN_DB_HOST} ${CONN_DB_PORT} -c ${SCHEMA_ONLY} --format=c "${db}" | ${BORG_CALL};
|
||||||
_backup_error=$?;
|
_backup_error=$?;
|
||||||
if [ $_backup_error -ne 0 ]; then
|
if [ $_backup_error -ne 0 ]; then
|
||||||
echo "[! $(date +'%F %T')] Backup creation failed for ${db} dump with error code: ${_backup_error}";
|
echo "[! $(date +'%F %T')] Backup creation failed for ${db} dump with error code: ${_backup_error}";
|
||||||
@@ -272,7 +275,7 @@ else
|
|||||||
else
|
else
|
||||||
echo "- [E] ${db}";
|
echo "- [E] ${db}";
|
||||||
fi;
|
fi;
|
||||||
DURATION=$[ $(date +'%s')-$LOCAL_START ];
|
DURATION=$(( $(date +'%s') - LOCAL_START ));
|
||||||
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
|
printf "${PRINTF_DB_RUN_TIME_SUB_BLOCK}" "DONE" "${db}" "${MODULE}" "$(convert_time ${DURATION})";
|
||||||
done;
|
done;
|
||||||
fi;
|
fi;
|
||||||
|
|||||||
@@ -13,20 +13,21 @@ TARGET_PORT="";
|
|||||||
TARGET_BORG_PATH="";
|
TARGET_BORG_PATH="";
|
||||||
# folder where the backup folder will be created
|
# folder where the backup folder will be created
|
||||||
TARGET_FOLDER="";
|
TARGET_FOLDER="";
|
||||||
# the backup file (folder) for this host $(hostname), must end with .borg
|
# the backup file (folder) for this backup, avoid dynamic variables in here, must end with .borg
|
||||||
BACKUP_FILE="";
|
BACKUP_FILE="";
|
||||||
# compression settings (empty for none, lz4, zstd, zlib, lzma)
|
# compression settings (none, lz4, zstd, zlib, lzma)
|
||||||
# level, if empty then default, else number between 0 and 9, or 1 to 22 for zstd
|
# empty is default zstd
|
||||||
# default is zstd, 3
|
|
||||||
COMPRESSION="";
|
COMPRESSION="";
|
||||||
|
# compression level, if empty then default 3, else number between 0 and 9, or 1 to 22 for zstd
|
||||||
COMPRESSION_LEVEL="";
|
COMPRESSION_LEVEL="";
|
||||||
# encryption settings:
|
# encryption settings:
|
||||||
# SHA-256: 'none', 'authenticated', 'repokey', 'keyfile'
|
# SHA-256: 'none', 'authenticated', 'repokey', 'keyfile'
|
||||||
# BLAKE2b: 'authenticated-blake2', 'repokey-blake2', 'keyfile-blake2'
|
# BLAKE2b: 'authenticated-blake2', 'repokey-blake2', 'keyfile-blake2'
|
||||||
# Note: none or empty does not encrypt
|
# Note: none does not encrypt and is not recommended
|
||||||
# Blank passwords allowed for only key (if used, use keyfile)
|
# Default is keyfile
|
||||||
|
# Blank passwords allowed for only keyfile, else passwords have to be set via BORG_PASSPHRASE or BORG_PASSCOMMAND
|
||||||
# See: http://borgbackup.readthedocs.io/en/stable/faq.html#how-can-i-specify-the-encryption-passphrase-programmatically
|
# See: http://borgbackup.readthedocs.io/en/stable/faq.html#how-can-i-specify-the-encryption-passphrase-programmatically
|
||||||
ENCRYPTION="";
|
ENCRYPTION=""
|
||||||
# force repository verify, default is off, set to true for verify on every run
|
# force repository verify, default is off, set to true for verify on every run
|
||||||
FORCE_VERIFY="";
|
FORCE_VERIFY="";
|
||||||
# compact interval, only if using borg 1.2 or higher
|
# compact interval, only if using borg 1.2 or higher
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# allow variables in printf format string
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
# Backup zabbix config and settings only
|
# Backup zabbix config and settings only
|
||||||
|
|
||||||
MODULE="zabbix"
|
MODULE="zabbix"
|
||||||
MODULE_VERSION="1.1.3";
|
MODULE_VERSION="1.1.4";
|
||||||
|
|
||||||
DIR="${BASH_SOURCE%/*}"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||||
@@ -52,7 +55,7 @@ if [ ! -f "${ZABBIX_DUMP_BIN}" ]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
# -i (ignore)/ -f (backup)
|
# -i (ignore)/ -f (backup)
|
||||||
if [ -n "${ZABBIX_UNKNOWN_TABLES}" ]; then
|
if [ ! -z "${ZABBIX_UNKNOWN_TABLES}" ]; then
|
||||||
OPT_ZABBIX_UNKNOWN_TABLES="-f";
|
OPT_ZABBIX_UNKNOWN_TABLES="-f";
|
||||||
else
|
else
|
||||||
OPT_ZABBIX_UNKNOWN_TABLES="-i";
|
OPT_ZABBIX_UNKNOWN_TABLES="-i";
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ if [ ${UMOUNT} -eq 0 ]; then
|
|||||||
. ${BASE_FOLDER}${SETTINGS_FILE}
|
. ${BASE_FOLDER}${SETTINGS_FILE}
|
||||||
# set the borg backup file base on the settings data
|
# set the borg backup file base on the settings data
|
||||||
# if we have user/host then we build the ssh command
|
# if we have user/host then we build the ssh command
|
||||||
if [ -n "${TARGET_USER}" ] && [ -n "${TARGET_HOST}" ]; then
|
if [ ! -z "${TARGET_USER}" ] && [ ! -z "${TARGET_HOST}" ]; then
|
||||||
TARGET_SERVER=${TARGET_USER}"@"${TARGET_HOST}":";
|
TARGET_SERVER=${TARGET_USER}"@"${TARGET_HOST}":";
|
||||||
fi;
|
fi;
|
||||||
REPOSITORY=${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE};
|
REPOSITORY=${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE};
|
||||||
@@ -90,7 +90,7 @@ if [ ${UMOUNT} -eq 0 ]; then
|
|||||||
|
|
||||||
# check that the repostiory exists
|
# check that the repostiory exists
|
||||||
REPOSITORY_OK=0;
|
REPOSITORY_OK=0;
|
||||||
if [ -n "${TARGET_SERVER}" ]; then
|
if [ ! -z "${TARGET_SERVER}" ]; then
|
||||||
# remove trailing : for this
|
# remove trailing : for this
|
||||||
TARGET_SERVER=${TARGET_SERVER/:};
|
TARGET_SERVER=${TARGET_SERVER/:};
|
||||||
# use ssh command to check remote existense
|
# use ssh command to check remote existense
|
||||||
|
|||||||
Reference in New Issue
Block a user