You've already forked Borgbackup-Schedule
Inital Commit
This commit is contained in:
97
root/usr/lib/borgbackup/check_conditions
Normal file
97
root/usr/lib/borgbackup/check_conditions
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Options Section
|
||||
#
|
||||
###
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Variable Section
|
||||
#
|
||||
###
|
||||
|
||||
export BORG_CACHE_DIR='/var/cache/borgbackup'
|
||||
export BORG_CONFIG_EXCLUDE='/etc/borgbackup/exclude'
|
||||
export BORG_CONFIG_FILE='/etc/borgbackup/config'
|
||||
export BORG_KEYS_DIR='/etc/borgbackup/keys'
|
||||
export BORG_LOG_DIR='/var/log/borgbackup'
|
||||
export BORG_POSTEXEC_DIR='/etc/borgbackup/postexec'
|
||||
export BORG_PREEXEC_DIR='/etc/borgbackup/preexec'
|
||||
export BORG_SECURITY_DIR='/var/lib/borgbackup'
|
||||
source '/etc/borgbackup/config'
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Function Section
|
||||
#
|
||||
###
|
||||
|
||||
function environment () {
|
||||
local INPUT
|
||||
local TYPE
|
||||
INPUT="${1}"
|
||||
/usr/bin/test -f "${INPUT}" && \
|
||||
TYPE='file'
|
||||
/usr/bin/test -d "${INPUT}" && \
|
||||
TYPE='directory'
|
||||
case "${TYPE}" in
|
||||
file)
|
||||
if [[ ! -f "${INPUT}" ]]; then
|
||||
INPUT=$(/usr/bin/basename "${INPUT}")
|
||||
/usr/bin/echo "ERROR: The required file '${INPUT}' could not be found."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
directory)
|
||||
if [[ ! -d "${INPUT}" ]]; then
|
||||
INPUT=$(/usr/bin/realpath "${INPUT}")
|
||||
/usr/bin/echo "ERROR: The required directory '${INPUT}' could not be found."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function configuration () {
|
||||
local INPUT
|
||||
INPUT="${1}"
|
||||
if [[ -z "${!INPUT}" ]]; then
|
||||
/usr/bin/echo "ERROR: The option '${INPUT}' is not set in configuration file."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Runtime Environment
|
||||
#
|
||||
###
|
||||
|
||||
if [[ "${TIMER}" != 'true' ]]; then
|
||||
exit 1
|
||||
fi
|
||||
environment "${BORG_CACHE_DIR}"
|
||||
environment "${BORG_CONFIG_EXCLUDE}"
|
||||
environment "${BORG_CONFIG_FILE}"
|
||||
environment "${BORG_KEYS_DIR}"
|
||||
environment "${BORG_LOG_DIR=}"
|
||||
environment "${BORG_POSTEXEC_DIR}"
|
||||
environment "${BORG_PREEXEC_DIR}"
|
||||
environment "${BORG_SECURITY_DIR}"
|
||||
configuration 'BORG_REPO'
|
||||
configuration 'BORG_COMPRESSION'
|
||||
configuration 'BORG_PRUNE_WITHIN'
|
||||
configuration 'BORG_PRUNE_DAILY'
|
||||
configuration 'BORG_PRUNE_WEEKLY'
|
||||
configuration 'BORG_PRUNE_MONTHLY'
|
||||
configuration 'BORG_FILES_CACHE_TTL'
|
||||
configuration 'BORG_SHOW_SYSINFO'
|
||||
88
root/usr/lib/borgbackup/start_backup
Normal file
88
root/usr/lib/borgbackup/start_backup
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Options Section
|
||||
#
|
||||
###
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Variable Section
|
||||
#
|
||||
###
|
||||
|
||||
export BORG_BASE_DIR='/nonexistent'
|
||||
export BORG_CACHE_DIR='/var/cache/borgbackup'
|
||||
export BORG_COMPRESSION
|
||||
export BORG_CONFIG_EXCLUDE='/etc/borgbackup/exclude'
|
||||
export BORG_CONFIG_FILE='/etc/borgbackup/config'
|
||||
export BORG_CONFIG_DIR='/etc/borgbackup'
|
||||
export BORG_FILES_CACHE_TTL
|
||||
export BORG_KEYS_DIR='/etc/borgbackup/keys'
|
||||
export BORG_LOG_CREATE='/var/log/borgbackup/create.log'
|
||||
export BORG_LOG_PRUNE='/var/log/borgbackup/prune.log'
|
||||
export BORG_PASSCOMMAND='/usr/bin/cat /etc/borgbackup/password'
|
||||
export BORG_POSTEXEC_DIR='/etc/borgbackup/postexec'
|
||||
export BORG_PREEXEC_DIR='/etc/borgbackup/preexec'
|
||||
export BORG_PRUNE_WITHIN
|
||||
export BORG_PRUNE_DAILY
|
||||
export BORG_PRUNE_MONTHLY
|
||||
export BORG_PRUNE_WEEKLY
|
||||
export BORG_REPO
|
||||
export BORG_SECURITY_DIR='/var/lib/borgbackup'
|
||||
export BORG_SHOW_SYSINFO
|
||||
export BORG_WORKAROUNDS
|
||||
export TMPDIR='/tmp'
|
||||
source '/etc/borgbackup/config'
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Runtime Environment
|
||||
#
|
||||
###
|
||||
|
||||
if [[ -n "${INVOCATION_ID}" ]]; then
|
||||
if ! source '/usr/lib/borgbackup/check_conditions'; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
/usr/bin/run-parts --new-session "${BORG_PREEXEC_DIR}"
|
||||
BORG_REPO_ID=$(/usr/bin/borg list | /usr/bin/tail --lines='1' | /usr/bin/mawk '{print $1}')
|
||||
BORG_REPO_ID=$(( "${BORG_REPO_ID}" + 1 ))
|
||||
/usr/bin/test ! -f "${BORG_LOG_CREATE}" && \
|
||||
/usr/bin/touch "${BORG_LOG_CREATE}"
|
||||
/usr/bin/test ! -f "${BORG_LOG_PRUNE}" && \
|
||||
/usr/bin/touch "${BORG_LOG_PRUNE}"
|
||||
DATE=$(/usr/bin/date)
|
||||
if [ ! -s "${BORG_LOG_CREATE}" ]; then
|
||||
/usr/bin/echo -n -e "Date: ${DATE}\nRepository ID: ${BORG_REPO_ID}\n\n" >> "${BORG_LOG_CREATE}"
|
||||
else
|
||||
/usr/bin/echo -n -e "\nDate: ${DATE}\nRepository ID: ${BORG_REPO_ID}\n\n" >> "${BORG_LOG_CREATE}"
|
||||
fi
|
||||
/usr/bin/borg create --debug \
|
||||
--compression "${BORG_COMPRESSION}" \
|
||||
--exclude-from "${BORG_CONFIG_EXCLUDE}" \
|
||||
::"${BORG_REPO_ID}" \
|
||||
'/' \
|
||||
&>> "${BORG_LOG_CREATE}"
|
||||
DATE=$(/usr/bin/date)
|
||||
if [ ! -s "${BORG_LOG_PRUNE}" ]; then
|
||||
/usr/bin/echo -n -e "Date: ${DATE}\nRepository ID: ${BORG_REPO_ID}\n\n" >> "${BORG_LOG_PRUNE}"
|
||||
else
|
||||
/usr/bin/echo -n -e "\nDate: ${DATE}\nRepository ID: ${BORG_REPO_ID}\n\n" >> "${BORG_LOG_PRUNE}"
|
||||
fi
|
||||
/usr/bin/borg prune --debug \
|
||||
--keep-within="${BORG_PRUNE_WITHIN}" \
|
||||
--keep-daily="${BORG_PRUNE_DAILY}" \
|
||||
--keep-weekly="${BORG_PRUNE_WEEKLY}" \
|
||||
--keep-monthly="${BORG_PRUNE_MONTHLY}" \
|
||||
--save-space \
|
||||
&>> "${BORG_LOG_PRUNE}"
|
||||
/usr/bin/run-parts --new-session "${BORG_POSTEXEC_DIR}"
|
||||
Reference in New Issue
Block a user