Updated dbbackup for internal MariaDB container

Added script for archiving of docker data
Updated ssl script to push to devices
This commit is contained in:
Matthew McKinnon 2022-10-22 12:01:49 +10:00
parent 1f4de1372a
commit 1d05bf7de2
4 changed files with 82 additions and 46 deletions

View File

@ -15,17 +15,16 @@
# GRANT LOCK TABLES, SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER ON *.* TO 'dbbackup'@'localhost'; # GRANT LOCK TABLES, SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER ON *.* TO 'dbbackup'@'localhost';
MAIL="support@comprofix.com"
MAILTO="support@comprofix.com" MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com" MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f) SQLSERVER="docker.comprofix.xyz"
SMTP="mail.comprofix.com" SMTP="comprofix-com.mail.protection.outlook.com"
SUBJECT="$(hostname -f) Database Backup Completed $BAKDATE"
BAKDATE=$(date +%Y%m%d) BAKDATE=$(date +%Y%m%d)
SUBJECT="$SQLSERVER Database Backup Completed - $BAKDATE"
DBUSER='dbbackup' DBUSER='dbbackup'
DBPASS='MdCg8uTSEWhmv7+D' DBPASS='MdCg8uTSEWhmv7+D'
BACKUPDIR='/BACKUP/db/' BACKUPDIR='/mnt/nfs/archive/db/'
rotate_backups() { rotate_backups() {
find $BACKUPDIR -type f -mtime +7 -exec rm -frv {} \; find $BACKUPDIR -type f -mtime +7 -exec rm -frv {} \;
@ -34,18 +33,18 @@ rotate_backups() {
rotate_backups rotate_backups
databases=$(mysql --user=$DBUSER --password=$DBPASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database) databases=$(mysql --user=$DBUSER --password=$DBPASS --host=$SQLSERVER -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
for db in $databases; do for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db" >> /tmp/dbbackup.msg echo "Dumping database: $db" >> /tmp/dbbackup.msg
mysqldump --force --opt --user=$DBUSER --password=$DBPASS --databases $db > $BACKUPDIR/$db.$BAKDATE.sql mysqldump --force --opt --user=$DBUSER --password=$DBPASS --host=$SQLSERVER --databases $db > $BACKUPDIR/$db.$BAKDATE.sql
fi fi
done done
#sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q sendemail -o tls=yes -s $SMTP -t $MAILTO -f "$SQLSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q
#Use Below to use systems postfix or local MTA #Use Below to use systems postfix or local MTA
cat /tmp/dbbackup.msg | mail -s "$SUBJECT" "$MAIL" #cat /tmp/dbbackup.msg | mail -s "$SUBJECT" "$MAIL"
rm -fr /tmp/dbbackup.msg rm -fr /tmp/dbbackup.msg

51
dockerdata Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
# Script Name: dbbackup
# Author: Matt McKinnon
# Date: 7th June 2016
# Description:
# This script will backup your mysql databases.
# Send an email report of databases that have been backed up.
# Rotate backups for 7 days
#
# NOTE:
# A user will need to be grated permissions on the databases
# Login to mysql with your root user.
#
# CREATE USER 'dbbackup'@'localhost' IDENTIFIED BY 'PASSWORD';
# GRANT LOCK TABLES, SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER ON *.* TO 'dbbackup'@'localhost';
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
SMTP="comprofix-com.mail.protection.outlook.com"
BAKDATE=$(date +%Y%m%d)
SUBJECT="Docker data backup completed - $BAKDATE"
BACKUPDIR='/mnt/nfs/archive/dockerdata/'
LOG="/tmp/dockerdata-backup.log"
MESSAGE="/tmp/message.log"
touch $LOG
touch $MESSAGE
rotate_backups() {
find $BACKUPDIR -type f -mtime +7 -exec rm -frv {} \;
}
rotate_backups
folders=$(find /mnt/nfs/docker/ -maxdepth 1 -mindepth 1 -type d)
for folder in $folders; do
echo "Archiving $folder" >> $MESSAGE
tar -Pzcvf $BACKUPDIR/${folder##*/}-$BAKDATE.tar.gz $folder &>> $LOG
done
sendemail -o tls=yes -s $SMTP -t $MAILTO -f "$SQLSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat $MESSAGE)" -a $LOG -q
#Use Below to use systems postfix or local MTA
#cat /tmp/backup.msg | mail -s "$SUBJECT" "$MAIL"
rm $MESSAGE
rm $LOG

23
ssl-copy Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# Script Name: ssl-install
# Author: Matt McKinnon
# Date: 28th May 2018
# Description:
#
# Script used to copy Let's Encrypt Generated Certificates from generating server to remote host .
DOCKER_HOST="docker.comprofix.xyz"
PROXMOX="pve1.comprofix.xyz"
TRUENAS="truenas.comprofix.xyz"
scp /mnt/nfs/docker/npm/letsencrypt/live/npm-21/fullchain.pem root@$PROXMOX:/etc/pve/nodes/pve1/pveproxy-ssl.pem
scp /mnt/nfs/docker/npm/letsencrypt/live/npm-21/privkey.pem root@$PROXMOX:/etc/pve/nodes/pve1/pveproxy-ssl.key
ssh -t root@$PROXMOX "systemctl restart pveproxy"
scp /mnt/nfs/docker/npm/letsencrypt/live/npm-21/fullchain.pem root@$TRUENAS:/etc/certificates/truenas_default.crt
scp /mnt/nfs/docker/npm/letsencrypt/live/npm-21/privkey.pem root@$TRUENAS:/etc/certificates/truenas_default.key
ssh -t root@$TRUENAS "systemctl restart nginx"
#ssh -t root@$ESXI_SERVER "/etc/init.d/vpxa restart"

View File

@ -1,37 +0,0 @@
#!/bin/bash
# Script Name: ssl-install
# Author: Matt McKinnon
# Date: 28th May 2018
# Description:
#
# Script used to copy Let's Encrypt Generated Certificates from generating server to ESXi VPS Server.
# This script requires acme.sh be used to setup your Let's Encrypt Certificates.
# - https://github.com/Neilpang/acme.sh
#
# SSH Key Login also needs to be enabled on ESXi
#
#
#
#
DOM_NAME="home.comprofix.com"
ESXI_SERVER="esxi.home.comprofix.com"
if [ ! -d $HOME/.acme.sh ]; then
echo "Folder does not exist"
exit 0
else
echo "You are using acme.sh. Well done"
fi
scp ~/.acme.sh/$DOM_NAME/$DOM_NAME.cer root@$ESXI_SERVER:/etc/vmware/ssl/rui.crt
scp ~/.acme.sh/$DOM_NAME/$DOM_NAME.key root@$ESXI_SERVER:/etc/vmware/ssl/rui.key
#ssh -qt root@$ESXI_SERVER "/sbin/services.sh restart"
ssh -t root@$ESXI_SERVER "/etc/init.d/hostd restart"
ssh -t root@$ESXI_SERVER "/etc/init.d/vpxa restart"