backup docker script

docker compose backup serverhost
This commit is contained in:
lucas committed 2026-10-01 14:07:31 +00:00
1 parent 3c69b2c915
commit 72fe77f040
6 files changed
+301

No files matched your search

@@ -0,0 +1,32 @@
services:
diun:
image: crazymax/diun:latest
container_name: diun
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data:/data
environment:
TZ: Europe/Vienna
# General
DIUN_WATCH_WORKERS: 20
DIUN_WATCH_SCHEDULE: "0 0 * * *"
DIUN_PROVIDERS_DOCKER: "true"
DIUN_PROVIDERS_DOCKER_WATCHBYDEFAULT: "true"
# Email notifications
DIUN_NOTIF_MAIL_HOST: smtp.web.de
DIUN_NOTIF_MAIL_PORT: 587
DIUN_NOTIF_MAIL_USERNAME: ll_m@web.de
DIUN_NOTIF_MAIL_PASSWORD: Mira2012
DIUN_NOTIF_MAIL_FROM: ll_m@web.de
DIUN_NOTIF_MAIL_TO: ll_m@web.de
DIUN_NOTIF_MAIL_INSECURESKIPVERIFY: "false"
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
@@ -0,0 +1,15 @@
services:
node-exporter:
container_name: node-exporter
image: prom/node-exporter:latest
restart: unless-stopped
pid: host
command:
- '--path.rootfs=/host'
- '--collector.textfile.directory=/textfile'
volumes:
- '/:/host:ro,rslave'
- ./node_exporter/textfile_collector:/textfile:ro
ports:
- '9100:9100'
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/with-contenv bash
set -e
cp -f /hostscripts/torrent_mqtt.py /config/
cp -f /hostscripts/torrent_qbittorrent_complete.sh /config/
chmod +x /config/torrent_qbittorrent_complete.sh
#if ! command -v scp >/dev/null 2>&1; then
# echo "Install scp"
#
# for i in {1..12}; do
# if apk add --no-cache openssh-client; then
# break
# fi
#
# echo "Retry $i/12"
# sleep 5
# done
#fi
if [ ! -d /config/.venv ]; then
echo "Generate venv"
python3 -m venv /config/.venv
/config/.venv/bin/pip install --upgrade pip
/config/.venv/bin/pip install paho-mqtt
fi
chmod 700 /config/.ssh
chmod 600 /config/.ssh/id_ed25519
chmod 644 /config/.ssh/id_ed25519.pub
@@ -0,0 +1,193 @@
#!/bin/bash
###############################################################################
# Description:
# qBittorrent external script that:
# 1. Receives torrent name, root path and category from qBittorrent.
# 2. Sends the torrent name to torrent_mqtt.py.
# 3. Copies the torrent contents to mediahost via SCP.
# 4. Logs all output to a timestamped logfile.
#
# Usage:
# torrent_complete.sh <torrent_name> <root_path> <category>
#
# qBittorrent configuration:
# /home/lucas/scripts/serverhost/torrent_complete.sh "%N" "%R" "%L"
#
# Arguments:
# $1 Torrent name
# $2 Root path
# $3 Torrent category
#
# Log files:
# /home/lucas/.LOG/log_torrent_name_YYYY-MM-DD_HH-MM-SS.log
#
# Requirements:
# - bash
# - scp
# - SSH access to "mediahost"
# - /home/lucas/scripts/serverhost/torrent_mqtt.py
###############################################################################
set -u
SCRIPT_NAME="$(basename "$0")"
###############################################################################
# Usage
###############################################################################
usage() {
cat <<EOF
Usage:
$SCRIPT_NAME <torrent_name> <root_path> <category>
Description:
Sends the torrent name to torrent_mqtt.py and copies the torrent
contents to mediahost.
Arguments:
torrent_name Torrent name
root_path Torrent root path
category Torrent category
Example:
$SCRIPT_NAME "Ubuntu 24.04" "/downloads/Ubuntu 24.04" "Linux"
qBittorrent:
$SCRIPT_NAME "%N" "%R" "%L"
EOF
}
###############################################################################
# Check arguments
###############################################################################
if [[ $# -ne 3 ]]; then
usage >&2
exit 1
fi
TORRENT_NAME="$1"
ROOT_PATH="$2"
CATEGORY="$3"
if [[ "$CATEGORY" != *arr* ]]; then
###############################################################################
# Start
###############################################################################
echo "=================================================="
echo "Torrent transfer started"
echo "Date: $(date)"
echo "Script: $SCRIPT_NAME"
echo "Torrent name: $TORRENT_NAME"
echo "Root path: $ROOT_PATH"
echo "Category: $CATEGORY"
echo "=================================================="
###############################################################################
# Check for scp command
###############################################################################
if ! command -v scp >/dev/null 2>&1; then
echo "Install scp"
sed -i 's|http://|https://|g' /etc/apk/repositories
for i in {1..12}; do
if apk add --no-cache openssh-client; then
break
fi
echo "Retry $i/12"
sleep 5
done
fi
###############################################################################
# Send torrent name to MQTT script
###############################################################################
echo
echo "--- Sending torrent name to torrent_mqtt.py ---"
/config/.venv/bin/python3 /config/torrent_mqtt.py "$TORRENT_NAME"
MQTT_STATUS=$?
echo "torrent_mqtt.py exit status: $MQTT_STATUS"
###############################################################################
# Check root path
###############################################################################
echo
echo "--- Checking root path ---"
if [[ ! -d "$ROOT_PATH" ]]; then
echo "ERROR: Root path does not exist or is not a directory:"
echo " $ROOT_PATH"
exit 1
fi
echo "Root path exists."
###############################################################################
# Copy torrent to mediahost
###############################################################################
basename_root=$(basename "$ROOT_PATH")
echo $basename_root
if [ "$basename_root" = "downloads" ]; then
remote_dir="$TORRENT_NAME"
else
remote_dir="$basename_root"
fi
echo
echo "--- Copying torrent to mediahost ---"
echo "Source: $ROOT_PATH"
echo "Destination: mediahost:/torrent/qbittorrent/mediahost/"
ssh -i /config/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
lucas@mediahost "mkdir -p \"/torrent/qbittorrent/mediahost/$remote_dir\""
SSH_STATUS=$?
scp -i /config/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-r "$ROOT_PATH"/. lucas@mediahost:/torrent/qbittorrent/mediahost/
SCP_STATUS=$?
echo "scp exit status: $SCP_STATUS"
###############################################################################
# Result
###############################################################################
echo
echo "=================================================="
if [[ $MQTT_STATUS -ne 0 ]]; then
echo "WARNING: torrent_mqtt.py failed."
fi
if [[ $SSH_STATUS -eq 0 ]]; then
echo "Target Dir generated"
else
echo "ERROR: Target dir generation failed."
fi
if [[ $SCP_STATUS -eq 0 ]]; then
echo "Torrent transfer completed successfully."
else
echo "ERROR: Torrent transfer failed."
fi
echo "Finished: $(date +'%y%m%d %H%M%Sr')"
echo "=================================================="
else
echo "ARR handled torrent: $(date +'%y%m%d %H%M%S'): $TORRENT_NAME"
fi
# Return SCP's exit status to qBittorrent
exit 0
@@ -0,0 +1,23 @@
services:
qbittorrent:
#image: "lscr.io/linuxserver/qbittorrent:latest"
build: .
container_name: "qbittorrent"
environment:
- PGID=1000
- TZ=Europe/Vienna
- PUID=1000
- WEBUI_PORT=8080
ports:
- "8080:8080/tcp"
- "55661:55661/udp"
- "55661:55661/tcp"
restart: "unless-stopped"
volumes:
- "./10-torrent-init.sh:/custom-cont-init.d/10-torrent-init.sh:ro"
- "./config:/config"
- "/home/lucas/scripts/torrent:/hostscripts:ro"
- "/torrent/qbittorrent/downloads:/downloads"
- "/torrent/qbittorrent/torrents:/torrents"
- "/torrent/qbittorrent/watch:/watch"