16 Commits

Author SHA1 Message Date
daniel156161 1445be23a0 mv TMP_FILE to borg_exporter.prom and only pars data that got fully written
Build and Push Docker Container / build-and-push (push) Successful in 1m8s
2026-05-02 11:18:08 +02:00
daniel156161 317e8b6b16 fix node exporter to keep last data
Build and Push Docker Container / build-and-push (push) Successful in 1m37s
2026-05-01 16:34:09 +02:00
daniel156161 338ca43328 fix environment file to not fill with duplicate values with restart container
Build and Push Docker Container / build-and-push (push) Successful in 58s
2026-04-17 16:21:51 +02:00
daniel156161 441d9a9890 update container version
Build and Push Docker Container / build-and-push (push) Successful in 1m4s
2026-04-17 11:48:15 +02:00
daniel156161 df3ac965b9 fixing terminal sepurator to fill it
Build and Push Docker Container / build-and-push (push) Successful in 56s
2026-04-17 10:26:13 +02:00
daniel156161 e61bcb7af4 fix that version is only once
Build and Push Docker Container / build-and-push (push) Successful in 55s
2026-04-17 10:11:26 +02:00
daniel156161 1a1c6cbfbe fix creting of docker client version
Build and Push Docker Container / build-and-push (push) Successful in 54s
2026-04-17 09:56:17 +02:00
daniel156161 29a072cabe fix setting of docker socket version and use it over ssh
Build and Push Docker Container / build-and-push (push) Successful in 53s
2026-04-17 09:42:04 +02:00
daniel156161 5e42200431 set docker socket api version for client
Build and Push Docker Container / build-and-push (push) Successful in 1m5s
2026-04-17 09:24:15 +02:00
daniel156161 c3b235e4ed fix creating of authorized_keys and give borg docker socket permissions
Build and Push Docker Container / build-and-push (push) Successful in 59s
2026-04-17 09:06:43 +02:00
daniel156161 0609c7fedc add docker-cli and set correct column lengh in terminal
Build and Push Docker Container / build-and-push (push) Successful in 1m8s
2026-04-17 08:40:33 +02:00
daniel156161 dc27d4ea69 install fastfetch and only show fastfetch when installed and fix update alias and building of spaceing
Build and Push Docker Container / build-and-push (push) Successful in 1m17s
2026-04-12 00:52:00 +02:00
daniel156161 04cd1a4ee3 fix borg_exporter datediff error becuase alpine not have it, changed to python
Build and Push Docker Container / build-and-push (push) Waiting to run
2026-04-12 00:43:19 +02:00
daniel156161 1da0105b61 fix creating if user already exists
Build and Push Docker Container / build-and-push (push) Successful in 2m18s
2026-04-12 00:04:10 +02:00
daniel156161 06c3aca483 Merge branch 'main' into alpine
Build and Push Docker Container / build-and-push (push) Successful in 1m30s
2026-04-11 23:42:29 +02:00
daniel156161 03f5eaf1d2 rewrite conatiner to use the base image alpine:3.23 2026-04-11 23:24:13 +02:00
10 changed files with 233 additions and 152 deletions
-3
View File
@@ -1,3 +0,0 @@
[submodule "package/teleport-bin"]
path = package/teleport-bin
url = git@git.yiprawr.dev:daniel156161/teleport-bin.git
+21 -39
View File
@@ -1,4 +1,4 @@
FROM archlinux:latest
FROM alpine:3.23
ENV USER=borg
ENV UID=1000
@@ -9,8 +9,18 @@ ENV RUN_INSTALL_SCRIPT="false"
ENV RUN_PROMETHEUS_EXPORTER="false"
ENV TZ=""
# Add Folders and Shell Scripts
RUN mkdir "/.ssh"
RUN apk add --no-cache \
bash sudo openssh-server shadow tzdata curl git dcron coreutils grep sed gawk util-linux ca-certificates tmux fastfetch prometheus-node-exporter \
borgbackup docker-cli \
&& mkdir -p \
/.ssh \
/backups \
/logs \
/run/sshd \
/root/.cache/crontab \
/sshkeys/clients \
/sshkeys/host
VOLUME ["/backups"]
VOLUME ["/logs"]
VOLUME ["/sshkeys/host"]
@@ -18,44 +28,16 @@ VOLUME ["/sshkeys/host"]
COPY entrypoint-script/entrypoint.sh /
COPY entrypoint-script/variables.sh /
COPY scripts/borgbackup.sh /usr/local/bin/
COPY bash-config/.bash_profile /root/
COPY bash-config/.bashrc_root /root/
COPY bash-config/.bash_profile /
COPY bash-config/.bashrc /
COPY bash-config/locale.gen /etc/locale.gen
COPY prometheus-borg-exporter/borg_exporter.sh /usr/local/bin/
COPY prometheus-borg-exporter/borg_exporter.rc /etc/
COPY bash-config/.bash_profile /root/
COPY bash-config/.bashrc_root /root/
COPY bash-config/.bash_profile /
COPY bash-config/.bashrc /
COPY sshd_config /etc/ssh/sshd_config
# Create .cache folder
RUN mkdir -p "/root/.cache/crontab"
# Create locale files
RUN locale-gen
# Install packages
RUN pacman-key --init
RUN pacman -Syu --noconfirm sudo bash-completion openssh fastfetch \
borgbackup dateutils prometheus-node-exporter wget git base-devel cron net-tools inetutils tmux
# Make Build User
RUN useradd builduser -m
RUN passwd -d builduser
RUN printf 'builduser ALL=(ALL) ALL\n' | tee -a /etc/sudoers
RUN sudo -u builduser bash -c 'cd ~ && git clone https://aur.archlinux.org/teleport-bin.git teleport && cd teleport && makepkg -si --noconfirm && cd ~ && rm -rf teleport'
#RUN sudo -u builduser bash -c 'cd ~ && git clone https://git.yiprawr.dev/daniel156161/teleport-bin.git teleport && cd teleport && makepkg -si --noconfirm && cd ~ && rm -rf teleport'
RUN userdel -r builduser
# Setup SSH-Server
RUN sed -ie 's/#Port 22/Port 22/g' /etc/ssh/sshd_config
RUN sed -ie 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
RUN sed -ie 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
RUN sed -ie 's|#HostKey /etc/ssh/ssh_host_rsa_key|HostKey /sshkeys/host/ssh_host_rsa_key|g' /etc/ssh/sshd_config
RUN sed -ie 's|#HostKey /etc/ssh/ssh_host_ecdsa_key|HostKey /sshkeys/host/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
RUN sed -ie 's|#HostKey /etc/ssh/ssh_host_ed25519_key|HostKey /sshkeys/host/ssh_host_ed25519_key|g' /etc/ssh/sshd_config
RUN chmod 0755 /entrypoint.sh /usr/local/bin/borgbackup.sh /usr/local/bin/borg_exporter.sh
EXPOSE 22
ENTRYPOINT [ "/entrypoint.sh" ]
ENTRYPOINT ["/entrypoint.sh"]
+12 -8
View File
@@ -1,9 +1,9 @@
if [ ! -z $(cat /etc/environment | grep "USE_TMUX_SHELL") ] && [[ -t 0 ]] && [ -z "$TMUX" ]; then
if grep -q "USE_TMUX_SHELL" /etc/environment && [[ -t 0 ]] && [ -z "$TMUX" ]; then
tmux attach || tmux new-session
exit
fi
alias update='sudo pacman -Syu --noconfirm'
alias update='sudo apk update && sudo apk upgrade'
export HISTTIMEFORMAT="%d/%m/%y %T "
export PS1='\u@\h:\W \$ '
@@ -14,19 +14,23 @@ alias ll='ls -alF'
alias ls='ls --color=auto'
export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "
##############################################################################################################################
###############################################################################
# Functions
##############################################################################################################################
###############################################################################
source "/variables.sh"
COLUMNS=$(/usr/bin/tput cols)
if command -v tput >/dev/null 2>&1; then
COLUMNS=$(tput cols)
fi
function print_container_info {
sepurator
echo "BorgServer powered by $BORG_VERSION - Image Hostname: $HOSTNAME | Image Version: $DOCKER_IMAGE_VERSION"
sepurator
}
##############################################################################################################################
###############################################################################
# Run Code
##############################################################################################################################
###############################################################################
print_container_info
fastfetch --config neofetch
if command -v fastfetch >/dev/null 2>&1; then
fastfetch --config neofetch
fi
+11 -7
View File
@@ -1,4 +1,4 @@
alias update='pacman -Syu --noconfirm'
alias update='apk update && apk upgrade'
export HISTTIMEFORMAT="%d/%m/%y %T "
export PS1='\u@\h:\W \$ '
@@ -9,11 +9,13 @@ alias ll='ls -alF'
alias ls='ls --color=auto'
export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "
##############################################################################################################################
###############################################################################
# Borg Repo finder
##############################################################################################################################
###############################################################################
source "/variables.sh"
COLUMNS=$(/usr/bin/tput cols)
if command -v tput >/dev/null 2>&1; then
COLUMNS=$(tput cols)
fi
function find_borg_repo {
repo_list=( $(find "$1" -name "index.*" -type f | rev | cut -d '/' -f "2-" | rev) )
@@ -84,9 +86,9 @@ function print_container_info {
echo "BorgServer powered by $BORG_VERSION - Image Hostname: $HOSTNAME | Image Version: $DOCKER_IMAGE_VERSION"
sepurator
}
##############################################################################################################################
###############################################################################
# Run Code
##############################################################################################################################
###############################################################################
if [ "$INTERACTIVE_MODE" != "false" ]; then
find_borg_repo /backups/
export BORG_REPO="${repo_list[selected_repo]}"
@@ -97,4 +99,6 @@ if [ "$INTERACTIVE_MODE" != "false" ]; then
fi
print_container_info
fastfetch --config neofetch
if command -v fastfetch >/dev/null 2>&1; then
fastfetch --config neofetch
fi
Executable → Regular
+117 -72
View File
@@ -1,17 +1,20 @@
#!/bin/bash
set -euo pipefail
source "/variables.sh"
#####################################################################################################
USER_GROUP="$USER"
###############################################################################
# Funktionen
#####################################################################################################
###############################################################################
function set_environment_variables_if_not_empty {
# Set Tmux Shell for .bashrc to load tmux and attach session if exists else create new session
if [ "$USE_TMUX_SHELL" != "" ]; then
echo "USE_TMUX_SHELL=$USE_TMUX_SHELL" >> /etc/environment
if [ -n "${USE_TMUX_SHELL:-}" ]; then
grep -q "^USE_TMUX_SHELL=" /etc/environment || echo "USE_TMUX_SHELL=$USE_TMUX_SHELL" >> /etc/environment
fi
# Set Server Timezone
if [ "$TZ" != "" ]; then
echo "TZ=$TZ" >> /etc/environment
if [ -n "${TZ:-}" ]; then
grep -q "^TZ=" /etc/environment || echo "TZ=$TZ" >> /etc/environment
ln -sf "/usr/share/zoneinfo/$TZ" /etc/localtime
fi
}
@@ -29,54 +32,105 @@ function print_user_info {
echo "* GROUP: $USER - GID: $GID"
}
function create_folder_and_change_permissions {
if [ ! -d "$1" ]; then
mkdir -p "$1"
fi
chown -R "$USER":"$USER_GROUP" "$1"
}
function add_borg_user {
if ! id "$USER" &>/dev/null; then
groupadd -g "$GID" "$USER" >> /dev/null
useradd -r -u "$UID" -g "$GID" -s "/bin/bash" "$USER" >> /dev/null
passwd -d "$USER" >> /dev/null
printf "$USER ALL=(ALL) NOPASSWD: ALL\n" | tee -a /etc/sudoers >> /dev/null
usermod -d / borg >> /dev/null
if ! id "$USER" >/dev/null 2>&1; then
local group_name="$USER"
local existing_group
existing_group="$(getent group "$GID" | cut -d: -f1 || true)"
if [ -n "$existing_group" ]; then
group_name="$existing_group"
elif ! getent group "$USER" >/dev/null 2>&1; then
groupadd -g "$GID" "$USER" >/dev/null
fi
USER_GROUP="$group_name"
if getent passwd "$UID" >/dev/null 2>&1; then
existing_user="$(getent passwd "$UID" | cut -d: -f1)"
usermod -l "$USER" "$existing_user" >/dev/null 2>&1 || true
usermod -d / -s /bin/bash -g "$group_name" "$USER" >/dev/null
else
useradd -M -u "$UID" -g "$group_name" -d / -s /bin/bash "$USER" >/dev/null
fi
printf "%s ALL=(ALL) NOPASSWD: ALL\n" "$USER" >> /etc/sudoers
create_folder_and_change_permissions "/.config"
create_folder_and_change_permissions "/.cache"
chmod 700 "/.cache"
else
USER_GROUP="$(id -gn "$USER")"
fi
random_pw="$(dd if=/dev/urandom bs=18 count=1 2>/dev/null | base64)"
echo "${USER}:${random_pw}" | chpasswd >/dev/null 2>&1 || true
}
function add_docker_socket_permission {
if [ ! -S /var/run/docker.sock ]; then
return
fi
local sock_gid
sock_gid="$(stat -c '%g' /var/run/docker.sock)"
local group_name
group_name="$(getent group "$sock_gid" | cut -d: -f1 || true)"
if [ -z "$group_name" ]; then
groupadd -g "$sock_gid" docker
group_name="docker"
fi
usermod -aG "$group_name" "$USER"
echo "* Docker socket access granted ($group_name GID=$sock_gid)"
local server_api
server_api="$(curl -sf --unix-socket /var/run/docker.sock http://localhost/version 2>/dev/null \
| grep -o '"ApiVersion":"[^"]*"' | head -1 | cut -d'"' -f4 | tr -d '[:space:]' || true)"
if [ -n "$server_api" ]; then
printf 'export DOCKER_API_VERSION="%s"\n' "$server_api" > /etc/profile.d/docker_api_version.sh
printf 'DOCKER_API_VERSION=%s\n' "$server_api" > "/.ssh/environment"
sed -i '/^DOCKER_API_VERSION=/d' /etc/environment
printf 'DOCKER_API_VERSION=%s\n' "$server_api" >> /etc/environment
export DOCKER_API_VERSION="$server_api"
echo "* Docker API version pinned to $server_api"
fi
}
function make_and_import_ssh_keys {
local create_folders="0"
if [ ! -f "/.ssh/authorized_keys" ]; then
touch "/.ssh/authorized_keys"
else
rm "/.ssh/authorized_keys"
touch "/.ssh/authorized_keys"
fi
mkdir -p "/.ssh"
: > "/.ssh/authorized_keys"
for key in ${SSH_FOLDERS[@]}; do
if [ ! -d "${key}" ]; then
mkdir -p "${key}"
echo "Created ${key}"
for key_dir in "${SSH_FOLDERS[@]}"; do
if [ ! -d "$key_dir" ]; then
mkdir -p "$key_dir"
echo "Created $key_dir"
create_folders="1"
fi
done
#chown -R "$USER":"$USER" "/sshkeys"
if [ $create_folders == "1" ]; then
if [ "$create_folders" = "1" ]; then
sepurator
fi
echo "* IMPORT SSH KEYS"
FILES=$(ls -1 /sshkeys/clients)
for key in $FILES; do
echo "- Adding SSH-Key $key"
cat "/sshkeys/clients/$key" >> "/.ssh/authorized_keys"
echo "" >> "/.ssh/authorized_keys"
shopt -s nullglob
for key in /sshkeys/clients/*; do
echo "- Adding SSH-Key $(basename "$key")"
awk 'NF' "$key" >> "/.ssh/authorized_keys"
printf '\n' >> "/.ssh/authorized_keys"
done
shopt -u nullglob
chown -R "$USER":"$USER" "/.ssh"
chown -R "$USER":"$USER_GROUP" "/.ssh"
chmod 700 "/.ssh"
chmod 600 "/.ssh/authorized_keys"
}
@@ -89,26 +143,30 @@ function print_message {
function generate_host_sshkey {
# Generate SSH-Keys
mkdir -p /sshkeys/host
if [ ! -f "/sshkeys/host/ssh_host_rsa_key" ]; then
sepurator
print_message "HOST SSH-KEY RSA not found, generating..."
ssh-keygen -t rsa -b 4096 -f "/sshkeys/host/ssh_host_rsa_key" -N ""
ssh-keygen -q -t rsa -b 4096 -f "/sshkeys/host/ssh_host_rsa_key" -N ""
print_message "HOST SSH-KEY RSA Generated"
fi
if [ ! -f "/sshkeys/host/ssh_host_ecdsa_key" ]; then
sepurator
print_message "HOST SSH-KEY ECDSA not found, generating..."
ssh-keygen -t ecdsa -b 521 -f "/sshkeys/host/ssh_host_ecdsa_key" -N ""
ssh-keygen -q -t ecdsa -b 521 -f "/sshkeys/host/ssh_host_ecdsa_key" -N ""
print_message "HOST SSH-KEY ECDSA Generated"
fi
if [ ! -f "/sshkeys/host/ssh_host_ed25519_key" ]; then
sepurator
print_message "HOST SSH-KEY ED25519 not found, generating..."
ssh-keygen -t ed25519 -b 521 -f "/sshkeys/host/ssh_host_ed25519_key" -N ""
ssh-keygen -q -t ed25519 -f "/sshkeys/host/ssh_host_ed25519_key" -N ""
print_message "HOST SSH-KEY ED25519 Generated"
fi
chown -R "$USER":"$USER" "/sshkeys/host"
chmod 600 /sshkeys/host/ssh_host_*_key
chmod 644 /sshkeys/host/ssh_host_*_key.pub
chown root:root /sshkeys/host/ssh_host_* || true
}
function maintenance_enable {
@@ -116,7 +174,7 @@ function maintenance_enable {
echo "* MAINTENANCE MODE - ENABLED"
if [ -f "/crontab.txt" ]; then
crontab "/crontab.txt"
crond -i 2> /dev/null
crond
echo "- Crontab loaded successfully"
else
echo "- Can not find /crontab.txt"
@@ -126,7 +184,7 @@ function maintenance_enable {
}
function show_timezone_output {
if [ "$TZ" != "" ]; then
if [ -n "${TZ:-}" ]; then
echo "* Setting Timezone to $TZ"
else
echo "* Timezone not set - Use UTC Time"
@@ -135,37 +193,26 @@ function show_timezone_output {
}
function run_install_script {
if [ "$RUN_INSTALL_SCRIPT" != "false" ]; then
if [ ! -f "/.runnedInstall" ]; then
echo "* RUNNING INSTALL SCRIPT"
sepurator
sh "$RUN_INSTALL_SCRIPT"
sepurator
touch "/.runnedInstall"
fi
if [ "$RUN_INSTALL_SCRIPT" != "false" ] && [ ! -f "/.runnedInstall" ]; then
echo "* RUNNING INSTALL SCRIPT"
sepurator
sh "$RUN_INSTALL_SCRIPT"
sepurator
touch "/.runnedInstall"
fi
}
function create_folder_and_change_permissions {
if [ ! -d "$1" ]; then
mkdir -p "$1"
fi
chown -R "$USER":"$USER" "$1"
}
function run_prometheus_exporter() {
function run_prometheus_exporter {
if [ "$RUN_PROMETHEUS_EXPORTER" != "false" ]; then
create_folder_and_change_permissions "/var/log/"
echo "* STARTING Prometheus Exporter for Borg Backup"
crontab -l > /tmp/cron_bkp
crontab -l > /tmp/cron_bkp 2>/dev/null || true
echo "" >> /tmp/cron_bkp
echo "- Add Cronjob to Crontab"
echo "$RUN_PROMETHEUS_EXPORTER su -c '/usr/local/bin/borg_exporter.sh 2>&1' -s /bin/bash borg" >> /tmp/cron_bkp
crontab /tmp/cron_bkp > /dev/null 2>&1
crontab /tmp/cron_bkp >/dev/null 2>&1
rm /tmp/cron_bkp
if [ ! -f "/var/log/borg_exporter.prom" ]; then
@@ -174,25 +221,24 @@ function run_prometheus_exporter() {
fi
echo "- STARTING Node Exporter"
sudo -H -u "$USER" bash -c "prometheus-node-exporter --collector.textfile.directory=$NODE_EXPORTER_DIR > /dev/null 2>&1 &"
if command -v prometheus-node-exporter >/dev/null 2>&1; then
sudo -H -u "$USER" bash -c "prometheus-node-exporter --collector.textfile.directory=$NODE_EXPORTER_DIR >/dev/null 2>&1 &"
elif command -v node_exporter >/dev/null 2>&1; then
sudo -H -u "$USER" bash -c "node_exporter --collector.textfile.directory=$NODE_EXPORTER_DIR >/dev/null 2>&1 &"
fi
if ! pgrep -x crond >/dev/null 2>&1; then
crond
fi
sepurator
fi
}
function run_correct_ssh_service() {
if [ -f "/etc/teleport.yaml" ]; then
echo "* STARTING Teleport Server"
exec teleport start -c /etc/teleport.yaml 2>&1
else
exec /usr/sbin/sshd -D -e "$@" 2>&1
fi;
}
#####################################################################################################
###############################################################################
# Main Code
#####################################################################################################
###############################################################################
set_environment_variables_if_not_empty
dbus-uuidgen --ensure=/etc/machine-id
add_borg_user
add_docker_socket_permission
print_container_info
print_user_info
@@ -209,5 +255,4 @@ run_install_script
echo "* Init done! - Starting SSH-Daemon..."
sepurator
run_correct_ssh_service
exec /usr/sbin/sshd -D -e "$@" 2>&1
+7 -6
View File
@@ -1,16 +1,17 @@
DOCKER_IMAGE_VERSION="3.0.0"
DOCKER_IMAGE_VERSION="3.1.0"
BORG_VERSION=$(borg -V)
SSH_FOLDERS=( "/sshkeys/clients" "/sshkeys/host" )
NODE_EXPORTER_DIR="/var/log"
COLUMNS="86"
##############################################################################################################################
DEFAULT_COLUMNS="86"
###############################################################################
# Funktionen
##############################################################################################################################
###############################################################################
function sepurator {
if [ ! -z "$2" ]; then
if [ -n "${2:-}" ]; then
local end="$2"
else
local end="$COLUMNS"
local end
end=$(tput cols 2>/dev/null || echo "${COLUMNS:-${DEFAULT_COLUMNS:-80}}")
fi
local start=1
+29 -15
View File
@@ -2,22 +2,17 @@
source /etc/borg_exporter.rc
source /variables.sh
TMP_FILE="/tmp/prometheus-borg"
DATEDIFF=`which datediff`
if [ -z "$DATEDIFF" ]; then
#ubuntu packages have a different executable name
DATEDIFF=`which dateutils.ddiff`
fi
TMP_FILE="/tmp/prometheus-borg.$$"
[ -e $TMP_FILE ] && rm -f $TMP_FILE
[ -e "$TMP_FILE" ] && rm -f "$TMP_FILE"
#prevent "Attempting to access a previously unknown unencrypted repository" prompt
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
HOSTNAME=$(hostname)
##############################################################################################################################
###################################################################################################
# Funktionen
##############################################################################################################################
###################################################################################################
function writeToFile() {
msg="$1"
local -n arr=$2
@@ -50,6 +45,20 @@ function calc_bytes {
esac
}
function calc_hours_diff {
local start_ts="$1"
local end_ts="$2"
python3 - "$start_ts" "$end_ts" <<'PY'
from datetime import datetime
import sys
start = datetime.strptime(sys.argv[1], "%Y-%m-%d %H:%M:%S")
end = datetime.strptime(sys.argv[2], "%Y-%m-%d %H:%M:%S")
print(int((end - start).total_seconds() // 3600))
PY
}
function writeDefinitionsToMetrics() {
#print the definition of the metrics
echo "# HELP borg_hours_from_last_archive How many hours have passed since the last archive was added to the repo (counted by borg_exporter.sh)" >> $TMP_FILE
@@ -101,7 +110,7 @@ function getBorgDataForRepository {
if [ -n "${LAST_ARCHIVE}" ]; then
LAST_ARCHIVE_DATE=$(echo $LAST_ARCHIVE | awk '{print $3" "$4}')
CURRENT_DATE="$(date '+%Y-%m-%d %H:%M:%S')"
NB_HOUR_FROM_LAST_BCK=$($DATEDIFF "$LAST_ARCHIVE_DATE" "$CURRENT_DATE" -f '%H')
NB_HOUR_FROM_LAST_BCK="$(calc_hours_diff "$LAST_ARCHIVE_DATE" "$CURRENT_DATE")"
# in case the date parsing from BORG didn't work (e.g. archive with space in it), datediff will output
# a usage message on stdout and will break prometheus formatting. We need to
@@ -182,13 +191,18 @@ function findRepositorysAndGetData() {
}
function sendDataToGatewayOrNodeExplorer() {
if ! grep -qE '^borg_[a-zA-Z_]+\{[^}]+\} [0-9]' "$TMP_FILE"; then
echo "No valid borg metric data collected; keeping previous metrics output untouched."
return 1
fi
if [ -n "${PUSHGATEWAY_URL}" ]; then
#send data via pushgateway
cat $TMP_FILE | curl --data-binary @- ${PUSHGATEWAY_URL}/metrics/job/borg-exporter/host/$HOSTNAME/repository/$REPOSITORY
curl --data-binary @"$TMP_FILE" "${PUSHGATEWAY_URL}/metrics/job/borg-exporter/host/$HOSTNAME/repository/${REPOSITORY:-auto}"
else
#send data via node_exporter
if [ -d "${NODE_EXPORTER_DIR}" ]; then
cp $TMP_FILE ${NODE_EXPORTER_DIR}/borg_exporter.prom
mv "$TMP_FILE" "${NODE_EXPORTER_DIR}/borg_exporter.prom"
else
echo "Please configure either PUSHGATEWAY_URL or NODE_EXPORTER_DIR in /etc/borg_exporter.rc"
fi
@@ -196,12 +210,12 @@ function sendDataToGatewayOrNodeExplorer() {
}
function cleanup() {
rm -f $TMP_FILE
rm -f "$TMP_FILE"
}
##############################################################################################################################
###################################################################################################
# Main Code
##############################################################################################################################
###################################################################################################
writeDefinitionsToMetrics
if [ -n "${REPOSITORY}" ]; then
getBorgDataForRepository "${REPOSITORY}" "${HOSTNAME}"
+35
View File
@@ -0,0 +1,35 @@
Port 22
Protocol 2
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
HostKey /sshkeys/host/ssh_host_rsa_key
HostKey /sshkeys/host/ssh_host_ecdsa_key
HostKey /sshkeys/host/ssh_host_ed25519_key
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
ChallengeResponseAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey
PermitEmptyPasswords no
AuthorizedKeysFile .ssh/authorized_keys
PermitUserEnvironment yes
StrictModes yes
AllowUsers borg
AllowAgentForwarding no
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no
PermitTTY yes
PermitTunnel no
TCPKeepAlive yes
ClientAliveInterval 300
ClientAliveCountMax 3
UseDNS no
PrintMotd no
Subsystem sftp internal-sftp