diff --git a/.gitignore b/.gitignore index 473656d..30ef9c9 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ office365.conf +godaddy_keys diff --git a/dbbackup.sh b/dbbackup.sh index 90f609e..07eb1ca 100755 --- a/dbbackup.sh +++ b/dbbackup.sh @@ -24,7 +24,7 @@ SMTP="mail.comprofix.com" SUBJECT="$(hostname -f) Database Backup Completed $BAKDATE" BAKDATE=$(date +%Y%m%d) DBUSER='dbbackup' -DBPASS='EWFfP3GZsqr427Yj' +DBPASS='MdCg8uTSEWhmv7+D' BACKUPDIR='/BACKUP/db/' rotate_backups() { @@ -44,8 +44,8 @@ for db in $databases; do done -sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q +#sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q #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 diff --git a/gitlabbackup.sh b/gitlabbackup.sh index 1d69506..c314e21 100755 --- a/gitlabbackup.sh +++ b/gitlabbackup.sh @@ -1,8 +1,76 @@ #!/bin/bash +# Script Name: gitlabbackup +# Author: Matt McKinnon +# Date: 04 May 2018 +# Description: +# This script will backup your gitlab configuration files. +# Send an email report. +# Rotate backups for 7 days +# # Add the following lines to /etc/gitlab/gitlab.rb once added # run gitlab-ctl reconfigure for changes to take effect # # gitlab_rails['backup_path'] = '' # gitlab_rails['backup_keep_time'] = 604800 #7 days of backups to keep -gitlab-rake gitlab:backup:create +MAIL="support@comprofix.com" +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" +SUBJECT="$(hostname -f) Gitlab Backup Completed $BAKDATE" +BAKDATE=$(date +%Y%m%d) +BACKUPDIR='/BACKUP' +VHOSTS='/var/www/vhosts/' +LOGFOLDER=/var/log/ +LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log` + + +rotate_backups() { + find $BACKUPDIR -type f -mtime +7 -exec rm -frv {} \; >> $LOGFILE + +} + +startlogging() { + echo $DASHES2 >> $LOGFILE + echo "$0 started running at $(date)" >> $LOGFILE + echo $DASHES >> $LOGFILE +} + +stoplogging() { + echo $DASHES >> $LOGFILE + echo "$0 finished running at $(date)" >> $LOGFILE + echo $DASHES2 >> $LOGFILE +} + +DASHES="---------------------------------------------------------------------------------" +DASHES2="=================================================================================" + +if [ ! -d "$BACKUPDIR" ]; then + # Control will enter here if $DIRECTORY doesn't exist. + mkdir $BACKUPDIR +fi + +startlogging + +# Rotate backup files +echo "$(date) [MESSAGE] Removing old backups" >> $LOGFILE +rotate_backups + +echo "$(date) [MESSAGE] Backing up gitlab for $(hostname -f)" >> $LOGFILE +gitlab-rake gitlab:backup:create >> $LOGFILE + +#Backup files to offsite location + +echo "$(date) [MESSAGE] Copying backup files to offsite location" >> $LOGFILE +scp -rq -P 2222 $BACKUPDIR/* moe@home.comprofix.com:/data/backup/website + +echo "$(date) [MESSAGE] Sending email of backup report" >> $LOGFILE + +stoplogging + +#sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q + +#Use below if using POSTFIX +cat $LOGFILE | mail -s "$SUBJECT" "$MAIL" + diff --git a/godaddy-ddns.sh b/godaddy-ddns.sh new file mode 100755 index 0000000..3dc9e4e --- /dev/null +++ b/godaddy-ddns.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection. +# Special thanks to mfox for his ps script +# https://github.com/markafox/GoDaddy_Powershell_DDNS +# +# First go to GoDaddy developer site to create a developer account and get your key and secret +# +# https://developer.godaddy.com/getstarted +# Be aware that there are 2 types of key and secret - one for the test server and one for the production server +# Get a key and secret for the production server +# +# +#Create a godaddy_keys file with the lines +# +# KEY +# SECRET +# +# +#Update the first 4 variables with your information + + +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +SMTP="mail.comprofix.com" + +domain="comprofix.com" # your domain +name="home" # name of A record to update +key=$(cat /opt/scripts/godaddy_keys | grep KEY | awk '{ print $2 }') # key for godaddy developer API +secret=$(cat /opt/scripts//godaddy_keys | grep SECRET | awk '{ print $2 }') # secret for godaddy developer API + +headers="Authorization: sso-key $key:$secret" + +# echo $headers + +result=$(curl -s -X GET -H "$headers" "https://api.godaddy.com/v1/domains/$domain/records/A/$name") + +# echo $result + +dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") + +# DEBUG: Remove hash from below line +# echo "dnsIp:" $dnsIp + +# Get public ip address there are several websites that can do this. +ret=$(curl -s GET "http://ipinfo.io/json") +currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") + +# DEBUG: Remove hash from below line +# echo "currentIp:" $currentIp + + if [ $dnsIp != $currentIp ]; + then + # echo "Ips are not equal" + request='{"data":"'$currentIp'","ttl":600}' + # echo $request + nresult=$(curl -i -s -X PUT \ + -H "$headers" \ + -H "Content-Type: application/json" \ + -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name") + # echo $nresult + + sendemail -o tls=no -s $SMTP -t $MAILTO -f "$name.$domain <$MAILFROM>" -u "$name.$domain IP has been updated" -m " + + $name.$domain IP has been updated + + $name.$domain IP is now: $currentIp + + + " -q + +fi diff --git a/plesk-backup.sh b/plesk-backup.sh new file mode 100755 index 0000000..a42a269 --- /dev/null +++ b/plesk-backup.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# Script Name:plesk-backup +# Author: Matt McKinnon +# Date: 04 May 2018 +# Description: +# This script will backup your plesk hosting files. +# Send an email report of plesk hosting files that have been backed up. +# Rotate backups for 7 days +# + +MAIL="support@comprofix.com" +MAILTO="support@comprofix.com" +MAILFROM="support@comprofix.com" +THISSERVER=$(hostname -f) +SMTP="mail.comprofix.com" +SUBJECT="$(hostname -f) Hosting Files Backup Completed $BAKDATE" +BAKDATE=$(date +%Y%m%d) +BACKUPDIR='/BACKUP' +VHOSTS='/var/www/vhosts/' +LOGFOLDER=/var/log/ +LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log` + + +rotate_backups() { + find $BACKUPDIR -type f -mtime +1 -exec rm -fr {} \; + +} + +startlogging() { + echo $DASHES2 >> $LOGFILE + echo "$0 started running at $(date)" >> $LOGFILE + echo $DASHES >> $LOGFILE +} + +stoplogging() { + echo $DASHES >> $LOGFILE + echo "$0 finished running at $(date)" >> $LOGFILE >> $LOGFILE + echo $DASHES2 >> $LOGFILE +} + +DASHES="---------------------------------------------------------------------------------" +DASHES2="=================================================================================" + +startlogging +rotate_backups + + +#Backup website files + +# Get domain ID +IDS=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select id from psa.domains, psa.hosting where id = dom_id order by id;') + +#Use ID to get domain name and www_root folders and create archive using domain name. +for ID in $IDS; do + DOMAIN_NAME=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select name from psa.domains,psa.hosting where id = '$ID' AND dom_id ='$ID' order by id;') + WWW_ROOT=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select www_root from psa.domains,psa.hosting where id = '$ID' AND dom_id ='$ID' order by id;') + + echo "$(date) [MESSAGE] Creating archive of $DOMAIN_NAME" >> $LOGFILE + if [ $DOMAIN_NAME = 'cloud.comprofix.com' ]; then + zip -rq $BACKUPDIR/$DOMAIN_NAME.$BAKDATE.zip $WWW_ROOT -x '*data*' + else + zip -rq $BACKUPDIR/$DOMAIN_NAME.$BAKDATE.zip $WWW_ROOT + fi + +done + +#Backup databases + +databases=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e "SHOW DATABASES;" | tr -d "| " | grep -v Database) + +for db in $databases; do + if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "apsc" ]] && [[ "$db" != "horde" ]] && [[ "$db" != phpmyadmin_* ]] && [[ "$db" != "psa" ]] && [[ "$db" != "roundcubemail" ]] ; then + echo "$(date) [MESSAGE] Dumping $db to sql file" >> $LOGFILE + mysqldump --force --opt --user=$DBUSER --password=$DBPASS --databases $db > $BACKUPDIR/$db.$BAKDATE.sql + fi +done + +#Backup files to offsite location + +echo "$(date) [MESSAGE] Copying backup files to offsite location" >> $LOGFILE +#scp -rq -P 2222 $BACKUPDIR/* moe@home.comprofix.com:/data/backup/website +rsync -avz -e "ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" /BACKUP/ moe@home.comprofix.com:/data/backup/websites/ >> $LOGFILE +echo "$(date) [MESSAGE] Sending email of backup report" >> $LOGFILE + +stoplogging + +#sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q + +#Use below if using POSTFIX +cat $LOGFILE | mail -s "$SUBJECT" "$MAIL" + + + diff --git a/ssl-install.sh b/ssl-install.sh new file mode 100755 index 0000000..5bd814f --- /dev/null +++ b/ssl-install.sh @@ -0,0 +1,34 @@ +#!/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 ~/.acme.sh ]; then + echo "Folder does not exist" + exit 0 +else + # echo "You are using acme.sh. Well done" +fi + + +scp -q ~/.acme.sh/$DOM_NAME/$DOM_NAME.cer root@$ESXI_SERVER:/etc/vmware/ssl/rui.crt +scp -q ~/.acme.sh/$DOM_NAME/$DOM_NAME.key root@$ESXI_SERVER:/etc/vmware/ssl/rui.key +ssh -qt root@$ESXI_SERVER "/sbin/services.sh restart" + + +