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:
15
Readme.md
15
Readme.md
@@ -59,15 +59,24 @@ override the default borg executable found in path
|
||||
### `-P`
|
||||
print list of archives created
|
||||
|
||||
### `-C`
|
||||
check if repository exists, if not abort
|
||||
### `-V`
|
||||
verify if repository exists, if not abort
|
||||
|
||||
### `-E`
|
||||
### `-e`
|
||||
exit after check
|
||||
|
||||
### `-I`
|
||||
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`
|
||||
print out only info
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Run -I first to initialize repository
|
||||
# There are no automatic repository checks unless -C is given
|
||||
# Plain file backup
|
||||
|
||||
# set last edit date + time
|
||||
MODULE="file";
|
||||
MODULE_VERSION="1.2.0";
|
||||
MODULE_VERSION="1.2.1";
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
@@ -14,10 +13,11 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
# include and exclude file
|
||||
INCLUDE_FILE="borg.backup.file.include";
|
||||
EXCLUDE_FILE="borg.backup.file.exclude";
|
||||
# init check file
|
||||
BACKUP_INIT_CHECK="borg.backup.file.init";
|
||||
# init verify file
|
||||
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
|
||||
if [ ! -f "${BASE_FOLDER}${INCLUDE_FILE}" ]; then
|
||||
|
||||
@@ -19,7 +19,7 @@ function version {
|
||||
}
|
||||
|
||||
# version for all general files
|
||||
VERSION="4.2.4";
|
||||
VERSION="4.3.0";
|
||||
|
||||
# borg version and borg comamnd
|
||||
BORG_VERSION="";
|
||||
@@ -41,19 +41,23 @@ SETTINGS_FILE="borg.backup.settings";
|
||||
# include files
|
||||
INCLUDE_FILE="";
|
||||
EXCLUDE_FILE="";
|
||||
# backup folder initialzed check
|
||||
BACKUP_INIT_CHECK="";
|
||||
# backup folder initialzed verify
|
||||
BACKUP_INIT_VERIFY="";
|
||||
BACKUP_INIT_DATE="";
|
||||
# one time backup prefix tag, if set will use <tag>.<prefix>-Y-M-DTh:m:s type backup prefix
|
||||
ONE_TIME_TAG="";
|
||||
DELETE_ONE_TIME_TAG="";
|
||||
# debug/verbose
|
||||
# check command prefix/glob
|
||||
CHECK_PREFIX="";
|
||||
# debug/verbose/other flags
|
||||
VERBOSE=0;
|
||||
LIST=0;
|
||||
DEBUG=0;
|
||||
DRYRUN=0;
|
||||
INFO=0;
|
||||
VERIFY=0;
|
||||
CHECK=0;
|
||||
CHECK_VERIFY_DATA=0;
|
||||
INIT=0;
|
||||
EXIT=0;
|
||||
PRINT=0;
|
||||
@@ -83,6 +87,7 @@ OPT_LIST="";
|
||||
OPT_REMOTE="";
|
||||
OPT_LOG_FOLDER="";
|
||||
OPT_EXCLUDE="";
|
||||
OPT_CHECK_VERIFY_DATA="";
|
||||
# config variables (will be overwritten from .settings file)
|
||||
TARGET_USER="";
|
||||
TARGET_HOST="";
|
||||
@@ -105,9 +110,10 @@ SUB_COMPRESSION_LEVEL="";
|
||||
# encryption settings
|
||||
DEFAULT_ENCRYPTION="none";
|
||||
ENCRYPTION="";
|
||||
# force check always
|
||||
DEFAULT_FORCE_CHECK="false";
|
||||
FORCE_CHECK="";
|
||||
# force verify always
|
||||
DEFAULT_FORCE_VERIFY="false";
|
||||
FORCE_VERIFY="";
|
||||
FORCE_CHECK=""; # Deprecated name, use FORCE_VERIFY
|
||||
BACKUP_SET="";
|
||||
SUB_BACKUP_SET="";
|
||||
# for database backup only
|
||||
@@ -168,9 +174,12 @@ function usage()
|
||||
-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
|
||||
-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
|
||||
-C: check if repository exists, if not abort
|
||||
-E: exit after check
|
||||
-V: verify if repository exists, if not abort
|
||||
-e: exit after verify
|
||||
-I: init repository (must be run first)
|
||||
-i: print out only info
|
||||
-l: list files during backup
|
||||
@@ -186,7 +195,7 @@ function usage()
|
||||
}
|
||||
|
||||
# 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
|
||||
c|config)
|
||||
BASE_FOLDER=${OPTARG};
|
||||
@@ -204,17 +213,30 @@ while getopts ":c:L:T:D:b:vldniCEIPh" opt; do
|
||||
OPT_BORG_EXECUTEABLE=${OPTARG};
|
||||
;;
|
||||
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;
|
||||
;;
|
||||
E|Exit)
|
||||
# exit after check
|
||||
y|Verify-Data)
|
||||
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;
|
||||
;;
|
||||
I|Init)
|
||||
# will check if there is a repo and init it
|
||||
# previoous this was default
|
||||
CHECK=1;
|
||||
VERIFY=1;
|
||||
INIT=1;
|
||||
;;
|
||||
P|Print)
|
||||
@@ -269,21 +291,21 @@ if [ ! -w "${BASE_FOLDER}" ]; then
|
||||
fi;
|
||||
|
||||
# info -i && -C/-I cannot be run together
|
||||
if [ ${CHECK} -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";
|
||||
if [ ${VERIFY} -eq 1 ] || [ ${INIT} -eq 1 ] && [ ${INFO} -eq 1 ]; then
|
||||
echo "Cannot have -i info option and -V verify or -I initialize option at the same time";
|
||||
exit 1;
|
||||
fi;
|
||||
# print -P cannot be run with -i/-C/-I together
|
||||
if [ ${PRINT} -eq 1 ] && ([ ${INIT} -eq 1 ] || [ ${CHECK} -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";
|
||||
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";
|
||||
exit 1;
|
||||
fi;
|
||||
# if tag is set, you can't have init, check, info, etc
|
||||
if [ ! -z "${ONE_TIME_TAG}" ] && ([ ${PRINT} -eq 1 ] || [ ${INIT} -eq 1 ] || [ ${CHECK} -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";
|
||||
# if tag is set, you can't have init, verify, info, etc
|
||||
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, -V verify, -I initialize or -P print option at the same time";
|
||||
exit 1;
|
||||
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
|
||||
echo "One time tag '${ONE_TIME_TAG}' must be alphanumeric with dashes and underscore only.";
|
||||
exit 1;
|
||||
@@ -292,18 +314,34 @@ elif [ ! -z "${ONE_TIME_TAG}" ]; then
|
||||
ONE_TIME_TAG=${ONE_TIME_TAG}".";
|
||||
fi;
|
||||
# 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
|
||||
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";
|
||||
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, -V verify, -I initialize or -P print option at the same time";
|
||||
exit 1;
|
||||
fi;
|
||||
# -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\*$ ]]
|
||||
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 "Note the dash (-) after the first *, also time (T) is a globa (*) must."
|
||||
exit 1;
|
||||
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
|
||||
if [ ${VERBOSE} -eq 1 ]; then
|
||||
@@ -320,6 +358,9 @@ if [ ${DRYRUN} -eq 1 ]; then
|
||||
else
|
||||
DRY_RUN_STATS="-s";
|
||||
fi;
|
||||
if [ ${CHECK_VERIFY_DATA} -eq 1 ] && [ ${CHECK} -eq 1 ]; then
|
||||
OPT_CHECK_VERIFY_DATA="--verify-data";
|
||||
fi;
|
||||
|
||||
# read config file
|
||||
. "${BASE_FOLDER}${SETTINGS_FILE}";
|
||||
@@ -339,12 +380,12 @@ elif [ ! -z "${BORG_EXECUTEABLE}" ]; then
|
||||
exit;
|
||||
fi;
|
||||
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;
|
||||
fi;
|
||||
# check that this is a borg executable, no detail check
|
||||
_BORG_COMMAND_CHECK=$(${BORG_COMMAND} -V | grep "borg");
|
||||
if [[ "${_BORG_COMMAND_CHECK}" =~ ${REGEX_ERROR} ]]; then
|
||||
# verify that this is a borg executable, no detail check
|
||||
_BORG_COMMAND_VERIFY=$(${BORG_COMMAND} -V | grep "borg");
|
||||
if [[ "${_BORG_COMMAND_VERIFY}" =~ ${REGEX_ERROR} ]]; then
|
||||
echo "Cannot extract borg info from command, is this a valid borg executable?: ${BORG_COMMAND}";
|
||||
exit;
|
||||
fi;
|
||||
@@ -363,8 +404,12 @@ fi;
|
||||
if [ -z "${ENCRYPTION}" ]; then
|
||||
ENCRYPTION="${DEFAULT_ENCRYPTION}";
|
||||
fi;
|
||||
if [ -z "${FORCE_CHECK}" ]; then
|
||||
FORCE_CHECK="${DEFAULT_FORCE_CHECK}";
|
||||
# deprecated name FORCE_CHECK, use FORCE_VERIFY instead
|
||||
if [ ! -z "${FORCE_CHECK}" ]; then
|
||||
FORCE_VERIFY="${FORCE_CHECK}";
|
||||
fi;
|
||||
if [ -z "${FORCE_VERIFY}" ]; then
|
||||
FORCE_VERIFY="${DEFAULT_FORCE_VERIFY}";
|
||||
fi;
|
||||
if [ -z "${KEEP_LAST}" ]; then
|
||||
KEEP_LAST="${DEFAULT_KEEP_LAST}";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# start time in seconds
|
||||
START=$(date +'%s');
|
||||
# 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
|
||||
exec &> >(tee -a "${LOG}");
|
||||
echo "=== [START : $(date +'%F %T')] ==[${MODULE}]====================================>";
|
||||
@@ -21,12 +21,12 @@ echo "Base folder : ${BASE_FOLDER}";
|
||||
# Module init date (when init file was writen)
|
||||
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
|
||||
if [ "${FORCE_CHECK,,}" = "true" ] && [ ${INFO} -eq 0 ]; then
|
||||
CHECK=1;
|
||||
if [ "${FORCE_VERIFY,,}" = "true" ] && [ ${INFO} -eq 0 ]; then
|
||||
VERIFY=1;
|
||||
if [ ${DEBUG} -eq 1 ]; then
|
||||
echo "Force repository check";
|
||||
echo "Force repository verify";
|
||||
fi;
|
||||
fi;
|
||||
|
||||
@@ -84,7 +84,7 @@ fi;
|
||||
REPOSITORY="${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE}";
|
||||
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='';
|
||||
if [ ! -z "${COMPRESSION}" ]; then
|
||||
# valid compression
|
||||
@@ -150,7 +150,7 @@ if [ ! -z "${ONE_TIME_TAG}" ]; then
|
||||
else
|
||||
# build options and info string,
|
||||
# also flag BACKUP_SET check if hourly is set
|
||||
BACKUP_SET_CHECK=0;
|
||||
BACKUP_SET_VERIFY=0;
|
||||
if [ ${KEEP_LAST} -gt 0 ]; then
|
||||
KEEP_OPTIONS+=("--keep-last=${KEEP_LAST}");
|
||||
KEEP_INFO="${KEEP_INFO}, last: ${KEEP_LAST}";
|
||||
@@ -158,7 +158,7 @@ else
|
||||
if [ ${KEEP_HOURS} -gt 0 ]; then
|
||||
KEEP_OPTIONS+=("--keep-hourly=${KEEP_HOURS}");
|
||||
KEEP_INFO="${KEEP_INFO}, hourly: ${KEEP_HOURS}";
|
||||
BACKUP_SET_CHECK=1;
|
||||
BACKUP_SET_VERIFY=1;
|
||||
fi;
|
||||
if [ ${KEEP_DAYS} -gt 0 ]; then
|
||||
KEEP_OPTIONS+=("--keep-daily=${KEEP_DAYS}");
|
||||
@@ -182,7 +182,7 @@ else
|
||||
KEEP_OPTIONS+=("--keep-within=${KEEP_WITHIN}");
|
||||
KEEP_INFO="${KEEP_INFO}, within: ${KEEP_WITHIN}";
|
||||
if [[ "${KEEP_WITHIN}" == *"H"* ]]; then
|
||||
BACKUP_SET_CHECK=1;
|
||||
BACKUP_SET_VERIFY=1;
|
||||
fi;
|
||||
else
|
||||
echo "[! $(date +'%F %T')] KEEP_WITHIN has invalid string.";
|
||||
@@ -200,7 +200,7 @@ else
|
||||
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 }
|
||||
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}/");
|
||||
fi;
|
||||
fi;
|
||||
@@ -235,39 +235,39 @@ fi;
|
||||
COMMAND_EXPORT="export BORG_BASE_DIR=\"${BASE_FOLDER}\";"
|
||||
COMMAND_INFO="${COMMAND_EXPORT}${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY}";
|
||||
# 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
|
||||
# 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')] --[${MODULE}]------------------------------------>";
|
||||
# if this is user@host, we need to use ssh command to verify if the file is there
|
||||
# else a normal verify is ok
|
||||
# unless explicit given, verify is skipped
|
||||
if [ ${VERIFY} -eq 1 ] || [ ${INIT} -eq 1 ]; then
|
||||
echo "--- [VERIFY: $(date +'%F %T')] --[${MODULE}]------------------------------------>";
|
||||
if [ ! -z "${TARGET_SERVER}" ]; then
|
||||
if [ ${DEBUG} -eq 1 ]; then
|
||||
echo "${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep \"Repository ID:\"";
|
||||
fi;
|
||||
# use borg info and check if it returns "Repository ID:" in the first line
|
||||
REPO_CHECK=$(${BORG_COMMAND} info ${OPT_REMOTE} ${REPOSITORY} 2>&1|grep "Repository ID:");
|
||||
# use borg info and verify if it returns "Repository ID:" in the first line
|
||||
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 checks if REPO_CHECK holds this error message and then starts init
|
||||
if [[ -z "${REPO_CHECK}" ]] || [[ "${REPO_CHECK}" =~ ${REGEX_ERROR} ]]; then
|
||||
# this checks if REPO_VERIFY holds this error message and then starts init
|
||||
if [[ -z "${REPO_VERIFY}" ]] || [[ "${REPO_VERIFY}" =~ ${REGEX_ERROR} ]]; then
|
||||
INIT_REPOSITORY=1;
|
||||
fi;
|
||||
elif [ ! -d "${REPOSITORY}" ]; then
|
||||
INIT_REPOSITORY=1;
|
||||
fi;
|
||||
# if check 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 ] &&
|
||||
[ ! -f "${BASE_FOLDER}${BACKUP_INIT_CHECK}" ]; then
|
||||
# if verrify but no init and repo is there but init file is missing set it
|
||||
if [ ${VERIFY} -eq 1 ] && [ ${INIT} -eq 0 ] && [ ${INIT_REPOSITORY} -eq 0 ] &&
|
||||
[ ! -f "${BASE_FOLDER}${BACKUP_INIT_VERIFY}" ]; then
|
||||
# write init file
|
||||
echo "[!] Add missing init check file";
|
||||
echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_CHECK}";
|
||||
echo "[!] Add missing init verify file";
|
||||
echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_VERIFY}";
|
||||
fi;
|
||||
# end if checked but repository is not here
|
||||
if [ ${CHECK} -eq 1 ] && [ ${INIT} -eq 0 ] && [ ${INIT_REPOSITORY} -eq 1 ]; then
|
||||
# end if verified but repository is not here
|
||||
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";
|
||||
. "${DIR}/borg.backup.functions.close.sh" 1;
|
||||
exit 1;
|
||||
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 "For more information run:"
|
||||
echo "${COMMAND_INFO}";
|
||||
@@ -284,7 +284,7 @@ if [ ${INIT} -eq 1 ] && [ ${INIT_REPOSITORY} -eq 1 ]; then
|
||||
# should trap and exit properly here
|
||||
${BORG_COMMAND} init ${OPT_REMOTE} -e ${ENCRYPTION} ${OPT_VERBOSE} ${REPOSITORY};
|
||||
# write init file
|
||||
echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_CHECK}";
|
||||
echo "$(date +%s)" > "${BASE_FOLDER}${BACKUP_INIT_VERIFY}";
|
||||
echo "Repository initialized";
|
||||
echo "For more information run:"
|
||||
echo "${COMMAND_INFO}";
|
||||
@@ -300,8 +300,8 @@ elif [ ${INIT} -eq 1 ] && [ ${INIT_REPOSITORY} -eq 0 ]; then
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# check for init file
|
||||
if [ ! -f "${BASE_FOLDER}${BACKUP_INIT_CHECK}" ]; then
|
||||
# verify for init file
|
||||
if [ ! -f "${BASE_FOLDER}${BACKUP_INIT_VERIFY}" ]; then
|
||||
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."
|
||||
. "${DIR}/borg.backup.functions.close.sh" 1;
|
||||
@@ -338,6 +338,40 @@ if [ ${PRINT} -eq 1 ]; then
|
||||
exit;
|
||||
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
|
||||
if [ ! -z "${DELETE_ONE_TIME_TAG}" ]; then
|
||||
echo "--- [DELETE: $(date +'%F %T')] --[${MODULE}]------------------------------------>";
|
||||
@@ -1,18 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Backup gitea database, all git folders and gitea settings
|
||||
|
||||
MODULE="gitea"
|
||||
MODULE_VERSION="1.1.1";
|
||||
MODULE_VERSION="1.1.2";
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
# init system
|
||||
. "${DIR}/borg.backup.functions.init.sh";
|
||||
|
||||
# init check file
|
||||
BACKUP_INIT_CHECK="borg.backup.gitea.init";
|
||||
# init verify file
|
||||
BACKUP_INIT_VERIFY="borg.backup.gitea.init";
|
||||
|
||||
# check valid data
|
||||
. "${DIR}/borg.backup.functions.check.sh";
|
||||
# verify valid data
|
||||
. "${DIR}/borg.backup.functions.verify.sh";
|
||||
# if info print info and then abort run
|
||||
. "${DIR}/borg.backup.functions.info.sh";
|
||||
|
||||
|
||||
@@ -5,12 +5,9 @@
|
||||
# config override set in borg.backup.mysql.settings
|
||||
# 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
|
||||
MODULE="mysql"
|
||||
MODULE_VERSION="1.1.0";
|
||||
MODULE_VERSION="1.1.1";
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
@@ -21,11 +18,11 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
INCLUDE_FILE="borg.backup.mysql.include";
|
||||
EXCLUDE_FILE="borg.backup.mysql.exclude";
|
||||
SCHEMA_ONLY_FILE="borg.backup.mysql.schema-only";
|
||||
# init check file
|
||||
BACKUP_INIT_CHECK="borg.backup.mysql.init";
|
||||
# init verify file
|
||||
BACKUP_INIT_VERIFY="borg.backup.mysql.init";
|
||||
|
||||
# check valid data
|
||||
. "${DIR}/borg.backup.functions.check.sh";
|
||||
# verify valid data
|
||||
. "${DIR}/borg.backup.functions.verify.sh";
|
||||
# if info print info and then abort run
|
||||
. "${DIR}/borg.backup.functions.info.sh";
|
||||
|
||||
@@ -50,10 +47,10 @@ if [ ! -f "${MYSQL_CMD}" ]; then
|
||||
. "${DIR}/borg.backup.functions.close.sh" 1;
|
||||
exit 1;
|
||||
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
|
||||
_MYSQL_CHECK=$(mysqladmin ${MYSQL_DB_CONFIG_PARAM} ping 2>&1);
|
||||
_MYSQL_OK=$(echo "${_MYSQL_CHECK}" | grep "is alive");
|
||||
_MYSQL_VERIFY=$(mysqladmin ${MYSQL_DB_CONFIG_PARAM} ping 2>&1);
|
||||
_MYSQL_OK=$(echo "${_MYSQL_VERIFY}" | grep "is alive");
|
||||
if [ -z "${_MYSQL_OK}" ]; then
|
||||
echo "[! $(date +'%F %T')] Current user has no access right to mysql database";
|
||||
. "${DIR}/borg.backup.functions.close.sh" 1;
|
||||
|
||||
@@ -5,12 +5,9 @@
|
||||
# config override set in borg.backup.pgsql.settings
|
||||
# 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
|
||||
MODULE="pgsql"
|
||||
MODULE_VERSION="1.2.0";
|
||||
MODULE_VERSION="1.2.1";
|
||||
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
@@ -23,11 +20,11 @@ INCLUDE_FILE="borg.backup.pgsql.include";
|
||||
EXCLUDE_FILE="borg.backup.pgsql.exclude";
|
||||
SCHEMA_ONLY_FILE="borg.backup.pgsql.schema-only";
|
||||
DATA_ONLY_FILE="borg.backup.pgsql.data-only";
|
||||
# init check file
|
||||
BACKUP_INIT_CHECK="borg.backup.pgsql.init";
|
||||
# init verify file
|
||||
BACKUP_INIT_VERIFY="borg.backup.pgsql.init";
|
||||
|
||||
# check valid data
|
||||
. "${DIR}/borg.backup.functions.check.sh";
|
||||
# verify valid data
|
||||
. "${DIR}/borg.backup.functions.verify.sh";
|
||||
# if info print info and then abort run
|
||||
. "${DIR}/borg.backup.functions.info.sh";
|
||||
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
# Backup zabbix config and settings only
|
||||
|
||||
MODULE="zabbix"
|
||||
MODULE_VERSION="1.1.1";
|
||||
MODULE_VERSION="1.1.2";
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
# init system
|
||||
. "${DIR}/borg.backup.functions.init.sh";
|
||||
|
||||
# init check file
|
||||
BACKUP_INIT_CHECK="borg.backup.zabbix.init";
|
||||
# init verify file
|
||||
BACKUP_INIT_VERIFY="borg.backup.zabbix.init";
|
||||
|
||||
# check valid data
|
||||
. "${DIR}/borg.backup.functions.check.sh";
|
||||
# verify valid data
|
||||
. "${DIR}/borg.backup.functions.verify.sh";
|
||||
# if info print info and then abort run
|
||||
. "${DIR}/borg.backup.functions.info.sh";
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "${0} Currently not checked";
|
||||
exit;
|
||||
|
||||
set -e -u -o pipefail
|
||||
|
||||
# mount this servers borg backup to a folder
|
||||
@@ -13,7 +16,7 @@ SETTINGS_FILE="borg.backup.settings";
|
||||
# base mount path (default)
|
||||
MOUNT_PATH="/mnt/restore/";
|
||||
# backup path to borg storage
|
||||
ATTIC_BACKUP_FILE='';
|
||||
BORG_BACKUP_FILE='';
|
||||
# if we are mount or unmount (default is mount)
|
||||
UMOUNT=0;
|
||||
|
||||
@@ -42,7 +45,7 @@ while getopts ":c:m:uf:h" opt do
|
||||
UMOUNT=1;
|
||||
;;
|
||||
f|file)
|
||||
ATTIC_BACKUP_FILE=${OPTARG};
|
||||
BORG_BACKUP_FILE=${OPTARG};
|
||||
;;
|
||||
h|help)
|
||||
usage;
|
||||
@@ -69,7 +72,7 @@ fi;
|
||||
|
||||
if [ ${UMOUNT} -eq 0 ]; then
|
||||
TARGET_SERVER='';
|
||||
if [ -z "${ATTIC_BACKUP_FILE}" ]; then
|
||||
if [ -z "${BORG_BACKUP_FILE}" ]; then
|
||||
if [ ! -f "${BASE_FOLDER}${SETTINGS_FILE}" ]; then
|
||||
echo "Cannot find ${BASE_FOLDER}${SETTINGS_FILE}";
|
||||
exit 0;
|
||||
@@ -82,7 +85,7 @@ if [ ${UMOUNT} -eq 0 ]; then
|
||||
fi;
|
||||
REPOSITORY=${TARGET_SERVER}${TARGET_FOLDER}${BACKUP_FILE};
|
||||
else
|
||||
REPOSITORY=${ATTIC_BACKUP_FILE};
|
||||
REPOSITORY=${BORG_BACKUP_FILE};
|
||||
fi;
|
||||
|
||||
# check that the repostiory exists
|
||||
|
||||
Reference in New Issue
Block a user