Updated README.md

Rename files and removed .sh
This commit is contained in:
Matthew McKinnon 2018-07-05 11:58:24 +10:00
parent 75935219c9
commit 844837b339
12 changed files with 37 additions and 123 deletions

View File

@ -4,101 +4,91 @@ Scripts for different tasks
These scripts perform multiple of different tasks that help monitor the server and send emails after performing functions.
To send emails the sendEmail package is required
<pre><code>apt-get install sendemail</code></pre>
<pre>
apt-get install sendemail
</pre>
Change the following lines in scripts that send emails
MAILFROM is set to determine the server name and domain name for the server and generate and email for it to determine where the email is coming from. This can be changed to specify an email address or you can leave it to generate one.
<pre><code>
MAILTO=user@example.com
<pre>MAILTO=user@example.com
SMTP=mail.example.com
MAILFROM=$(hostaname)@$(dnsdomainname)
</code></pre>
</pre>
#### 00logwatch
This script sends a report based on the log files and settings.
<b>Installation</b>
<pre><code>
apt-get install logwatch
<pre>apt-get install logwatch
ln -s $(pwd)/00logwatch /etc/cron.daily
</code></pre>
</pre>
#### check_updates_deb_sh
#### check_updates_deb
This script checks for updates on your Debian based systems. If any updates are found it will download them ready for Installation and an email will be sent to an email address specified
<b>Installation</b>
<pre><code>
ln -s $(pwd)/check_updates_deb_sh /etc/cron.daily
</code></pre>
<pre>ln -s $(pwd)/check_updates_deb /etc/cron.daily
</pre>
#### dbbackup.sh
#### check_updates_rpm
This script checks for updates on your RPM based systems. If any updates are found it will download them ready for Installation and an email will be sent to an email address specified
<b>Installation</b>
<pre>ln -s $(pwd)/check_updates_rpm /etc/cron.daily
</pre>
#### dbbackup
This scripts backs up mysql databases and rotates the number of backups through seven days.
Specify the user and password that has access to the databases.
<pre><code>
DBUSER='dbbackup'
<pre>DBUSER='dbbackup'
DBPASS='EWFfP3GZsqr427Yj'
BACKUPDIR='/BACKUP/db/'
</code></pre>
</pre>
#### diskalert.sh
<b>Installation</b>
<pre>ln -s $(pwd)/dbbackup /etc/cron.daily
</pre>
#### diskalert
Sends and email when disk space reaches greater than 90%.
<b>Installation</b>
<pre><code>
ln -s ${pwd}/diskalert.sh /etc/cron.hourly
</code></pre>
#### gitlabbackup.sh
If you run your own gitlab server.
Add the following lines to /etc/gitlab/gitlab.rb once added run gitlab-ctl reconfigure for changes to take effect
<pre><code>
gitlab_rails['backup_path'] = 'BACKUP FOLDER'
gitlab_rails['backup_keep_time'] = 604800 #7 days of backups to keep
</code></pre>
Change the BACKUP FOLDER to a location where you want the backups to be saved.
<b>Installation</b>
<pre><code>
ln -s ${PWD}/gitlabbackup.sh /etc/cron.daily
</code></pre>
<pre>ln -s ${pwd}/diskalert.sh /etc/cron.hourly
</pre>
#### nasbackup.sh
This script does an rsync from one folder location to another
<b>Installation</b>
<pre><code>
ln -s ${PWD}/nasbackup.sh /etc/cron.daily
</code></pre>
<pre>
ln -s ${PWD}/nasbackup /etc/cron.daily
</pre>
#### mailQWatch.sh
#### mailQWatch
Script checks mailq size on a postfix system and sends an email when queue size is greater than threshold.
Update variables in scripts to suit your needs.
<pre><code>
QUEUELIMIT=75
<pre>QUEUELIMIT=75
SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
MAILTO="user@example.com"
</code></pre>
</pre>
<b>Installation</b>
As root, sudo will not work.
<pre><code>
echo "*/5 * * * * ${PWD}/mailQWatch.sh" >> /etc/crontab
</code></pre>
<pre>echo "*/5 * * * * ${PWD}/mailQWatch.sh" >> /etc/crontab
</pre>

View File

@ -1,76 +0,0 @@
#!/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'] = '<BACKUP FOLDER>'
# gitlab_rails['backup_keep_time'] = 604800 #7 days of backups to keep
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"