Matthew McKinnon
1d05bf7de2
Added script for archiving of docker data Updated ssl script to push to devices
52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/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
|