Inital Commit
All checks were successful
Borgbackup Schedule / Borgbackup Schedule [arm64] (push) Successful in 16s
Borgbackup Schedule / Borgbackup Schedule [amd64] (push) Successful in 12s

This commit is contained in:
Cantibra
2025-10-26 21:11:04 +01:00
commit a6db7726e6
18 changed files with 1177 additions and 0 deletions

4
root/DEBIAN/conffiles Normal file
View File

@@ -0,0 +1,4 @@
/etc/borgbackup/config
/etc/borgbackup/exclude
/etc/borgbackup/password
/etc/cron.d/borgbackup

10
root/DEBIAN/control Normal file
View File

@@ -0,0 +1,10 @@
Package: borgbackup-schedule
Version: 1.0.0
Architecture:
Installed-Size:
Depends: borgbackup, fuse, python3-llfuse
Priority: optional
Section: misc
Homepage: http://www.privlab.it
Maintainer: PrivLab <hostmaster@privlab.it>
Description: Borgbackup schedule backup service

40
root/DEBIAN/postinst Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/sh
set -e
set -u
if [ -d '/run/systemd/system' ]; then
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
/usr/bin/true
fi
case "${1}" in
configure)
if [ -x '/usr/bin/deb-systemd-helper' ]; then
/usr/bin/deb-systemd-helper unmask 'borgbackup.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-helper unmask 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
if /usr/bin/deb-systemd-helper --quiet was-enabled 'borgbackup.timer'; then
/usr/bin/deb-systemd-helper enable 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
else
/usr/bin/deb-systemd-helper update-state 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
/usr/bin/chgrp --quiet 'adm' '/var/log/borgbackup'
/usr/bin/chgrp --quiet 'adm' '/var/logrotate/borgbackup'
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
/usr/bin/true
if [ -n "${2}" ]; then
_dh_action='restart'
else
_dh_action='start'
fi
/usr/bin/deb-systemd-invoke "${_dh_action}" 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
;;
esac

46
root/DEBIAN/postrm Normal file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/sh
set -e
set -u
if [ -d '/run/systemd/system' ]; then
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
/usr/bin/true
fi
case "${1}" in
remove)
if [ -x '/usr/bin/deb-systemd-helper' ]; then
/usr/bin/deb-systemd-helper mask 'borgbackup.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-helper mask 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
/usr/bin/rm --force --recursive '/var/cache/borgbackup/'*
/usr/bin/rm --force --recursive '/var/cache/borgbackup/'.*
/usr/bin/rm --force --recursive '/var/log/borgbackup/'*
/usr/bin/rm --force --recursive '/var/log/borgbackup/'.*
/usr/bin/rm --force --recursive '/var/logrotate/borgbackup/'*
/usr/bin/rm --force --recursive '/var/logrotate/borgbackup/'.*
;;
purge)
if [ -x '/usr/bin/deb-systemd-helper' ]; then
/usr/bin/deb-systemd-helper purge 'borgbackup.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-helper purge 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-helper unmask 'borgbackup.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-helper unmask 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
/usr/bin/rm --force --recursive '/var/cache/borgbackup/'*
/usr/bin/rm --force --recursive '/var/cache/borgbackup/'.*
/usr/bin/rm --force --recursive '/var/lib/borgbackup/'*
/usr/bin/rm --force --recursive '/var/lib/borgbackup/'.*
/usr/bin/rm --force --recursive '/var/log/borgbackup/'*
/usr/bin/rm --force --recursive '/var/log/borgbackup/'.*
/usr/bin/rm --force --recursive '/var/logrotate/borgbackup/'*
/usr/bin/rm --force --recursive '/var/logrotate/borgbackup/'.*
;;
esac

19
root/DEBIAN/prerm Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/sh
set -e
set -u
case "${1}" in
remove)
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
/usr/bin/deb-systemd-invoke stop 'borgbackup.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-invoke stop 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-invoke disable 'borgbackup.service' > '/dev/null' 2>&1 || \
/usr/bin/true
/usr/bin/deb-systemd-invoke disable 'borgbackup.timer' > '/dev/null' 2>&1 || \
/usr/bin/true
fi
;;
esac

View File

