Add borg check and rename options

Because we added borg check functionality, some of the Options have been
renamed:
-C -> -V
-E -> -e (as it is a sub)

-C: check
-y: --verify-data
-p: prefix or glob for check

Internal variables with CHECK have been renamed or changed to VERIFY

Borg -C without any extra parameters is equal to borg check.
-y adds the --verify-data and -p is a mix of the -P and -a options. If
there is a "*" in the option then -a will be used, else -P

Note that repair command has to be run manually. Run -C with -v
(verbose) to see the repair command structure.

borg check can take a long time on very large repositories.
This commit is contained in:
2022-04-18 15:30:03 +09:00
parent b5ead9a2e1
commit 2ae05f5302
9 changed files with 190 additions and 103 deletions

View File

@@ -59,15 +59,24 @@ override the default borg executable found in path
### `-P` ### `-P`
print list of archives created print list of archives created
### `-C` ### `-V`
check if repository exists, if not abort verify if repository exists, if not abort
### `-E` ### `-e`
exit after check exit after check
### `-I` ### `-I`
init repository (must be run first) init repository (must be run first)
### `-C`
run `borg check` over given repository
#### `-y`
Add `--verify-data` to `borg check`. Only works with `-C`
#### `-p <prefix|glob>`
Only `borg check` data that has given prefix or glob (with *). Only works with `-C`
### `-i` ### `-i`
print out only info print out only info

View File

@@ -1,11 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Run -I first to initialize repository # Plain file backup
# There are no automatic repository checks unless -C is given
# set last edit date + time # set last edit date + time
MODULE="file"; MODULE="file";
MODULE_VERSION="1.2.0"; MODULE_VERSION="1.2.1";
DIR="${BASH_SOURCE%/*}" DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
@@ -14,10 +13,11 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
# include and exclude file # include and exclude file
INCLUDE_FILE="borg.backup.file.include"; INCLUDE_FILE="borg.backup.file.include";
EXCLUDE_FILE="borg.backup.file.exclude"; EXCLUDE_FILE="borg.backup.file.exclude";
# init check file # init verify file
BACKUP_INIT_CHECK="borg.backup.file.init"; BACKUP_INIT_VERIFY="borg.backup.file.init";
. "${DIR}/borg.backup.functions.check.sh"; # verify valid data
. "${DIR}/borg.backup.functions.verify.sh";
# exit if include file is missing # exit if include file is missing
if [ ! -f "${BASE_FOLDER}${INCLUDE_FILE}" ]; then if [ ! -f "${BASE_FOLDER}${INCLUDE_FILE}" ]; then

View File

