Borg backup wrapper update, config update

Add a .gitignore for all other files that can appear in this
folder
(.config, .cache, settings files, etc)
Add backward compability check for file backup to
not auto add -file for
the file module unless flag is set
(FILE_REPOSITORY_COMPATIBLE)
This commit is contained in:
Clemens Schwaighofer
2021-12-13 13:19:31 +09:00
parent 93f8ea6054
commit a661678441
8 changed files with 44 additions and 21 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
.cache/
.config/
borg.backup.settings
borg.backup.*.settings
borg.backup.*.include
borg.backup.*.exclude
borg.backup.*.schema-only
borg.backup.*.init

View File

@@ -0,0 +1,9 @@
# Borg backup wrapper scripts settings: file
# rename to borg.backup.file.settings to use
# set to false to use -file, current default is "true"
#FILE_REPOSITORY_COMPATIBLE="false"
# override settings in borg.backup.settings with SUB_ prefix
# valid for BACKUP_FILE, BACKUP_SET, COMPRESSION*, KEEP_*

View File

@@ -5,7 +5,7 @@
# set last edit date + time
MODULE="file";
MODULE_VERSION="0.1.0";
MODULE_VERSION="1.0.0";
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
@@ -23,6 +23,7 @@ if [ ! -f "${BASE_FOLDER}${INCLUDE_FILE}" ]; then
echo "[! $(date +'%F %T')] The include folder file ${INCLUDE_FILE} is missing";
exit 1;
fi;
echo "--- [INCLUDE: $(date +'%F %T')] --[${MODULE}]------------------------------------>";
# folders to backup
FOLDERS=();
# this if for debug output with quoted folders
@@ -87,6 +88,7 @@ done<"${BASE_FOLDER}${INCLUDE_FILE}";
# exclude list
if [ -f "${BASE_FOLDER}${EXCLUDE_FILE}" ]; then
echo "--- [EXCLUDE: $(date +'%F %T')] --[${MODULE}]------------------------------------>";
# check that the folders in that exclude file are actually valid,
# remove non valid ones and warn
#TMP_EXCLUDE_FILE=$(mktemp --tmpdir ${EXCLUDE_FILE}.XXXXXXXX); # non mac
@@ -152,7 +154,7 @@ COMMAND=${COMMAND}${REPOSITORY}::${BACKUP_SET};
. "${DIR}/borg.backup.functions.info.sh";
if [ $FOLDER_OK -eq 1 ]; then
echo "--- [BACKUP: $(date +'%F %T')] ------------------------------------------->";
echo "--- [BACKUP: $(date +'%F %T')] --[${MODULE}]------------------------------------>";
# show command
if [ ${DEBUG} -eq 1 ]; then
echo $(echo ${COMMAND} | sed -e 's/[ ][ ]*/ /g') ${FOLDERS_Q[*]};
@@ -173,7 +175,7 @@ else
fi;
# clean up, always verbose
echo "--- [PRUNE : $(date +'%F %T')] ------------------------------------------->";
echo "--- [PRUNE : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
# build command
COMMAND="borg prune ${OPT_REMOTE} -v -s --list ${PRUNE_DEBUG} ${KEEP_OPTIONS[*]} ${REPOSITORY}";
echo "Prune repository with keep${KEEP_INFO:1}";

View File

