Clean up bash shell code and add proper ENCRYPTION support

- check for invalid encryption setting
- switch from none to keyfile type (without password)
- error for no password for repokey or authentication type encryption
- update init and print out the key file data
This commit is contained in:
Clemens Schwaighofer
2025-12-01 16:53:50 +09:00
parent 297c745df7
commit 7e4dc8d500
13 changed files with 206 additions and 147 deletions

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash
# allow variables in printf format string
# shellcheck disable=SC2059
if [ -z "${MODULE}" ]; then
echo "Script cannot be run on its own";
exit 1;
@@ -7,7 +10,7 @@ fi;
# compact (only if BORG COMPACT is set)
# only for borg 1.2
if [ $(version $BORG_VERSION) -ge $(version "1.2.0") ]; then
if [ "$(version "$BORG_VERSION")" -ge "$(version "1.2.0")" ]; then
RUN_COMPACT=0;
if [ $# -ge 1 ] && [ "$1" = "auto" ]; then
# strip any spaces and convert to int
@@ -18,11 +21,11 @@ if [ $(version $BORG_VERSION) -ge $(version "1.2.0") ]; then
fi;
# get current date timestmap
CURRENT_DATE=$(date +%s);
if [ ${COMPACT_INTERVAL} -eq 1 ]; then
if [ "${COMPACT_INTERVAL}" -eq 1 ]; then
RUN_COMPACT=1;
# set new compact time here
echo ${CURRENT_DATE} > "${BASE_FOLDER}${BACKUP_COMPACT_FILE}";
elif [ ${COMPACT_INTERVAL} -gt 1 ]; then
echo "${CURRENT_DATE}" > "${BASE_FOLDER}${BACKUP_COMPACT_FILE}";
elif [ "${COMPACT_INTERVAL}" -gt 1 ]; then
# else load last timestamp and check if today - last time stamp > days
if [ -z "${LAST_COMPACT_DATE}" ]; then
LAST_COMPACT_DATE=$(cat "${BASE_FOLDER}${BACKUP_COMPACT_FILE}" 2>/dev/null | sed -e 's/ //g');
@@ -32,25 +35,25 @@ if [ $(version $BORG_VERSION) -ge $(version "1.2.0") ]; then
LAST_COMPACT_DATE=0;
fi;
# 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;
# set new compact time here
echo ${CURRENT_DATE} > "${BASE_FOLDER}${BACKUP_COMPACT_FILE}";
echo "${CURRENT_DATE}" > "${BASE_FOLDER}${BACKUP_COMPACT_FILE}";
fi;
fi;
elif [ ${COMPACT} -eq 1 ]; then
elif [ "${COMPACT}" -eq 1 ]; then
RUN_COMPACT=1;
fi;
if [ ${RUN_COMPACT} -eq 1 ]; then
if [ "${RUN_COMPACT}" -eq 1 ]; then
# reset to normal IFS, so command works here
IFS=${_IFS};
printf "${PRINTF_SUB_BLOCK}" "COMPACT" "$(date +'%F %T')" "${MODULE}";
BORG_COMPACT="${BORG_COMMAND} compact ${OPT_REMOTE} -v ${OPT_PROGRESS} ${REPOSITORY}";
if [ ${DEBUG} -eq 1 ]; then
if [ "${DEBUG}" -eq 1 ]; then
echo "${BORG_COMPACT}";
fi;
if [ ${DRYRUN} -eq 0 ]; then
if [ "${DRYRUN}" -eq 0 ]; then
${BORG_COMPACT};
fi;
fi;