@@ -19,7 +19,7 @@ function version {
} }
# version for all general files # version for all general files
VERSION="4.2.4"; VERSION="4.3.0";
# borg version and borg comamnd # borg version and borg comamnd
BORG_VERSION=""; BORG_VERSION="";
@@ -41,19 +41,23 @@ SETTINGS_FILE="borg.backup.settings";
# include files # include files
INCLUDE_FILE=""; INCLUDE_FILE="";
EXCLUDE_FILE=""; EXCLUDE_FILE="";
# backup folder initialzed check # backup folder initialzed verify
BACKUP_INIT_CHECK=""; BACKUP_INIT_VERIFY="";
BACKUP_INIT_DATE=""; BACKUP_INIT_DATE="";
# one time backup prefix tag, if set will use <tag>.<prefix>-Y-M-DTh:m:s type backup prefix # one time backup prefix tag, if set will use <tag>.<prefix>-Y-M-DTh:m:s type backup prefix
ONE_TIME_TAG=""; ONE_TIME_TAG="";
DELETE_ONE_TIME_TAG=""; DELETE_ONE_TIME_TAG="";
# debug/verbose # check command prefix/glob
CHECK_PREFIX="";
# debug/verbose/other flags
VERBOSE=0; VERBOSE=0;
LIST=0; LIST=0;
DEBUG=0; DEBUG=0;
DRYRUN=0; DRYRUN=0;
INFO=0; INFO=0;
VERIFY=0;
CHECK=0; CHECK=0;
CHECK_VERIFY_DATA=0;
INIT=0; INIT=0;
EXIT=0; EXIT=0;
PRINT=0; PRINT=0;
@@ -83,6 +87,7 @@ OPT_LIST="";
OPT_REMOTE=""; OPT_REMOTE="";
OPT_LOG_FOLDER=""; OPT_LOG_FOLDER="";
OPT_EXCLUDE=""; OPT_EXCLUDE="";
OPT_CHECK_VERIFY_DATA="";
# config variables (will be overwritten from .settings file) # config variables (will be overwritten from .settings file)
TARGET_USER=""; TARGET_USER="";
TARGET_HOST=""; TARGET_HOST="";
@@ -105,9 +110,10 @@ SUB_COMPRESSION_LEVEL="";
# encryption settings # encryption settings
DEFAULT_ENCRYPTION="none"; DEFAULT_ENCRYPTION="none";
ENCRYPTION=""; ENCRYPTION="";
# force check always # force verify always
DEFAULT_FORCE_CHECK="false"; DEFAULT_FORCE_VERIFY="false";
FORCE_CHECK=""; FORCE_VERIFY="";
FORCE_CHECK=""; # Deprecated name, use FORCE_VERIFY
BACKUP_SET=""; BACKUP_SET="";
SUB_BACKUP_SET=""; SUB_BACKUP_SET="";
# for database backup only # for database backup only
@@ -168,9 +174,12 @@ function usage()
-T <tag>: create one time stand alone backup prefixed with tag name -T <tag>: create one time stand alone backup prefixed with tag name
-D <tag backup set>: remove a tagged backup set, full name must be given -D <tag backup set>: remove a tagged backup set, full name must be given
-b <borg executable>: override default path -b <borg executable>: override default path
-C: run borg check if repository is ok
-y: in combination with -C: add --verify-data
-p <archive prefix|glob>: in combinatio with -C: only check archives with prefix or glob
-P: print list of archives created -P: print list of archives created
-C: check if repository exists, if not abort -V: verify if repository exists, if not abort
-E: exit after check -e: exit after verify
-I: init repository (must be run first) -I: init repository (must be run first)
-i: print out only info -i: print out only info
-l: list files during backup -l: list files during backup
@@ -186,7 +195,7 @@ function usage()
} }
# set options # set options
while getopts ":c:L:T:D:b:vldniCEIPh" opt; do while getopts ":c:L:T:D:b:p:vldniCVeIPyh" opt; do
case "${opt}" in case "${opt}" in
c|config) c|config)
BASE_FOLDER=${OPTARG}; BASE_FOLDER=${OPTARG};
@@ -204,17 +213,30 @@ while getopts ":c:L:T:D:b:vldniCEIPh" opt; do
OPT_BORG_EXECUTEABLE=${OPTARG}; OPT_BORG_EXECUTEABLE=${OPTARG};
;; ;;
C|Check) C|Check)
# will check if repo is there and abort if not # will run borg check
# alt modes --repository-only, --archives-only,
# add mode --verify-data
# note that --repair has to be called manually is it might damange backups
CHECK=1; CHECK=1;
;; ;;
E|Exit) y|Verify-Data)
# exit after check CHECK_VERIFY_DATA=1;
;;
p|prefix-glob)
CHECK_PREFIX=${OPTARG};
;;
V|Verify)
# will verify if repo is there and abort if not
VERIFY=1;
;;
e|exit)
# exit after verify or init (default off)
EXIT=1; EXIT=1;
;; ;;
I|Init) I|Init)
# will check if there is a repo and init it # will check if there is a repo and init it
# previoous this was default # previoous this was default
CHECK=1; VERIFY=1;
INIT=1; INIT=1;
;; ;;
P|Print) P|Print)
@@ -269,21 +291,21 @@ if [ ! -w "${BASE_FOLDER}" ]; then
fi; fi;
# info -i && -C/-I cannot be run together # info -i && -C/-I cannot be run together
if [ ${CHECK} -eq 1 ] || [ ${INIT} -eq 1 ] && [ ${INFO} -eq 1 ]; then if [ ${VERIFY} -eq 1 ] || [ ${INIT} -eq 1 ] && [ ${INFO} -eq 1 ]; then
echo "Cannot have -i info option and -C check or -I initialize option at the same time"; echo "Cannot have -i info option and -V verify or -I initialize option at the same time";
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 ] || [ ${CHECK} -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, -C check 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, check, info, etc # if tag is set, you can't have init, verify, info, etc
if [ ! -z "${ONE_TIME_TAG}" ] && ([ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${CHECK} -eq 1 ] || [ ${INFO} -eq 1 ]); then if [ ! -z "${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, -C check, -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;
# check only alphanumeric, no spaces, only underscore and dash # verify only alphanumeric, no spaces, only underscore and dash
if [ ! -z "${ONE_TIME_TAG}" ] && ! [[ "${ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+$ ]]; then if [ ! -z "${ONE_TIME_TAG}" ] && ! [[ "${ONE_TIME_TAG}" =~ ^[A-Za-z0-9_-]+$ ]]; then
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;
@@ -292,18 +314,34 @@ elif [ ! -z "${ONE_TIME_TAG}" ]; then
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 [ ! -z "${DELETE_ONE_TIME_TAG}" ] && ([ ! -z "${ONE_TIME_TAG}" ] || [ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${CHECK} -eq 1 ] || [ ${INFO} -eq 1 ]); then if [ ! -z "${DELETE_ONE_TIME_TAG}" ] && ([ ! -z "${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, -C check, -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 [ ! -z "${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 [ ! -z "${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. Please check existing tags with -P option." echo "Delete one time tag '${DELETE_ONE_TIME_TAG}' is in an invalid format. "
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."
exit 1; exit 1;
fi; fi;
# -y can't be set without -C
if [ ${CHECK_VERIFY_DATA} -eq 1 ] && [ ${CHECK} -eq 0 ]; then
echo "-y (verify-data) cannot be run without -C (Check) option";
exit 1;
fi;
# -p can't be set without -C
if [ ! -z "${CHECK_PREFIX}" ] && [ ${CHECK} -eq 0 ]; then
echo "-p (pattern|glob) for check cannot be run without -C (Check) options";
exit 1;
fi;
# can't have -e if VERIFY or INIT is not set
if [ ${EXIT} -eq 1 ] && [ ${VERIFY} -eq 0 ] && [ ${INIT} -eq 0 ]; then
echo "-e (exit) can only be used with -V (Verify) and -I (Init)";
exit 1;
fi;
# verbose & progress # verbose & progress
if [ ${VERBOSE} -eq 1 ]; then if [ ${VERBOSE} -eq 1 ]; then
@@ -320,6 +358,9 @@ if [ ${DRYRUN} -eq 1 ]; then
else else
DRY_RUN_STATS="-s"; DRY_RUN_STATS="-s";
fi; fi;
if [ ${CHECK_VERIFY_DATA} -eq 1 ] && [ ${CHECK} -eq 1 ]; then
OPT_CHECK_VERIFY_DATA="--verify-data";
fi;
# read config file # read config file
. "${BASE_FOLDER}${SETTINGS_FILE}"; . "${BASE_FOLDER}${SETTINGS_FILE}";
@@ -339,12 +380,12 @@ elif [ ! -z "${BORG_EXECUTEABLE}" ]; then
exit; exit;
fi; fi;
elif ! command -v borg &> /dev/null; then elif ! command -v borg &> /dev/null; then
echo "borg backup seems not to be installed, please check paths"; echo "borg backup seems not to be installed, please verify paths";
exit; exit;
fi; fi;
# check that this is a borg executable, no detail check # verify that this is a borg executable, no detail check
_BORG_COMMAND_CHECK=$(${BORG_COMMAND} -V | grep "borg"); _BORG_COMMAND_VERIFY=$(${BORG_COMMAND} -V | grep "borg");
if [[ "${_BORG_COMMAND_CHECK}" =~ ${REGEX_ERROR} ]]; then if [[ "${_BORG_COMMAND_VERIFY}" =~ ${REGEX_ERROR} ]]; then
echo "Cannot extract borg info from command, is this a valid borg executable?: ${BORG_COMMAND}"; echo "Cannot extract borg info from command, is this a valid borg executable?: ${BORG_COMMAND}";
exit; exit;
fi; fi;
@@ -363,8 +404,12 @@ fi;
if [ -z "${ENCRYPTION}" ]; then if [ -z "${ENCRYPTION}" ]; then
ENCRYPTION="${DEFAULT_ENCRYPTION}"; ENCRYPTION="${DEFAULT_ENCRYPTION}";
fi; fi;
if [ -z "${FORCE_CHECK}" ]; then # deprecated name FORCE_CHECK, use FORCE_VERIFY instead
FORCE_CHECK="${DEFAULT_FORCE_CHECK}"; if [ ! -z "${FORCE_CHECK}" ]; then
FORCE_VERIFY="${FORCE_CHECK}";
fi;
if [ -z "${FORCE_VERIFY}" ]; then
FORCE_VERIFY="${DEFAULT_FORCE_VERIFY}";
fi; fi;
if [ -z "${KEEP_LAST}" ]; then if [ -z "${KEEP_LAST}" ]; then
KEEP_LAST="${DEFAULT_KEEP_LAST}"; KEEP_LAST="${DEFAULT_KEEP_LAST}";

View File

@@ -3,7 +3,7 @@
# start time in seconds # start time in seconds
START=$(date +'%s'); 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=$(printf '%(%c)T' $(cat "${BASE_FOLDER}${BACKUP_INIT_CHECK}" 2>/dev/null)); BACKUP_INIT_DATE=$(printf '%(%c)T' $(cat "${BASE_FOLDER}${BACKUP_INIT_VERIFY}" 2>/dev/null));
# start logging from here # start logging from here
exec &> >(tee -a "${LOG}"); exec &> >(tee -a "${LOG}");
echo "=== [START : $(date +'%F %T')] ==[${MODULE}]====================================>"; echo "=== [START : $(date +'%F %T')] ==[${MODULE}]====================================>";
@@ -21,12 +21,12 @@ echo "Base folder : ${BASE_FOLDER}";
# Module init date (when init file was writen) # Module init date (when init file was writen)
echo "Module init date: ${BACKUP_INIT_DATE}"; echo "Module init date: ${BACKUP_INIT_DATE}";
# if force check is true set CHECK to 1unless INFO is 1 # if force verify is true set VERIFY to 1 unless INFO is 1
# Needs bash 4.0 at lesat for this # Needs bash 4.0 at lesat for this
if [ "${FORCE_CHECK,,}" = "true" ] && [ ${INFO} -eq 0 ]; then if [ "${FORCE_VERIFY,,}" = "true" ] && [ ${INFO} -eq 0 ]; then
CHECK=1; VERIFY=1;
if [ ${DEBUG} -eq 1 ]; then if [ ${DEBUG} -eq 1 ]; then
echo "Force repository check"; echo "Force repository verify";
fi; fi;
fi; fi;
@@ -84,7 +84,7 @@ fi;
REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}"; REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}";
echo "Repository : ${REPOSITORY}"; echo "Repository : ${REPOSITORY}";
# check compression if given is valid and check compression level is valid if given # check if given compression name and level are valid
OPT_COMPRESSION=''; OPT_COMPRESSION='';
if [ ! -z "${COMPRESSION}" ]; then if [ ! -z "${COMPRESSION}" ]; then
# valid compression # valid compression
@@ -150,7 +150,7 @@ if [ ! -z "${ONE_TIME_TAG}" ]; then
else else
# build options and info string, # build options and info string,
# also flag BACKUP_SET check if hourly is set # also flag BACKUP_SET check if hourly is set
BACKUP_SET_CHECK=0; BACKUP_SET_VERIFY=0;
if [ ${KEEP_LAST} -gt 0 ]; then if [ ${KEEP_LAST} -gt 0 ]; then
KEEP_OPTIONS+=("--keep-last=${KEEP_LAST}"); KEEP_OPTIONS+=("--keep-last=${KEEP_LAST}");
KEEP_INFO="${KEEP_INFO}, last: ${KEEP_LAST}"; KEEP_INFO="${KEEP_INFO}, last: ${KEEP_LAST}";
@@ -158,7 +158,7 @@ else
if [ ${KEEP_HOURS} -gt 0 ]; then if [ ${KEEP_HOURS} -gt 0 ]; then
KEEP_OPTIONS+=("--keep-hourly=${KEEP_HOURS}"); KEEP_OPTIONS+=("--keep-hourly=${KEEP_HOURS}");
KEEP_INFO="${KEEP_INFO}, hourly: ${KEEP_HOURS}"; KEEP_INFO="${KEEP_INFO}, hourly: ${KEEP_HOURS}";
BACKUP_SET_CHECK=1; BACKUP_SET_VERIFY=1;
fi; fi;
if [ ${KEEP_DAYS} -gt 0 ]; then if [ ${KEEP_DAYS} -gt 0 ]; then
KEEP_OPTIONS+=("--keep-daily=${KEEP_DAYS}"); KEEP_OPTIONS+=("--keep-daily=${KEEP_DAYS}");
@@ -182,7 +182,7 @@ else
KEEP_OPTIONS+=("--keep-within=${KEEP_WITHIN}"); KEEP_OPTIONS+=("--keep-within=${KEEP_WITHIN}");
KEEP_INFO="${KEEP_INFO}, within: ${KEEP_WITHIN}"; KEEP_INFO="${KEEP_INFO}, within: ${KEEP_WITHIN}";
if [[ "${KEEP_WITHIN}" == *"H"* ]]; then if [[ "${KEEP_WITHIN}" == *"H"* ]]; then
BACKUP_SET_CHECK=1; BACKUP_SET_VERIFY=1;
fi; fi;
else else
echo "[! $(date +'%F %T')] KEEP_WITHIN has invalid string."; echo "[! $(date +'%F %T')] KEEP_WITHIN has invalid string.";
@@ -200,7 +200,7 @@ else
fi; fi;
# backup set check, and there is no hour entry (%H) in the archive string # backup set check, and there is no hour entry (%H) in the archive string
# we add T%H:%M:%S in this case, before the last } # we add T%H:%M:%S in this case, before the last }
if [ ${BACKUP_SET_CHECK} -eq 1 ] && [[ "${BACKUP_SET}" != *"%H"* ]]; then if [ ${BACKUP_SET_VERIFY} -eq 1 ] && [[ "${BACKUP_SET}" != *"%H"* ]]; then
BACKUP_SET=$(echo "${BACKUP_SET}" | sed -e "s/}/T%H:%M:%S}/"); BACKUP_SET=$(echo "${BACKUP_SET}" | sed -e "s/}/T%H:%M:%S}/");
fi; fi;
fi; fi;
@@ -235,39 +235,39 @@ fi;
COMMAND_EXPORT="export BORG_BASE_DIR=\"${BASE_FOLDER}\";" COMMAND_EXPORT="export BORG_BASE_DIR=\"${BASE_FOLDER}\";"
COMMAND_INFO="${COMMAND_EXPORT}${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY}"; COMMAND_INFO="${COMMAND_EXPORT}${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY}";
# if the is not there, call init to create it # if the is not there, call init to create it
# if this is user@host, we need to use ssh command to check 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 check is ok # else a normal verify is ok
# unless explicit given, check is skipped # unless explicit given, verify is skipped
if [ ${CHECK} -eq 1 ] || [ ${INIT} -eq 1 ]; then if [ ${VERIFY} -eq 1 ] || [ ${INIT} -eq 1 ]; then
echo "--- [CHECK : $(date +'%F %T')] --[${MODULE}]------------------------------------>"; echo "--- [VERIFY: $(date +'%F %T')] --[${MODULE}]------------------------------------>";
if [ ! -z "${TARGET_SERVER}" ]; then if [ ! -z "${TARGET_SERVER}" ]; then
if [ ${DEBUG} -eq 1 ]; then if [ ${DEBUG} -eq 1 ]; then
echo "${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep \"Repository ID:\""; echo "${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep \"Repository ID:\"";
fi; fi;
# use borg info and check if it returns "Repository ID:" in the first line # use borg info and verify if it returns "Repository ID:" in the first line
REPO_CHECK=$(${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep "Repository ID:"); REPO_VERIFY=$(${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep "Repository ID:");
# this is currently a hack to work round the error code in borg info # this is currently a hack to work round the error code in borg info
# this checks if REPO_CHECK holds this error message and then starts init # this checks if REPO_VERIFY holds this error message and then starts init
if [[ -z "${REPO_CHECK}" ]] || [[ "${REPO_CHECK}" =~ ${REGEX_ERROR} ]]; then if [[ -z "${REPO_VERIFY}" ]] || [[ "${REPO_VERIFY}" =~ ${REGEX_ERROR} ]]; then
INIT_REPOSITORY=1; INIT_REPOSITORY=1;
fi; fi;
elif [ ! -d "${REPOSITORY}" ]; then elif [ ! -d "${REPOSITORY}" ]; then
INIT_REPOSITORY=1; INIT_REPOSITORY=1;
fi; fi;
# if check 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
if [ ${CHECK} -eq 1 ] && [ ${INIT} -eq 0 ] && [ ${INIT_REPOSITORY} -eq 0 ] && if [ ${VERIFY} -eq 1 ] && [ ${INIT} -eq 0 ] && [ ${INIT_REPOSITORY} -eq 0 ] &&
[ ! -f "${BASE_FOLDER}${BACKUP_INIT_CHECK}" ]; then [ ! -f "${BASE_FOLDER}${BACKUP_INIT_VERIFY}" ]; then
# write init file # write init file
echo "[!] Add missing init check file"; echo "[!] Add missing init verify file";
echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_CHECK}"; echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_VERIFY}";
fi; fi;
# end if checked but repository is not here # end if verified but repository is not here
if [ ${CHECK} -eq 1 ] && [ ${INIT} -eq 0 ] && [ ${INIT_REPOSITORY} -eq 1 ]; then if [ ${VERIFY} -eq 1 ] && [ ${INIT} -eq 0 ] && [ ${INIT_REPOSITORY} -eq 1 ]; then
echo "[! $(date +'%F %T')] No repository. Please run with -I flag to initialze repository"; echo "[! $(date +'%F %T')] No repository. Please run with -I flag to initialze repository";
. "${DIR}/borg.backup.functions.close.sh" 1; . "${DIR}/borg.backup.functions.close.sh" 1;
exit 1; exit 1;
fi; fi;
if [ ${EXIT} -eq 1 ] && [ ${CHECK} -eq 1 ] && [ ${INIT} -eq 0 ]; then if [ ${EXIT} -eq 1 ] && [ ${VERIFY} -eq 1 ] && [ ${INIT} -eq 0 ]; then
echo "Repository exists"; echo "Repository exists";
echo "For more information run:" echo "For more information run:"
echo "${COMMAND_INFO}"; echo "${COMMAND_INFO}";
@@ -284,7 +284,7 @@ if [ ${INIT} -eq 1 ] && [ ${INIT_REPOSITORY} -eq 1 ]; 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};
# write init file # write init file
echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_CHECK}"; echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_VERIFY}";
echo "Repository initialized"; echo "Repository initialized";
echo "For more information run:" echo "For more information run:"
echo "${COMMAND_INFO}"; echo "${COMMAND_INFO}";
@@ -300,8 +300,8 @@ elif [ ${INIT} -eq 1 ] && [ ${INIT_REPOSITORY} -eq 0 ]; then
exit 1; exit 1;
fi; fi;
# check for init file # verify for init file
if [ ! -f "${BASE_FOLDER}${BACKUP_INIT_CHECK}" ]; then if [ ! -f "${BASE_FOLDER}${BACKUP_INIT_VERIFY}" ]; 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;
@@ -338,6 +338,40 @@ if [ ${PRINT} -eq 1 ]; then
exit; exit;
fi; fi;
# run borg check command
if [ ${CHECK} -eq 1 ]; then
echo "--- [CHECK : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
# repare command
OPT_GLOB="";
if [[ "${CHECK_PREFIX}" =~ $REGEX_GLOB ]]; then
OPT_GLOB="-a '${CHECK_PREFIX}'"
else
OPT_GLOB="-p ${CHECK_PREFIX}";
fi;
# debug/dryrun
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} check -p ${OPT_CHECK_VERIFY_DATA} ${OPT_GLOB} ${REPOSITORY}";
fi;
# run info command if not a dry drun
if [ ${DRYRUN} -eq 0 ]; then
# if glob add glob command directly
if [[ "${CHECK_PREFIX}" =~ $REGEX_GLOB ]]; then
${BORG_COMMAND} check -p ${OPT_CHECK_VERIFY_DATA} -a "${CHECK_PREFIX}" ${REPOSITORY};
else
${BORG_COMMAND} check -p ${OPT_CHECK_VERIFY_DATA} ${OPT_GLOB} ${REPOSITORY};
fi;
fi;
# print additional info for use --repair command
if [ ${VERBOSE} -eq 1 ]; then
echo "";
echo "In case of repair: "
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";${BORG_COMMAND} check -p --repair ${OPT_GLOB} ${REPOSITORY}";
echo "Before running repair, a copy from the backup should be made because repair might damage a backup"
fi;
. "${DIR}/borg.backup.functions.close.sh";
exit;
fi;
# DELETE ONE TIME TAG # DELETE ONE TIME TAG
if [ ! -z "${DELETE_ONE_TIME_TAG}" ]; then if [ ! -z "${DELETE_ONE_TIME_TAG}" ]; then
echo "--- [DELETE: $(date +'%F %T')] --[${MODULE}]------------------------------------>"; echo "--- [DELETE: $(date +'%F %T')] --[${MODULE}]------------------------------------>";

View File

@@ -1,18 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Backup gitea database, all git folders and gitea settings
MODULE="gitea" MODULE="gitea"
MODULE_VERSION="1.1.1"; MODULE_VERSION="1.1.2";
DIR="${BASH_SOURCE%/*}" DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
# init system # init system
. "${DIR}/borg.backup.functions.init.sh"; . "${DIR}/borg.backup.functions.init.sh";
# init check file # init verify file
BACKUP_INIT_CHECK="borg.backup.gitea.init"; BACKUP_INIT_VERIFY="borg.backup.gitea.init";
# check valid data # verify valid data
. "${DIR}/borg.backup.functions.check.sh"; . "${DIR}/borg.backup.functions.verify.sh";
# if info print info and then abort run # if info print info and then abort run
. "${DIR}/borg.backup.functions.info.sh"; . "${DIR}/borg.backup.functions.info.sh";

View File

@@ -5,12 +5,9 @@
# config override set in borg.backup.mysql.settings # config override set in borg.backup.mysql.settings
# if run as mysql user, be sure user is in the backup group # if run as mysql user, be sure user is in the backup group
# Run -I first to initialize repository
# There are no automatic repository checks unless -C is given
# set last edit date + time # set last edit date + time
MODULE="mysql" MODULE="mysql"
MODULE_VERSION="1.1.0"; MODULE_VERSION="1.1.1";
DIR="${BASH_SOURCE%/*}" DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
@@ -21,11 +18,11 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
INCLUDE_FILE="borg.backup.mysql.include"; INCLUDE_FILE="borg.backup.mysql.include";
EXCLUDE_FILE="borg.backup.mysql.exclude"; EXCLUDE_FILE="borg.backup.mysql.exclude";
SCHEMA_ONLY_FILE="borg.backup.mysql.schema-only"; SCHEMA_ONLY_FILE="borg.backup.mysql.schema-only";
# init check file # init verify file
BACKUP_INIT_CHECK="borg.backup.mysql.init"; BACKUP_INIT_VERIFY="borg.backup.mysql.init";
# check valid data # verify valid data
. "${DIR}/borg.backup.functions.check.sh"; . "${DIR}/borg.backup.functions.verify.sh";
# if info print info and then abort run # if info print info and then abort run
. "${DIR}/borg.backup.functions.info.sh"; . "${DIR}/borg.backup.functions.info.sh";
@@ -50,10 +47,10 @@ if [ ! -f "${MYSQL_CMD}" ]; then
. "${DIR}/borg.backup.functions.close.sh" 1; . "${DIR}/borg.backup.functions.close.sh" 1;
exit 1; exit 1;
fi; fi;
# check that the user can actually do, else abort here # verify that the user can actually do, else abort here
# note: this is the only way to not error # note: this is the only way to not error
_MYSQL_CHECK=$(mysqladmin ${MYSQL_DB_CONFIG_PARAM} ping 2>&1); _MYSQL_VERIFY=$(mysqladmin ${MYSQL_DB_CONFIG_PARAM} ping 2>&1);
_MYSQL_OK=$(echo "${_MYSQL_CHECK}" | grep "is alive"); _MYSQL_OK=$(echo "${_MYSQL_VERIFY}" | grep "is alive");
if [ -z "${_MYSQL_OK}" ]; then if [ -z "${_MYSQL_OK}" ]; then
echo "[! $(date +'%F %T')] Current user has no access right to mysql database"; echo "[! $(date +'%F %T')] Current user has no access right to mysql database";
. "${DIR}/borg.backup.functions.close.sh" 1; . "${DIR}/borg.backup.functions.close.sh" 1;

View File

@@ -5,12 +5,9 @@
# config override set in borg.backup.pgsql.settings # config override set in borg.backup.pgsql.settings
# if run as postgres user, be sure user is in the backup group # if run as postgres user, be sure user is in the backup group
# Run -I first to initialize repository
# There are no automatic repository checks unless -C is given
# set last edit date + time # set last edit date + time
MODULE="pgsql" MODULE="pgsql"
MODULE_VERSION="1.2.0"; MODULE_VERSION="1.2.1";
DIR="${BASH_SOURCE%/*}" DIR="${BASH_SOURCE%/*}"
@@ -23,11 +20,11 @@ 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"; DATA_ONLY_FILE="borg.backup.pgsql.data-only";
# init check file # init verify file
BACKUP_INIT_CHECK="borg.backup.pgsql.init"; BACKUP_INIT_VERIFY="borg.backup.pgsql.init";
# check valid data # verify valid data
. "${DIR}/borg.backup.functions.check.sh"; . "${DIR}/borg.backup.functions.verify.sh";
# if info print info and then abort run # if info print info and then abort run
. "${DIR}/borg.backup.functions.info.sh"; . "${DIR}/borg.backup.functions.info.sh";

View File

@@ -3,18 +3,18 @@
# Backup zabbix config and settings only # Backup zabbix config and settings only
MODULE="zabbix" MODULE="zabbix"
MODULE_VERSION="1.1.1"; MODULE_VERSION="1.1.2";
DIR="${BASH_SOURCE%/*}" DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
# init system # init system
. "${DIR}/borg.backup.functions.init.sh"; . "${DIR}/borg.backup.functions.init.sh";
# init check file # init verify file
BACKUP_INIT_CHECK="borg.backup.zabbix.init"; BACKUP_INIT_VERIFY="borg.backup.zabbix.init";
# check valid data # verify valid data
. "${DIR}/borg.backup.functions.check.sh"; . "${DIR}/borg.backup.functions.verify.sh";
# if info print info and then abort run # if info print info and then abort run
. "${DIR}/borg.backup.functions.info.sh"; . "${DIR}/borg.backup.functions.info.sh";

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "${0} Currently not checked";
exit;
set -e -u -o pipefail set -e -u -o pipefail
# mount this servers borg backup to a folder # mount this servers borg backup to a folder
@@ -13,7 +16,7 @@ SETTINGS_FILE="borg.backup.settings";
# base mount path (default) # base mount path (default)
MOUNT_PATH="/mnt/restore/"; MOUNT_PATH="/mnt/restore/";
# backup path to borg storage # backup path to borg storage
ATTIC_BACKUP_FILE=''; BORG_BACKUP_FILE='';
# if we are mount or unmount (default is mount) # if we are mount or unmount (default is mount)
UMOUNT=0; UMOUNT=0;
@@ -42,7 +45,7 @@ while getopts ":c:m:uf:h" opt do
UMOUNT=1; UMOUNT=1;
;; ;;
f|file) f|file)
ATTIC_BACKUP_FILE=${OPTARG}; BORG_BACKUP_FILE=${OPTARG};
;; ;;
h|help) h|help)
usage; usage;
@@ -69,7 +72,7 @@ fi;
if [ ${UMOUNT} -eq 0 ]; then if [ ${UMOUNT} -eq 0 ]; then
TARGET_SERVER=''; TARGET_SERVER='';
if [ -z "${ATTIC_BACKUP_FILE}" ]; then if [ -z "${BORG_BACKUP_FILE}" ]; then
if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
echo "Cannot find ${BASE_FOLDER}${SETTINGS_FILE}"; echo "Cannot find ${BASE_FOLDER}${SETTINGS_FILE}";
exit 0; exit 0;
@@ -82,7 +85,7 @@ if [ ${UMOUNT} -eq 0 ]; then
fi; fi;
REPOSITORY=${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}; REPOSITORY=${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE};
else else
REPOSITORY=${ATTIC_BACKUP_FILE}; REPOSITORY=${BORG_BACKUP_FILE};
fi; fi;
# check that the repostiory exists # check that the repostiory exists