@@ -177,16 +177,9 @@ if [ -z "${KEEP_OPTIONS}" ]; then
echo "[! $(date +'%F %T')] It seems no KEEP_* entries where set in a valid format.";
exit 1;
fi;
# set BACKUP_SET if empty, check for for DATE is set
# set BACKUP_SET if empty, set to Year-month-day
if [ -z "${BACKUP_SET}" ]; then
# DATE is deprecated and will be removed
if [ ! -z "${DATE}" ]; then
echo "[!] DEPRECATED: The use of DATE variable is deprecated, use BACKUP_SET instead";
BACKUP_SET="${DATE}";
else
# default
BACKUP_SET="{now:%Y-%m-%d}";
fi;
BACKUP_SET="{now:%Y-%m-%d}";
fi;
# 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 }
@@ -222,7 +215,7 @@ COMMAND_INFO="${COMMAND_EXPORT}borg info ${OPT_REMOTE} ${REPOSITORY}";
# else a normal check is ok
# unless explicit given, check is skipped
if [ ${CHECK} -eq 1 ] || [ ${INIT} -eq 1 ]; then
echo "--- [CHECK : $(date +'%F %T')] ------------------------------------------->";
echo "--- [CHECK : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
if [ ! -z "${TARGET_SERVER}" ]; then
if [ ${DEBUG} -eq 1 ]; then
echo "borg info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep \"Repository ID:\"";
@@ -259,7 +252,7 @@ if [ ${CHECK} -eq 1 ] || [ ${INIT} -eq 1 ]; then
fi;
fi;
if [ ${INIT} -eq 1 ] && [ ${INIT_REPOSITORY} -eq 1 ]; then
echo "--- [INIT : $(date +'%F %T')] ------------------------------------------->";
echo "--- [INIT : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "borg init ${OPT_REMOTE} -e ${ENCRYPTION} ${OPT_VERBOSE} ${REPOSITORY}";
fi
@@ -291,7 +284,7 @@ fi;
# PRINT OUT current data, only do this if REPO exists
if [ ${PRINT} -eq 1 ]; then
echo "--- [PRINT : $(date +'%F %T')] ------------------------------------------->";
echo "--- [PRINT : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
FORMAT="{archive} {comment:6} {start} - {end} [{id}] ({username}@{hostname}){NL}"
# show command on debug or dry run
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
if [ ${INFO} -eq 1 ]; then
echo "--- [INFO : $(date +'%F %T')] ------------------------------------------->";
echo "--- [INFO : $(date +'%F %T')] --[${MODULE}]------------------------------------>";
# show command on debug or dry run
if [ ${DEBUG} -eq 1 ] || [ ${DRYRUN} -eq 1 ]; then
echo "export BORG_BASE_DIR=\"${BASE_FOLDER}\";borg info ${OPT_REMOTE} ${REPOSITORY}";

View File

@@ -47,6 +47,11 @@ PRINT=0;
# flags, set to no to disable
_BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="yes";
_BORG_RELOCATED_REPO_ACCESS_IS_OK="yes";
# compatible settings
# NOTE: to keep the old .borg repository name for file module set this to true
# if set to false (future) it will add -file to the repository name like for other
# modules
FILE_REPOSITORY_COMPATIBLE="true";
# other variables
TARGET_SERVER="";
REGEX="";
@@ -81,7 +86,6 @@ SUB_COMPRESSION_LEVEL="";
ENCRYPTION="none";
# force check always
FORCE_CHECK="false";
DATE=""; # to be deprecated
BACKUP_SET="";
SUB_BACKUP_SET="";
# for database backup only
@@ -245,8 +249,6 @@ if [ -f "${BASE_FOLDER}${SETTINGS_FILE_SUB}" ]; then
if [ ! -z "${SUB_BACKUP_FILE}" ]; then
BACKUP_FILE=${SUB_BACKUP_FILE}
fi;
# add module name to backup file, always
BACKUP_FILE=${BACKUP_FILE/.borg/-${MODULE,,}.borg};
# if sub backup set it set, override current
if [ ! -z "${SUB_BACKUP_SET}" ]; then
BACKUP_SET=${SUB_BACKUP_SET};
@@ -281,6 +283,11 @@ if [ -f "${BASE_FOLDER}${SETTINGS_FILE_SUB}" ]; then
KEEP_WITHIN=${SUB_KEEP_WITHIN};
fi;
fi;
# add module name to backup file, always
# except if FILE module and FILE_REPOSITORY_COMPATIBLE="true"
if ([ "${FILE_REPOSITORY_COMPATIBLE}" = "false" ] && [ "${MODULE,,}" = "file" ]) || [ "${MODULE,,}" != "file" ]; then
BACKUP_FILE=${BACKUP_FILE/.borg/-${MODULE,,}.borg};
fi;
# backup file must be set
if [ -z "${BACKUP_FILE}" ]; then
echo "No BACKUP_FILE set";

View File

@@ -1,4 +1,6 @@
# Borg backup wrapper scripts settings
# Borg backup wrapper scripts settings: MySQL
# rename to borg.backup.mysql.settings to use
# override settings in borg.backup.settings with SUB_ prefix
# valid for BACKUP_FILE, BACKUP_SET, COMPRESSION*, KEEP_*

View File

@@ -1,4 +1,6 @@
# Borg backup wrapper scripts settings
# Borg backup wrapper scripts settings: PostgreSQL
# rename to borg.backup.pgsql.settings to use
# override settings in borg.backup.settings with SUB_ prefix
# valid for BACKUP_FILE, BACKUP_SET, COMPRESSION*, KEEP_*