Files
BorgBackupWrapper/borg.mount.sh
Clemens Schwaighofer 2ae05f5302 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.
2022-04-18 15:41:28 +09:00

119 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
echo "${0} Currently not checked";
exit;
set -e -u -o pipefail
# mount this servers borg backup to a folder
# if no command is given the target folder is /mnt/restore
# if this folder does not exist, script will exit with an error
# base folder
BASE_FOLDER="/usr/local/scripts/backup/";
# borg settings file
SETTINGS_FILE="borg.backup.settings";
# base mount path (default)
MOUNT_PATH="/mnt/restore/";
# backup path to borg storage
BORG_BACKUP_FILE='';
# if we are mount or unmount (default is mount)
UMOUNT=0;
function usage ()
{
cat <<- EOT
Usage: ${0##/*/} [-c <config folder>] [-m <mount path>] [-f <borg backup file>] [-u <mount path]
-c <config folder>: if this is not given, ${BASE_FOLDER} is used
-m <mount path>: where to mount the image
-u umount mounted image
-f <borg backup file>: override full path to backup file instead of using the settings info
EOT
}
# set options
while getopts ":c:m:uf:h" opt do
case "${opt}" in
c|config)
BASE_FOLDER=${OPTARG};
;;
m|mount)
MOUNT_PATH=${OPTARG};
;;
u|umount)
UMOUNT=1;
;;
f|file)
BORG_BACKUP_FILE=${OPTARG};
;;
h|help)
usage;
exit 0;
;;
:)
echo "Option -$OPTARG requires an argument."
;;
\?)
echo -e "\n Option does not exist: ${OPTARG}\n";
usage;
exit 1;
;;
esac;
done;
if [ ! -d "${MOUNT_PATH}" ]; then
echo "The mount path ${MOUNT_PATH} cannot be found";
exit 0;
fi;
# add trailing slahd for base folder
[[ "${BASE_FOLDER}" != */ ]] && BASE_FOLDER="${BASE_FOLDER}/";
if [ ${UMOUNT} -eq 0 ]; then
TARGET_SERVER='';
if [ -z "${BORG_BACKUP_FILE}" ]; then
if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
echo "Cannot find ${BASE_FOLDER}${SETTINGS_FILE}";
exit 0;
fi;
. ${BASE_FOLDER}${SETTINGS_FILE}
# set the borg backup file base on the settings data
# if we have user/host then we build the ssh command
if [ ! -z "${TARGET_USER}" ] && [ ! -z "${TARGET_HOST}" ]; then
TARGET_SERVER=${TARGET_USER}"@"${TARGET_HOST}":";
fi;
REPOSITORY=${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE};
else
REPOSITORY=${BORG_BACKUP_FILE};
fi;
# check that the repostiory exists
REPOSITORY_OK=0;
if [ ! -z "${TARGET_SERVER}" ]; then
# remove trailing : for this
TARGET_SERVER=${TARGET_SERVER/:};
# use ssh command to check remote existense
if [ `ssh "${TARGET_SERVER}" "if [ -d \"${TARGET_FOLDER}${BACKUP_FILE}\" ]; then echo 1; else echo 0; fi;"` -eq 1 ]; then
REPOSITORY_OK=1;
fi;
elif [ -d "${REPOSITORY}" ]; then
REPOSITORY_OK=1;
fi;
if [ ${REPOSITORY_OK} -eq 0 ]; then
echo "Repository ${REPOSITORY} does not exists";
exit 0;
fi;
echo "Mounting ${REPOSITORY} on ${MOUNT_PATH}";
# all ok, lets mount it
borg mount "${REPOSITORY}" "${MOUNT_PATH}";
else
echo "Unmounting ${MOUNT_PATH}";
# will fail with error if not mounted, but not critical
borg umount "${MOUNT_PATH}";
fi;
## END