@@ -0,0 +1,81 @@
# Borgbackup Configuration File
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
# Run Borgbackup every 6 hours.
#
TIMER='false'
# Set the repository location.
#
BORG_REPO=''
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
# Select compression algorithm.
# none - No Compression
# lz4 - Low Compression
# auto,lz4 - Low Compression of compressible data
# zlib - High Compression
# auto,zlib - High Compression of compressible data
# lzma,N - Very High Compression
# auto,lzma,N - Very High Compression of compressible data
#
BORG_COMPRESSION='auto,zlib'
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
# Keep all archives within this time interval.
#
BORG_PRUNE_WITHIN='1d'
# Keep number of daily archives.
#
BORG_PRUNE_DAILY='7'
# Keep number of weekly archives.
#
BORG_PRUNE_WEEKLY='4'
# Keep number of monthly archives.
#
BORG_PRUNE_MONTHLY='3'
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
# A numeric value, this determines the maximum "time to live" for the
# files cache entries.
#
BORG_FILES_CACHE_TTL='7'
# When set, system information (like OS, Python version, …) in exceptions
# is shown.
#
BORG_SHOW_SYSINFO='no'
# A list of comma separated strings that trigger workarounds in borg, e.g.
# to work around bugs in other software.
#
# basesyncfile - Use the more simple BaseSyncFile code to
# avoid issues with sync_file_range. You might
# need this to run borg on WSL (Windows
# Subsystem for Linux) or in systemd.nspawn
# containers on some architectures (e.g. ARM).
# Using this does not affect data safety, but
# might result in a more bursty write to disk
# behaviour (not continuously
# streaming to disk).
#
# retry_erofs - Retry opening a file without O_NOATIME if
# opening a file with O_NOATIME caused EROFS.
# You will need this to make archives from
# volume shadow copies in WSL1
# (Windows Subsystem for Linux 1).
#
# authenticated_no_key - Work around a lost passphrase or key for an
# authenticated mode repository (these are only
# authenticated, but not encrypted). If the key
# is missing in the repository config, add
# key = anything there.
#
BORG_WORKAROUNDS=''

View File

@@ -0,0 +1,9 @@
# Borgbackup Exclusion List
# Defines which data are not included in the backup.
/dev/*
/lost+found/*
/proc/*
/run/*
/sys/*
/tmp/*
/var/tmp/*

View File

@@ -0,0 +1,17 @@
# /etc/cron.d/borgbackup
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# * * * * * user command to execute
# | | | | |
# | | | | |
# | | | | |_______________ day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# | | | |______________________ month (1 - 12)
# | | |_____________________________ day of month (1 - 31)
# | |____________________________________ hour (0 - 23)
# |___________________________________________ min (0 - 59)
#
0 */6 * * * root if [ -d '/run/systemd/system' ]; then exit 0; fi; if ! '/usr/lib/borgbackup/check_condition'; then exit 1; fi; '/usr/lib/borgbackup/start_backup';
#

View File

@@ -0,0 +1,74 @@
/var/log/borgbackup/*.log {
# Truncate the original log file in place after creating a copy,
# instead of moving the old log file and optionally creating a
# new one. It can be used when some program cannot be told to
# close its logfile and thus might continue writing (appending)
# to the previous log file forever. Note that there is a very
# small time slice between copying the file and truncating it, so
# some logging data might be lost. When this option is used, the
# create option will have no effect, as the old log file stays in
# place.
copytruncate
# Archive old versions of log files adding a daily extension like
# YYYYMMDD instead of simply adding a number. The extension may
# be configured using the dateformat option.
dateext
# Specify the extension for dateext using the notation similar to
# strftime(3) function. Only %Y %m %d and %s specifiers are allowed.
# The default value is -%Y%m%d. Note that also the character
# separating log name from the extension is part of the dateformat
# string. The system clock must be set past Sep 9th 2001 for %s to
# work correctly. Note that the datestamps generated by this format
# must be lexically sortable (i.e., first the year, then the month
# then the day. e.g., 2001/12/01 is ok, but 01/12/2001 is not, since
# 01/11/2002 would sort lower while it is later). This is because when
# using the rotate option, logrotate sorts all rotated filenames to
# find out which logfiles are older and should be removed.
dateformat .%Y-%m-%d
# Use yesterday's instead of today's date to create the dateext
# extension, so that the rotated log file has a date in its name that
# is the same as the timestamps within it.
dateyesterday
# Postpone compression of the previous log file to the next rotation
# cycle. This only has effect when used in combination with compress.
# It can be used when some program cannot be told to close its logfile
# and thus might continue writing to the previous log file for some time.
delaycompress
# Do not copy the original log file and leave it in place.
nocopy
# New log files are not created.
nocreate
# Don't mail old log files to any address.
nomail
# Do not use shred when deleting old log files.
noshred
# Do not rotate the log if it is empty.
notifempty
# Logs are moved into directory for rotation. The directory must be on the
# same physical device as the log file being rotated, and is assumed to be
# relative to the directory holding the log file unless an absolute path
# name is specified. When this option is used all old versions of the log
# end up in directory.
olddir /var/logrotate/borgbackup
# Log files are rotated count times before being removed or mailed to the
# address specified in a mail directive. If count is 0, old versions are
# removed rather than rotated.
rotate 12
# Log files are rotated if the current weekday is less than the weekday of
# the last rotation or if more than a week has passed since the last
# rotation. This is normally the same as rotating logs on the first day of
# the week, but it works better if logrotate is not run every night.
weekly
}

View File

@@ -0,0 +1,13 @@
[Unit]
Description=Borgbackup Automatic Backup Service
After=network.target network-online.target
Wants=network.target
[Service]
Type=simple
ExecCondition=/usr/lib/borgbackup/check_conditions
ExecStart=/usr/lib/borgbackup/start_backup
PrivateTmp=true
[Install]
WantedBy=timers.target

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Borgbackup Automatic Backup Timer
[Timer]
OnCalendar=*-*-* 00/6:00:00
Persistent=true
[Install]
WantedBy=timers.target

View 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'

View 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}"