From 9d6f036eade494b346997f5275c444b27988ddf4 Mon Sep 17 00:00:00 2001 From: sujiba Date: Sun, 7 Jul 2024 21:01:50 +0200 Subject: [PATCH] first commit :rocket: --- backup.sh | 24 ++++++++++++++++++++++++ check-ssl.sh | 24 ++++++++++++++++++++++++ container-update.sh | 38 ++++++++++++++++++++++++++++++++++++++ copy.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 backup.sh create mode 100644 check-ssl.sh create mode 100644 container-update.sh create mode 100644 copy.sh diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..4fbcd2d --- /dev/null +++ b/backup.sh @@ -0,0 +1,24 @@ +#!/bin/bash +HOSTNAME=$(hostname -s) +IP= +SOURCE=/opt/backup/ +DEST=/volume2/backup +NTFY_TOKEN= +NTFY_CHANNEL=https://ntfy.exmaple.tld/backups + +if ping -c 1 $IP &> /dev/null +then + echo "> success" + # Delete old rsync.log + rm /var/log/rsync.log + # Mount synology nfs share + /usr/bin/mount $IP:$DEST/$HOSTNAME /mnt/backup/ + # Backup files with rsync + rsync --log-file=/var/log/rsync.log --delete --stats -rlhPt $SOURCE /mnt/backup \ + && curl -H "Authorization: Bearer $NTFY_TOKEN" -H prio:low -d "docker-01: backup to nas succeeded" $NTFY_CHANNEL \ + || curl -H "Authorization: Bearer $NTFY_TOKEN" -H tags:warning -H prio:high -d "docker-01: backup to nas failed" $NTFY_CHANNEL + # Unmount nfs share + /usr/bin/umount /mnt/backup/ +else + echo "> error" +fi \ No newline at end of file diff --git a/check-ssl.sh b/check-ssl.sh new file mode 100644 index 0000000..16c4b9c --- /dev/null +++ b/check-ssl.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Test SSL/TLS + +GREEN=$(tput setaf 2) +CYAN=$(tput setaf 6) +RESET=$(tput sgr0) + +echo -e "${CYAN}" +echo " > testssl.sh is a free command line tool" +echo " > which checks a server's service on any port" +echo " > for the support of TLS/SSL ciphers," +echo " > protocols as well as some cryptographic flaws." + +echo "" +echo " > Find more @ https://github.com/drwetter/testssl.sh" + +echo -e "$GREEN" +echo " > Bitte gib die komplette URL (z.B. https://test.example.com) an." +read -p " > Welche Webseite soll getestet werden? " WEBSITE +echo -e "${RESET}" + +docker pull drwetter/testssl.sh + +docker run --rm -ti drwetter/testssl.sh $WEBSITE diff --git a/container-update.sh b/container-update.sh new file mode 100644 index 0000000..78afc20 --- /dev/null +++ b/container-update.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e + +for compose_file in /opt/docker/**/docker-compose.yml; do + if [[ $(docker compose -f "$compose_file" ps -q) ]]; then + echo "> Updating $compose_file" + docker compose -f "$compose_file" pull + docker compose -f "$compose_file" up -d --remove-orphans + echo "" + else + echo "> Skipping $compose_file as it's not running." + echo "" + fi +done + +echo "> Containers have been updated." +echo "" + +confirm=n +read -p " +> Do you want to prune docker? [y/N] +> WARNING! This will remove: +> - all stopped containers +> - all networks not used by at least one container +> - all dangling images +> - unused build cache +" confirm +echo "" + +if [[ $confirm == [yY] ]]; then + docker system prune -f -a + echo "> Docker has been pruned." +else + echo "> Nothing has been changed." +fi + +exit diff --git a/copy.sh b/copy.sh new file mode 100644 index 0000000..611fc57 --- /dev/null +++ b/copy.sh @@ -0,0 +1,42 @@ +#!/bin/bash +IP= +SOURCE=/opt/docker/ +DEST=/volume2/video/uploads + +if ping -c 1 $IP &> /dev/null +then + echo "> success" + + # Delete old rsync.log + rm /var/log/rsync.log + + # Mount synology nfs share + echo "> mounting nfs share" + /usr/bin/mount $IP:$DEST /mnt/uploads/ + + # Copy files with rsync + echo "> syncing files" + rsync --log-file=/var/log/rsync.log --stats -rlhPt $SOURCE/ /mnt/uploads + + # Unmount nfs share + echo "> unmounting nfs share" + /usr/bin/umount /mnt/uploads/ + + # if rsync is successful, remove all files + if [ "$?" -eq "0" ] + then + rm -rf rm $SOURCE/* + echo "> synced files have been removed from source" + else + echo "> error" + echo "> see /var/log/rsync.log" + echo "> exit" + exit + fi + +else + echo "> error" + echo "> cannot reach server" + echo "> exit" + exit +fi \ No newline at end of file